Search in sources :

Example 1 with DirectoryName

use of de.carne.certmgr.certs.x509.DirectoryName in project certmgr by hdecarne.

the class GeneralNameFactory method directoryName.

private static GeneralName directoryName(String name) throws IllegalArgumentException {
    String directoryNameString = Strings.safe(name).trim();
    if (Strings.isEmpty(directoryNameString)) {
        throw new IllegalArgumentException(GeneralNameFactoryI18N.formatSTR_MESSAGE_NO_DIRECTORY_NAME());
    }
    X500Principal directoryNameX500;
    try {
        directoryNameX500 = X500Names.fromString(directoryNameString);
    } catch (IllegalArgumentException e) {
        throw new IllegalArgumentException(GeneralNameFactoryI18N.formatSTR_MESSAGE_INVALID_DIRECTORY_NAME(directoryNameString, e.getLocalizedMessage()), e);
    }
    return new DirectoryName(directoryNameX500);
}
Also used : X500Principal(javax.security.auth.x500.X500Principal) DirectoryName(de.carne.certmgr.certs.x509.DirectoryName)

Example 2 with DirectoryName

use of de.carne.certmgr.certs.x509.DirectoryName in project certmgr by hdecarne.

the class ASN1DataTest method testGeneralNames.

/**
 * Test encoding & decoding of {@link GeneralNames} object.
 */
@Test
public void testGeneralNames() {
    try {
        GeneralNames in = new GeneralNames();
        DirectoryName inNameA = new DirectoryName(new X500Principal("CN=localhost"));
        GenericName inNameB = new GenericName(GeneralNameType.X400_ADDRESS, new DEROctetString("test".getBytes()).getEncoded());
        IPAddressName inNameC = new IPAddressName(InetAddress.getByName("127.0.0.1"), null);
        IPAddressName inNameD = new IPAddressName(InetAddress.getByName("127.0.0.1"), InetAddress.getByName("255.255.255.255"));
        IPAddressName inNameE = new IPAddressName(InetAddress.getByName("::1"), null);
        IPAddressName inNameF = new IPAddressName(InetAddress.getByName("::1"), InetAddress.getByName("ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff"));
        OtherName inNameG = new OtherName("1.2.3.4", new DEROctetString("test".getBytes()).getEncoded());
        RegisteredIDName inNameH = new RegisteredIDName("1.2.3.4");
        StringName inNameI = new StringName(GeneralNameType.UNIFORM_RESOURCE_IDENTIFIER, "https://localhost/test.crl");
        in.addName(inNameA);
        in.addName(inNameB);
        in.addName(inNameC);
        in.addName(inNameD);
        in.addName(inNameE);
        in.addName(inNameF);
        in.addName(inNameG);
        in.addName(inNameH);
        in.addName(inNameI);
        byte[] inEncoded = in.getEncoded();
        GeneralNames out = GeneralNames.decode(decodeBytes(inEncoded));
        byte[] outEncoded = out.getEncoded();
        Assert.assertArrayEquals(inEncoded, outEncoded);
    } catch (IOException e) {
        e.printStackTrace();
        Assert.fail(e.getLocalizedMessage());
    }
}
Also used : GenericName(de.carne.certmgr.certs.x509.GenericName) GeneralNames(de.carne.certmgr.certs.x509.GeneralNames) IPAddressName(de.carne.certmgr.certs.x509.IPAddressName) RegisteredIDName(de.carne.certmgr.certs.x509.RegisteredIDName) StringName(de.carne.certmgr.certs.x509.StringName) OtherName(de.carne.certmgr.certs.x509.OtherName) X500Principal(javax.security.auth.x500.X500Principal) IOException(java.io.IOException) DirectoryName(de.carne.certmgr.certs.x509.DirectoryName) DEROctetString(org.bouncycastle.asn1.DEROctetString) Test(org.junit.Test)

Example 3 with DirectoryName

use of de.carne.certmgr.certs.x509.DirectoryName in project certmgr by hdecarne.

the class ASN1DataTest method testDistributionPoint.

/**
 * Test encoding & decoding of {@link DistributionPoint} object.
 */
@Test
public void testDistributionPoint() {
    try {
        // DistributionPointName based
        GeneralNames in1FullName = new GeneralNames();
        StringName in1NameA = new StringName(GeneralNameType.UNIFORM_RESOURCE_IDENTIFIER, "https://localhost/test.crl");
        DirectoryName in1NameB = new DirectoryName(new X500Principal("CN=localhost"));
        in1FullName.addName(in1NameA);
        in1FullName.addName(in1NameB);
        DistributionPointName in1Name = new DistributionPointName(in1FullName);
        DistributionPoint in1 = new DistributionPoint(in1Name);
        byte[] in1Encoded = in1.getEncoded();
        DistributionPoint out1 = DistributionPoint.decode(decodeBytes(in1Encoded));
        byte[] out1Encoded = out1.getEncoded();
        Assert.assertArrayEquals(in1Encoded, out1Encoded);
        // GeneralName based
        GeneralNames in2CrlIssuers = new GeneralNames();
        StringName in2NameA = new StringName(GeneralNameType.UNIFORM_RESOURCE_IDENTIFIER, "https://localhost/test.crl");
        DirectoryName in2NameB = new DirectoryName(new X500Principal("CN=localhost"));
        in1FullName.addName(in2NameA);
        in1FullName.addName(in2NameB);
        DistributionPoint in2 = new DistributionPoint(in2CrlIssuers);
        byte[] in2Encoded = in2.encode().toASN1Primitive().getEncoded();
        DistributionPoint out2 = DistributionPoint.decode(decodeBytes(in2Encoded));
        byte[] out2Encoded = out2.encode().toASN1Primitive().getEncoded();
        Assert.assertArrayEquals(in2Encoded, out2Encoded);
    } catch (IOException e) {
        e.printStackTrace();
        Assert.fail(e.getLocalizedMessage());
    }
}
Also used : GeneralNames(de.carne.certmgr.certs.x509.GeneralNames) StringName(de.carne.certmgr.certs.x509.StringName) DistributionPointName(de.carne.certmgr.certs.x509.DistributionPointName) X500Principal(javax.security.auth.x500.X500Principal) DistributionPoint(de.carne.certmgr.certs.x509.DistributionPoint) IOException(java.io.IOException) DirectoryName(de.carne.certmgr.certs.x509.DirectoryName) Test(org.junit.Test)

Aggregations

DirectoryName (de.carne.certmgr.certs.x509.DirectoryName)3 X500Principal (javax.security.auth.x500.X500Principal)3 GeneralNames (de.carne.certmgr.certs.x509.GeneralNames)2 StringName (de.carne.certmgr.certs.x509.StringName)2 IOException (java.io.IOException)2 Test (org.junit.Test)2 DistributionPoint (de.carne.certmgr.certs.x509.DistributionPoint)1 DistributionPointName (de.carne.certmgr.certs.x509.DistributionPointName)1 GenericName (de.carne.certmgr.certs.x509.GenericName)1 IPAddressName (de.carne.certmgr.certs.x509.IPAddressName)1 OtherName (de.carne.certmgr.certs.x509.OtherName)1 RegisteredIDName (de.carne.certmgr.certs.x509.RegisteredIDName)1 DEROctetString (org.bouncycastle.asn1.DEROctetString)1