use of sun.security.util.DerValue in project jdk8u_jdk by JetBrains.
the class UnknownAttribute method main.
public static void main(String[] args) throws Exception {
// Unknown attr
PKCS9Attribute p1 = new PKCS9Attribute(PKCS9Attribute.CHALLENGE_PASSWORD_STR, "t0p5ecr3t");
if (!p1.isKnown()) {
throw new Exception();
}
// Unknown attr from DER
byte[] data = { // SEQUENCE OF
0x30, // SEQUENCE OF
0x08, // OID 1.2.3 and
0x06, // OID 1.2.3 and
0x02, // OID 1.2.3 and
0x2A, // OID 1.2.3 and
0x03, // an empty SET
0x31, // an empty SET
0x02, // an empty SET
0x05, // an empty SET
0x00 };
PKCS9Attribute p2 = new PKCS9Attribute(new DerValue(data));
if (p2.isKnown()) {
throw new Exception();
}
ByteArrayOutputStream bout = new ByteArrayOutputStream();
p2.derEncode(bout);
new HexDumpEncoder().encodeBuffer(bout.toByteArray(), System.err);
if (!Arrays.equals(data, bout.toByteArray())) {
throw new Exception();
}
// Unknown attr from value
try {
new PKCS9Attribute(new ObjectIdentifier("1.2.3"), "hello");
throw new Exception();
} catch (IllegalArgumentException iae) {
// Good. Unknown attr must have byte[] value type
}
PKCS9Attribute p3 = new PKCS9Attribute(new ObjectIdentifier("1.2.3"), new byte[] { 0x31, 0x02, 0x05, 0x00 });
if (p3.isKnown()) {
throw new Exception();
}
bout = new ByteArrayOutputStream();
p3.derEncode(bout);
if (!Arrays.equals(data, bout.toByteArray())) {
throw new Exception();
}
}
use of sun.security.util.DerValue in project jdk8u_jdk by JetBrains.
the class NamedBitList method main.
public static void main(String[] args) throws Exception {
boolean[] bb = (new boolean[] { true, false, true, false, false, false });
GeneralNames gns = new GeneralNames();
gns.add(new GeneralName(new DNSName("dns")));
DerOutputStream out;
// length should be 5 since only {T,F,T} should be encoded
KeyUsageExtension x1 = new KeyUsageExtension(bb);
check(new DerValue(x1.getExtensionValue()).getUnalignedBitString().length(), 3);
NetscapeCertTypeExtension x2 = new NetscapeCertTypeExtension(bb);
check(new DerValue(x2.getExtensionValue()).getUnalignedBitString().length(), 3);
ReasonFlags r = new ReasonFlags(bb);
out = new DerOutputStream();
r.encode(out);
check(new DerValue(out.toByteArray()).getUnalignedBitString().length(), 3);
// Read sun.security.x509.DistributionPoint for ASN.1 definition
DistributionPoint dp = new DistributionPoint(gns, bb, gns);
out = new DerOutputStream();
dp.encode(out);
DerValue v = new DerValue(out.toByteArray());
// skip distributionPoint
v.data.getDerValue();
// read reasons
DerValue v2 = v.data.getDerValue();
// reset to BitString since it's context-specfic[1] encoded
v2.resetTag(DerValue.tag_BitString);
// length should be 5 since only {T,F,T} should be encoded
check(v2.getUnalignedBitString().length(), 3);
BitArray ba;
ba = new BitArray(new boolean[] { false, false, false });
check(ba.length(), 3);
ba = ba.truncate();
check(ba.length(), 1);
ba = new BitArray(new boolean[] { true, true, true, true, true, true, true, true, false, false });
check(ba.length(), 10);
check(ba.toByteArray().length, 2);
ba = ba.truncate();
check(ba.length(), 8);
check(ba.toByteArray().length, 1);
ba = new BitArray(new boolean[] { true, true, true, true, true, true, true, true, true, false });
check(ba.length(), 10);
check(ba.toByteArray().length, 2);
ba = ba.truncate();
check(ba.length(), 9);
check(ba.toByteArray().length, 2);
}
use of sun.security.util.DerValue in project jdk8u_jdk by JetBrains.
the class DomainComponentEncoding method testDN.
private static void testDN(String dn) throws Exception {
X500Principal p = new X500Principal(dn);
byte[] encoded = p.getEncoded();
// name is a sequence of RDN's
DerInputStream dis = new DerInputStream(encoded);
DerValue[] nameseq = dis.getSequence(3);
boolean passed = false;
for (int i = 0; i < nameseq.length; i++) {
// each RDN is a set of AttributeTypeAndValue
DerInputStream is = new DerInputStream(nameseq[i].toByteArray());
DerValue[] ava = is.getSet(3);
for (int j = 0; j < ava.length; j++) {
ObjectIdentifier oid = ava[j].data.getOID();
if (oid.equals(X500Name.DOMAIN_COMPONENT_OID)) {
DerValue value = ava[j].data.getDerValue();
if (value.getTag() == DerValue.tag_IA5String) {
passed = true;
break;
} else {
throw new SecurityException("Test failed, expected DOMAIN_COMPONENT tag '" + DerValue.tag_IA5String + "', got '" + value.getTag() + "'");
}
}
}
if (passed) {
break;
}
}
if (passed) {
System.out.println("Test passed");
} else {
throw new SecurityException("Test failed");
}
}
use of sun.security.util.DerValue in project jdk8u_jdk by JetBrains.
the class LocaleInTime method main.
public static void main(String[] args) throws Exception {
DerOutputStream out = new DerOutputStream();
out.putUTCTime(new Date());
DerValue val = new DerValue(out.toByteArray());
System.out.println(val.getUTCTime());
}
use of sun.security.util.DerValue in project jdk8u_jdk by JetBrains.
the class EmptyValue method main.
public static void main(String[] args) throws Exception {
DerValue v = new DerValue(new byte[] { 4, 0 });
if (v.getOctetString().length != 0) {
throw new Exception("Get octet string error");
}
v = new DerValue(new byte[] { 0x30, 0 });
if (v.data.available() != 0) {
throw new Exception("Get sequence error");
}
}
Aggregations