コンシューマー側で SOAP メッセージを保護するには、 Web サービス・セキュリティー API (WSS API) を使用して、応答コンシューマー (クライアント・サイド) で 検証パーツ情報を構成します。確認するアルゴリズム方式と SOAP メッセージのパーツを 指定することができます。ダイジェスト方式または変換方式を変更するには、WSSVerifyPart API を使用します。 WSSVerifyPart API は、com.ibm.websphere.wssecurity.wssapi.verification パッケージに 含まれています。
署名検証情報を使用して SOAP メッセージを保護するには、 以下のタスクのいずれかを実行する必要があります。
WebSphere Application Server では、デフォルト・コンシューマー用の 署名情報を使用してメッセージの署名済みパーツを検証します。WSSVerifyPart API は、 応答コンシューマー (要求側) でしかサポートされていません。
以下の表に、 デジタル・シグニチャー・セキュリティー制約 (保全性) が定義される場合に 必須の検証パーツを示します。
検証パーツ情報 | 説明 |
---|---|
keyword | 以下のキーワードで検証パーツを設定します。
WS-Addressing ヘッダーは暗号化解除されませんが、 署名したり検証したりすることはできます。 |
xpath | XPath 式で検証パーツを設定します。 |
header | ヘッダー (QName で指定) を必須の検証パーツとして 設定します。 |
シグニチャー検証では、特定のデフォルトの動作が発生します。WSSVerification API を 使用する最も簡単な方法は、デフォルトの動作を使用することです (コード例を 参照してください)。署名アルゴリズムと正規化アルゴリズム、 および検証パーツでは、デフォルト値は WSS API によって定義されます。
検証パーツの決定項目 | デフォルトの動作 |
---|---|
指定するキーワード | 署名してメッセージ保護に使用する SOAP メッセージの 各種パーツ。WebSphere Application Server は以下のキーワードをサポートします。
|
使用する変換方式 (アルゴリズム) | 変換方式を追加します。変換アルゴリズムは、
<Transform> エレメント内で指定され、シグニチャーの変換アルゴリズムを
指定します。デフォルトの変換方式は TRANSFORM_EXC_C14N です。 WebSphere Application Server は、 以下の事前構成済み変換アルゴリズムをサポートします。
|
使用するダイジェスト方式 (アルゴリズム) | ダイジェスト・アルゴリズム方式を設定します。
<DigestMethod> エレメント内で指定されるダイジェスト方式アルゴリズムは、
<SigningInfo> エレメントで使用されます。
デフォルトのダイジェスト方式は SHA1 です。 WebSphere Application Server は、以下のダイジェスト・メソッド・アルゴリズムをサポートします。
|
次の例は、SOAP メッセージの署名情報を確認する 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 certStore 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 callback handler (step: c) 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 specified by WSSVerifyPart (step: e) WSSVerifyPart verPart = factory.newWSSVerifyPart(); // Set the part to be specified by the keyword (step: f) verPart.setRequiredVerifyPart(WSSVerification.BODY); // Set the candidates for the digest method for verification (step: g) // DEFAULT : WSSVerifyPart.SHA1 verPart.addAllowedDigestMethod(WSSVerifyPart.SHA256); // Set the candidates for the transform method for verification (step: h) // DEFAULT : WSSVerifypart.TRANSFORM_EXC_C14N : String verPart.addAllowedTransform(WSSVerifyPart.TRANSFORM_STRT10); // Set WSSVerifyPart to WSSVerification (step: i) ver.addRequiredVerifyPart(verPart); // Add WSSVerification to WSSConsumingContext (step: j) concont.add(ver); //Validate the WS-Security header (step: k) concont.process(msgcontext);