首页 | 新闻 | 新品 | 文库 | 方案 | 视频 | 下载 | 商城 | 开发板 | 数据中心 | 座谈新版 | 培训 | 工具 | 博客 | 论坛 | 百科 | GEC | 活动 | 主题月 | 电子展
返回列表 回复 发帖

在 Web 上发布重要的公共警报(2)

在 Web 上发布重要的公共警报(2)

对 CAP 警报进行数字签名经过数字签名的 CAP 警报允许收件人检验这个警报的真实性。在处理公共安全情况时,这种安全措施对于确保警报分布系统不被滥用是非常重要的。
为了使用示例实现对警报进行签名,需要可选的 Abdera 安全模块、用来产生数字签名的私钥和一个 X.509 证书(其中包含用来检验签名的公钥)。 演示了这个过程。对 getSignatureOptions(...) 的调用为签名过程准备私钥和 X.509 证书。
清单 4. 对 CAP 警报进行数字签名
1
2
3
4
5
6
7
Abdera abdera = new Abdera();
//... create the Alert document
AbderaSecurity absec = new AbderaSecurity(abdera);
Signature sig = absec.getSignature();
SignatureOptions sigoptions = getSignatureOptions(sig);

doc = sig.sign(doc.getRoot(), sigoptions).getDocument();




在签名之后,警报文档就包含一个封装的签名,其中包含 X.509 证书,如  所示。
清单 5. 经过数字签名的 CAP 警报
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
<alert xmlns="urnasis:names:tc:emergency:cap:1.1">
  <identifier>ABC123DEF456</identifier>
  <sender>jasnell@example.org</sender>
  <sent>2007-06-30T19:15:32.468Z</sent>
  <status>Actual</status>
  <info>...</info>
  <ds:Signature xmlns:ds="http://www.w3.org/2000/09/xmldsig#">
    <ds:SignedInfo>
      <ds:CanonicalizationMethod
        Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-20010315" />
      <ds:SignatureMethod
        Algorithm="http://www.w3.org/2000/09/xmldsig#dsa-sha1" />
      <ds:Reference URI="">
        <ds:Transforms>
          <ds:Transform
            Algorithm="http://www.w3.org/2000/09/xmldsig#enveloped-signature" />
          <ds:Transform
            Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#" />
        </ds:Transforms>
        <dsigestMethod
          Algorithm="http://www.w3.org/2000/09/xmldsig#sha1" />
        <dsigestValue>...</dsigestValue>
      </ds:Reference>
    </ds:SignedInfo>
    <ds:SignatureValue>...</ds:SignatureValue>
    <ds:KeyInfo>
      <ds:X509Data>
        <ds:X509Certificate>
          ...
        </ds:X509Certificate>
      </ds:X509Data>
    </ds:KeyInfo>
  </ds:Signature>
</alert>




在生成数字签名之后,如果警报的任何部分被修改了,那么签名就会失效。如果签名是有效的,而且签名中的 X.509 证书是可信的,那么收件人就可以认为警报是可信的,至少没有被第三方修改过。
在包含 X.509 证书的签名的警报中,包含检验签名所需的所有信息,见 。
清单 6. 检验经过数字签名的 CAP 警报
1
2
3
4
5
6
Abdera abdera = new Abdera();
//... parse the Alert document
AbderaSecurity absec = new AbderaSecurity(abdera);
Signature sig = absec.getSignature();

boolean isValid = sig.verify(doc.getRoot(),null);




这个示例应用程序要求通过 Atom Publishing Protocol 发布的所有 CAP 警报都包含有效的数字签名。另外,它以一种特定的方式重新分布这些警报,能够让签名在分布之后仍然有效。
对 CAP 警报进行加密警报常常包含机密信息,只有经过适当授权的某些人才能访问这些信息。尽管可以按照许多方式确保警报的机密性,但是 CAP 规范明确要求支持 XML Encryption。这里的示例应用程序没有使用加密的文档,但是基于 Abdera 的实现可以轻松地处理这种加密,见 。
清单 7. 对 CAP 警报进行加密
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
Alert alert = //... create the CAP Alert

String jceAlgorithmName = "AES";
KeyGenerator keyGenerator =
    KeyGenerator.getInstance(jceAlgorithmName);
keyGenerator.init(128);
SecretKey key = keyGenerator.generateKey();

AbderaSecurity absec = new AbderaSecurity(abdera);

Encryption enc = absec.getEncryption();
EncryptionOptions options = enc.getDefaultEncryptionOptions();
options.setDataEncryptionKey(key);

// Encrypt the document using the generated key
Document enc_doc = enc.encrypt(alert.getDocument(), options);




在这个示例中,使用一个对称密钥对警报文档进行加密,接收方必须知道这个密钥才能对文档进行解密。使用对称密钥只是为了简化这个示例。使用公钥/私钥对的非对称密钥加密或者 Diffie-Hellman 等密钥交换方法也是可行的,而且在某些情况下建议采用这些更安全的方法。 的结果是一个加密的 XML 文档,见 (缩略形式)。
清单 8. 加密的 CAP 警报
1
2
3
4
5
6
7
8
9
10
<?xml version='1.0' encoding='utf-8'?>
<xenc:EncryptedData
  xmlns:xenc="http://www.w3.org/2001/04/xmlenc#"
  Type="http://www.w3.org/2001/04/xmlenc#Element">
  <xenc:EncryptionMethod
    Algorithm="http://www.w3.org/2001/04/xmlenc#aes128-cbc" />
  <xenc:CipherData>
    <xenc:CipherValue>...</xenc:CipherValue>
  </xenc:CipherData>
</xenc:EncryptedData>




因为许多攻击方法无需破解密码,就可以修改加密的数据,所以在对警报文档进行加密之前,强烈建议先进行数字签名,以防止这些攻击。
返回列表