Skip to main content

This is documentation for Caché & Ensemble. See the InterSystems IRIS version of this content.Opens in a new tab

For information on migrating to InterSystems IRISOpens in a new tab, see Why Migrate to InterSystems IRIS?

暗号化と署名の組み合わせ

同じメッセージ内で暗号化と署名を実行できます。ほとんどの場合、前述の各章で説明した方法を単純に組み合わせることができます。この章では、以下のシナリオについて説明します。

非対称鍵を使用して署名してから暗号化する方法

非対称鍵を使用して署名してから暗号化するには、以下の手順を実行します。

  1. デジタル・シグニチャの追加” の各手順を実行します。

  2. セキュリティ・ヘッダ要素の暗号化” の各手順を実行します。

    または、“SOAP 本文の暗号化” の各手順を実行します。

非対称鍵を使用して暗号化してから署名する方法

非対称鍵を使用して SOAP 本文のみを暗号化してからデジタル・シグニチャを追加するには、以下の手順を実行します。

  1. SOAP 本文の暗号化” の各手順を実行します。

  2. デジタル・シグニチャの追加” の各手順を実行します。

非対称鍵を使用して任意のセキュリティ・ヘッダ要素を暗号化してからデジタル・シグニチャを追加するには、最上位レベルの <ReferenceList> 要素を使用する必要があります。この要素は、このドキュメントの前述の部分では必要ありませんでした。この場合、以下の手順を実行します。

  1. このドキュメントで前述の “セキュリティ・ヘッダ要素の暗号化” の手順 1 — 4 を実行します。

  2. 各セキュリティ・ヘッダ要素を暗号化するには、その要素に基づいて <EncryptedData> 要素を作成します。そのためには、%XML.Security.EncryptedDataOpens in a new tabCreate() クラス・メソッドを呼び出します。この手順では、以下の 3 つの引数すべてを指定します。

    1. 前の手順で作成した暗号化キーのインスタンス。

    2. 暗号化するセキュリティ・ヘッダ要素。

    3. <EncryptedData> が暗号化キーのインスタンスを使用する方法を指定する $$$SOAPWSReferenceEncryptedKey

    以下はその例です。

     set refopt=$$$SOAPWSReferenceEncryptedKey
     set encdata=##class(%XML.Security.EncryptedData).Create(enckey,userToken,refopt)
  3. <ReferenceList> 要素を作成します。そのためには、%XML.Security.ReferenceListOpens in a new tab クラスの %New() メソッドを呼び出します。以下はその例です。

     set reflist=##class(%XML.Security.ReferenceList).%New() 
  4. この <ReferenceList> 内で、<EncryptedData> 要素を指す <Reference> を作成します。そのためには、各 <EncryptedData> に対して、以下の手順を実行します。

    1. %XML.Security.DataReferenceOpens in a new tabCreate() クラス・メソッドを呼び出し、暗号化されたデータのインスタンスを引数として指定します。このメソッドは %XML.Security.DataReferenceOpens in a new tab のインスタンスを返します。

    2. 参照リストのインスタンスの AddReference() メソッドを呼び出し、データ参照のインスタンスを引数として指定します。

    以下はその例です。

     set dataref=##class(%XML.Security.DataReference).Create(encdata)
     do reflist.AddReference(dataref)
  5. WS-Security ヘッダ要素に <ReferenceList> 要素を追加します。そのためには、Web クライアントまたは Web サービスの SecurityOut プロパティの AddSecurityElement() メソッドを呼び出します。追加する要素に対して、参照リストのインスタンスを指定します。以下はその例です。

     do ..SecurityOut.AddSecurityElement(reflist)
    Note:

    <ReferenceList> 要素は、その他のアイテムを追加する前に追加する必要があります。

  6. WS-Security ヘッダ要素に <EncryptedKey> 要素を追加します。AddSecurityElement() を使用します。以下はその例です。

     do ..SecurityOut.AddSecurityElement(enckey)
  7. 暗号化されたセキュリティ・ヘッダ要素を WS-Security ヘッダ要素に追加します。そのためには、Web クライアントまたは Web サービスの SecurityOut プロパティの AddSecurityElement() メソッドを呼び出します。この場合、以下の 2 つの引数を指定します。

    1. 組み込むセキュリティ・ヘッダ要素 (その要素に基づく %XML.Security.EncryptedDataOpens in a new tab のインスタンスではない)。

    2. 暗号化キー・インスタンス。2 番目の引数は、最初の引数が指定するアイテムの配置場所を指定します。引数が A、B の場合、Caché は、A が B のであることを確認します。これを指定して、受信者が暗号化キーを最初に処理し、これに依存する暗号化されたセキュリティ・ヘッダ要素を後で処理するようにします。

    以下はその例です。

     do ..SecurityOut.AddSecurityElement(userToken,enckey)

    または、暗号化されたセキュリティ・ヘッダ要素が <Signature> の場合、代わりに AddSecurityElement() を使用します。

  8. このドキュメントで前述の “デジタル・シグニチャの追加” の各手順を実行します。

  9. SOAP メッセージを送信します。このドキュメントで前述の “セキュリティ・ヘッダ要素の追加” の一般的な手順を参照してください。

対称鍵を使用して署名してから暗号化する方法

対称鍵を使用して署名してから暗号化するには、以下の手順を実行します。

  1. 暗号化への <DerivedKeyToken> の使用” の各手順を実行します。

  2. 署名への <DerivedKeyToken> の使用” の各手順を実行します。

<DerivedKeyToken> 要素の使用

以下の例では、対称鍵を使用して署名してから暗号化します。メッセージ受信者の公開鍵を使用して <EncryptedKey> 要素を作成し、これを使用して 2 つの <DerivedKeyToken> 要素 (署名用と暗号化用) を生成します。

 // create UsernameToken
  set userToken=##class(%SOAP.Security.UsernameToken).Create("_SYSTEM","SYS")

  //get credentials of message recipient
  set x509alias = "servernopassword"
  set cred = ##class(%SYS.X509Credentials).GetByAlias(x509alias) 

  //get EncryptedKey element
  set enc=##class(%XML.Security.EncryptedKey).CreateX509(cred,$$$SOAPWSEncryptNone)
  do client.SecurityOut.AddSecurityElement(enc)

  // get derived keys
  set dkenc=##class(%SOAP.WSSC.DerivedKeyToken).Create(enc,$$$SOAPWSReferenceEncryptedKey)
  do client.SecurityOut.AddSecurityElement(dkenc)
  set dksig=##class(%SOAP.WSSC.DerivedKeyToken).Create(enc,$$$SOAPWSReferenceEncryptedKey)
  do client.SecurityOut.AddSecurityElement(dksig)

  // create and add signature
  set sig=##class(%XML.Security.Signature).Create(dksig,,$$$SOAPWSReferenceDerivedKey)
  do client.SecurityOut.AddSecurityElement(sig) 
 
  // ReferenceList to encrypt Body and Username. Add after signing
  set reflist=##class(%XML.Security.ReferenceList).%New()
  set refopt=$$$SOAPWSReferenceDerivedKey
  set encryptedData=##class(%XML.Security.EncryptedData).Create(dkenc,userToken,refopt)
  set dataref=##class(%XML.Security.DataReference).Create(encryptedData)
  do reflist.AddReference(dataref)
  set encryptedData=##class(%XML.Security.EncryptedData).Create(dkenc,"",refopt)
  set dataref=##class(%XML.Security.DataReference).Create(encryptedData)
  do reflist.AddReference(dataref)
  do client.SecurityOut.AddSecurityElement(reflist)
  
  // Add UsernameToken; force after ReferenceList so that it can decrypt properly
  do client.SecurityOut.AddSecurityElement(userToken,reflist)

このクライアントは、次のようなメッセージを送信します。

<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#" 
                       Id="Id-A0CBB4B7-18A8-40C1-A2CD-C0C383BF9531">
            <EncryptionMethod Algorithm="[parts omitted]#rsa-oaep-mgf1p">
               <DigestMethod xmlns="http://www.w3.org/2000/09/xmldsig#" 
                             Algorithm="[parts omitted]#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">
              5afOHv1w7WSXwDyz6F3WdM1r6cM=</KeyIdentifier>
               </SecurityTokenReference>
            </KeyInfo>
            <CipherData>
               <CipherValue>fR4hoJy4[parts omitted]Gmq1xg==</CipherValue>
            </CipherData>
         </EncryptedKey>
         <DerivedKeyToken xmlns="http://docs.oasis-open.org/ws-sx/ws-secureconversation/200512" 
                          xmlns:wsc="http://docs.oasis-open.org/ws-sx/ws-secureconversation/200512" 
                          wsu:Id="Enc-43F73EB2-77EC-4D72-9DAD-17B1781BC49C">
            <SecurityTokenReference xmlns="[parts omitted]oasis-200401-wss-wssecurity-secext-1.0.xsd">
               <Reference URI="#Id-A0CBB4B7-18A8-40C1-A2CD-C0C383BF9531"></Reference>
            </SecurityTokenReference>
            <Nonce>Q1wDt0PSSLmARcy+Pg49Sg==</Nonce>
         </DerivedKeyToken>
         <DerivedKeyToken xmlns="http://docs.oasis-open.org/ws-sx/ws-secureconversation/200512" 
                          xmlns:wsc="http://docs.oasis-open.org/ws-sx/ws-secureconversation/200512" 
                          wsu:Id="Enc-ADE64310-E695-4630-9DA6-A818EF5CEE9D">
            <SecurityTokenReference xmlns="[parts omitted]oasis-200401-wss-wssecurity-secext-1.0.xsd">
               <Reference URI="#Id-A0CBB4B7-18A8-40C1-A2CD-C0C383BF9531"></Reference>
            </SecurityTokenReference>
            <Offset>0</Offset>
            <Length>24</Length>
            <Nonce>PvaakhgdxoBVLR6I1j6KGA==</Nonce>
         </DerivedKeyToken>
         <ReferenceList xmlns="http://www.w3.org/2001/04/xmlenc#">
            <DataReference URI="#Enc-F8013636-5339-4C25-87CD-C241330865F5"></DataReference>
            <DataReference URI="#Enc-CDF877AC-8347-4903-97D9-E8238C473DC4"></DataReference>
         </ReferenceList>
         <EncryptedData xmlns="http://www.w3.org/2001/04/xmlenc#" 
                        Id="Enc-F8013636-5339-4C25-87CD-C241330865F5" 
                        Type="http://www.w3.org/2001/04/xmlenc#Element">
            <EncryptionMethod Algorithm="[parts omitted]#aes256-cbc"></EncryptionMethod>
            <KeyInfo xmlns="http://www.w3.org/2000/09/xmldsig#">
               <SecurityTokenReference xmlns="[parts omitted]oasis-200401-wss-wssecurity-secext-1.0.xsd">
                  <Reference URI="#Enc-43F73EB2-77EC-4D72-9DAD-17B1781BC49C"></Reference>
               </SecurityTokenReference>
            </KeyInfo>
            <CipherData>
               <CipherValue>ebxkmD[parts omitted]ijtJg==</CipherValue>
            </CipherData>
         </EncryptedData>
         <Signature xmlns="http://www.w3.org/2000/09/xmldsig#">
            <SignedInfo>
               <CanonicalizationMethod Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#">
               </CanonicalizationMethod>
               <SignatureMethod Algorithm="[parts omitted]#hmac-sha1"></SignatureMethod>
               <Reference URI="#Body-C0D7FF05-EE59-41F6-939D-7B2F2B883E5F">
                  <Transforms>
                     <Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"></Transform>
                  </Transforms>
                  <DigestMethod Algorithm="[parts omitted]#sha1"></DigestMethod>
                  <DigestValue>vic7p2selz4Wvm1nAX67p0xF1VI=</DigestValue>
               </Reference>
            </SignedInfo>
            <SignatureValue>TxIBa4a8wX5oFN+eyjjsUuLdn7U=</SignatureValue>
            <KeyInfo>
               <SecurityTokenReference xmlns="[parts omitted]oasis-200401-wss-wssecurity-secext-1.0.xsd">
                  <Reference URI="#Enc-ADE64310-E695-4630-9DA6-A818EF5CEE9D"></Reference>
               </SecurityTokenReference>
            </KeyInfo>
         </Signature>
      </Security>  
   </SOAP-ENV:Header>  
   <SOAP-ENV:Body wsu:Id="Body-C0D7FF05-EE59-41F6-939D-7B2F2B883E5F">
      <EncryptedData xmlns="http://www.w3.org/2001/04/xmlenc#" 
                     Id="Enc-CDF877AC-8347-4903-97D9-E8238C473DC4" 
                     Type="http://www.w3.org/2001/04/xmlenc#Content">
         <EncryptionMethod Algorithm="[parts omitted]#aes256-cbc"></EncryptionMethod>
         <KeyInfo xmlns="http://www.w3.org/2000/09/xmldsig#">
            <SecurityTokenReference xmlns="[parts omitted]oasis-200401-wss-wssecurity-secext-1.0.xsd">
               <Reference URI="#Enc-43F73EB2-77EC-4D72-9DAD-17B1781BC49C"></Reference>
            </SecurityTokenReference>
         </KeyInfo>
         <CipherData>
            <CipherValue>vYtzDsv[parts omitted]GohGsL6</CipherValue>
         </CipherData>
      </EncryptedData>
   </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

対称鍵を使用して暗号化してから署名する方法

対称鍵を使用して暗号化してから署名するには、以下の手順を実行します。

  1. 署名への <DerivedKeyToken> の使用” の各手順を実行します。

  2. 暗号化への <DerivedKeyToken> の使用” の各手順を実行します。

セキュリティ・ヘッダ要素の順序

通常、処理を実行する順序で、セキュリティ要素をセキュリティ・ヘッダに追加する必要があります。メッセージ受信者は、転送参照なしで、メッセージを最初から最後まで処理できる必要があります。

以下のテーブルは、非対称鍵を使用したときに、結果として得られるセキュリティ・ヘッダ要素の順序のリストを示しています (このシナリオでは、非対称鍵バインディングを使用します)。

署名してから暗号化 暗号化してから署名
  1. その他のヘッダ要素

  2. <EncryptedKey>

  3. <Signature>

  1. その他のヘッダ要素

  2. <EncryptedKey>

  3. <Signature>

  4. <ReferenceList>

以下のテーブルは、対称鍵を使用したときに、結果として得られるセキュリティ・ヘッダ要素の順序のリストを示しています (このシナリオでは、対称鍵バインディングを使用します)。

署名してから暗号化 暗号化してから署名
  1. その他のヘッダ要素

  2. <EncryptedKey>

  3. <DerivedKeyToken>

  4. <DerivedKeyToken>

  5. <ReferenceList>

  6. <Signature>

  1. その他のヘッダ要素

  2. <EncryptedKey>

  3. <DerivedKeyToken>

  4. <DerivedKeyToken>

  5. <Signature>

  6. <ReferenceList>

FeedbackOpens in a new tab