WSS API を使用して、コンシューマー・バインディングの署名検査情報を構成できます。 変換アルゴリズム方式とダイジェスト方式がコンシューマー・バインディングで使用されます。 アルゴリズム方式を構成するには、WSSVerifyPart API を使用します。 WSSVerifyPart API は、com.ibm.websphere.wssecurity.wssapi.verification パッケージに同梱されています。
コンシューマー検査パーツ情報を構成してメッセージの保全性を保護するには、最初にデジタルで署名してから SOAP メッセージのシグニチャーと署名済みパーツを検査してください。 機密性が暗号化を意味するのに対して、「保全性」はデジタル・シグニチャーを意味します。 保全性によって、データがネットワーク内を伝送されている間に変更されるリスクが減少します。
ダイジェスト方式アルゴリズムはエレメント内で指定され、<Digest> エレメントで使用されます。WebSphere Application Server は次の事前構成済みダイジェスト・アルゴリズムをサポートしています。
ダイジェスト方式 | 説明 |
---|---|
WSSVerifyPart.SHA1 (デフォルト値) | ダイジェスト・アルゴリズム SHA1 の URI: http://www.w3.org/2000/09/xmldsig#sha1 |
WSSVerifyPart.SHA256 | ダイジェスト・アルゴリズム SHA256 の URI: http://www.w3.org/2001/04/xmlenc#sha256 |
WSSVerifyPart.SHA512 | ダイジェスト・アルゴリズム SHA256 の URI: http://www.w3.org/2001/04/xmlenc#sha512 |
変換アルゴリズムは、<Transform> エレメント内で指定され、署名済みパーツの変換アルゴリズムを指定します。 WebSphere Application Server は、以下の事前構成済み変換アルゴリズムをサポートします。
ダイジェスト方式 | 説明 |
---|---|
WSSVerifyPart.TRANSFORM_ENVELOPED_SIGNATURE | 変換アルゴリズム enveloped signature の URI: http://www.w3.org/2000/09/xmldsig#enveloped-signature |
WSSVerifyPart.TRANSFORM_STRT10 | 変換アルゴリズム STR-Transform の URI: http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#STR-Transform |
WSSVerifyPart.TRANSFORM_EXC_C14N (デフォルト値) | 変換アルゴリズム Exc-C14N の URI: http://www.w3.org/2001/10/xml-exc-c14n# |
WSSVerifyPart.TRANSFORM_XPATH2_FILTER | 変換アルゴリズム XPath2 フィルターの URI: http://www.w3.org/2002/06/xmldsig-filter2 |
以下の例は、ダイジェスト方式として SHA256 を使用し、変換方式として TRANSFORM_EXC_14N および TRANSFORM_STRT10 を使用して本文を検査する場合の WSS API サンプル・コードです。
// get the message context Object msgcontext = getMessageContext(); // generate WSSFactory instance WSSFactory factory = WSSFactory.getInstance(); // generate WSSConsumingContext instance WSSConsumingContext concont = factory.newWSSConsumingContext(); // generate the cert list String certpath = "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 X509ConsumeCallbackHandler callbackHandler = new X509ConsumeCallbackHandler( "dsig-receiver.ks", "jks", "server".toCharArray(), certList, java.security.Security.getProvider("IBMCertPath") ); //generate WSSVerification instance WSSVerification ver = factory.newWSSVerification(X509Token.class, callbackHandler); //set one or more candidates of the signature method used for the verification (step. 1) // DEFAULT : WSSVerification.RSA_SHA1 ver.addAllowedSignatureMethod(WSSVerification.HMAC_SHA1); //set one or more candidates of the canonicalization method used for the verification (step. 2) // DEFAULT : WSSVerification.EXC_C14N ver.addAllowedCanonicalizationMethod(WSSVerification.C14N); ver.addAllowedCanonicalizationMethod(WSSVerification.EXC_C14N); //set the part to be specified by WSSVerifyPart WSSVerifyPart verPart = factory.newWSSVerifyPart(); //set the part to be specified by the keyword verPart.setRequiredVerifyPart(WSSVerification.BODY); //set the candidates of digest methods to use for verification (step. 3) // DEFAULT : WSSVerifypart.TRANSFORM_EXC_C14N verPart.addAllowedTransform(WSSVerifyPart.TRANSFORM_EXC_C14N); verPart.addAllowedTransform(WSSVerifyPart.TRANSFORM_STRT10); //set the candidates of digest methods to use for verification (step. 4) // DEFAULT : WSSVerifyPart.SHA1 verPart.addAllowedDigestMethod(WSSVerifyPart.SHA256); //set WSSVerifyPart to WSSVerification ver.addRequiredVerifyPart(verPart); //add the WSSVerification to the WSSConsumingContext concont.add(ver); //validate the WS-Security header concont.process(msgcontext);