目前我们使用 jarsigner 来签署我们的 jar。然后,我们会显示某些特定类的一些 SHA1-Digest 值,以向外部审计员证明代码在不同版本之间没有更改。
我们只依赖META-INF/xxx.SF
文件来获取摘要信息,我们从不使用META-INF/xxx.DSA
签名 block 文件.
因为我们只需要在代码中进行摘要计算,所以我想知道是否可以使用某些 java 工具生成 .SF
文件而不实际使用 key 。
我读了http://docs.oracle.com/javase/6/docs/technotes/tools/windows/jarsigner.html但看起来 key 是强制性的。
最佳答案
这应该是可能的。 MANIFEST.MF 文件包含相应类文件的 Base64 编码 SHA-1。
来自您的文档:
In the manifest file, the SHA digest value for each source file is the
digest (hash) of the binary data in the source file. In the .SF file,
on the other hand, the digest value for a given source file is the
hash of the three lines in the manifest file for the source file.
因此,遍历所有类文件,计算 SHA-1,按照它出现在 MANIFEST.MF 中的方式进行格式化,然后对其进行哈希处理并按照它出现在 SF 文件中的方式进行格式化。
计算中不涉及 key 。
示例:考虑“jce1_2_2.jar”(或您已正确签名的任何内容)。这包含
MANIFEST.MF 形式的条目
Name: javax/crypto/KeyAgreement.class SHA1-Digest: c2p0JimzpV0dG+NChGLl5cI7MuY= <empty line>
它们是“KeyAgreement.class”的 Base64(SHA1-1)(路径不相关)。注意第三个空行。行结尾是 CRLF (Windows)。
META-INF/4JCEJARS.SF 条目
Name: javax/crypto/KeyAgreement.class SHA1-Digest: whGBXE+AvYO6wAoVCdnocOPIrsE=
这不是文件的哈希值,而是上面三行的哈希值。
关于java - 是否可以在 java Manifest 文件中使用 SHA1-Digest 而无需实际使用 key ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9275780/