Transparent Data Encryption – Creación de wallets

Cuando se desea cifrar la información dentro de una base de datos Oracle, se recomienda usar el producto Transparent Data Encryption (TDE) que forma parte de Advanced Security Option (ASO). Esta opción de la BBDD, como su nombre indica, permite cifrar los datos de manera “trasparente” para las aplicaciones, esto es, que las aplicaciones sigan accediendo a los datos normalmente (como lo hacían antes del cifrado): no es necesario modificarlas ni adaptarlas, pero a nivel de sistema operativo/backups los datos quedan almacenados en forma cifrada, evitando que si alguien tienen acceso a ellos pueda extraer la información. ASO es una opción disponible en Oracle Database Enterprise Edition.

Arquitectura TDE

TDE es capaz de utilizar diferentes algoritmos al cifrar la información y todos ellos hacen uso de una clave de cifrado maestra (Master Encryption Key). Esta clave se guarda en un almacén externo de claves (keystore) que puede ser hardware o software. En sqlnet.ora se indica dónde está el almacén de claves y de qué tipo es. Es altamente recomendable hacer backup del almacén de claves al mismo tiempo que se hace backup de la base de datos.

A continuación vamos a hablar de las opciones existentes para crear un almacén de claves software en nuestro entorno, consistentes en hacer uso de wallets de Oracle. Existen 3 tipos de wallets (Password-based, Auto-login y Local auto-login) y se deberá escoger dependiendo de las necesidades de cada entorno. El siguiente paso sería cifrar la información de nuestra base de datos, pero eso ya cae fuera del alcance de este post.

Nota: Todos los ejemplos se han realizado en una base de datos 11gR2 Enterprise Edition.

1) Password-based
Los wallets basados en password o password-based necesitan de su apertura explícita con una contraseña antes de poder ser usados. Si no se hace así, al intentar acceder a los datos cifrados la base de datos da el error ‘ORA-28365: wallet is not open’.

Hay que diferenciar entre la contraseña para abrir el wallet y la Master Encryption Key. La primera es la que nos permite acceder al contenido del wallet y hacerlo disponible a la base de datos. La segunda es la que se utiliza para cifrar los datos de la base de datos. Pueden ser iguales, aunque se recomienda que ambas sean contraseñas complejas y diferentes.

Para crear un wallet de este tipo se puede hacer de dos formas. La primera ejecutando desde sqlplus:

1
ALTER SYSTEM SET ENCRYPTION KEY IDENTIFIED BY "password";

Lo que esta sentencia hace realmente es asignar la Master Encryption Key al wallet. Dado que no tenemos un wallet definido en nuestro entorno, lo crea con la Master Encryption Key especificada en una ruta por defecto (ORACLE_BASE/admin/DB_UNIQUE_NAME/wallet o también ORACLE_HOME/admin/DB_UNIQUE_NAME/wallet) que no es necesario registrar en el fichero sqlnet.ora. El password para abrir el wallet y la Master Encryption Key serán idénticos.

Si cuando se crea el wallet de esta manera da el error ‘ORA-28368: cannot auto-create wallet’, suele ser porque no existen los directorios y es necesario crearlos manualmente. Una vez creado, se puede consultar información del wallet en la vista V$ENCRYPTION_WALLET:

1
2
3
4
5
SQL> select * from V$ENCRYPTION_WALLET;
WRL_TYPE             WRL_PARAMETER                                                STATUS
-------------------- ------------------------------------------------------------ ------------------
file                 /u01/app/oracle/product/11.2.0/dbhome_2/admin/orcl/wallet    OPEN

Si se renicia la base de datos se puede abrir el wallet ejecutando:

1
2
3
SQL> ALTER SYSTEM SET ENCRYPTION WALLET OPEN IDENTIFIED BY "welcome1";
System altered.

A pesar de lo anterior, para tener más control sobre nuestro entorno, poder diferenciar entre la contraseña para abrir el wallet y la Master Encryption Key y seguir las buenas prácticas definidas, es recomendable crear los wallets con la herramienta orapki en una ruta fuera del ORACLE_BASE y definir explícitamente en el sqlnet.ora donde se encuentran. Lo que nos lleva a la segunda forma de crear un wallet basado en password. La sintaxis es la siguiente:

orapki wallet create -wallet ruta_al_wallet [-pwd password]

Aunque el password se puede incluir en el comando, es recomendable no hacerlo porque en algunos entornos puede quedarse en el historial. En este caso, durante el proceso de creación se solicita su introducción en el momento. Ejemplo de creación:

1
2
3
4
5
6
7
[oracle@localhost ~]$ orapki wallet create -wallet /etc/oracle/wallets
Oracle PKI Tool : Version 11.2.0.4.0 - Production
Copyright (c) 2004, 2013, Oracle and/or its affiliates. All rights reserved.
Enter password:          
Enter password again:

Tras introducir la información de este nuevo wallet en el sqlnet.ora, y reiniciar, vemos que la base de datos lo ha reconocido y está pendiente de abrir:

1
2
3
4
5
SQL> select * from V$ENCRYPTION_WALLET;
WRL_TYPE             WRL_PARAMETER             STATUS
-------------------- ------------------------- ------------------
file                 /etc/oracle/wallets       CLOSED

Lo abrimos y se observa que no tiene Master Encryption Key (lógico, pues solamente hemos creado el wallet):

1
2
3
4
5
6
7
8
9
SQL> ALTER SYSTEM SET ENCRYPTION WALLET OPEN IDENTIFIED BY "welcome1";
System altered.
SQL> select * from V$ENCRYPTION_WALLET;
WRL_TYPE             WRL_PARAMETER             STATUS
-------------------- ------------------------- ------------------
file                 /etc/oracle/wallets       OPEN_NO_MASTER_KEY

También se puede comprobar desde sistema operativo que no tiene Master Encryption Key:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
[oracle@localhost ~]$ orapki wallet display -wallet /etc/oracle/wallets
Oracle PKI Tool : Version 11.2.0.4.0 - Production
Copyright (c) 2004, 2013, Oracle and/or its affiliates. All rights reserved.
Enter wallet password:          
Requested Certificates:
User Certificates:
Trusted Certificates:
Subject:        OU=Class 1 Public Primary Certification Authority,O=VeriSign\, Inc.,C=US
Subject:        OU=Class 3 Public Primary Certification Authority,O=VeriSign\, Inc.,C=US
Subject:        OU=Class 2 Public Primary Certification Authority,O=VeriSign\, Inc.,C=US
Subject:        OU=Secure Server Certification Authority,O=RSA Data Security\, Inc.,C=US
Subject:        CN=GTE CyberTrust Global Root,OU=GTE CyberTrust Solutions\, Inc.,O=GTE Corporation,C=US

Solamente quedaría crear la Master Encryption Key. Es recomendable que sea diferente a la clave para abrir el wallet, pero por faciliar el ejemplo hemos configurado las mismas:

1
2
3
4
5
6
7
8
9
SQL> ALTER SYSTEM SET ENCRYPTION KEY IDENTIFIED BY "welcome1";
System altered.
SQL> select * from V$ENCRYPTION_WALLET;
WRL_TYPE             WRL_PARAMETER             STATUS
-------------------- ------------------------- ------------------
file                 /etc/oracle/wallets       OPEN

Comprobamos también desde sistema operativo que, efectivamente, ya tiene la Master Encryption Key:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
[oracle@localhost ~]$ orapki wallet display -wallet /etc/oracle/wallets
Oracle PKI Tool : Version 11.2.0.4.0 - Production
Copyright (c) 2004, 2013, Oracle and/or its affiliates. All rights reserved.
Enter wallet password:          
Requested Certificates:
User Certificates:
Oracle Secret Store entries:
ORACLE.SECURITY.DB.ENCRYPTION.AZj+WhNiOE8fv//Tf+uuUPYAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
ORACLE.SECURITY.DB.ENCRYPTION.MASTERKEY
Trusted Certificates:
Subject:        OU=Class 1 Public Primary Certification Authority,O=VeriSign\, Inc.,C=US
Subject:        OU=Class 3 Public Primary Certification Authority,O=VeriSign\, Inc.,C=US
Subject:        OU=Class 2 Public Primary Certification Authority,O=VeriSign\, Inc.,C=US
Subject:        OU=Secure Server Certification Authority,O=RSA Data Security\, Inc.,C=US
Subject:        CN=GTE CyberTrust Global Root,OU=GTE CyberTrust Solutions\, Inc.,O=GTE Corporation,C=US

2) Auto-login
El segundo tipo de wallets es el auto-login. Un wallet auto-login se puede abrir, borrar o modificar sin utilizar password, y la única seguridad existente es la proporcionada por el host físico o el sistema de ficheros. La sintaxis para crear un wallet de este tipo es:

orapki wallet create -wallet ruta_al_wallet -auto_login_only

Ejemplo de creación:

1
2
3
[oracle@localhost ~]$ orapki wallet create -wallet /etc/oracle/wallets -auto_login_only
Oracle PKI Tool : Version 11.2.0.4.0 - Production
Copyright (c) 2004, 2013, Oracle and/or its affiliates. All rights reserved.

Reiniciamos la base de datos y, como era de esperar, el wallet se abre automáticamente y tampoco tiene Master Encryption Key:

1
2
3
4
5
SQL> select * from V$ENCRYPTION_WALLET;
WRL_TYPE             WRL_PARAMETER             STATUS
-------------------- ------------------------- ------------------
file                 /etc/oracle/wallets       OPEN_NO_MASTER_KEY

Dado que la seguridad de este tipo de wallets es mínima, es posible crearlos con un password. De esta manera se facilita la operatividad con la base de datos al abrirse de manera automática, pero se añade seguridad al necesitar de una contraseña para modificar o borrar el wallet. La sintaxis es:

orapki wallet create -wallet ruta_al_wallet -auto_login [-pwd password]

Ejemplo de creación:

1
2
3
4
5
6
7
[oracle@localhost ~]$ orapki wallet create -wallet /etc/oracle/wallets -auto_login
Oracle PKI Tool : Version 11.2.0.4.0 - Production
Copyright (c) 2004, 2013, Oracle and/or its affiliates. All rights reserved.
Enter password:          
Enter password again:

Reiniciamos y vemos que está abierto:

1
2
3
4
5
SQL> select * from V$ENCRYPTION_WALLET;
WRL_TYPE             WRL_PARAMETER             STATUS
-------------------- ------------------------- ------------------
file                 /etc/oracle/wallets       OPEN_NO_MASTER_KEY

Añadimos la clave maestra de cifrado:

1
2
3
4
5
6
7
8
9
SQL> ALTER SYSTEM SET ENCRYPTION KEY IDENTIFIED BY "welcome1";
System altered.
SQL> select * from V$ENCRYPTION_WALLET;
WRL_TYPE             WRL_PARAMETER             STATUS
-------------------- ------------------------- ------------------
file                 /etc/oracle/wallets       OPEN

3) Local auto-login
El tercer y último tipo de wallet son los llamados local auto-login. Mantienen la agilidad de trabajo al no tener que abrirlos explícitamente, tienen la seguridad de una contraseña para realizar modificaciones y, además, si se copian a otra máquina dejan de funcionar. De manera habitual éste suele ser el tipo de wallet recomendado. La sintaxis de creación es:

orapki wallet create -wallet ruta_al_wallet -auto_login_local [-pwd password]

Ejemplo:

1
2
3
4
5
6
7
[oracle@localhost ~]$ orapki wallet create -wallet /etc/oracle/wallets -auto_login_local
Oracle PKI Tool : Version 11.2.0.4.0 - Production
Copyright (c) 2004, 2013, Oracle and/or its affiliates. All rights reserved.
Enter password:          
Enter password again:

Una vez creado, la operatoria es idéntica al tipo de wallet Auto-login:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
SQL> select * from V$ENCRYPTION_WALLET;
WRL_TYPE             WRL_PARAMETER             STATUS
-------------------- ------------------------- ------------------
file                 /etc/oracle/wallets       OPEN_NO_MASTER_KEY
SQL> ALTER SYSTEM SET ENCRYPTION KEY IDENTIFIED BY "welcome1";
System altered.
SQL> select * from V$ENCRYPTION_WALLET;
WRL_TYPE             WRL_PARAMETER             STATUS
-------------------- ------------------------- ------------------
file                 /etc/oracle/wallets       OPEN
[oracle@localhost ~]$  orapki wallet display -wallet /etc/oracle/wallets
Oracle PKI Tool : Version 11.2.0.4.0 - Production
Copyright (c) 2004, 2013, Oracle and/or its affiliates. All rights reserved.
Requested Certificates:
User Certificates:
Oracle Secret Store entries:
ORACLE.SECURITY.DB.ENCRYPTION.AUYWTrbxbE8cv561lbCo1qUAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
ORACLE.SECURITY.DB.ENCRYPTION.MASTERKEY
Trusted Certificates:
Subject:        OU=Class 1 Public Primary Certification Authority,O=VeriSign\, Inc.,C=US
Subject:        OU=Class 3 Public Primary Certification Authority,O=VeriSign\, Inc.,C=US
Subject:        OU=Class 2 Public Primary Certification Authority,O=VeriSign\, Inc.,C=US
Subject:        OU=Secure Server Certification Authority,O=RSA Data Security\, Inc.,C=US
Subject:        CN=GTE CyberTrust Global Root,OU=GTE CyberTrust Solutions\, Inc.,O=GTE Corporation,C=US
Twitter
LinkedIn
Evolución, innovación y transformación
37 Service Expertise avalados por Oracle 
Our value proposition
100% Oracle posts
Follow our day-to-day activities