【发布时间】:2015-05-21 22:58:31
【问题描述】:
我生成了一个 PGP 密钥对并将公钥提供给另一方。他们正在加密消息并将其发送给我。我正在使用 Camel Crypto/PGP 尝试解密它。我在 Camel 2.15.0 中有一个简单的路线设置:
from("direct://TestPGPDecrypt")
.routeId("TestPGPDecrypt")
.log(LoggingLevel.INFO, "com.company.camel.flows.CryptoFlows", "Calling PGP Decryption Using PGP Key: " + Vault.TestPGP.keyUserId)
.unmarshal(pgpDecryptTest)
.log(LoggingLevel.INFO, "com.company.camel.flows.CryptoFlows", "Decrypted Original ${header[CamelFileName]}")
这样我传入一个 .asc (Armored-ASCII) 文件,我得到以下异常:
Exchange[
Id ID-MBProi7-54281-1432247325866-1-12
ExchangePattern InOnly
BodyType org.apache.camel.component.file.GenericFile
Body [Body is file based: GenericFile[2015-140-1244-yf3ar85p3zsqpfgk73_resp.asc]]
]
Stacktrace
------------------------------------------------------------------------------------------------------------------------
java.lang.IllegalArgumentException: The input message body has an invalid format.
The PGP decryption/verification processor expects a sequence of PGP packets of
the form (entries in brackets are optional and ellipses indicate repetition,
comma represents sequential composition, and vertical bar separates
alternatives): Public Key Encrypted Session Key ..., Symmetrically Encrypted Data
| Sym. Encrypted and Integrity Protected Data, Compressed Data, (One Pass Signature ...,) Literal Data, (Signature ...,)
at org.apache.camel.converter.crypto.PGPKeyAccessDataFormat.getFormatException(PGPKeyAccessDataFormat.java:488)
at org.apache.camel.converter.crypto.PGPKeyAccessDataFormat.getUncompressedData(PGPKeyAccessDataFormat.java:424)
at org.apache.camel.converter.crypto.PGPKeyAccessDataFormat.unmarshal(PGPKeyAccessDataFormat.java:363)
显然,问题似乎出在“某处”消息的解析上——堆栈显示它在 PGPKeyAccessDataFormat 内的这段代码中:
private InputStream getUncompressedData(InputStream encData) throws IOException, PGPException {
PGPObjectFactory pgpFactory = new PGPObjectFactory(encData, new BcKeyFingerprintCalculator());
Object compObj = pgpFactory.nextObject();
if (!(compObj instanceof PGPCompressedData)) {
throw getFormatException();
}
我不知道为什么这个输入流没有作为 PGPCompressedData 的实例返回...
如果我使用 gpg 在本地 (Unix/Mac OS X) 解密此文件 - 没问题。事实上,我可以看到详细运行的输出。
如果我加密本地文件,然后尝试通过 Camel Crypto 对其进行解密,则没有问题
我只有这个文件有问题。 我什至尝试调整 PGPDataFormat 的配置,但无济于事:
PGPDataFormat pgpDecryptTest = new PGPDataFormat();
pgpDecryptTest.setKeyFileName(Vault.secret.keyFileName);
pgpDecryptTest.setKeyUserid(Vault.secret.keyUserId);
pgpDecryptTest.setArmored(true);
pgpDecryptTest.setPassword(Vault.secret.getTestKeyRingPwd());
pgpDecryptTest.setIntegrity(false);
pgpDecryptTest.setHashAlgorithm(HashAlgorithmTags.SHA1);
pgpDecryptTest.setAlgorithm(SymmetricKeyAlgorithmTags.TRIPLE_DES);
pgpDecryptTest.setSignatureKeyFileName(Vault.TRDParty.keyFileName);
pgpDecryptTest.setSignatureKeyUserid(Vault.TRDParty.keyUserId);
pgpDecryptTest.setSignatureVerificationOption("ignore");
有什么想法吗? [编辑] 根据请求,这里是有关 PGP 数据包的信息。 Camel解密有问题的加密文件:
gpg --list-packets 2015-140-1244-yf3ar85p3zsqpfgk73_resp.asc
:pubkey enc packet: version 3, algo 1, keyid xxxxxxxxxxxxxxx
data: [2046 bits]
You need a passphrase to unlock the secret key for
user: "Your Key <you@company.com>"
2048-bit RSA key, ID XXXXXXXX, created 2015-05-18 (main key ID YYYYYYYYY)
:encrypted data packet:
length: 52051
gpg: encrypted with 2048-bit RSA key, ID XXXXXXXX, created 2015-05-18
"Your Key <you@company.com>"
:onepass_sig packet: keyid ABVBBBBBBBBBB
version 3, sigclass 0x00, digest 2, pubkey 17, last=1
:literal data packet:
mode b (62), created 1432151886, name="",
raw data: 51945 bytes
:signature packet: algo 17, keyid CCCCCCCCCCCCCC
version 4, created 1432151886, md5len 0, sigclass 0x00
digest algo 2, begin of digest e4 5a
hashed subpkt 2 len 4 (sig created 2015-05-20)
subpkt 16 len 8 (issuer key ID CCCCCCCCCCCCCC)
data: [159 bits]
data: [160 bits]
gpg: WARNING: message was not integrity protected
然后进行比较,我使用 gpg 对同一文件内容的(明文版本)进行了加密,然后在其上运行列表数据包:
gpg --list-packets encrypted.asc
:pubkey enc packet: version 3, algo 1, keyid XXXXXXXXXXX
data: [2045 bits]
You need a passphrase to unlock the secret key for
user: "Your Key <you@company.com>"
2048-bit RSA key, ID 8EFFC26E, created 2015-05-18 (main key ID YYYYYYYYY)
:encrypted data packet:
length: unknown
mdc_method: 2
gpg: encrypted with 2048-bit RSA key, ID XXXXXXXX, created 2015-05-18
"Your Key <you@company.com>"
:compressed packet: algo=2
:literal data packet:
mode b (62), created 1432321235, name="clear.out.xml",
raw data: 51945 bytes
【问题讨论】:
-
您能否在您的问题中转储
gpg --list-packets [encrypted-file]的输出?如果需要,您可以剥离密钥 ID;我担心它包含 Apache Camel 不支持的任何功能。不过,我找不到任何描述受支持内容的 Camel 规格表,但我们可能会在其中找到“可疑的”OpenPGP 数据包或算法。 -
形成我能说的:在 Mac OS X 上使用我的本地工具 - 我正在使用:GPG 工具,Camel 阅读这个没有问题(这也是我获得列表数据包的方式在工作示例中)。另一方面,无法在 Camel 中运行的版本是使用 Cryptix Open PGP 构建的 - 我四处搜索 one_pass_sig 数据包,但还有其他一些关于它的投诉
-
原始数据不仅经过加密,而且还使用DSA密钥进行了签名,但这应该没有问题; DSA 已经被指定了很长时间。进一步阅读错误消息并与您发布的数据包结构信息进行比较,您似乎调用了一个用于解密对称加密数据包的函数。您之前可能需要调用其他一些函数。
-
我的假设是,如果是密钥错误,那么它应该只是抛出一个关于密钥错误/无效,未找到的异常。根据错误所说的内容(根据编写消息的开发人员),它正在寻找:“压缩数据”,然后是可选的一次传递。我认为它缺少压缩数据,这正是异常所抱怨的。关闭加密不起作用 - 该错误并不表示压缩数据是可选的。我的工作示例有 :compressed packet: algo=2 (Zlib)
-
嗨,@BoneSmuggler 你找到问题的根本原因了吗?
标签: java encryption apache-camel pgp