Reader small image

You're reading from  Oracle Database 12c Security Cookbook

Product typeBook
Published inJun 2016
PublisherPackt
ISBN-139781782172123
Edition1st Edition
Right arrow
Authors (2):
Zoran Pavlovic
Zoran Pavlovic
author image
Zoran Pavlovic

Zoran Pavlovic is currently working as an Oracle Technical Architect in his company. He works with Oracle technologies (primary Oracle Database) since 2005. Areas of his expertise are Security and Performance Tuning of Oracle Database. Zoran has worked on various complex database environments including RAC, ASM, Data Guard, etc. He has worked as a consultant for Oracle Consulting as well as instructor for Oracle University across EMEA region. Zoran is first member of Oracle ACE Program in Serbia, and a featured speaker/author at many conferences/magazines.
Read more about Zoran Pavlovic

Maja Veselica
Maja Veselica
author image
Maja Veselica

Maja Veselica, MSc in software engineering, is currently working for Parallel d.o.o., Belgrade, as an Oracle Database consultant (security, performance tuning, and so on). She has been working as an instructor for Oracle University since 2010. In the last couple of years, she has also been working for Oracle Consulting. Also, Maja is a member of Oracle ACE Program and has more than 20 Oracle certificates. She enjoys (beta) testing Oracle products and participating in other Oracle-related activities.
Read more about Maja Veselica

View More author details
Right arrow

Chapter 8. Transparent Data Encryption

In this chapter, we will cover the following tasks:

  • Configuring a keystore location in sqlnet.ora

  • Creating and opening the keystore

  • Setting a master encryption key in a software keystore

  • Column encryption - adding a new encrypted column to a table

  • Column encryption - creating a new table that has encrypted column(s)

  • Using salt and MAC

  • Column encryption - encrypting the existing column

  • Autologin keystore

  • Encrypting tablespace

  • Rekeying

  • Backup and recovery

Introduction


Encryption is a very important security mechanism used to enforce confidentiality of data. There are two types of encryption that can be used in the Oracle Database. The first type is application-based encryption, which is implemented using the DBMS_CRYPTO PL/SQL package (this type is not covered in this book), and the second type is Transparent Data Encryption (TDE). TDE is a part of Advanced Security option of Oracle Database Enterprise Edition. It can be used to encrypt data in rest (table columns and tablespaces inside the database) and in transit (network, Recovery Manager (RMAN) backups, and Data Pump Exports).

The word transparent in Transparent Data Encryption means that application is not aware that data is encrypted in any way. In other words, application will never see the encrypted data-if user is not authorized to see the data, error (for example, insufficient privileges, table, or view does not exist) will be shown. The only way that a user will see encrypted data...

Configuring keystore location in sqlnet.ora


In this recipe, you're going to configure the location of a software keystore in a regular file system. If you want to use Hardware Security Module (HSM), see the official Oracle documentation (Chapter 3 in Oracle Advanced Security Guide, part named Configuring Hardware Keystore).

How to do it...

  1. Create a directory, to hold a keystore, that is accessible to the owner of Oracle software (for example, $ORACLE_BASE/admin/ora12cR1/wallet). See Figure 1:

    Figure 1 - Create a directory and edit sqlnet.ora

  2. Edit sqlnet.ora and add entry to specify the location of the keystore (see Figure 1 and 2). This step is optional if you are using default location for the wallet, which is $ORACLE_HOME/admin/<db_name>/wallet.

    Figure 2 - Define ENCRYPTION_WALLET_LOCATION parameter

Creating and opening the keystore


In this recipe, you're going to create a password-based keystore. Open it and learn to check its status.

Getting ready

It is assumed that the keystore location is already configured (instructions are given in the recipe Configuring keystore location in sqlnet.ora). In this recipe, you'll grant, as the SYS user, administer key management privilege, or SYSKM administrative privilege to an existing user (for example, maja).

How to do it...

  1. Connect to the database as a user who can grant administer key management privilege (for example, SYS) and grant the privilege to an existing user (for example, maja).

  2. To create a password-based software keystore, connect to the database as the user in the previous step (for example, maja) and execute the following statement (after you change parameters so that they are appropriate for your environment) (an example is shown in Figure 3):

    SQL> ADMINISTER KEY MANAGEMENT CREATE KEYSTORE 'keystore_location' 
           IDENTIFIED...

Setting master encryption key in software keystore


In this recipe, you're going to create the first master key for the password-based software keystore you created and opened in the previous recipe.

Getting ready

It is assumed that software keystore is already opened. To complete this recipe, you'll need an existing user who has the SYSKM administrative or administer key management privilege (for example, maja).

How to do it...

  1. Connect to the database as a user who has the SYSKM administrative or administer key management privilege (for example, maja):

    $ sqlplus maja
    
  2. Create a master key for the password-based keystore (Figure 7 shows the creation of master key for the keystore you created in the recipe Creating and opening the keystore):

    SQL> ADMINISTER KEY MANAGEMENT SET KEY IDENTIFIED BY
           keystore_password
    	   WITH BACKUP
    	   USING 'desc_purpose';
    

    Figure 7

There's more...

The WITH BACKUP clause in step 2 instructs Oracle Database to create a backup of a keystore before the creation...

Column encryption - adding new encrypted column to table


In this recipe, you'll add a new column, which will be encrypted using a nondefault encryption algorithm, to an existing table.

Getting ready

It is assumed that a keystore is opened and a master key is created.

How to do it...

  1. Connect to the database as a user who has administer key privilege or SYSKM privilege (for example, maja) and verify that the keystore is in the OPEN status. You should get the result similar to the one depicted in Figure 9:

    $ sqlplus maja
    

    Figure 9

  2. Add a column (for example, bonus) to a table (for example, hr.employees), encrypted using the AES 256 algorithm.

    Figure 10 - Adding the new encrypted column to the table

Column encryption - creating new table that has encrypted column(s)


In this recipe, you're going to learn to use TDE column encryption to encrypt columns in a newly created table.

Getting ready

It is assumed that a keystore is opened and a master key is created.

How to do it...

  1. Connect to the database as a user who has administer key privilege or SYSKM privilege (for example, maja):

    $ sqlplus maja
    
  2. Create a new table (for example, table enc_cols in schema hr) that has, for example, the following structure:

    Column name

    Column type

    Encrypted

    NAME

    VARCHAR2 (50)

    No

    CREDIT_LIMIT

    NUMBER (10)

    Yes, AES192

    SALARY

    NUMBER (10)

    Yes, AES192

    Figure 11 - A syntax to create the table hr.enc_cols

  3. Connect to the database as a user who can insert and view data in the table (for example, hr user):

    SQL> connect hr
    
  4. Insert several arbitrary values into the table HR.ENC_COLS.

    Figure 12 - Test values

  5. Verify that the user can view unencrypted values in all columns.

    Figure 13- Encryption is transparent

  6. Connect...

Using salt and MAC


In this recipe, you'll understand when you should use salt and MAC.

Getting ready

It is assumed that a keystore is opened and a master key is created.

How to do it...

  1. Connect to the database as a user who has administer key privilege or SYSKM privilege (for example, maja):

    $ connect maja
    
  2. Encrypt two columns in an existing table (for example, sh.customers)

    Figure 15 - Using salt and MAC

How it works...

In step 2:

  • You encrypted the last_name column using the AES256 algorithm with salt and used MAC

  • You encrypted the cust_street_address column using the AES256 algorithm with no salt and used MAC

In general, you have to use same encryption algorithm for all encrypted columns at the same time. You can choose a SALT option on the encrypted column level in a table, but you have to choose either the MAC or NOMAC option on a table level (meaning that all encryption columns in a table must use the same option).

There's more...

To understand why salt is important, let's consider a basic scenario...

Column encryption - encrypting existing column


It is common case that organizations first create database and later decide that they want to implement encryption. In this recipe, you're going to encrypt an existing column using TDE column encryption.

Getting ready

It is assumed that a keystore is opened and a master key is created.

How to do it...

  1. Connect to the database as a user who can read data from the OE.CUSTOMERS table (for example, the oe user):

    $ sqlplus oe
    
  2. Select data from column you want to encrypt (for example, cust_email), just to verify that the user can view it.

    Figure 18 - A test query

  3. Connect to the database as a user who has administer key privilege or SYSKM privilege (for example, maja):

    SQL> connect maja
    
  4. Encrypt the cust_email column in the oe.customers table using the default encryption algorithm (AES192) and no salt.

    Figure 19 - Encrypting an existing column, which has an index

  5. Execute steps 1 and 2 again to verify that there is no change in the way user/application views...

Auto-login keystore


Autologin keystore is a type of keystore that doesn't need to be manually opened. The local autologin keystore can be opened only from computer where it has been created. Autologin keystores have system-generated passwords. They are less secure than password-based keystores. They are created from password-based software keystores.

Getting ready

It is assumed that password-based software keystore is created.

How to do it...

  1. Connect to the database as a user who has administer key privilege or SYSKM privilege (for example, maja):

    $ sqlplus maja
    
  2. Create (local) an autologin keystore. In our case, keystore_location is /u01/app/oracle/admin/ora12cR1/wallet and keystore_password is welcome1:

    SQL> ADMINISTER KEY MANAGEMENT CREATE LOCAL AUTO_LOGIN KEYSTORE FROM 
    KEYSTORE 'keystore_location' IDENTIFIED BY keystore_password;
    OR
    SQL> ADMINISTER KEY MANAGEMENT CREATE AUTO_LOGIN KEYSTORE FROM 
    KEYSTORE 'keystore_location' IDENTIFIED BY keystore_password;
    

How it works.....

Encrypting tablespace


It is not possible to encrypt an existing tablespace using TDE tablespace encryption. In this recipe, you'll create a new encrypted tablespace.

Getting ready

It is assumed that a keystore is opened and a master key is created.

How to do it...

  1. Connect to the database as a user who has a create tablespace privilege (for example, zoran):

    $ sqlplus zoran
    
  2. Create encrypted tablespace (for example, TEST_ENC) using AES192 encryption algorithm:

    SQL> CREATE TABLESPACE TEST_ENC
    DATAFILE '/u01/app/oracle/oradata/ORA12CR1/datafile/testenc01.dbf'
    SIZE 20M
    ENCRYPTION USING 'AES192'
    DEFAULT STORAGE (ENCRYPT);
    

    Figure 22 - Encrypting tablespace

How it works...

In step 2, you create an encrypted tablespace TEST_ENC. To find information about encrypted tablespaces, you can query the V$ENCRYPTED_TABLESPACES view.

Figure 23 - Finding information about encrypted tablespace

There's more...

You can import existing tables into encrypted tablespace using Oracle Data Pump. Another option is to use SQL...

Rekeying


You can change (rekey) a master key and table keys. You cannot rekey tablespace keys.

Getting ready

It is assumed that a keystore is opened and a master key is created.

How to do it...

  1. Connect to the database as a user who has administer key privilege or SYSKM privilege (for example, maja):

    $ sqlplus maja
    
  2. To rekey a table (for example, the oe.customer) using a different encryption algorithm (for example, AES128), execute the following statement:

    Figure 24 - Rekeying a table key

  3. Change a master key by executing the following statement (in our example, keystore_password is welcome1):

    SQL> ADMINISTER KEY MANAGEMENT SET KEY IDENTIFIED BY
    keystore_password
    WITH BACKUP;
    

    Figure 25 - Rekeying a master key

How it works...

When you changed a table key, in step 2, all encrypted data in the oe.customers table were decrypted and then encrypted using the new table key and the new encryption algorithm. If you just want to change key and use the same algorithm as before, syntax for rekeying is...

Backup and Recovery


RMAN supports three encryption modes:

  • Transparent mode

  • Password mode

  • Dual mode

In this recipe, you're going to learn to create encrypted backups using RMAN.

How to do it...

  1. Connect to the RMAN as user who has the sysbackup privilege:

    $ rman target '"zoran@orcl as sysbackup"'
    
  2. Configure encryption on a database level:

    RMAN> CONFIGURE ENCRYPTION FOR DATABASE ON;
    
  3. Backup a tablespace example in transparent mode:

    RMAN> BACKUP TABLESPACE EXAMPLE tag 'tran_mode';
    
  4. Enable dual mode encryption and backup tablespace example in dual mode:

    RMAN> SET ENCRYPTION ON IDENTIFIED BY "password_1";RMAN> BACKUP TABLESPACE EXAMPLE tag 'dual_mode';
    
  5. Enable password mode and backup tablespace example in password mode:

    RMAN> SET ENCRYPTION ON IDENTIFIED BY "password_2" ONLY;
    RMAN> BACKUP TABLESPACE EXAMPLE tag 'pass_mode';
    

There's more...

If a backup is created in transparent mode, it can be restored only by using a key that is used to create the backup (stored in the external keystore...

lock icon
The rest of the chapter is locked
You have been reading a chapter from
Oracle Database 12c Security Cookbook
Published in: Jun 2016Publisher: PacktISBN-13: 9781782172123
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
undefined
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime

Authors (2)

author image
Zoran Pavlovic

Zoran Pavlovic is currently working as an Oracle Technical Architect in his company. He works with Oracle technologies (primary Oracle Database) since 2005. Areas of his expertise are Security and Performance Tuning of Oracle Database. Zoran has worked on various complex database environments including RAC, ASM, Data Guard, etc. He has worked as a consultant for Oracle Consulting as well as instructor for Oracle University across EMEA region. Zoran is first member of Oracle ACE Program in Serbia, and a featured speaker/author at many conferences/magazines.
Read more about Zoran Pavlovic

author image
Maja Veselica

Maja Veselica, MSc in software engineering, is currently working for Parallel d.o.o., Belgrade, as an Oracle Database consultant (security, performance tuning, and so on). She has been working as an instructor for Oracle University since 2010. In the last couple of years, she has also been working for Oracle Consulting. Also, Maja is a member of Oracle ACE Program and has more than 20 Oracle certificates. She enjoys (beta) testing Oracle products and participating in other Oracle-related activities.
Read more about Maja Veselica