I'm trying to sign an invoice for the spanish administration using xades4j. They provide an online checker for the signed xml and just one step of the overall check is failing:
Step: Checks if the signature policy is correct
Result: Unknown policy self:policy/general
Other steps like integrity and certificate status are ok.
My guess is self:policy/general is some kind of placeholder in the xades4j library that I should somehow override?
Right now I'm using this code for the policy
SignaturePolicyInfoProvider policyInfoProvider = new SignaturePolicyInfoProvider()
{
String FACTURAE_URL = "http://www.facturae.es/politica_de_firma_formato_facturae/politica_de_firma_formato_facturae_v3_1.pdf";
public SignaturePolicyBase getSignaturePolicy()
{
InputStream is = null;
try {
URL url = new URL(FACTURAE_URL);
URLConnection conn = url.openConnection();
is = conn.getInputStream();
} catch (IOException e) {
e.printStackTrace();
}
SignaturePolicyBase base = new SignaturePolicyIdentifierProperty(new ObjectIdentifier(FACTURAE_URL),is);
return base;
}
};
The requirements are in this online document (spanish) https://www.facturae.gob.es/politica_de_firma_formato_facturae/politica_de_firma_formato_facturae_v3_1.pdf
My xml output seems to comply:
<xades:SignaturePolicyIdentifier>
<xades:SignaturePolicyId>
<xades:SigPolicyId>
<xades:Identifier>http://www.facturae.es/politica_de_firma_formato_facturae/politica_de_firma_formato_facturae_v3_1.pdf</xades:Identifier>
</xades:SigPolicyId>
<xades:SigPolicyHash>
<ds:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"/>
<ds:DigestValue>2jmj7l5rSw0yVb/vlWAYkK/YBwk=</ds:DigestValue>
</xades:SigPolicyHash>
</xades:SignaturePolicyId>
</xades:SignaturePolicyIdentifier>
There's no such thing. This is probably a detail of the verifying application.
I noticed that the URL in the question text is HTTPS, while the one in the code is HTTP. It seems that the later redirects to HTTPs, but it seems that
URLConnectiondoesn't follow redirects when protocols are different.Try using the final HTTPS URL in your code.