Search in sources :

Example 1 with GenericName

use of de.carne.certmgr.certs.x509.GenericName 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)

Aggregations

DirectoryName (de.carne.certmgr.certs.x509.DirectoryName)1 GeneralNames (de.carne.certmgr.certs.x509.GeneralNames)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 StringName (de.carne.certmgr.certs.x509.StringName)1 IOException (java.io.IOException)1 X500Principal (javax.security.auth.x500.X500Principal)1 DEROctetString (org.bouncycastle.asn1.DEROctetString)1 Test (org.junit.Test)1