天天看點

Oracle Databasae wallet使用指南

Oracle從10gR2開始就提供了wallet,用于解決使用者認證資訊(使用者名和密碼)的存放問題,通過使用wallet可以實作無密碼登入資料庫,

這樣一來就不需要在應用程式中嵌入資料庫密碼(或者在配置檔案中明文存放密碼),同時更加友善維護大量伺服器的環境的資料庫密碼維護工作,

因為可以直接分發wallet檔案,實作批量修改密碼。

另外,如果我們在pl/sql中使用utl_http包通路需要使用者名和密碼的url時,也可以不用将使用者名和密碼嵌入代碼中,而直接讓其通路wallet中的認證資訊,類似于

web容器中使用jndi的方式通路資料源

下面我們以windows 7 + oracle client 11.2.0.1.0環境為例,講解具體使用方法。

注:使用oracle wallet隻需安裝oracle database client即可。

一、建立wallet

1、建立wallet

文法:mkstore -wrl <wallet_location> -create

D:\app\Oracle>mkstore -wrl . -create                   ---- wrl參數後跟wallet的存放路徑,點表目前目錄

Oracle Secret Store Tool: 版本 11.2.0.1.0 - Production

版權所有 (c) 2004, 2009, Oracle 和/或其子公司。保留所有權利。

輸入密碼:                         ----------輸入自定義的wallet密碼,該密碼是打開wallet的時候需要提供的密碼,與資料庫密碼無關

再次輸入密碼:                  ----------确認自定義的wallet密碼 

D:\app\Oracle>dir .

 驅動器 D 中的卷沒有标簽。

 卷的序列号是 BA8C-3377

 D:\app\Oracle 的目錄

2015/11/17  21:55    <DIR>          .

2015/11/17  21:55    <DIR>          ..

2015/11/17  21:55             3,589 cwallet.sso    ---對應的wallet檔案

2015/11/17  21:55             3,512 ewallet.p12   ---對應的wallet檔案

2013/11/18  11:45    <DIR>          Middleware

               2 個檔案          7,101 位元組

               3 個目錄 14,528,782,336 可用位元組

更多指令資訊請輸入mkstore -help檢視幫助

2、添加資料庫連接配接認證資訊到wallet中

文法:mkstore -wrl <wallet_location> -createCredential <db_connect_string> <username> <password>

D:\app\Oracle>mkstore -wrl . -createCredential 192.168.56.101_scott scott tiger    ---192.168.56.101_scott為tnsnames.ora中的tns名稱,scott為使用者名,tiger為密碼

Oracle Secret Store Tool: 版本 11.2.0.1.0 - Production

版權所有 (c) 2004, 2009, Oracle 和/或其子公司。保留所有權利。

輸入 Wallet 密碼:                  --輸入第1步中建立wallet時提供的wallet密碼

Create credential oracle.security.client.connect_string1

注意:這樣一個tns名隻能對應一個資料庫使用者,是以我們在名稱上加了_scott字尾用于區分;如果使用者名或者密碼中有特殊字元,請用單引号引起來

如:mkstore -wrl /home/mseibt/pstore -createCredential 192.168.56.101_scott 'scott' tiger

3、修改sqlnet.ora

加入如下參數:

WALLET_LOCATION =

   (SOURCE =

      (METHOD = FILE)

      (METHOD_DATA = (DIRECTORY = D:\app\Oracle))    #第一步中建立wallet時的位址

)

SQLNET.WALLET_OVERRIDE = TRUE

4、測試無密碼登入資料庫

D:\app\Oracle>sqlplus /@192.168.56.101_scott

SQL*Plus: Release 11.2.0.1.0 Production on 星期二 11月 17 22:25:21 2015

Copyright (c) 1982, 2010, Oracle.  All rights reserved.

連接配接到:

Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production

With the Partitioning, OLAP, Data Mining and Real Application Testing options

SQL> show user;

USER 為 "SCOTT"

測試通過。

注:現在使用pl/sql developer也可以不用輸入使用者名和密碼登入了。

二、維護wallet

1、檢視wallet中的認證資訊

D:\app\Oracle>mkstore -wrl . -listCredential
Oracle Secret Store Tool: 版本 11.2.0.1.0 - Production
版權所有 (c) 2004, 2009, Oracle 和/或其子公司。保留所有權利。

輸入 Wallet 密碼:

List credential (index: connect_string username)
1: 192.168.56.101_scott scott
           

2、修改wallet中的認證資訊

D:\app\Oracle>mkstore -wrl . -modifyCredential 192.168.56.101_scott scott newpassword
Oracle Secret Store Tool: 版本 11.2.0.1.0 - Production
版權所有 (c) 2004, 2009, Oracle 和/或其子公司。保留所有權利。

輸入 Wallet 密碼:

Modify credential
Modify 1
           

注意:隻能修改使用者名和密碼,而不能修改db_connect_string,因為這裡是把db_connect_string當作key

3、删除wallet中的認證資訊

D:\app\Oracle>mkstore -wrl . -deleteCredential 192.168.56.101_scott
Oracle Secret Store Tool: 版本 11.2.0.1.0 - Production
版權所有 (c) 2004, 2009, Oracle 和/或其子公司。保留所有權利。

輸入 Wallet 密碼:

Delete credential
Delete 1
           

4、檢視wallet中的條目

D:\app\Oracle>mkstore -wrl . -list
Oracle Secret Store Tool: 版本 11.2.0.1.0 - Production
版權所有 (c) 2004, 2009, Oracle 和/或其子公司。保留所有權利。

輸入 Wallet 密碼:

Oracle 密鑰存儲條目:
oracle.security.client.connect_string1
oracle.security.client.password1
oracle.security.client.username1
           

注意:因為我們目前隻添加了一個連接配接資訊,是以條目名都是xxxx1

5、檢視wallet中條目的值

D:\app\Oracle>mkstore -wrl . -viewEntry oracle.security.client.connect_string1
Oracle Secret Store Tool: 版本 11.2.0.1.0 - Production
版權所有 (c) 2004, 2009, Oracle 和/或其子公司。保留所有權利。

輸入 Wallet 密碼:

oracle.security.client.connect_string1 = 192.168.56.101_scott
           

6、修改wallet中條目的值

D:\app\Oracle>mkstore -wrl . -modifyEntry oracle.security.client.connect_string1 192.168.56.101_hr
Oracle Secret Store Tool: 版本 11.2.0.1.0 - Production
版權所有 (c) 2004, 2009, Oracle 和/或其子公司。保留所有權利。

輸入 Wallet 密碼:
           

注意:前面第2步中無法修改連接配接串的名稱,使用本步中的方法就可以修改連接配接串的名稱

三、wallet分發和備份

對于wallect的分發和備份就很簡單了,直接從作業系統上拷貝wallect的兩個檔案即可。

同時問題又來了,如何防止本機的wallect檔案被拷貝到其它機器上呢?

從11.2版本開始,wallect新增加了一個auto_login_local 參數,通過使用這個參數,就能解決這個問題。指令如下:

D:\app\Oracle1>orapki wallet create -wallet . -pwd "welcome1" -auto_login_local
Oracle PKI Tool: 版本 11.2.0.1.0 - Production
版權所有 (c) 2004, 2009, Oracle 和/或其子公司。保留所有權利。
           

注意:此時是使用的orakpi指令,而非mkstore指令。wallect建立好之後,維護操作就和上面的相同了。

在linux中,如果在使用的過程中抱ORA-12578: TNS:wallet open failed的錯誤,請檢查/etc/hosts檔案

確定按照如下格式配置

<IP> <HOSTNAME> [ <ALIAS> ]

且IP不能是叢集環境的虛拟IP

全文完。