配置oracle的ssl连接

网上也没有中文资料,我硬着头皮看官方文档肯完,终于配置成功,下面是我配置步骤

配置安全套接层连接oracle

目录
1.        配置简介        1
2.        使用Wallet Manager创建Wallet和生成认证请求        2
2.1.        创建Wallet        2
2.2.        创建认证请求        2
2.3.        导出证书请求        3
2.4.        保存Wallet位置        3
2.5.        让Wallet自动登录        3
3.        使用openssl工具制作数字证书        4
3.1.        创建制作证书目录        4
3.2.        制作发行证书        4
3.3.        制作用户证书        4
4.        导入信认根证书和用户证书        5
4.1.        导入信认根证书        5
4.2.        导入用户证书        5
5.        配置使用SSL的TCP/IP连接服务端        5
5.1.        确认服务器已经生成Wallet        5
5.2.        指定监听服务Wallet存放位置        5
5.3.        创建监听使用ssl的TCP/IP协议        7
5.4.        配制数据库监听位置        8
6.        配置使用SSL的TCP/IP连接客户端        10
6.1.        确认客户端已经生成Wallet        10
6.2.        配置的Oracle网络服务名称        10
6.3.        客户端配置Wallet位置        12
7.        连接数据库        13
8.        疑难解答        13
9.        Wallet管理方案        16
10.        参考文献        17


1.        配置简介
这里采用安全套接层连接oracle指的是使用ssl的tcp/ip协议连接oracle数据库,由于ssl的tcps/ip协议是采用公钥和私钥进行数据加密,为了解决通信双方的可信问题,使用了数字证书,而orcle是采用“Wallet Manager”来管理证书和公钥和私钥。
配置ssl的tcp/ip协议连接oracle数据库,大体步骤分为以下6步:
        使用Wallet Manager创建Wallet和生成认证请求;
        使用openssl工具制作数字证书;
        导入信认根证书和用户证书;
        配置使用SSL的TCP/IP连接服务端;
        配置使用SSL的TCP/IP连接客户端;
        连接数据库。
注意!以下例子使用的数据库版本为ORACLE 10g 10.2.0.4,如果是其他版本,会有所差异。
2.        使用Wallet Manager创建Wallet和生成认证请求
Wallet Manager 有以下几点功能:
        产生公私密钥对,并生成证书请求;
        存储用户证书相匹配的私钥;
        配置可信任证书
详细配置步骤如下:
2.1.        创建Wallet
首先启动Wallet Manager工具:
•        (Windows) 选择 开始, 程序, Oracle-HOME_NAME, 集成管理工具, Wallet Manager
•        (UNIX) 在命令行, 输入 owm。
打开Wallet Manager工具后,选择Wallet,新建。在弹出对话框输入密码,此密码是oracle的Wallet密码,密必是字母和数字结合,而且大于8位字符,Wallet选择标准,点确定。
2.2.        创建认证请求
在上面操作点确定以后,提示“是否希望现在创建一个认证请求?”点是。
也可以在选择 操作,添加认证请求,在弹出输入信息,信息内容如下表格:
字段名称 
描述 

公用名称 
必填项。 输入的用户的名称或服务的身份。 输入用户的姓名。

组织单元 
可选项。 输入部门的名称。 例如:财务。 

组织 
可选项。输入组织的名称身。 例如:某公司 

地区/城市         可选项。 输入居住城市。 

省/市/自治区         可选项。 输入姓名的州或省的身份在其中居住。 
输入完整的国家的名字,因为有些证书当局不接受两个字母的缩写。 

国家 
必填项。 选择国家 ,以查看清单,国家缩写。 选择在哪个国家组织的所在地。中国为CN
密钥长度
必填项。 选择密钥长度,建议选择1024以上长度。

DN
可选项。 选择高级 ,以查看高级证书申请对话。 使用该字段编辑或自定义身份的辨别名称( DN ) 。 例如,您可以编辑充分国家名称和地点。 
以上表格必填项填好后,点确定生成认证表求。接下来的工作是导出证书请求了。
2.3.        导出证书请求
选择左边树的Wallet下的证书[请求],在选择操作,导出认证请求。输入要保存文件名[c:\ssl\ request.txt],点保证后导出。
        导出认证请求后,接下来就需要使用第3节使用openssl工具来制作数字证书了。
2.4.        保存Wallet位置
Wallet创建以后,需要保存Wallet信息,oracle建议保存系统默认位置。系统默认的Wallet文件存放如下Unix和Windows平台: 
•        (UNIX) etc/ORACLE/WALLETS/username
•        (Windows) %USERPROFILE%\ORACLE\WALLETS
选择Wallet,系统默认位置,或保存,输入保存路径,点确认。
注!
        如果Wallet不存放在默认位置,oracle一些程序无法使用。
2.5.        让Wallet自动登录
如果不选择Wallet自动登录,在连接数据库的时候会报ORA-28759: 无法打开文件。
选择Wallet,自动登录,把自动登录勾打上。
3.        使用openssl工具制作数字证书
OpenSSL是一个开放源代码的实现了SSL及相关加密技术的软件包,由加拿大的Eric Yang等发起编写的。OpenSSL的官方网站为http://www.openssl.org/,源代码可以从ftp://ftp.openssl.org/source/上下载,也可以从OpenSSL的镜像网站下载。
        注!在redhat linux下,默认安装有安装好的openssl,而http://www.openssl.org/都是原代码,而且需要懂的C语方的编译才能编译成功,此处从网上收集了for Windows openssl已经编译好的二进制代码。
  
我们这里使用openssl用来生成根证书和信任的用户证书。由于网上收集这两个包压开来需要经过配置,而我的机器又装有MKS Toolkit for Developers Web-extracting tool带有openssl,以下例子使用openssl是MKS Toolkit for Developers Web-extracting tool工具上带的,如果是使用redhat linux,也可以在redhat linux下制作。
3.1.        创建制作证书目录
mkdir c:\ssl
cd ssl
mkdir ca
3.2.        制作发行证书
由于证书需要一个发行机构,我们就用openssl制作一个发行证书。然后在把这个发行证书导入到可信任根证下面,这样这个发行的证书就全部生效了。首先来制作一个发行证书的请求。
openssl req -new -newkey rsa:1024 -nodes -out c:/ssl/ca/ca.csr –keyout c:/ssl/ca/ca.key
输入发行机构的信息后,根据生成的证书请生成证书。
openssl x509  -signkey c:/ssl/ca/ca.key -req -in c:/ssl/ca/ca.csr -out c:/ssl/ca/ca.crt -CAcreateserial -days 365

3.3.        制作用户证书
以上已经制作好发行的信任证书了,现在就根据上面发行的信任证书来制作用户证书。这里用户证书的请求就是第2节的导出证书请求的文件,此例中文件名为:c:\ssl\ request.txt,输入如下命令:
openssl x509 -req -in c:\ssl\request.txt -out user.crt -CA c:/ssl/ca/ca.crt -CAkey c:/ssl/ca/ca.key -CAcreateserial -days 365
以上命令生成用户证书名为user.crt,现在把c:/ssl/ca/ca.crt和user.crt文件都发给申请请求用户者。
4.        导入信认根证书和用户证书
通过第三节已经制作好用户证书了,但此用户证书制作机构不是“VeriSign Class 3 Public Primary CA”等在名顶顶的认证机构,我们首先需要把制作用户发行机构的证书导入到可信根证书,也就是第3节的c:/ssl/ca/ca.crt文件。
4.1.        导入信认根证书
打开oracle的Wallet Manager工具,选择操作,导入信任证书,选择包含证书的文件,点确定,选择c:\ssl\ca\ca.crt文件。在左边的树中出现导入信任证书。
4.2.        导入用户证书
在以上导入了信任证书后,就可以导入用户证书了。选择操作,导入用户证书,选择包含证书的文件,点确定,选择c:\ssl\user.crt文件。在左边的树中出现证书[就绪]。
至此,证书的制作和导入都已经完成。然后按快捷键Ctl+W来保存,同时检查Wallter菜单下自动登录旁边框打上小钩。接下来就配制服务端监听ssl的配置了。
5.        配置使用SSL的TCP/IP连接服务端
在配置服务器端的ssl的TCP/IP连接需要以下几步骤:
        确认服务器已经生成Wallter
        指定监听服务Wallter存放位置
        创建监听使用ssl的TCP/IP协议
配置好以后,需要重新启动监听服务,在命令行下输入
lsnrctl stop
lsnrctl start
5.1.        确认服务器已经生成Wallet
确认第2节中的Wallet是否创建,确认用户证书是否就绪,同时检查Wallet是否自动登录。
5.2.        指定监听服务Wallet存放位置
首先启动Net Manager工具:
•        (Windows) 选择 开始, 程序, Oracle-HOME_NAME, 配置和移植工具, Net Manager
•        (UNIX) 在命令行, 输入 netmgr
打开Net Manager工具后,选择右边Oracle Net配置,本地,概要文件,在右边最上面下拉框选择Oracle 高级安全性,单击SSL标签。
配置方法:选择文件系统。
Wallet目录:输入Wallet存放位置。
为以下目标配置SSL选择服务器。

输入以上信息后,点文件菜单下的保存网络配置。
在sqlnet.ora和listener.ora文件更新如下:
WALLET_LOCATION =
  (SOURCE =
    (METHOD = FILE)
    (METHOD_DATA =
      (DIRECTORY = d:\oracle\WALLETS)
    )
  )
5.3.        创建监听使用ssl的TCP/IP协议
在Net Manager工具左边树中选择Oracle Net配置,本地,监听程序,LISTENER(如果不存在监听程序,程序编辑菜单下的创建来创建一个监听),在右边最上面下拉框选择监听位置,在下面点添加地址。
协议:使用SSL的TCP/IP;
主机:输入机器名或要监听的本机IP地址;
端口:输入监听的端口号,Oracle 推荐使用的2484作为SSL的TCP/IP协议监听端口。

输入以上信息后,点文件菜单下的保存网络配置。
在listener.ora文件更新如下:
LISTENER =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCPS)(HOST = zhoujunhe)(PORT = 2484))
  )
在sqlnet.ora文件更新如下:
SQLNET.AUTHENTICATION_SERVICES= (BEQ, TCPS, NTS)
注意,TCPS必需存在,如果这行不存在或这行值没有TCPS,可以手工加sqlnet.ora这个文件内容。
5.4.        配制数据库监听位置
由于我们配制监听的时候使用了2484这个端口,而这个端口不是oracle默认动态PMON进程向监听注册端口,所以我们需要配置静态监听数据库服务。
在Net Manager工具左边树中选择Oracle Net配置,本地,监听程序,LISTENER(如果不存在监听程序,程序编辑菜单下的创建来创建一个监听),在右边最上面下拉框选择数据库服务。如果要监听的数据服务已经配置,接下来就不需要配置了。点下面按钮的添加数据库。
全局数据库名:输入创建数据时候的全局名。
Oracle主目录:输入Oracle的Home目录,如:D:\oracle\product\10.2.0\db_1
SID:输入数据库实例的sid。

输入以上信息后,点文件菜单下的保存网络配置。
在listener.ora文件更新如下:
SID_LIST_LISTENER =
  (SID_LIST =
    (SID_DESC =
      (GLOBAL_DBNAME = ora10g.unimassystem.com)
      (ORACLE_HOME = D:\oracle\product\10.2.0\db_1)
      (SID_NAME = ora10g)
    )
  )

至此,服务端的SSL的TCP/IP协议已经配置完,如果监听已经启动,可以重启监听了,在命令行下输入:
lsnrctl stop
lsnrctl start
如果没有报错,证明配制正确。以下是重启监听信息:
C:\>lsnrctl stop

LSNRCTL for 32-bit Windows: Version 10.2.0.4.0 - Production on 28-7月 -2009 15:37:43

Copyright (c) 1991, 2007, Oracle.  All rights reserved.

正在连接到 (DESCRIPTION=(ADDRESS=(PROTOCOL=TCPS)(HOST=zhoujunhe)(PORT=2484)))
命令执行成功

C:\>lsnrctl start

LSNRCTL for 32-bit Windows: Version 10.2.0.4.0 - Production on 28-7月 -2009 15:37:46

Copyright (c) 1991, 2007, Oracle.  All rights reserved.

启动tnslsnr: 请稍候...

TNSLSNR for 32-bit Windows: Version 10.2.0.4.0 - Production
系统参数文件为D:\oracle\product\10.2.0\db_1\network\admin\listener.ora
写入D:\oracle\product\10.2.0\db_1\network\log\listener.log的日志信息
监听: (DESCRIPTION=(ADDRESS=(PROTOCOL=tcps)(HOST=zhoujunhe.unimassystem.com)(PORT=2484)))

正在连接到 (DESCRIPTION=(ADDRESS=(PROTOCOL=TCPS)(HOST=zhoujunhe)(PORT=2484)))
LISTENER 的 STATUS
------------------------
别名                      LISTENER
版本                      TNSLSNR for 32-bit Windows: Version 10.2.0.4.0 - Production
启动日期                  28-7月 -2009 15:37:48
正常运行时间              0 天 0 小时 0 分 2 秒
跟踪级别                  off
安全性                    ON: Local OS Authentication
SNMP                      OFF
监听程序参数文件          D:\oracle\product\10.2.0\db_1\network\admin\listener.ora
监听程序日志文件          D:\oracle\product\10.2.0\db_1\network\log\listener.log
监听端点概要...
  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcps)(HOST=zhoujunhe.unimassystem.com)(PORT=2484)))
服务摘要..
服务 "ora10g.unimassystem.com" 包含 1 个例程。
  例程 "ora10g", 状态 UNKNOWN, 包含此服务的 1 个处理程序...
命令执行成功
如果启动过程有错误,证明配置有错误,查看后面疑难解答。
6.        配置使用SSL的TCP/IP连接客户端
在上面一节讲的是服务器端的配置,如果使用是本机连接,这节只需要配置第2小节就可以跳转到第7节连接数据库
6.1.        确认客户端已经生成Wallet
如果客户机和服务端不在同一台机器,在一步前必需确认Wallet是否创建,而且确认自动登录,如果没有创建好,请返回前面三节来创建Wallet,并生成证书。
注!如果是本机连接,由于配置服务端的时候,Wallet和ssl都已经配置好了,只需要配置下面节的Oracle网络配置就可以连接数据库了。
6.2.        配置的Oracle网络服务名称
在Net Manager工具左边树中选择Oracle Net配置,本地,服务命名,选择要配制服务名(如果需要重新创建一个服务名,程序编辑菜单下的创建来创建一个服务名)。
服务名:输入和配置数据库监听相同服务名;
连接类型:选择数据库默认设置。
在地址配置先项
协议:选择使用SSL的TCP/IP;
主机名:输入服务器的机器名或IP地址;
端口号:输入服务配置使用SSL的TCP/IP协议端口号(oracle推荐使用2484),此处端口号和服务端端口一致。

输入以上信息后,点文件菜单下的保存网络配置。
在配置好以上信息后,须手动修改客户端的网络配置文件tnsnames.ora和sqlnet.ora。在不同系统位于不同位置
        (UNIX) $ORACLE_HOME /network/admin/ 
        (Windows) %ORACLE_BASE%\%ORACLE_HOME%\network\admin\
在添加如下粗体信息
SSL =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCPS)(HOST = zhoujunhe)(PORT = 2484))
    )
    (CONNECT_DATA =
      (SERVICE_NAME = ora10g.unimassystem.com)
    )
    (SECURITY=
          (SSL_SERVER_CERT_DN=" cn=finance,cn=OracleContext,c=us,o=acme")
        )
  )
注意!双引号里的内容必必是服务端用户证书的DN(主题名),此DN可以用Wallet Mangaget打开服务端的Wallet来查看用户证书的DN(主题名)。
在sqlnet.ora文件更新如下:
SQLNET.AUTHENTICATION_SERVICES= (BEQ, TCPS, NTS)
注意,TCPS必需存在,如果这行不存在或这行值没有TCPS,可以手工加sqlnet.ora这个文件内容。

6.3.        客户端配置Wallet位置
打开Net Manager工具,选择右边Oracle Net配置,本地,概要文件,在右边最上面下拉框选择Oracle 高级安全性,单击SSL标签。
配置方法:选择文件系统。
Wallet目录:输入客户端Wallet存放位置。
为以下目标配置SSL选择客户机。

输入以上信息后,点文件菜单下的保存网络配置。
在sqlnet.ora文件更新如下:
WALLET_LOCATION =
  (SOURCE =
    (METHOD = FILE)
    (METHOD_DATA =
      (DIRECTORY = d:\oracle\WALLETS)
    )
  )
这样,以上一个简单的ssl协议连接已经配置好,接下来测试连接数据了。

7.        连接数据库
sqlplus user/password@ssl
如果连接报有错误,查看后面疑难解答。
8.        疑难解答
The following section lists the most common errors you may receive while using the Oracle Advanced Security SSL adapter.
It may be necessary to enable Oracle Net tracing to determine the cause of an error. For information about setting tracing parameters to enable Oracle Net tracing, refer to Oracle Database Net Services Administrator's Guide.
ORA-28759: Failure to Open File 
Cause: The system could not open the specified file. Typically, this error occurs because the wallet cannot be found.
Action: Check the following: 
•        Ensure that the correct wallet location is specified in the sqlnet.ora file. This should be the same directory location where you saved the wallet.
•        Enable Oracle Net tracing to determine the name of the file that cannot be opened and the reason.
•        Ensure that auto login was enabled when you saved the wallet. Refer to "Using Auto Login"
ORA-28786: Decryption of Encrypted Private Key Failure 
Cause: An incorrect password was used to decrypt an encrypted private key. Frequently, this happens because an auto login wallet is not being used.
Action: Use Oracle Wallet Manager to turn the auto login feature on for the wallet. Then save the wallet again. Refer to, "Using Auto Login".
ORA-28858: SSL Protocol Error 
Cause: This is a generic error that can occur during SSL handshake negotiation between two processes.
Action: Enable Oracle Net tracing and attempt the connection again to produce trace output. Then contact Oracle customer support with the trace output.
ORA-28859 SSL Negotiation Failure 
Cause: An error occurred during the negotiation between two processes as part of the SSL protocol. This error can occur when two sides of the connection do not support a common cipher suite.
Action: Check the following: 
•        Use Oracle Net Manager to ensure that the SSL versions on both the client and the server match, or are compatible. For example, if the server accepts only SSL 3.0 and the client accepts only TLS 1.0, then the SSL connection will fail.
•        Use Oracle Net Manager to check what cipher suites are configured on the client and the server, and ensure that compatible cipher suites are set on both.
See Also:
"Step 4: Set the Client SSL Cipher Suites (Optional)" for details about setting compatible cipher suites on the client and the server
Note:
If you do not configure any cipher suites, then all available cipher suites are enabled.
ORA-28862: SSL Connection Failed 
Cause: This error occurred because the peer closed the connection.
Action: Check the following: 
•        Ensure that the correct wallet location is specified in the sqlnet.ora file so the system can find the wallet.
•        Use Oracle Net Manager to ensure that cipher suites are set correctly in the sqlnet.ora file. Sometimes this error occurs because the sqlnet.ora has been manually edited and the cipher suite names are misspelled. Ensure that case sensitive string matching is used with cipher suite names.
•        Use Oracle Net Manager to ensure that the SSL versions on both the client and the server match or are compatible. Sometimes this error occurs because the SSL version specified on the server and client do not match. For example, if the server accepts only SSL 3.0 and the client accepts only TLS 1.0, then the SSL connection will fail.
•        For more diagnostic information, enable Oracle Net tracing on the peer.
ORA-28865: SSL Connection Closed 
Cause: The SSL connection closed because of an error in the underlying transport layer, or because the peer process quit unexpectedly.
Action: Check the following: 
•        Use Oracle Net Manager to ensure that the SSL versions on both the client and the server match, or are compatible. Sometimes this error occurs because the SSL version specified on the server and client do not match. For example, if the server accepts only SSL 3.0 and the client accepts only TLS 1.0, then the SSL connection will fail.
•        If you are using a Diffie-Hellman anonymous cipher suite and the SSL_CLIENT_AUTHENTICATION parameter is set to true in the server's listener.ora file, then the client does not pass its certificate to the server. When the server does not receive the client's certificate, it (the server) cannot authenticate the client so the connection is closed. To resolve this use another cipher suite, or set this listener.ora parameter to false.
•        Enable Oracle Net tracing and check the trace output for network errors.
•        For details, refer to Actions listed for "ORA-28862: SSL Connection Failed"
ORA-28868: Peer Certificate Chain Check Failed 
Cause: When the peer presented the certificate chain, it was checked and that check failed. This failure can be caused by a number of problems, including: 
•        One of the certificates in the chain has expired.
•        A certificate authority for one of the certificates in the chain is not recognized as a trust point.
•        The signature in one of the certificates cannot be verified.
Action: Refer to, "Opening an Existing Wallet" to use Oracle Wallet Manager to open your wallet and check the following: 
•        Ensure that all of the certificates installed in your wallet are current (not expired).
•        Ensure that a certificate authority's certificate from your peer's certificate chain is added as a trusted certificate in your wallet. Refer to, "Importing a Trusted Certificate" to use Oracle Wallet Manager to import a trusted certificate.
ORA-28885: No certificate with the required key usage found. 
Cause: Your certificate was not created with the appropriate X.509 version 3 key usage extension.
Action: Use Oracle Wallet Manager to check the certificate's key usage. Refer to, Table 9-1, "KeyUsage Values".
ORA-29024: Certificate Validation Failure 
Cause: The certificate sent by the other side could not be validated. This may occur if the certificate has expired, has been revoked, or is invalid for any other reason.
Action: Check the following: 
•        Check the certificate to determine whether it is valid. If necessary, get a new certificate, inform the sender that her certificate has failed, or resend.
•        Check to ensure that the server's wallet has the appropriate trust points to validate the client's certificate. If it does not, then use Oracle Wallet Manager to import the appropriate trust point into the wallet. Refer to, "Importing a Trusted Certificate" for details.
•        Ensure that the certificate has not been revoked and that certificate revocation list (CRL) checking is turned on. For details, refer to "Configuring Certificate Validation with Certificate Revocation Lists"
ORA-29223: Cannot Create Certificate Chain 
Cause: A certificate chain cannot be created with the existing trust points for the certificate being installed. Typically, this error is returned when the peer does not give the complete chain and you do not have the appropriate trust points to complete it.
Action: Use Oracle Wallet Manager to install the trust points that are required to complete the chain. Refer to,"Importing a Trusted Certificate"

9.        Wallet管理方案
经过本人多次试验,客户端和服务端的用户证书,只要双方都信任,就可以建立使用ssl的TCP/IP协议连接。如果双信签发证书机构是同一机构,这样只要所有机器导入一个信任证书和各自的用户证书,这样就方便的进行数据库连接部署了。如果双方的用户证书签方证书是不同机构,如果这样客户端和服务器建立连接,需要把各自签发机构的信任证书都要导入到双方信任证书列表,这样管理就复杂化了。
如果此数据库只在一个组织内部运用,同时又考虑到传输安全,可以制作一个根证书,然后为所有客户端(包括服务端)制作一个用户证书,然后把信任证书导入到所有客户端(包括服务端)信任证书列表内,然后为每个用户导入用户证书。
如果连接数据库版本相同,也可以这样管理,在一台机器制作好Wallet,当然已经导入信任证书和用户证书,然后在Wallet存放位置下把ewallet.p12, cwallet.sso文件复制到其他机器上,这样就可以一个证书在多台机器上使用了。当然,这样证书不易安全管理。
由于时间有限,对证书验证和撤销还没有来得及研究,如果有时间会继续探索。如果有研究好同志,可以转发一份给我。
10.        参考文献
Oracle® Database Advanced Security Administrator's Guide 10g Release 2 (10.2) Part Number B14268-02 第2,8,9节。
http://download.oracle.com/docs/ ... .102/b14268/toc.htm
http://blogger.org.cn/blog/more.asp?name=OpenSSL&id=18971
http://www.openssl.org
  • 2
    点赞
  • 15
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值