構成用ポリシー・セットを使用しなくても、Web Services Security API (WSS API) を使用することで SOAP メッセージをセキュアにすることができます。 クライアント・サイド要求の コンシューマー・バインディング・セクションで署名情報を確認するには、 WSSVerification API を使用します。検証するアルゴリズム方式と SOAP メッセージの シグニチャー・パーツも指定する必要があります。 WSSVerification API は、com.ibm.websphere.wssecurity.wssapi.verification パッケージに 含まれています。
署名情報の検証には、WSS API を使用するか、管理コンソールから ポリシー・セットを構成します。SOAP メッセージを保護するためには、 以下のシグニチャー・タスクを実行する必要があります。
WebSphere Application Server は、デフォルト・ジェネレーターの 署名情報を使用してメッセージ・パーツに署名し、RSA-SHA1、HMAC-SHA1 など既存の アルゴリズムで XML デジタル・シグニチャーを使用します。
XML Signature は、鍵情報を記述するための多くのメソッドを定義し、 新規メソッドの定義を使用可能にします。XML Signature を 使用するときには、たいていの場合、XML 正規化 (C14N) が必要になります。情報は、シリアライズされた XML 文書内で、さまざまな方法で表すことができます。 C14N プロセスは、XML 情報を正規化するために使用されます。正規化される情報が このアルゴリズムに依存するため、該当する C14N アルゴリズムを 選択します。
以下の表に、デジタル・シグニチャー・セキュリティー制約 (保全性) が 定義される場合の、必須およびオプションのバインディング情報を 示します。
検証パーツ | 説明 |
---|---|
キーワード | キーワードによって、検証のターゲットとして
必要なシグニチャー・パーツを追加します。ジェネレーター側の要求のメッセージ保護には、
さまざまなメッセージ・パーツを指定できます。必須のシグニチャー検証パーツには
以下のキーワードを使用します。
|
xpath | XPath 式によって検証パーツを追加します。 |
part | WSSVerifyPart オブジェクトを検証パーツとして追加します。 |
header | ヘッダー (QName で指定) を検証パーツとして 追加します。 |
シグニチャー検証情報では、 特定のデフォルトの動作が発生します。WSSVerification API を使用する最も簡単な方法は、 デフォルトの動作を使用することです。
ダイジェスト方式、 変換方式、セキュリティー・トークン、および必須検証パーツでは、 デフォルト値は WSS API によって定義されます。
シグニチャー検証の決定項目 | デフォルトの動作 |
---|---|
使用するシグニチャー方式 (アルゴリズム) | シグニチャー・アルゴリズム方式を設定します。データ暗号化、
シグニチャーおよび正規化の両方を指定できます。デフォルトのシグニチャー方式は
RSA SHA1 です。WebSphere Application Server は、以下の事前構成されたシグニチャー方式をサポートします。
|
使用する正規化方式 (アルゴリズム) | 正規化アルゴリズム方式を設定します。データ暗号化、
シグニチャーおよび正規化の両方を指定できます。
デフォルトのシグニチャー方式は EXC_C14N です。WebSphere Application Server は、
以下の事前構成の正規化方式をサポートします。
|
シグニチャー確認が必要かどうか | WSSSignature API でシグニチャー確認が必要と
指定した場合は、WSSVerification API が、受信時にシグニチャー確認値が
添付されている応答メッセージでのシグニチャー確認値を
検証します。シグニチャー確認は、OASIS Web Services Security バージョン 1.1 仕様で
定義されます。 デフォルトのシグニチャー確認は false です。 |
指定するセキュリティー・トークン (securityToken) | securityToken オブジェクトをシグニチャー・パーツとして追加します。 WebSphere Application Server で、検証に使用するトークン情報を設定します。 WebSphere Application Server は、次の事前構成済み署名用トークンをサポートしています。
|
次の例は、WSSVerification API で定義されるメソッドを 使用したサンプル・コードです。
// Get the message context Object msgcontext = getMessageContext(); // Generate the WSSFactory instance (step: a) WSSFactory factory = WSSFactory.getInstance(); // Generate the WSSConsumingContext instance (step: b) WSSConsumingContext concont = factory.newWSSConsumingContext(); // Generate the certificate list String certpath = "c:/WebSphere/AppServer/etc/ws-security/samples/intca2.cer"; // The location of the X509 certificate file X509Certificate x509cert = null; try { InputStream is = new FileInputStream(certpath); CertificateFactory cf = CertificateFactory.getInstance("X.509"); x509cert = (X509Certificate)cf.generateCertificate(is); } catch(FileNotFoundException e1){ throw new WSSException(e1); } catch (CertificateException e2) { throw new WSSException(e2); } Set<Object> eeCerts = new HashSet<Object>(); eeCerts.add(x509cert); // Create the certificate store java.util.List<CertStore> certList = new java.util.ArrayList<CertStore>(); CollectionCertStoreParameters certparam = new CollectionCertStoreParameters(eeCerts); CertStore cert = null; try { cert = CertStore.getInstance("Collection", certparam, "IBMCertPath"); } catch (NoSuchProviderException e1) { throw new WSSException(e1); } catch (InvalidAlgorithmParameterException e2) { throw new WSSException(e2); } catch (NoSuchAlgorithmException e3) { throw new WSSException (e3); } if(certList != null ){ certList.add(cert); } // Generate the callback handler X509ConsumeCallbackHandler callbackHandler = new X509ConsumeCallbackHandler( "dsig-receiver.ks", "jks", "server".toCharArray(), certList, java.security.Security.getProvider("IBMCertPath") ); // Generate the WSSVerification instance (step: d) WSSVerification ver = factory.newWSSVerification(X509Token.class, callbackHandler); // Set the part to be verified (step: e) // DEFAULT: WSSVerification.BODY, WSSSignature.ADDRESSING_HEADERS, // and WSSSignature.TIMESTAMP. // Set the part in the SOAP header to be specified by QName (step: e) ver.addRequiredVerifyHeader(new QName("http://www.w3.org/2005/08/addressing", "MessageID")); // Set the part to be specified by the keyword (step: e) ver.addRequiredVerifyPart(WSSVerification.BODY); // Set the part to be specified by WSSVerifyPart (step: e) WSSVerifyPart verPart = factory.newWSSVerifyPart(); verPart.setRequiredVerifyPart(WSSVerification.BODY); verPart.addAllowedDigestMethod(WSSVerifyPart.SHA256); ver.addRequiredVerifyPart(verPart); // Set the part specified by XPath expression (step: e) StringBuffer sb = new StringBuffer(); sb.append("/*[namespace-uri()='http://schemas.xmlsoap.org/soap/envelope/' and local-name()='Envelope']"); sb.append("/*[namespace-uri()='http://schemas.xmlsoap.org/soap/envelope/' and local-name()='Body']"); sb.append("/*[namespace-uri()='http://xmlsoap.org/Ping' and local-name()='Ping']"); sb.append("/*[namespace-uri()='http://xmlsoap.org/Ping' and local-name()='Text']"); ver.addRequiredVerifyPartByXPath(sb.toString()); // Set one or more canonicalization method candidates for verification (step: f) // DEFAULT : WSSVerification.EXC_C14N ver.addAllowedCanonicalizationMethod(WSSVerification.C14N); ver.addAllowedCanonicalizationMethod(WSSVerification.EXC_C14N); // Set one or more signature method candidates for verification (step: g) // DEFAULT : WSSVerification.RSA_SHA1 ver.addAllowedSignatureMethod(WSSVerification.HMAC_SHA1); // Set the candidate security token to used for the verification (step: h) X509ConsumeCallbackHandler callbackHandler2 = getCallbackHandler2(); ver.addToken(X509Token.class, callbackHandler2); // Set the flag to require the signature confirmation (step: i) ver.requireSignatureConfirmation(); // Add the WSSVerification to the WSSConsumingContext (step: j) concont.add(ver); //Validate the WS-Security header (step: k) concont.process(msgcontext);
シグニチャーの検証と SOAP メッセージに対するアルゴリズム方式の設定を 終えると、ダイジェスト方式や変換方式を設定できるようになります。 これらの方式を設定するには、WSSVerifyPart API を使用するか、 管理コンソールからポリシー・セットを構成します。