use of org.mozilla.jss.netscape.security.util.DerInputStream in project jss by dogtagpki.
the class CertificateValidity method construct.
// Construct the class from the DerValue
private void construct(DerValue derVal) throws IOException {
if (derVal.tag != DerValue.tag_Sequence) {
throw new IOException("Invalid encoded CertificateValidity, " + "starting sequence tag missing.");
}
// check if UTCTime encoded or GeneralizedTime
if (derVal.data.available() == 0)
throw new IOException("No data encoded for CertificateValidity");
DerInputStream derIn = new DerInputStream(derVal.toByteArray());
DerValue[] seq = derIn.getSequence(2);
if (seq.length != 2)
throw new IOException("Invalid encoding for CertificateValidity");
if (seq[0].tag == DerValue.tag_UtcTime) {
notBefore = derVal.data.getUTCTime();
} else if (seq[0].tag == DerValue.tag_GeneralizedTime) {
notBefore = derVal.data.getGeneralizedTime();
} else {
throw new IOException("Invalid encoding for CertificateValidity");
}
if (seq[1].tag == DerValue.tag_UtcTime) {
notAfter = derVal.data.getUTCTime();
} else if (seq[1].tag == DerValue.tag_GeneralizedTime) {
notAfter = derVal.data.getGeneralizedTime();
} else {
throw new IOException("Invalid encoding for CertificateValidity");
}
}
use of org.mozilla.jss.netscape.security.util.DerInputStream in project jss by dogtagpki.
the class Extensions method decode.
/**
* Decode the extensions from the InputStream.
*
* @param in the InputStream to unmarshal the contents from.
* @exception IOException on decoding or validity errors.
*/
@Override
public void decode(InputStream in) throws IOException {
DerValue val = new DerValue(in);
DerInputStream str = val.toDerInputStream();
map = new Hashtable<>();
DerValue[] exts = str.getSequence(5);
for (int i = 0; i < exts.length; i++) {
Extension ext = new Extension(exts[i]);
parseExtension(ext);
}
}
use of org.mozilla.jss.netscape.security.util.DerInputStream in project jss by dogtagpki.
the class AlgorithmId method parse.
/**
* Parse (unmarshal) an ID from a DER sequence input value. This form
* parsing might be used when expanding a value which has already been
* partially unmarshaled as a set or sequence member.
*
* @exception IOException on error.
* @param val the input value, which contains the algid and, if
* there are any parameters, those parameters.
* @return an ID for the algorithm. If the system is configured
* appropriately, this may be an instance of a class
* with some kind of special support for this algorithm.
* In that case, you may "narrow" the type of the ID.
*/
public static AlgorithmId parse(DerValue val) throws IOException {
if (val.tag != DerValue.tag_Sequence)
throw new IOException("algid parse error, not a sequence");
/*
* Get the algorithm ID and any parameters.
*/
ObjectIdentifier algid;
DerValue params;
DerInputStream in = val.toDerInputStream();
algid = in.getOID();
if (in.available() == 0)
params = null;
else {
params = in.getDerValue();
if (params.tag == DerValue.tag_Null)
params = null;
}
/*
* Figure out what class (if any) knows about this oid's
* parameters. Make one, and give it the data to decode.
*/
AlgorithmId alg = null;
// omit parameter field for ECDSA
if (!algid.equals(sha224WithEC_oid) && !algid.equals(sha256WithEC_oid) && !algid.equals(sha384WithEC_oid) && !algid.equals(sha512WithEC_oid)) {
alg = new AlgorithmId(algid, params);
} else {
try {
alg = new AlgorithmId(algid);
} catch (Exception e) {
throw new IOException(e);
}
}
if (params != null)
alg.decodeParams();
/*
* Set the raw params string in case
* higher level code might want the info
*/
String paramStr = null;
if (params != null) {
paramStr = params.toString();
}
alg.setParametersString(paramStr);
return alg;
}
use of org.mozilla.jss.netscape.security.util.DerInputStream in project jss by dogtagpki.
the class PKCS9Attributes method decode.
/**
* Decode this set of PKCS9 attribute set from the contents of its
* DER encoding.
*
* @param buf
* the contents of the DER encoding of the attribute set.
*
* @exception IOException
* on i/o error, encoding syntax error, unacceptable or
* unsupported attribute, or duplicate attribute.
*/
private byte[] decode(DerInputStream in) throws IOException {
DerValue val = in.getDerValue();
// save the DER encoding with its proper tag byte.
byte[] derEncoding = val.toByteArray();
derEncoding[0] = DerValue.tag_SetOf;
DerInputStream derIn = new DerInputStream(derEncoding);
DerValue[] derVals = derIn.getSet(3, true);
PKCS9Attribute attrib;
ObjectIdentifier oid;
for (int i = 0; i < derVals.length; i++) {
attrib = new PKCS9Attribute(derVals[i]);
oid = attrib.getOID();
if (attributes.get(oid) != null)
throw new IOException("Duplicate PKCS9 attribute: " + oid);
if (permittedAttributes != null && !permittedAttributes.containsKey(oid))
throw new IOException("Attribute " + oid + " not permitted in this attribute set");
attributes.put(oid, attrib);
}
return derEncoding;
}
use of org.mozilla.jss.netscape.security.util.DerInputStream in project jss by dogtagpki.
the class PresenceServerExtension method decodeThis.
public void decodeThis() throws IOException {
DerInputStream val = new DerInputStream(this.extensionValue);
byte[] data = null;
DerValue[] seq = val.getSequence(0);
mVersion = seq[0].getInteger().toInt();
data = null;
if (seq[1].length() > 0) {
data = seq[1].getOctetString();
}
if (data == null) {
mStreetAddress = "";
} else {
mStreetAddress = new String(data);
}
data = null;
if (seq[2].length() > 0)
data = seq[2].getOctetString();
if (data == null) {
mTelephoneNumber = "";
} else {
mTelephoneNumber = new String(data);
}
data = null;
if (seq[3].length() > 0)
data = seq[3].getOctetString();
if (data == null) {
mRFC822Name = "";
} else {
mRFC822Name = new String(data);
}
data = null;
if (seq[4].length() > 0)
data = seq[4].getOctetString();
if (data == null) {
mID = "";
} else {
mID = new String(data);
}
data = null;
if (seq[5].length() > 0)
data = seq[5].getOctetString();
if (data == null) {
mHostName = "";
} else {
mHostName = new String(data);
}
mPortNumber = seq[6].getInteger().toInt();
mMaxUsers = seq[7].getInteger().toInt();
mServiceLevel = seq[8].getInteger().toInt();
}
Aggregations