我使用PDFBOX创建了一个PDF PAdES签名,我正在使用ETSI在线验证器1 (它需要注册),现在我在报告中只得到了两个错误,但是我有点不知道它们是什么,或者如何修复它们。
这是etsi在线验证器报告:

这是我用来签名的代码:
@Override
public byte[] sign(InputStream content) throws IOException {
try {
CMSSignedDataGenerator signGenerator = new CMSSignedDataGenerator();
X509Certificate userCert = (X509Certificate) this.certificateChain[0];
ContentSigner mySigner = new CustomSigner(this.signerKeyHandle);
// TODO check to use cavium as digest provider
MessageDigest md = MessageDigest.getInstance("SHA-256", "Cavium");
md.update(userCert.getEncoded());
byte[] userCertHash = md.digest();
X509CertificateHolder issuerCert = new X509CertificateHolder(this.certificateChain[1].getEncoded());
// IssuerSerial is = new IssuerSerial(issuerCert.get,
// issuerCert.getSerialNumber());
ESSCertIDv2 certid = new ESSCertIDv2(new AlgorithmIdentifier(NISTObjectIdentifiers.id_sha256),
userCertHash);
ESSCertIDv2[] essCert1Arr = { certid };
SigningCertificateV2 sigcert = new SigningCertificateV2(certid);
final DERSet attrValues = new DERSet(sigcert);
Attribute attr = new Attribute(PKCSObjectIdentifiers.id_aa_signingCertificateV2, attrValues);
ASN1EncodableVector v = new ASN1EncodableVector();
v.add(attr);
AttributeTable atttributeTable = new AttributeTable(v);
//Create a standard attribute table from the passed in parameters - certhash
CMSAttributeTableGenerator attrGen = new DefaultSignedAttributeTableGenerator(atttributeTable){
protected Hashtable createStandardAttributeTable(Map parameters)
{
Hashtable result = super.createStandardAttributeTable(parameters);
result.remove(CMSAttributes.signingTime);
return result;
}
};
JcaSignerInfoGeneratorBuilder signerBuilder = new JcaSignerInfoGeneratorBuilder( new JcaDigestCalculatorProviderBuilder().build());
signerBuilder.setSignedAttributeGenerator(attrGen);
SignerInfoGenerator signerInfoGenerator = signerBuilder.build(mySigner, userCert);
signGenerator.addSignerInfoGenerator(signerInfoGenerator);
signGenerator.addCertificates(new JcaCertStore(Arrays.asList(certificateChain)));
CMSProcessableInputStream msg = new CMSProcessableInputStream(content);
CMSSignedData signedData = signGenerator.generate(msg, false);
return signedData.getEncoded();
} catch (GeneralSecurityException | CMSException | OperatorCreationException e) {
System.err.println(e.getMessage());
throw new RuntimeException("unable to sign pdf!");
}
}我不太清楚这些问题会发生在哪里,也不知道为什么会产生这些问题,起初我有5个问题,现在只剩下这两个问题,所以我们非常感谢你的任何投入。
发布于 2020-10-22 15:20:50
原来的问题
您使用DefaultSignedAttributeTableGenerator
signerBuilder.setSignedAttributeGenerator(new DefaultSignedAttributeTableGenerator(new AttributeTable(v)));根据其JavaDocs,它将
/* Create a standard attribute table from the passed in parameters - this will
* normally include contentType, signingTime, messageDigest, and CMS algorithm protection.
* If the constructor using an AttributeTable was used, entries in it for contentType, signingTime, and
* messageDigest will override the generated ones.特别是,它将创建一个signingTime签名属性。
但是对于(非遗留的) PAdES签名,嵌入的CMS容器不能包含signingTime属性,请参阅ETSI EN 319 142-1节6.3中的基线签名。
SPO: CMS签名中的签名时间属性.将不在场
而原来的ETSI TS 102 778-3节第4.5.3节为帕德斯-贝斯和帕德斯-埃普斯签名要求
不应使用签名时间属性。
(严格地说,目前的ETSI EN 319 142-2 PAdES和PAdES配置文件似乎不再禁止使用,他们只是建议使用M签名字典条目。但是对于BES/EPES的软件检查通常仍然是基于旧的TS,这是禁止的,见上文。现在我们应该去做基线签名。)
因此,您应该使用不包含签名时间属性的CMSAttributeTableGenerator实现,例如复制DefaultSignedAttributeTableGenerator代码并从其createStandardAttributeTable方法中删除签名时间。
更新的问题
在一条评论中,您说在解决了上面的问题后,仍然存在一个错误:
现在,这是唯一的一个错误,它的数字63说,Location-{CodeTest}:Contents/CAdESSignature/content/signedData/signerInfos/signerInfo1/signedAttrs/attribute4/attrValues/NotKnownComponent1-{ForAllTheChildrenDo},一个未知的组件已经到达。因此,它的孩子和他们的处理是未知的TLCC。将不再对此组件进行检查。
从2011年4月开始,SignerInfo中的最后(第四个)签名属性是一个根据RFC 6211的算法标识符保护属性。考虑到ETSI签名一致性检查器的历史,它可能确实不知道这个属性。
如果希望一致性检查器不显示该错误,只需从DefaultSignedAttributeTableGenerator的标准属性表中删除该属性,就像删除签名时间属性一样。
https://stackoverflow.com/questions/64474359
复制相似问题