美文网首页
第二十二章 加密 SOAP 主体 - 变体:使用签名的 SAML

第二十二章 加密 SOAP 主体 - 变体:使用签名的 SAML

作者: Cache技术分享 | 来源:发表于2024-09-11 09:00 被阅读0次

第二十二章 加密 SOAP 主体 - 变体:使用签名的 SAML 断言

要使用签名的 SAML 断言中的证书中包含的公钥进行加密,请执行以下操作:

  1. 跳过前面步骤中的步骤 1–4
  2. 使用 Holder-of-key 方法的 <SubjectConfirmation>元素创建签名的 SAML 断言。请参阅创建和添加 SAML 令牌。
  3. 创建 <EncryptedKey> 元素。执行此操作时,使用签名的 SAML 断言作为 CreateX509() 类方法的第一个参数。例如:
 set enckey=##class(%XML.Security.EncryptedKey).CreateX509(signedassertion)
  1. 继续前面步骤中的步骤5。

消息加密示例

在此示例中,Web 客户端(未显示)发送签名的请求消息,而 Web 服务发送加密响应。

Web 服务从请求消息签名中的客户端证书中获取公钥,并使用该公钥在其响应中添加一个加密的 <EncryptedKey> 元素。 <EncryptedKey> 元素使用客户端的公钥加密,它包含用于加密响应消息正文的对称密钥。

Web服务如下:

Class XMLEncr.DivideWS Extends %SOAP.WebService
{

Parameter SECURITYIN = "REQUIRE";

Parameter SERVICENAME = "XMLEncryptionDemo";

Parameter NAMESPACE = "http://www.myapp.org";

Method Divide(arg1 As %Numeric = 2, arg2 As %Numeric = 8) As %Numeric [ WebMethod ]
{
  Do ..EncryptBody() 
  Try {
      Set ans=arg1 / arg2
      } Catch {
      Do ..ApplicationError("division error")
      }
  Quit ans
}

Method EncryptBody()
{
  //Retrieve X.509 certificate from the signature of the inbound request
  Set clientsig = ..SecurityIn.Signature
  Set clientcred = clientsig.X509Credentials
  set bst=##class(%SOAP.Security.BinarySecurityToken).CreateX509Token(clientcred)
  do ..SecurityOut.AddSecurityElement(bst)
  
  //generate a symmetric key, encrypt that with the public key of
  //the certificate contained in the token, and create an 
  //<EncryptedKey> element with a direct reference to the token (default)
  Set enc=##class(%XML.Security.EncryptedKey).CreateX509(bst)
  
  //add the <EncryptedKey> element to the security header
  Do ..SecurityOut.AddSecurityElement(enc)
}

///  Create our own method to produce application specific SOAP faults.
Method ApplicationError(detail As %String)
{
    //details omitted
}

}

该服务发送如下响应消息:

<?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">
            <BinarySecurityToken wsu:Id="SecurityToken-4EC1997A-AD6B-48E3-9E91-8D50C8EA3B53" 
                                 EncodingType="[parts omitted]#Base64Binary" 
                                 ValueType="[parts omitted]#X509v3">
                         MIICnDCCAYQ[parts omitted]ngHKNhh
            </BinarySecurityToken>
            <EncryptedKey xmlns="http://www.w3.org/2001/04/xmlenc#">
               <EncryptionMethod Algorithm="[parts omitted]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">
                     <Reference URI="#SecurityToken-4EC1997A-AD6B-48E3-9E91-8D50C8EA3B53" 
                                ValueType="[parts omitted]#X509v3"></Reference>
                  </SecurityTokenReference>
               </KeyInfo>
               <CipherData>
                  <CipherValue>WtE[parts omitted]bSyvg==</CipherValue>
               </CipherData>
               <ReferenceList>
                  <DataReference URI="#Enc-143BBBAA-B75D-49EB-86AC-B414D818109F"></DataReference>
               </ReferenceList>
            </EncryptedKey>
         </Security>  
      </SOAP-ENV:Header>  
      <SOAP-ENV:Body>
         <EncryptedData xmlns="http://www.w3.org/2001/04/xmlenc#" 
                        Id="Enc-143BBBAA-B75D-49EB-86AC-B414D818109F" 
                        Type="http://www.w3.org/2001/04/xmlenc#Content">
            <EncryptionMethod Algorithm="[parts omitted]#aes128-cbc"></EncryptionMethod>
            <CipherData>
               <CipherValue>MLwR6hvKE0gon[parts omitted]8njiQ==</CipherValue>
            </CipherData>
         </EncryptedData>
      </SOAP-ENV:Body>
   </SOAP-ENV:Envelope>

指定块加密算法

默认情况下,消息本身使用 $$$SOAPWSaes128cbc 加密。您可以指定不同的算法。为此,请设置 %XML.Security.EncryptedKey实例的算法属性。

可能的值是 $$$SOAPWSaes128cbc(默认值)、$$$SOAPWSaes192cbc$$$SOAPWSaes256cbc

例如:

 set enckey.Algorithm=$$$SOAPWSaes256cbc

如其他地方所述,当在其他场景中创建 <EncryptedKey> 时,此信息也适用。

指定密钥传输算法

密钥传输算法是用于对称密钥的公钥加密算法(请参阅 https://www.w3.org/TR/xmlenc-core/)。默认情况下,这是 $$$SOAPWSrsaoaep。可以改用 $$$SOAPWSrsa15。为此,请调用上一步中创建的 %XML.Security.EncryptedKey实例的 SetEncryptionMethod() 方法。此方法的参数可以是 $$$SOAPWSrsaoaep(默认值)或 $$$SOAPWSrsa15

例如:

 do enckey.SetEncryptionMethod($$$SOAPWSrsa15)

如其他地方所述,当您在其他场景中创建<EncryptedKey> 时,此信息也适用。

相关文章

  • SAML Binding

    1. SOAP A system entity acting as a SAML requester transm...

  • 密码学基础(五):证书体系

    摘要算法 略 对称加密 略 非对称加密 略 数字签名 使用摘要算法对原文进行签名后使用rsa的私钥对摘要进行加密。...

  • 数字签名

    签名:用私钥加密 验证:用公钥解密 加密:用公钥加密 解密:用私钥解密 数字签名签名的数据 数字签名主要使用来做数...

  • 网络中的数字签名

    数字签名 防止抵赖、能够检查签名之后是否被更改用私钥进行签名A使用私钥将数据进行加密,之后将原数据和加密之后的数据...

  • Android 中使用系统签名的方法

    Android 中使用系统签名的方法 Android Build中系统签名使用方法 Key的目录 默认加密key是...

  • nodejs 使用md5加密和Python、php的不一样

    当对接腾讯的语音识别相关的api的时候,签名需要使用md5加密,但是我使用node加密后,接口一直说签名无效,原来...

  • openssl

    RSA 加密 关于diff更多使用 详细参考diff 签名 CA 证书 参考 数字签名是什么?

  • RSA加密算法

    RSA加解密、签名验签過程 RSA加密是一种非对称加密,通常使用公钥加密,私钥解密,私钥签名,公钥验签。私钥是個人...

  • Postman中文文档——发出SOAP请求

    发出SOAP请求 使用Postman构造SOAP请求: 给SOAP端点作为URL。如果您正在使用WSDL,则将WS...

  • 计算机安全学-第四次实践作业-2018/4/17

    [new] 1、用Python或Sage实现RSA算法的加密、解密、签名/验证签名使用sage实现RSA算法进行加...

网友评论

      本文标题:第二十二章 加密 SOAP 主体 - 变体:使用签名的 SAML

      本文链接:https://www.haomeiwen.com/subject/gvzuljtx.html