Я пытаюсь передать <NextMsg ID="Edoc">2019-09-20T14:57:46</NextMsg>
функции и подписать ее цифровой подписью, завернутой в корень <EDoc></Edoc>
тег
Это ожидаемый результат:
<?xml version="1.0" encoding="UTF-8"?>
<EDoc>
<NextMsg ID="Edoc">2019-09-20T14:57:46</NextMsg>
<Signature xmlns="http://www.w3.org/2000/09/xmldsig#" Id="DS_A2B2112853C1478C8860CB8DC6FA23D2">
<SignedInfo>
<CanonicalizationMethod Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-20010315"/>
<SignatureMethod Algorithm="http://www.w3.org/2001/04/xmldsig-more#rsa-sha256"/>
<Reference URI="">
<Transforms>
<Transform Algorithm="http://www.w3.org/2000/09/xmldsig#enveloped-signature"/>
</Transforms>
<DigestMethod Algorithm="http://www.w3.org/2001/04/xmlenc#sha256"/>
<DigestValue>op0/fC+H5/0h7AGdUiEaNnNzd9WXs3VDouQQhRk8XgU=</DigestValue>
</Reference>
<Reference URI="#SP_A2B2112853C1478C8860CB8DC6FA23D2" Type="http://uri.etsi.org/01903/v1.1.1#SignedProperties">
<DigestMethod Algorithm="http://www.w3.org/2001/04/xmlenc#sha256"/>
<DigestValue>Kv75qkIImVnf9H7PZV+1er1n8YIBY5yRGXdpWSUIAX4=</DigestValue>
</Reference>
</SignedInfo>
<SignatureValue>=sign-value=</SignatureValue>
<ds:Object xmlns="http://uri.etsi.org/01903/v1.1.1#" xmlns:ds="http://www.w3.org/2000/09/xmldsig#">
<QualifyingPropertiesReference URI="http://www.test.com"/>
<QualifyingProperties Target="#DS_A2B2112853C1478C8860CB8DC6FA23D2">
<SignedProperties Id="SP_A2B2112853C1478C8860CB8DC6FA23D2">
<SignedSignatureProperties>
<SigningTime>2019-09-20T14:57:48+03:00</SigningTime>
<SigningCertificate>
<Cert>
<CertDigest>
<DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"/>
<DigestValue>woG3fsImDUeqxznickzLkpeY9R4=</DigestValue>
</CertDigest>
<IssuerSerial>
<ds:X509IssuerName>XXX</ds:X509IssuerName>
<ds:X509SerialNumber>YYY</ds:X509SerialNumber>
</IssuerSerial>
</Cert>
</SigningCertificate>
<SignaturePolicyIdentifier>
<SignaturePolicyImplied/>
</SignaturePolicyIdentifier>
</SignedSignatureProperties>
</SignedProperties>
</QualifyingProperties>
</ds:Object>
</Signature>
</EDoc>
мой фактическийфункция такова:
public static String getSignatureXadesTBes(String xmlrequest, PrivateKey pk, X509Certificate cert) throws
javax.xml.parsers.ParserConfigurationException, org.xml.sax.SAXException, java.io.FileNotFoundException,
javax.xml.transform.TransformerConfigurationException, javax.xml.transform.TransformerException,
javax.xml.transform.TransformerException, java.io.IOException, java.security.KeyStoreException,
xades4j.XAdES4jException
{
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
InputSource is = new InputSource(new StringReader(xmlrequest));
Document doc = dbf.newDocumentBuilder().parse(is);
Element elem = doc.getDocumentElement();
DOMHelper.useIdAsXmlId(elem);
KeyingDataProvider keyingProvider = new DirectKeyingDataProvider(cert, pk);
DataObjectDesc obj = new DataObjectReference("")
.withTransform(new EnvelopedSignatureTransform());
SignedDataObjects dataObjs = new SignedDataObjects().withSignedDataObject(obj);
XadesSigningProfile p = new XadesTSigningProfile(keyingProvider);
p.withTimeStampTokenProvider(
new DefaultTimeStampTokenProvider(
new DefaultMessageDigestProvider()
));
BasicSignatureOptionsProvider sop = new DefaultBasicSignatureOptionsProvider(false, false, false);
p.withBasicSignatureOptionsProvider(sop);
AlgorithmsProviderEx ap = new DefaultAlgorithmsProviderEx() {
@Override
public String getDigestAlgorithmForDataObjsReferences() {
return MessageDigestAlgorithm.ALGO_ID_DIGEST_SHA256;
}
@Override
public String getDigestAlgorithmForReferenceProperties() {
return MessageDigestAlgorithm.ALGO_ID_DIGEST_SHA1;
}
@Override
public Algorithm getSignatureAlgorithm(String keyAlgorithmName) throws UnsupportedAlgorithmException {
return new GenericAlgorithm(XMLSignature.ALGO_ID_SIGNATURE_RSA_SHA256);
}
};
p.withAlgorithmsProviderEx(ap);
XadesSigner signer = p.newSigner();
XadesSignatureResult result = signer.sign(dataObjs, elem);
XMLSignature signature = result.getSignature();
Document docs = signature.getDocument();
OutputStream os = new FileOutputStream("..\\cfgFiles\\out_xades.xml");
XMLUtils.outputDOM(doc, os);
}
Но это приводит к
<NextMsg Id="Edoc">2019-09-20T14:57:46<ds:Signature xmlns:ds="http://www.w3.org/2000/09/xmldsig#" Id="xmldsig-24f667da-ced7-4727-b107-0daa2be5b690">
<ds:SignedInfo>
<ds:CanonicalizationMethod Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-20010315"/>
<ds:SignatureMethod Algorithm="http://www.w3.org/2001/04/xmldsig-more#rsa-sha256"/>
<ds:Reference Id="xmldsig-24f667da-ced7-4727-b107-0daa2be5b690-ref0" URI="">
<ds:Transforms>
<ds:Transform Algorithm="http://www.w3.org/2000/09/xmldsig#enveloped-signature"/>
</ds:Transforms>
<ds:DigestMethod Algorithm="http://www.w3.org/2001/04/xmlenc#sha256"/>
<ds:DigestValue>8t2TvSeJ1iz7XTyYV7VHYJtTRLrbx/72Z35rkyEBGLs=</ds:DigestValue>
</ds:Reference>
<ds:Reference Type="http://uri.etsi.org/01903#SignedProperties" URI="#xmldsig-24f667da-ced7-4727-b107-0daa2be5b690-signedprops">
<ds:Transforms>
<ds:Transform Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-20010315"/>
</ds:Transforms>
<ds:DigestMethod Algorithm="http://www.w3.org/2001/04/xmlenc#sha256"/>
<ds:DigestValue>t6UMqsiPZoXoxf7wOOg+beyztdEjD4u5GjWMrlyS1nI=</ds:DigestValue>
</ds:Reference>
</ds:SignedInfo>
<ds:SignatureValue Id="xmldsig-24f667da-ced7-4727-b107-0daa2be5b690-sigvalue">
STjMdaycvdWLWYVMd2bCvxjIUxoI0/aOWFshihQ8lurmLnmAMlQGAt7yzYMcrywV/7t58Eip+xOp
fuU+S7UsB9b9cS9iy1m0U5fy9pGdud5HqKgDEeNjx//kAGKSZQP232PVTlZ5i+QB1kfotpfrZp6h
FAtwJGd4fijdJ5JuAYI=
</ds:SignatureValue>
<ds:Object>
<xades:QualifyingProperties xmlns:xades="http://uri.etsi.org/01903/v1.3.2#" xmlns:xades141="http://uri.etsi.org/01903/v1.4.1#" Target="#xmldsig-24f667da-ced7-4727-b107-0daa2be5b690">
<xades:SignedProperties Id="xmldsig-24f667da-ced7-4727-b107-0daa2be5b690-signedprops">
<xades:SignedSignatureProperties>
<xades:SigningTime>2019-09-20T20:21:33.956+03:00</xades:SigningTime>
<xades:SigningCertificate>
<xades:Cert>
<xades:CertDigest>
<ds:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"/>
<ds:DigestValue>woG3fsImDUeqxznickzLkpeY9R4=</ds:DigestValue>
</xades:CertDigest>
<xades:IssuerSerial>
<ds:X509IssuerName>cn=LB-LITAS-CA,ou=MSD,o=Lietuvos bankas,l=Vilnius,c=LT</ds:X509IssuerName>
<ds:X509SerialNumber>105704079740755226136574</ds:X509SerialNumber>
</xades:IssuerSerial>
</xades:Cert>
</xades:SigningCertificate>
</xades:SignedSignatureProperties>
</xades:SignedProperties>
<xades:UnsignedProperties>
<xades:UnsignedSignatureProperties>
<xades:SignatureTimeStamp>
<ds:CanonicalizationMethod Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-20010315"/>
</xades:SignatureTimeStamp>
</xades:UnsignedSignatureProperties>
</xades:UnsignedProperties>
</xades:QualifyingProperties>
</ds:Object>
</ds:Signature>
</NextMsg>
Мне кажется, я испортил конвертирование xades4j или переданных параметров.Я действительно не хочу, чтобы подпись внутри элемента была подписана - я хочу, чтобы подпись была включена вдоль него, как в вышеупомянутой ожидаемой структуре.Может ли кто-нибудь указать мне, что я делаю здесь неправильно?