我们想创建一个验证“XADES”签名的 java web 应用程序,这个应用程序应该有两个文件:原始文件和他的分离签名。
我正在使用 XADES4j 库,这是一个很棒的项目。使用 XADES4j 是否可以在不验证 URI 文件参考的情况下验证签名?因为无法访问 xml 签名中的给定参考文件。
参考验证:我希望比较从给定的原始文件计算的摘要值和从签名文件中提取的摘要值。
这是例外
Exception in thread "main" xades4j.XAdES4jXMLSigException: Error verifying the signature
at xades4j.verification.XadesVerifierImpl.doCoreVerification(XadesVerifierImpl.java:285)
at xades4j.verification.XadesVerifierImpl.verify(XadesVerifierImpl.java:188)
at com.wct.VerifyXades.main(VerifyXades.java:33)
Caused by: org.apache.xml.security.signature.MissingResourceFailureException: The Reference for URI file:/D:/workspace/xades4j-487d7a9bb9e5/data_to_sign/test.txt has no XMLSignatureInput
Original Exception was org.apache.xml.security.signature.ReferenceNotInitializedException: D:\workspace\xades4j-487d7a9bb9e5\data_to_sign\test.txt (Le fichier spécifié est introuvable)
Original Exception was org.apache.xml.security.signature.ReferenceNotInitializedException: D:\workspace\xades4j-487d7a9bb9e5\data_to_sign\test.txt (Le fichier spécifié est introuvable)
Original Exception was org.apache.xml.security.signature.ReferenceNotInitializedException: D:\workspace\xades4j-487d7a9bb9e5\data_to_sign\test.txt (Le fichier spécifié est introuvable)
Original Exception was org.apache.xml.security.utils.resolver.ResourceResolverException: D:\workspace\xades4j-487d7a9bb9e5\data_to_sign\test.txt (Le fichier spécifié est introuvable)
Original Exception was java.io.FileNotFoundException: D:\workspace\xades4j-487d7a9bb9e5\data_to_sign\test.txt (Le fichier spécifié est introuvable)
at org.apache.xml.security.signature.Manifest.verifyReferences(Manifest.java:412)
at org.apache.xml.security.signature.SignedInfo.verify(SignedInfo.java:256)
at org.apache.xml.security.signature.XMLSignature.checkSignatureValue(XMLSignature.java:764)
at org.apache.xml.security.signature.XMLSignature.checkSignatureValue(XMLSignature.java:696)
at xades4j.verification.XadesVerifierImpl.doCoreVerification(XadesVerifierImpl.java:278)
... 2 more
这是我用来验证 XADES 签名的源代码:
package com.wct;
import java.io.FileInputStream;
import java.security.cert.X509CertSelector;
import java.security.cert.X509Certificate;
import java.util.Collection;
import java.util.Date;
import java.util.List;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import org.w3c.dom.Document;
import xades4j.providers.CertificateValidationException;
import xades4j.providers.CertificateValidationProvider;
import xades4j.providers.ValidationData;
import xades4j.verification.UnexpectedJCAException;
import xades4j.verification.XAdESVerificationResult;
import xades4j.verification.XadesVerificationProfile;
import xades4j.verification.XadesVerifier;
public class VerifyXades {
public static void main(String[] args) throws Exception {
CertificateValidationProvider certValidator = new CertificateValidationProviderImpl();
XadesVerificationProfile p = new XadesVerificationProfile(certValidator);
p.acceptUnknownProperties(true);
XadesVerifier v = p.newVerifier();
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
dbf.setNamespaceAware(true);
DocumentBuilder db = dbf.newDocumentBuilder();
Document doc = db.parse(new FileInputStream("data_signed/detachedTestSignature.xml"));
XAdESVerificationResult vr = v.verify(doc.getDocumentElement(), null);
}
}
class CertificateValidationProviderImpl implements CertificateValidationProvider {
@Override
public ValidationData validate(X509CertSelector certSelector,
Date validationDate, Collection<X509Certificate> otherCerts)
throws CertificateValidationException, UnexpectedJCAException {
return new ValidationData((List<X509Certificate>) otherCerts);
}
}
我是签名/验证开发的新手,我没有很好的经验。请帮忙
提前感谢您的帮助