Search in sources :

Example 1 with DefaultX500NameStyleProvider

use of xades4j.providers.impl.DefaultX500NameStyleProvider in project xades4j by luisgoncalves.

the class KeyInfoBuilderTest method testIncludeCertAndKey.

@Test
public void testIncludeCertAndKey() throws Exception {
    System.out.println("includeCertAndKey");
    KeyInfoBuilder keyInfoBuilder = new KeyInfoBuilder(new BasicSignatureOptions().includeSigningCertificate(SigningCertificateMode.SIGNING_CERTIFICATE).includePublicKey(true), new SignatureAlgorithms(), new TestAlgorithmsParametersMarshallingProvider(), new DefaultX500NameStyleProvider());
    XMLSignature xmlSignature = getTestSignature();
    keyInfoBuilder.buildKeyInfo(certificates, xmlSignature);
    Assert.assertEquals(0, xmlSignature.getSignedInfo().getLength());
    KeyValue kv = xmlSignature.getKeyInfo().itemKeyValue(0);
    Assert.assertTrue(kv.getPublicKey().getAlgorithm().startsWith("RSA"));
    XMLX509Certificate x509Certificate = xmlSignature.getKeyInfo().itemX509Data(0).itemCertificate(0);
    Assert.assertEquals(testCertificate, x509Certificate.getX509Certificate());
}
Also used : XMLX509Certificate(org.apache.xml.security.keys.content.x509.XMLX509Certificate) KeyValue(org.apache.xml.security.keys.content.KeyValue) XMLSignature(org.apache.xml.security.signature.XMLSignature) DefaultX500NameStyleProvider(xades4j.providers.impl.DefaultX500NameStyleProvider) Test(org.junit.Test)

Example 2 with DefaultX500NameStyleProvider

use of xades4j.providers.impl.DefaultX500NameStyleProvider in project xades4j by luisgoncalves.

the class KeyInfoBuilderTest method testIncludeCertChain.

@Test
public void testIncludeCertChain() throws Exception {
    System.out.println("includeCertChain");
    KeyInfoBuilder keyInfoBuilder = new KeyInfoBuilder(new BasicSignatureOptions().includeSigningCertificate(SigningCertificateMode.FULL_CHAIN), new SignatureAlgorithms(), new TestAlgorithmsParametersMarshallingProvider(), new DefaultX500NameStyleProvider());
    XMLSignature xmlSignature = getTestSignature();
    keyInfoBuilder.buildKeyInfo(certificates, xmlSignature);
    Assert.assertEquals(0, xmlSignature.getSignedInfo().getLength());
    Assert.assertEquals(1, xmlSignature.getKeyInfo().lengthX509Data());
    Assert.assertEquals(2, xmlSignature.getKeyInfo().itemX509Data(0).lengthCertificate());
    XMLX509Certificate x509Certificate = xmlSignature.getKeyInfo().itemX509Data(0).itemCertificate(0);
    Assert.assertEquals(testCertificate, x509Certificate.getX509Certificate());
    x509Certificate = xmlSignature.getKeyInfo().itemX509Data(0).itemCertificate(1);
    Assert.assertEquals(intermCertificate, x509Certificate.getX509Certificate());
}
Also used : XMLX509Certificate(org.apache.xml.security.keys.content.x509.XMLX509Certificate) XMLSignature(org.apache.xml.security.signature.XMLSignature) DefaultX500NameStyleProvider(xades4j.providers.impl.DefaultX500NameStyleProvider) Test(org.junit.Test)

Example 3 with DefaultX500NameStyleProvider

use of xades4j.providers.impl.DefaultX500NameStyleProvider in project xades4j by luisgoncalves.

the class KeyInfoBuilderTest method testSignKeyInfo.

@Test
public void testSignKeyInfo() throws Exception {
    System.out.println("signKeyInfo");
    KeyInfoBuilder keyInfoBuilder = new KeyInfoBuilder(new BasicSignatureOptions().signKeyInfo(true), new SignatureAlgorithms(), new TestAlgorithmsParametersMarshallingProvider(), new DefaultX500NameStyleProvider());
    XMLSignature xmlSignature = getTestSignature();
    keyInfoBuilder.buildKeyInfo(certificates, xmlSignature);
    SignedInfo signedInfo = xmlSignature.getSignedInfo();
    Assert.assertEquals(1, signedInfo.getLength());
    Node refNode = signedInfo.item(0).getContentsBeforeTransformation().getSubNode();
    Assert.assertSame(xmlSignature.getKeyInfo().getElement(), refNode);
}
Also used : XMLSignature(org.apache.xml.security.signature.XMLSignature) Node(org.w3c.dom.Node) DefaultX500NameStyleProvider(xades4j.providers.impl.DefaultX500NameStyleProvider) SignedInfo(org.apache.xml.security.signature.SignedInfo) Test(org.junit.Test)

Example 4 with DefaultX500NameStyleProvider

use of xades4j.providers.impl.DefaultX500NameStyleProvider in project xades4j by luisgoncalves.

the class X500NameStyleProviderTest method normalWithExtendKeywords.

@Test
public void normalWithExtendKeywords() {
    X500NameStyleProvider x500NameStyleProvider = new DefaultX500NameStyleProvider();
    X500Principal name1 = x500NameStyleProvider.fromString(NAME_CANONICAL);
    X500Principal name2 = x500NameStyleProvider.fromString(NAME_SIMPLE_NORMAL);
    RFC4519ExtensibleStyle es = new RFC4519ExtensibleStyle();
    es.addSymbol("1.2.840.113549.1.9.1", "E");
    X500NameStyleProvider x500NameStyleProviderExtend = new DefaultX500NameStyleProvider(es);
    X500Principal name3 = x500NameStyleProviderExtend.fromString(NAME_SIMPLE);
    Assert.assertEquals(name1, name2);
    Assert.assertEquals(name1, name3);
}
Also used : DefaultX500NameStyleProvider(xades4j.providers.impl.DefaultX500NameStyleProvider) X500NameStyleProvider(xades4j.providers.X500NameStyleProvider) X500Principal(javax.security.auth.x500.X500Principal) DefaultX500NameStyleProvider(xades4j.providers.impl.DefaultX500NameStyleProvider) Test(org.junit.Test)

Example 5 with DefaultX500NameStyleProvider

use of xades4j.providers.impl.DefaultX500NameStyleProvider in project xades4j by luisgoncalves.

the class KeyInfoBuilderTest method testIncludeIssuerSerial.

@Test
public void testIncludeIssuerSerial() throws Exception {
    System.out.println("includeIssuerSerial");
    KeyInfoBuilder keyInfoBuilder = new KeyInfoBuilder(new BasicSignatureOptions().includeIssuerSerial(true), new SignatureAlgorithms(), new TestAlgorithmsParametersMarshallingProvider(), new DefaultX500NameStyleProvider());
    XMLSignature xmlSignature = getTestSignature();
    keyInfoBuilder.buildKeyInfo(certificates, xmlSignature);
    Assert.assertEquals(1, xmlSignature.getKeyInfo().lengthX509Data());
    Assert.assertEquals(1, xmlSignature.getKeyInfo().itemX509Data(0).lengthIssuerSerial());
}
Also used : XMLSignature(org.apache.xml.security.signature.XMLSignature) DefaultX500NameStyleProvider(xades4j.providers.impl.DefaultX500NameStyleProvider) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)6 DefaultX500NameStyleProvider (xades4j.providers.impl.DefaultX500NameStyleProvider)6 XMLSignature (org.apache.xml.security.signature.XMLSignature)5 XMLX509Certificate (org.apache.xml.security.keys.content.x509.XMLX509Certificate)2 X500Principal (javax.security.auth.x500.X500Principal)1 KeyValue (org.apache.xml.security.keys.content.KeyValue)1 SignedInfo (org.apache.xml.security.signature.SignedInfo)1 Node (org.w3c.dom.Node)1 X500NameStyleProvider (xades4j.providers.X500NameStyleProvider)1