WSSDecryption API を使用した SOAP メッセージの暗号化解除
構成用ポリシー・セットを使用しなくても、Web Services Security API (WSS API) を使用することで SOAP メッセージをセキュアにすることができます。 応答 (クライアント) コンシューマー側でクライアントを暗号化解除用に構成するには、 WSSDecryption API を使用して SOAP メッセージを暗号化解除します。WSSDecryption API で、 クライアントを構成するときに暗号化解除する要求 SOAP メッセージ・パーツを指定します。
始める前に
WSS API を使用するか、管理コンソールでポリシー・セットを使用して、 暗号化解除を有効にし、コンシューマー・セキュリティー・トークンを SOAP メッセージに追加できます。 SOAP メッセージをセキュアにするには、以下の暗号化解除タスクを完了しておく必要があります。
- SOAP メッセージの暗号化
- 暗号化解除方式の選択
このタスクについて
コンシューマー側の暗号化情報は、応答コンシューマー (クライアント側) バインディングに関する 着信 SOAP メッセージの暗号化解除に使用されます。 クライアント・コンシューマー構成は、 プロバイダー・ジェネレーターの構成と一致する必要があります。
機密性設定では、生成されたメッセージに機密性の制約が適用される必要があります。
以下の暗号化解除パーツを構成できます。
暗号化解除パーツ | 説明 |
---|---|
part | WSSDecryptPart オブジェクトを暗号化解除パーツのターゲットとして追加します。 |
keyword | キーワードを使用して暗号化解除パーツを追加します。WebSphere® Application Server は、
以下のキーワードをサポートしています。
|
xpath | XPath 式を使用して暗号化解除パーツを追加します。 |
verification | WSSVerification インスタンスを暗号化解除パーツのターゲットとして追加します。 |
header | (QName で指定された) SOAP ヘッダーを暗号化解除パーツのターゲットとして追加します。 |
暗号化解除では、ある決まったデフォルトの動作が行われます。 暗号化解除に WSS API を使用する一番簡単な方法はデフォルトの動作を使用することです (サンプル・コードを参照)。 WSSDecryption は、鍵暗号化アルゴリズム、データ暗号化アルゴリズム、および暗号化解除パーツ (SOAP 本体の内容、シグニチャーなど) のデフォルトを提供します。 暗号化解除のデフォルトの動作には、以下のものがあります。
暗号化解除の決定 | デフォルトの動作 |
---|---|
暗号化解除するパーツ | デフォルトの暗号化解除パーツは、BODY_CONTENT と SIGNATURE です。WebSphere Application Server は、以下のキーワードの使用をサポートしています。
どのメッセージ・パーツの暗号化解除を行うかを指定した後、コンシューマー要求メッセージを暗号化解除するときに使用する方式を指定する必要があります。 例えば、シグニチャーと本体の内容の両方が暗号化に適用される場合、 暗号化解除される SOAP メッセージ・パーツには同じパーツが含まれます。 |
鍵を暗号化するかどうか (isEncrypt) | デフォルト値では鍵が暗号化されます (true)。 |
選択するデータ暗号化解除アルゴリズム (方式) | デフォルトのデータ暗号化解除アルゴリズム方式は AES128 です。 WebSphere Application Server は、以下のデータ暗号化方式をサポートしています。
|
選択する鍵暗号化解除方式 (アルゴリズム) | デフォルトの鍵暗号化解除アルゴリズム方式は、鍵ラップ RSA OAEP です。WebSphere Application Server は、以下の鍵暗号化方式をサポートしています。
|
指定するセキュリティー・トークン | デフォルトのセキュリティー・トークン・タイプは X509 トークンです。 WebSphere Application Server は、 以下の事前構成済みコンシューマー・トークン・タイプを提供します。
|
手順
タスクの結果
例
以下の例は、SOAP メッセージ本体の内容を暗号化解除するサンプル・コードです。
// Get the message context
Object msgcontext = getMessageContext();
// Generate the WSSFactory instance (step: a)
WSSFactory factory = WSSFactory.getInstance();
// Generate the WSSConsumingContext instance (step: b)
WSSConsumingContext gencont = factory.newWSSConsumingContext();
// Generate the callback handler (step: c)
X509ConsumeCallbackHandler callbackHandler = new
X509ConsumeCallbackHandler(
"",
"enc-sender.jceks",
"jceks",
"storepass".toCharArray(),
"alice",
"keypass".toCharArray(),
"CN=Alice, O=IBM, C=US");
// Generate the WSSDecryption instance (step: d)
WSSDecryption dec = factory.newWSSDecryption(X509Token.class,
callbackHandler);
// Set the part to be encrypted (step: e)
// DEFAULT: WSSEncryption.BODY_CONTENT and WSSEncryption.SIGNATURE
// Set the part to be encrypted (step: e)
// DEFAULT: WSSEncryption.BODY_CONTENT and WSSEncryption.SIGNATURE
// Set the part specified by the keyword (step: e)
dec.addRequiredDecryptPart(WSSDecryption.BODY_CONTENT);
// Set the part in the SOAP Header specified by QName (step: e)
dec.addRequiredDecryptHeader(new
QName("http://www.w3.org/2005/08/addressing",
"MessageID"));
// Set the part specified by WSSVerification (step: e)
X509ConsumeCallbackHandler verifyCallbackHandler =
getCallbackHandler();
WSSVerification ver = factory.newWSSVerification(X509Token.class,
verifyCallbackHandler);
dec.addRequiredDecryptPart(ver);
// 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']");
dec.addRequiredDecryptPartByXPath(sb.toString());
// Set the part in the SOAP header to be decrypted specified by QName (step: e)
dec.addRequiredDecryptHeader(new
QName("http://www.w3.org/2005/08/addressing",
"MessageID"));
// Set the candidates for the data encryption method (step: f)
// DEFAULT : WSSDecryption.AES128
dec.addAllowedEncryptionMethod(WSSDecryption.AES128);
dec.addAllowedEncryptionMethod(WSSDecryption.AES192);
// Set the candidates for the key encryption method (step: g)
// DEFAULT : WSSDecryption.KW_RSA_OAEP
dec.addAllowedKeyEncryptionMethod(WSSDecryption.KW_TRIPLE_DES);
// Set the candidate security token to used for the decryption (step: h)
X509ConsumeCallbackHandler callbackHandler2 = getCallbackHandler2();
dec.addToken(X509Token.class, callbackHandler2);
// Set whether or not the key should be encrypted in the incoming SOAP message (step: i)
// DEFAULT: true
dec.encryptKey(true);
// Add the WSSDecryption to the WSSConsumingContext (step: j)
concont.add(dec);
// Validate the WS-Security header (step: k)
concont.process(msgcontext);
次のタスク
次に、コンシューマー・メッセージ用の暗号化解除パーツを追加するために、WSSDecryptPart API を使用するか、または管理コンソールを使用してポリシー・セットを構成します。