科技行者

行者学院 转型私董会 科技行者专题报道 网红大战科技行者

知识库

知识库 安全导航

至顶网软件频道使用XML-Encryption实现安全SOAP消息

使用XML-Encryption实现安全SOAP消息

  • 扫一扫
    分享文章到微信

  • 扫一扫
    关注官方公众号
    至顶头条

  自1977年以来,使用最为广泛的加密算法是数据加密标准(Data Encryption Standard,DES)。但是事实表明,由于近几年计算能力的极大提高,DES可以在一天之内被攻破。所以2001年。

作者:中国IT实验室 来源:中国IT实验室 2007年9月22日

关键字: SOAP 编程 java

  • 评论
  • 分享微博
  • 分享邮件

  自1977年以来,使用最为广泛的加密算法是数据加密标准(Data Encryption Standard,DES)。但是事实表明,由于近几年计算能力的极大提高,DES可以在一天之内被攻破。所以2001年,联邦政府引入了一个新的标准:高级加密标准(Advanced Encryption Standard,AES)。DES和AES使用的都是对称密钥加密算法。顾名思义,其加密和解密是使用同一个密码块进行的。在一个客户-服务器环境中,如何创建、分发用于加密和解密消息的密钥并对其达成协议是首要的问题。

  XML-Encryption指定EncryptedKey机制,使用RSA――一种公钥加密体制――来加密密钥。我们需要记住,在非对称加密中,我们使用公钥来加密,而使用私钥来解密。所以,密钥由消息发送方创建,并使用接收方的公钥进行加密。然后用于加密的密钥会包含在消息中。接收方根据KeyInfo元素得出解密密钥(私钥)。

  让我们来详细看一下由WebLogic Server 9.0所生成的示例消息:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
  <soapenv:Header>
    <wsse:Security
      xmlns:wsse="…/oasis-200401-wss-wssecurity-secext-1.0.xsd"
      soapenv:mustUnderstand="1">
       <ns1:EncryptedKey Id="encrypt"
           xmlns:ns1="http://www.w3.org/2001/04/xmlenc#">
       <ns1:EncryptionMethod Algorithm="…#rsa-1_5"/>
       <ns2:KeyInfo xmlns:ns2="…/xmldsig#">
         <wsse:SecurityTokenReference wsu:Id="Dk8Xm"
             xmlns:wsu="…/oasis-200401-wss-wssecurity-utility-1.0.xsd"
             xmlns:wsse="…/oasis-200401-wss-wssecurity-secext1.0.xsd">
             <ns2:X509Data>
                <ns2:X509IssuerSerial>
                   <ns2:X509IssuerName>CN=CertGenCAB…C=US</ns2:X509IssuerName>
                   <ns2:X509SerialNumber>-</ns2:X509SerialNumber>
                </ns2:X509IssuerSerial>
             </ns2:X509Data>
          </wsse:SecurityTokenReference>
       </ns2:KeyInfo>
       <ns1:CipherData>
            <ns1:CipherValue>aSMjPEHitl/2doflGwDQ==</ns1:CipherValue>
       </ns1:CipherData>
       <ns1:ReferenceList>
           <ns1:DataReference URI="#Dk8Zw31"/>
       </ns1:ReferenceList>
     </ns1:EncryptedKey>
    </wsse:Security>
   </soapenv:Header>
   <soapenv:Body>
      <ns1:EncryptedData Id=" Dk8Zw31" Type="…#Content"
         MimeType="text/xml" Encoding="UTF-8" xmlns:ns1="…/xmlenc#">
         <ns1:EncryptionMethod Algorithm="…#tripledescbc"/>
         <ns1:CipherData>
            <ns1:CipherValue>2HIkjvUdSL9qpqhP</ns1:CipherValue>
         </ns1:CipherData>
       </ns1:EncryptedData>
   </soapenv:Body>
</soapenv:Envelope>

  SecurityTokenReference元素指定接收方的X509证书的X509IssuerSerial。接收方应该能够从密钥库查找相应的私钥来执行解密操作。除了X509IssuerSerial,X509证书的Subject Key Identifier (SKID)也可以用来描述用于加密的密钥。

<wsse:SecurityTokenReference>
  <wsse:KeyIdentifier
    ValueType="...#X509SubjectKeyIdentifier">
      Xeg55vRyK3ZhAEhEf+YT0z986L0=
  </wsse:KeyIdentifier>
</wsse:SecurityTokenReference>

  如果X509证书中包含SKID,WebLogic Server 9.0就总会在SecurityTokenReference中生成KeyIdentifier。而如果X509证书中没有SKID,那么就会在SecurityTokenReference中使用X509IssuerSerial。

  只要响应消息需要加密,客户端就会将它的公钥作为请求消息的一部分发送,以便服务器使用其中的密钥来加密响应消息。

<soapenv:Envelope
   xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
   <soapenv:Header>
     <wsse:Security
       xmlns:wsse=".../oasis-200401 wss-wssecurity-secext-1.0.xsd"
       soapenv:mustUnderstand="1">
       <wsse:BinarySecurityToken wsu:Id="encrypt-token"
          xmlns:wsu="…/oasis-200401-wss-wssecurity-utility-1.0.xsd"
          ValueType="…#X509v3"
          EncodingType="…#Base64Binary">BZEWX…
       </wsse:BinarySecurityToken>
     </wsse:Security>
   </soapenv:Header>
   <soapenv:Body>
       <m:encryptResponse xmlns:m="http://dev2dev.bea.com">
          <m:s>Only response message isencrypted!</m:s>
       </m:encryptResponse>
   </soapenv:Body>
</soapenv:Envelope>

查看本文来源

    • 评论
    • 分享微博
    • 分享邮件