use of sun.security.x509.IPAddressName 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());
}
}
use of sun.security.x509.IPAddressName in project OpenAttestation by OpenAttestation.
the class X509Builder method ipAlternativeName.
public X509Builder ipAlternativeName(String ip) {
try {
v3();
String alternativeName = ip;
if (ip.startsWith("ip:")) {
alternativeName = ip.substring(3);
}
// InetAddress ipAddress = new InetAddress.getByName(alternativeName.substring(3));
// IPAddressName ipAddressName = new IPAddressName(ipAddress.getAddress());
IPAddressName ipAddressName = new IPAddressName(alternativeName);
if (alternativeNames == null) {
alternativeNames = new GeneralNames();
}
alternativeNames.add(new GeneralName(ipAddressName));
SubjectAlternativeNameExtension san = new SubjectAlternativeNameExtension(alternativeNames);
if (certificateExtensions == null) {
certificateExtensions = new CertificateExtensions();
}
certificateExtensions.set(san.getExtensionId().toString(), san);
info.set(X509CertInfo.EXTENSIONS, certificateExtensions);
// ObjectIdentifier("2.5.29.17") , false, "ipaddress".getBytes()
} catch (Exception e) {
fault(e, "ipAlternativeName(%s)", ip);
}
return this;
}
Aggregations