天天看點

配置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。

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協定已經配置完,如果監聽已經啟動,可以重新開機監聽了,在指令行下輸入:

如果沒有報錯,證明配制正确。以下是重新開機監聽資訊:

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

啟動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)))

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 =

    (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(主題名)。

6.3.        用戶端配置Wallet位置

打開Net Manager工具,選擇右邊Oracle Net配置,本地,概要檔案,在右邊最上面下拉框選擇Oracle 進階安全性,單擊SSL标簽。

Wallet目錄:輸入用戶端Wallet存放位置。

為以下目标配置SSL選擇客戶機。

這樣,以上一個簡單的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.

•        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.

•        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.

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.

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

•        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.

•        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

上一篇: ^_^小麥苗^_^
下一篇: DTD 教程