263.4. 在 PGP 签名验证过程中限制签名身份

自 Camel 2.12.3 起.

如果您验证签名不仅要验证签名的正确性,而且您还需要检查签名是否来自特定身份或一组特定的身份。因此,可以限制公共密钥环中的公钥数量,这些公钥可用于验证签名。 

签名用户 ID

// specify the User IDs of the expected signer identities
 List<String> expectedSigUserIds = new ArrayList<String>();
 expectedSigUserIds.add("Trusted company1");
 expectedSigUserIds.add("Trusted company2");
 
 PGPDataFormat pgpVerifyWithSpecificKeysAndDecrypt = new PGPDataFormat();
 pgpVerifyWithSpecificKeysAndDecrypt.setPassword("my password"); // for decrypting with private key
 pgpVerifyWithSpecificKeysAndDecrypt.setKeyFileName(keyfileName);
 pgpVerifyWithSpecificKeysAndDecrypt.setSignatureKeyFileName(signatgureKeyfileName);
 pgpVerifyWithSpecificKeysAndDecrypt.setSignatureKeyUserids(expectedSigUserIds); // if you have only one signer identity then you can also use setSignatureKeyUserid("expected Signer")
 
from("direct:start")
         ...
        .unmarshal(pgpVerifyWithSpecificKeysAndDecrypt)
        ...
  • 如果 PGP 内容有几个签名,则在验证一个签名后立即进行验证。
  • 如果您不想限制 signer 身份进行验证,请不要指定签名密钥用户 ID。在这种情况下,公共密钥环中的所有公钥都会被考虑。