| Oracle® Fusion Middleware Oracle Security Developer Toolsによるセキュアなアプリケーションの開発 11gリリース1 (11.1.1) B61386-04 |
|
![]() 前 |
![]() 次 |
XKMS (XML Key Management Specification)は、公開鍵の管理に関するW3C仕様です。これを使用すると、開発者はデジタル署名の処理に関するXMLトランザクションを記述できるため、公開鍵のインフラストラクチャを簡単に処理できるようになります。
この章に含まれる内容は次のとおりです。
Oracle XKMSは、複数の業務やアプリケーションにわたって鍵の検出とユーザー・アイデンティティの検証を行うためのツールキットからなるPure Javaソリューションです。これを使用すると、Webサービスに必要な安全かつ信頼できるメッセージングをサポートできるほか、PKIに関連するコストや複雑性をある程度軽減することができます。
PKI機能への容易なアクセス - W3C XKMS Standardを実装したOracle XKMSは、XMLの簡易性とPKIの堅牢性を兼ね備えています。このツールキットを利用すると、開発者は安全で軽量なクライアント・ソフトウェアをデプロイすることにより、堅牢なアプリケーション機能を簡単にデプロイできるようになります。
鍵/証明書のライフ・サイクルの完全サポート - Oracle XKMSでは、軽量のWebサービス・インフラストラクチャを使用して、エンタープライズ・アプリケーションによる署名と暗号鍵の検出、取得、検証を行うことができます。
XML署名を使用したXKMSメッセージのセキュリティ保護 - Oracle XMLツールキットを使用して、リクエストとレスポンスにデジタル署名を付けることができます。
ネイティブ・メソッドのない100% Java
JAXP 1.1準拠のXMLパーサーとの連携
Oracleセキュリティ開発ツールは、Oracle WebLogic ServerとともにORACLE_HOMEにインストールされます。この項では、Oracle XKMSの環境を設定する方法について説明します。次の項目について説明します。
Oracle XKMSを使用するには、システムに次のコンポーネントがインストールされている必要があります。
Java Development Kit (JDK)バージョン1.6以上
Oracle XML Securityツールキット
CLASSPATH環境変数には、必要なjarファイルおよびclassファイルのフルパスとファイル名を指定してください。次のファイルをCLASSPATHに指定します。
osdt_core.jar
osdt_cert.jar
osdt_xmlsec.jar
org.jaxen_1.1.1.jar。セキュリティ・ツール・ディストリビューションの$ORACLE_HOME/modules/ディレクトリにあります。Oracle XML Securityは、XPathの処理のためにJaxen XPathエンジンを利用します。
WindowsでCLASSPATHを設定する手順を次に示します。
Windowsの「コントロール パネル」で「システム」を選択します。
「システムのプロパティ」ダイアログで「詳細設定」タブを選択します。
「環境変数」をクリックします。
ユーザー環境変数のセクションで「新規」をクリックし、CLASSPATH環境変数をユーザー・プロファイルに追加します。CLASSPATH環境変数がすでに存在している場合は、選択して「編集」をクリックします。
必要なjarファイルおよびclassファイルすべてのフルパスとファイル名をCLASSPATHに追加します。
たとえば、CLASSPATHは次のようになります。
C:%ORACLE_HOME%\modules\oracle.osdt_11.1.1\osdt_core.jar; %ORACLE_HOME%\modules\oracle.osdt_11.1.1\osdt_cert.jar; %ORACLE_HOME%\modules\oracle.osdt_11.1.1\osdt_xmlsec.jar; %ORACLE_HOME%\modules\org.jaxen_1.1.1.jar;
「OK」をクリックします。
UNIXでは、必要なjarファイルおよびclassファイルすべてのフルパスとファイル名を含むようにCLASSPATH環境変数を設定します。次に例を示します。
setenv CLASSPATH $CLASSPATH: $ORACLE_HOME/modules/oracle.osdt_11.1.1/osdt_core.jar: $ORACLE_HOME/modules/oracle.osdt_11.1.1/osdt_cert.jar: $ORACLE_HOME/modules/oracle.osdt_11.1.1/osdt_xmlsec.jar %ORACLE_HOME%\modules\org.jaxen_1.1.1.jar;
この項では、Oracle XKMSの主要なクラスとインタフェースの使用について説明し、コード例を示します。コア・クラスを次に示します。
このクラスは、XKMSのLocateRequest要素を表します。
例12-1に、LocateRequestのインスタンスを作成する方法を示します。
例12-1 LocateRequestのインスタンスの作成
// Parse the XML document containing the dsig:Signature. Document sigDoc = //Instance of org.w3c.dom.Document; //Create Query Key Binding QueryKeyBinding queryKeyBinding = new QueryKeyBinding(sigDoc); queryKeyBinding.setTimeInstant(new Date()); // Create the xkms:LocateRequest. LocateRequest loc = new LocateRequest(sigDoc, queryKeyBinding);
LocateRequestタイプのクライアント・リクエストには、xkms:RespondWith属性を含める必要があります。
例12-2に、RespondWithをLocateRequestに追加する方法を示します。
このクラスは、xkms:LocateResult要素を表します。
例12-3に、LocateResultのインスタンスを作成する方法を示します。
例12-3 LocateResultのインスタンスの作成
//Parse the XML document containin the dsig:Signature Document sigDoc = //Instance of org.w3c.doc.Document; // Create the xkms:LocateResult LocateResult locRes = new LocateResult(sigDoc); //Set ResultMajor to Success. locRes.setResultCode(XKMSURI.result_major_success, null);
LocateRequestにX509CertificateのRespondWith属性が含まれている場合は、次のコードを使用してX509証明書をLocateResultに追加します。
例12-4 LocateResultに対するX509証明書の追加
//Creating a signature and adding X509 certificate to the KeyInfo element. X509Certificate userCert = // Instance of java.security.cert.X509Certificate XSSignature Sig = XSSignature.newInstance(sigDoc, "MySignature"); XSKeyInfo xsInfo = sig.getKeyInfo(); X509Data xData = xsInfo.createX509Data(userCert); //Add X509Data to the KeyInfo xsInfo.addKeyInfoData(xData); //Set Key Binding and add KeyInfo the the KeyBinding UnverifiedKeyBinding keyBinding = new UnverifiedKeyBinding(sigDoc); keyBinding.setKeyInfo(xsInfo); //Add Key Binding to LocateResult locRes.addKeyBinding(keyBinding);
このクラスは、XKMSのxkms:ValidateRequest要素を表します。
例12-5に、xkms:ValidateRequestのインスタンスを作成する方法を示します。
例12-5 ValidateRequestのインスタンスの作成
// Parse the XML document containing the dsig:Signature. Document sigDoc = //Instance of org.w3c.dom.Document; //Create Query Key Binding QueryKeyBinding queryKeyBinding = new QueryKeyBinding(sigDoc); queryKeyBinding.setTimeInstant(new Date()); // Create the xkms:ValidateRequest. ValidateRequest validateReq = new ValidateRequest(sigDoc, queryKeyBinding);
ValidateRequestタイプのリクエストには、xkms:RespondWith属性を含める必要があります。例12-6に、RespondWithをValidateRequestに追加する方法を示します。
このクラスは、XKMSのValidateResult要素を表します。
例12-7に、ValidateResultのインスタンスを作成する方法を示します。
例12-7 ValidateResultのインスタンスの作成
//Parse the XML document containin the dsig:Signature Document sigDoc = //Instance of org.w3c.doc.Document; // Create the xkms:ValidateResult ValidateResult valRes = new ValidateResult(sigDoc); //Set ResultMajor to Success. valRes.setResultCode(XKMSURI.result_major_success, null);
ValidateRequestに対するレスポンスでステータスを設定するには、次のコードを使用します。
例12-8 ValidateRequestのレスポンス・ステータスの設定
//Create a status element and add reasons.
Status responseStatus = new Status(sigDoc);
responseStatus.addValidReason(XKMSURI.reasonCode_IssuerTrust);
responseStatus.addValidReason(XKMSURI.reasonCode_RevocationStatus);
responseStatus.addValidReason(XKMSURI.reasonCode_ValidityInterval);
responseStatus.addValidReason(XKMSURI.reasonCode_Signature);
//Create a xkms:KeyBinding to add status and X509Data
XSKeyInfo xsInfo =
// Instance of oracle.security.xmlsec.dsig.XSKeyInfo,
// which contains X509Data
KeyBinding keyBinding = new KeyBinding(sigDoc);
keyBinding.setStatus(responseStatus);
keyBinding.setKeyInfo(xsInfo);
// Add the key binding to the ValidateResult.
valRes.addKeyBinding(keyBinding);
このクラスは、XKMSのRecoverRequest要素を表します。
例12-9に、RecoverRequestのインスタンスを作成する方法を示します。
例12-9 RecoverRequestのインスタンスの作成
// Parse the XML document containing the dsig:Signature. Document sigDoc = //Instance of org.w3c.dom.Document; // Create the xkms:RecoverRequest RecoverRequest recReq = new RecoverRequest(sigDoc); //Set RespondWith to PrivateKey, so that the RecoverResult contains the private key. recReq.addRespondWith(XKMSURI.respondWith_PrivateKey);
RecoverRequestには、Authentication要素とRecoverKeyBinding要素を含める必要があります。これらを追加するには、次のコードを使用します。
例12-10 RecoverRequestに対するAuthenticationおよびRecoverKeyBindingの追加
//Create an instance of XSSignature.
XSSignature sig =
//Instance of oracle.security.xmlsec.dsig.XSSignature
//Create an instance of Authentication element.
Authentication auth = new Authentication(sigDoc);
//Set key binding authentication.
auth.setKeyBindingAuthentication(sig);
//Set Authentication for the RecoverRequest.
recReq.setAuthentication(auth);
//Add RecoverKeyBinding to RecoverRequest.
RecoverKeyBinding recKeyBind = new RecoverKeyBinding(sigDoc);
//Add Key Info on the key to be recovered.
XSKeyInfo xsInfo =
//Instance of oracle.security.xmlsec.dsig.XSKeyInfo
recKeyBind.setKeyInfo(xsInfo);
//Adding status, as known to the key holder, to the KeyBinding
Status keyStatus = new Status(sigDoc);
keyStatus.setStatusValue(XKMSURI.kbs_Indeterminate);
recKeyBind.setStatus(keyStatus);
//Adding RecoverKeyBinding to RecoverRequest.
recReq.setKeyBinding(recKeyBind);
このクラスは、xkms:RecoverResult要素を表します。
例12-11に、RecoverResultのインスタンスを作成する方法を示します。
例12-11 xkms:RecoverResultのインスタンスの作成
// Parse the XML document containing the dsig:Signature. Document sigDoc = //Instance of org.w3c.dom.Document; // Create the xkms:RecoverResult RecoverResult recResult = new RecoverResult(sigDoc); //Set ResultMajor to Success. recResult.setResultCode(XKMSURI.result_major_success, null);
RecoverResultには、KeyBindingを設定する必要があります。この設定を行うには、次のコードを使用します。
例12-12 RecoverResultに対する鍵のバインディングの作成
//Create a xkms:KeyBinding to add status and X509Data
XSKeyInfo xsInfo =
//Instance of oracle.security.xmlsec.dsig.XSKeyInfo,
//which contains X509Data
KeyBinding keyBinding = new KeyBinding(sigDoc);
keyBinding.setKeyInfo(xsInfo);
//Create a status element and add reasons.
//Status is set to Invalid because the service can decide
//to revoke the key binding in the case of recovery.
Status responseStatus = new Status(sigDoc);
responseStatus.addInvalidReason(XKMSURI.reasonCode_IssuerTrust);
responseStatus.addInvalidReason(XKMSURI.reasonCode_RevocationStatus);
responseStatus.addInvalidReason(XKMSURI.reasonCode_ValidityInterval);
responseStatus.addInvalidReason(XKMSURI.reasonCode_Signature);
responseStatus.setStatusValue(XKMSURI.kbs_Invalid);
keyBinding.setStatus(responseStatus);
//Set KeyBinding into RecoverResult
recResult.addKeyBinding(keyBinding);
例12-13に、復元されたPrivateKeyをRecoverResultに設定する方法を示します。
例12-13 RecoverResultに対する復元された秘密鍵の設定
//Create an Instance of dsig:XEEncryptedData XEEncryptedData encryptedData = //Instance of oracle.security.xmlsec.enc.XEEncryptedData //Create an instance of oracle.security.xmlsec.xkms.xkrss.PrivateKey PrivateKey privKey = new PrivateKey(sigDoc); privKey.setEncryptedData(encryptedData); //Add PrivateKey to RecoverResult recResult.setPrivateKey(privKey);