Search in sources :

Example 1 with KeyValue

use of org.apache.xml.security.keys.content.KeyValue in project xades4j by luisgoncalves.

the class KeyInfoBuilderTest method testIgnoreSignSigningCertificateIfNotIncluded.

@Test
public void testIgnoreSignSigningCertificateIfNotIncluded() throws Exception {
    System.out.println("ignoreSignSigningCertificateIfNotIncluded");
    KeyInfoBuilder keyInfoBuilder = new KeyInfoBuilder(new TestBasicSignatureOptionsProvider(false, true, true), new TestAlgorithmsProvider(), new TestAlgorithmsParametersMarshallingProvider());
    XMLSignature xmlSignature = getTestSignature();
    keyInfoBuilder.buildKeyInfo(testCertificate, xmlSignature);
    Assert.assertEquals(0, xmlSignature.getSignedInfo().getLength());
    KeyValue kv = xmlSignature.getKeyInfo().itemKeyValue(0);
    Assert.assertTrue(kv.getPublicKey().getAlgorithm().startsWith("RSA"));
    Assert.assertEquals(0, xmlSignature.getKeyInfo().lengthX509Data());
}
Also used : KeyValue(org.apache.xml.security.keys.content.KeyValue) XMLSignature(org.apache.xml.security.signature.XMLSignature) Test(org.junit.Test)

Example 2 with KeyValue

use of org.apache.xml.security.keys.content.KeyValue in project santuario-java by apache.

the class KeyValueTest method testDSAPublicKey.

@org.junit.Test
public void testDSAPublicKey() throws Exception {
    File f = null;
    String filename = "src/test/resources/ie/baltimore/merlin-examples/merlin-xmldsig-twenty-three/signature-enveloping-dsa.xml";
    if (BASEDIR != null && !"".equals(BASEDIR)) {
        f = new File(BASEDIR + SEP + filename);
    } else {
        f = new File(filename);
    }
    Document doc = db.parse(new FileInputStream(f));
    NodeList nl = doc.getElementsByTagNameNS(Constants.SignatureSpecNS, "Signature");
    XMLSignature sig = new XMLSignature((Element) nl.item(0), f.toURI().toURL().toString());
    KeyInfo ki = sig.getKeyInfo();
    KeyValue kv = ki.itemKeyValue(0);
    PublicKey pk = kv.getPublicKey();
    assertNotNull(pk);
}
Also used : KeyValue(org.apache.xml.security.keys.content.KeyValue) KeyInfo(org.apache.xml.security.keys.KeyInfo) XMLSignature(org.apache.xml.security.signature.XMLSignature) PublicKey(java.security.PublicKey) NodeList(org.w3c.dom.NodeList) Document(org.w3c.dom.Document) File(java.io.File) FileInputStream(java.io.FileInputStream)

Example 3 with KeyValue

use of org.apache.xml.security.keys.content.KeyValue 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 4 with KeyValue

use of org.apache.xml.security.keys.content.KeyValue in project santuario-java by apache.

the class KeyUtils method prinoutKeyInfo.

/**
 * Method prinoutKeyInfo
 *
 * @param ki
 * @param os
 * @throws XMLSecurityException
 */
public static void prinoutKeyInfo(KeyInfo ki, PrintStream os) throws XMLSecurityException {
    for (int i = 0; i < ki.lengthKeyName(); i++) {
        KeyName x = ki.itemKeyName(i);
        os.println("KeyName(" + i + ")=\"" + x.getKeyName() + "\"");
    }
    for (int i = 0; i < ki.lengthKeyValue(); i++) {
        KeyValue x = ki.itemKeyValue(i);
        PublicKey pk = x.getPublicKey();
        os.println("KeyValue Nr. " + i);
        os.println(pk);
    }
    for (int i = 0; i < ki.lengthMgmtData(); i++) {
        MgmtData x = ki.itemMgmtData(i);
        os.println("MgmtData(" + i + ")=\"" + x.getMgmtData() + "\"");
    }
    for (int i = 0; i < ki.lengthX509Data(); i++) {
        X509Data x = ki.itemX509Data(i);
        os.println("X509Data(" + i + ")=\"" + (x.containsCertificate() ? "Certificate " : "") + (x.containsIssuerSerial() ? "IssuerSerial " : "") + "\"");
    }
}
Also used : KeyName(org.apache.xml.security.keys.content.KeyName) KeyValue(org.apache.xml.security.keys.content.KeyValue) MgmtData(org.apache.xml.security.keys.content.MgmtData) PublicKey(java.security.PublicKey) X509Data(org.apache.xml.security.keys.content.X509Data)

Aggregations

KeyValue (org.apache.xml.security.keys.content.KeyValue)4 XMLSignature (org.apache.xml.security.signature.XMLSignature)3 PublicKey (java.security.PublicKey)2 Test (org.junit.Test)2 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 KeyInfo (org.apache.xml.security.keys.KeyInfo)1 KeyName (org.apache.xml.security.keys.content.KeyName)1 MgmtData (org.apache.xml.security.keys.content.MgmtData)1 X509Data (org.apache.xml.security.keys.content.X509Data)1 XMLX509Certificate (org.apache.xml.security.keys.content.x509.XMLX509Certificate)1 Document (org.w3c.dom.Document)1 NodeList (org.w3c.dom.NodeList)1 DefaultX500NameStyleProvider (xades4j.providers.impl.DefaultX500NameStyleProvider)1