このトピックでは、InterSystems IRIS Web サービスおよび Web クライアントによって送信されるメッセージの WS-Security ヘッダ内の要素を暗号化する方法について説明します(ここで説明するツールは、単独でまたはセキュリティ・ヘッダ要素と組み合わせて、SOAP 本文の暗号化にも使用できます)。
基本的な例
以下の例は、Web クライアントを呼び出し、暗号化された <UsernameToken> を送信します。この例では、本文は暗号化されません。
Set client=##class(XMLEncrSecHeader.Client.XMLEncrSecHeaderSoap).%New()
// Create UsernameToken
set user="_SYSTEM"
set pwd="SYS"
set userToken=##class(%SOAP.Security.UsernameToken).Create(user,pwd)
//get credentials for encryption
set cred = ##class(%SYS.X509Credentials).GetByAlias("servernopassword")
//get EncryptedKey element and add it
set encropt=$$$SOAPWSEncryptNone ; means do not encrypt body
set enckey=##class(%XML.Security.EncryptedKey).CreateX509(cred,encropt)
//create EncryptedData and add a reference to it from EncryptedKey
set encdata=##class(%XML.Security.EncryptedData).Create(,userToken)
set dataref=##class(%XML.Security.DataReference).Create(encdata)
do enckey.AddReference(dataref)
//add EncryptedKey to security header
do client.SecurityOut.AddSecurityElement(enckey)
//add UsernameToken and place it after EncryptedKey
do client.SecurityOut.AddSecurityElement(userToken,enckey)
Quit client.Divide(1,2)
このクライアントは、次のようなメッセージを送信します。
<?xml version="1.0" encoding="UTF-8" ?>
<SOAP-ENV:Envelope [parts omitted]>
<SOAP-ENV:Header>
<Security xmlns="[parts omitted]oasis-200401-wss-wssecurity-secext-1.0.xsd">
<EncryptedKey xmlns="http://www.w3.org/2001/04/xmlenc#">
<EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#rsa-oaep-mgf1p">
<DigestMethod
xmlns="http://www.w3.org/2000/09/xmldsig#"
Algorithm="http://www.w3.org/2000/09/xmldsig#sha1">
</DigestMethod>
</EncryptionMethod>
<KeyInfo xmlns="http://www.w3.org/2000/09/xmldsig#">
<SecurityTokenReference
xmlns="[parts omitted]oasis-200401-wss-wssecurity-secext-1.0.xsd">
<KeyIdentifier EncodingType="[parts omitted]#Base64Binary"
ValueType="[parts omitted]#ThumbprintSHA1">[omitted]</KeyIdentifier>
</SecurityTokenReference>
</KeyInfo>
<CipherData>
<CipherValue>pftET8jFDEjNC2x[parts omitted]xEjNC2==</CipherValue>
</CipherData>
<ReferenceList>
<DataReference URI="#Enc-61000920-44DE-471E-B39C-6D08CB17FDC2">
</DataReference>
</ReferenceList>
</EncryptedKey>
<EncryptedData xmlns="http://www.w3.org/2001/04/xmlenc#"
Id="Enc-61000920-44DE-471E-B39C-6D08CB17FDC2"
Type="http://www.w3.org/2001/04/xmlenc#Element">
<EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#aes128-cbc">
</EncryptionMethod>
<CipherData>
<CipherValue>wW3ZM5tgPD[parts omitted]tgPD==</CipherValue>
</CipherData>
</EncryptedData>
</Security>
</SOAP-ENV:Header>
<SOAP-ENV:Body>
[omitted]
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
単純なバリエーションとして、前のセクションの手順を考えてみます。手順 4 で以下を実行し、他には変更しないものとします。
set enckey=##class(%XML.Security.EncryptedKey).CreateX509(credset)
この場合、クライアントからのメッセージには、暗号化された本文および暗号化された <UsernameToken> が含まれています。
<?xml version="1.0" encoding="UTF-8" ?>
<SOAP-ENV:Envelope [parts omitted]>
<SOAP-ENV:Header>
<Security xmlns="[parts omitted]oasis-200401-wss-wssecurity-secext-1.0.xsd">
<EncryptedKey xmlns="http://www.w3.org/2001/04/xmlenc#">
<EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#rsa-oaep-mgf1p">
<DigestMethod xmlns="http://www.w3.org/2000/09/xmldsig#"
Algorithm="http://www.w3.org/2000/09/xmldsig#sha1">
</DigestMethod>
</EncryptionMethod>
<KeyInfo xmlns="http://www.w3.org/2000/09/xmldsig#">
<SecurityTokenReference
xmlns="[parts omitted]oasis-200401-wss-wssecurity-secext-1.0.xsd">
<KeyIdentifier EncodingType="[parts omitted]#Base64Binary"
ValueType="[parts omitted]#ThumbprintSHA1">
5a[parts omitted]dM1r6cM=
</KeyIdentifier>
</SecurityTokenReference>
</KeyInfo>
<CipherData>
<CipherValue>TB8uavpr[parts omitted]nZBiMCcg==</CipherValue>
</CipherData>
<ReferenceList>
<DataReference URI="#Enc-43FE435F-D1D5-4088-A343-0E76D154615A"></DataReference>
<DataReference URI="#Enc-55FE109A-3C14-42EB-822B-539E380EDE48"></DataReference>
</ReferenceList>
</EncryptedKey>
<EncryptedData xmlns="http://www.w3.org/2001/04/xmlenc#"
Id="Enc-43FE435F-D1D5-4088-A343-0E76D154615A"
Type="http://www.w3.org/2001/04/xmlenc#Element">
<EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#aes128-cbc">
</EncryptionMethod>
<CipherData>
<CipherValue>G+X7dqI[parts omitted]nojroQ==</CipherValue>
</CipherData>
</EncryptedData>
</Security>
</SOAP-ENV:Header>
<SOAP-ENV:Body>
<EncryptedData xmlns="http://www.w3.org/2001/04/xmlenc#"
Id="Enc-55FE109A-3C14-42EB-822B-539E380EDE48"
Type="http://www.w3.org/2001/04/xmlenc#Content">
<EncryptionMethod Algorithm="[parts omitted]aes128-cbc"></EncryptionMethod>
<CipherData>
<CipherValue>YJbzyi[parts omitted]NhJoln==</CipherValue>
</CipherData>
</EncryptedData>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
前の例と比べると、この場合、<EncryptedKey> 要素には、2 つの <EncryptedData> 要素への参照が含まれています。一方は、セキュリティ・ヘッダの <EncryptedData> 要素で、これには <UsernameToken> が含まれています。この参照は、手動で作成および追加されました。もう一方は、SOAP 本文の <EncryptedData> 要素です。この参照は、自動で追加されました。