use of sun.security.util.DerInputStream in project jdk8u_jdk by JetBrains.
the class DSAPublicKey method parseKeyBits.
protected void parseKeyBits() throws InvalidKeyException {
try {
DerInputStream in = new DerInputStream(getKey().toByteArray());
y = in.getBigInteger();
} catch (IOException e) {
throw new InvalidKeyException("Invalid key: y value\n" + e.getMessage());
}
}
use of sun.security.util.DerInputStream in project jdk8u_jdk by JetBrains.
the class GSSNameElement method export.
public byte[] export() throws GSSException {
byte[] nameVal = cStub.exportName(pName);
// Need to strip off the mech Oid portion of the exported
// bytes since GSSNameImpl class will subsequently add it.
int pos = 0;
if ((nameVal[pos++] != 0x04) || (nameVal[pos++] != 0x01))
throw new GSSException(GSSException.BAD_NAME);
int mechOidLen = (((0xFF & nameVal[pos++]) << 8) | (0xFF & nameVal[pos++]));
ObjectIdentifier temp = null;
try {
DerInputStream din = new DerInputStream(nameVal, pos, mechOidLen);
temp = new ObjectIdentifier(din);
} catch (IOException e) {
throw new GSSExceptionImpl(GSSException.BAD_NAME, e);
}
Oid mech2 = new Oid(temp.toString());
assert (mech2.equals(getMechanism()));
pos += mechOidLen;
int mechPortionLen = (((0xFF & nameVal[pos++]) << 24) | ((0xFF & nameVal[pos++]) << 16) | ((0xFF & nameVal[pos++]) << 8) | (0xFF & nameVal[pos++]));
if (mechPortionLen < 0) {
throw new GSSException(GSSException.BAD_NAME);
}
byte[] mechPortion = new byte[mechPortionLen];
System.arraycopy(nameVal, pos, mechPortion, 0, mechPortionLen);
return mechPortion;
}
use of sun.security.util.DerInputStream in project jdk8u_jdk by JetBrains.
the class PKCS10AttributeReader method main.
public static void main(String[] args) throws Exception {
// Decode base64 encoded DER file
byte[] pkcs10Bytes = Base64.getMimeDecoder().decode(ATTRIBS.getBytes());
HashMap<ObjectIdentifier, Object> RequestStander = new HashMap() {
{
put(PKCS9Attribute.CHALLENGE_PASSWORD_OID, "GuessWhoAmI");
put(PKCS9Attribute.SIGNING_TIME_OID, new Date(861720610000L));
put(PKCS9Attribute.CONTENT_TYPE_OID, new ObjectIdentifier("1.9.50.51.52"));
}
};
int invalidNum = 0;
PKCS10Attributes resp = new PKCS10Attributes(new DerInputStream(pkcs10Bytes));
Enumeration eReq = resp.getElements();
int numOfAttrs = 0;
while (eReq.hasMoreElements()) {
numOfAttrs++;
PKCS10Attribute attr = (PKCS10Attribute) eReq.nextElement();
if (RequestStander.containsKey(attr.getAttributeId())) {
if (RequestStander.get(attr.getAttributeId()).equals(attr.getAttributeValue())) {
System.out.println(attr.getAttributeId() + " " + attr.getAttributeValue());
} else {
invalidNum++;
System.out.println("< " + attr.getAttributeId() + " " + attr.getAttributeValue());
System.out.println("< " + attr.getAttributeId() + " " + RequestStander.get(attr.getAttributeId()));
}
} else {
invalidNum++;
System.out.println("No" + attr.getAttributeId() + "in Certificate Request list");
}
}
if (numOfAttrs != RequestStander.size()) {
invalidNum++;
System.out.println("Incorrect number of attributes.");
}
System.out.println();
if (invalidNum > 0) {
throw new RuntimeException("Attributes Compared with Stander :" + " Failed");
}
System.out.println("Attributes Compared with Stander: Pass");
}
use of sun.security.util.DerInputStream in project jdk8u_jdk by JetBrains.
the class BigInteger0 method main.
public static void main(String[] args) throws Exception {
try {
DerInputStream derin = new DerInputStream(INT_LEN0);
BigInteger bi = derin.getBigInteger();
throw new Exception("Succeeded parsing invalid zero length value");
} catch (IOException e) {
System.out.println("OK, zero length value rejected.");
}
DerInputStream derin = new DerInputStream(INT0);
BigInteger bi = derin.getBigInteger();
if (bi.equals(BigInteger.ZERO) == false) {
throw new Exception("Failed to parse Integer 0");
}
}
use of sun.security.util.DerInputStream 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");
}
}
Aggregations