use of org.bouncycastle.asn1.ASN1TaggedObject in project certmgr by hdecarne.
the class GeneralName method decode.
/**
* Decode {@code GeneralName} object from an ASN.1 data object.
*
* @param primitive The ASN.1 data object to decode.
* @return The decoded name object.
* @throws IOException if an I/O error occurs during decoding.
*/
public static GeneralName decode(ASN1Primitive primitive) throws IOException {
ASN1TaggedObject taggedObject = decodePrimitive(primitive, ASN1TaggedObject.class);
int nameTypeTag = taggedObject.getTagNo();
GeneralName name;
switch(nameTypeTag) {
case GeneralNameType.OTHER_NAME_TAG:
name = OtherName.decode(primitive);
break;
case GeneralNameType.RFC822_NAME_TAG:
name = StringName.decode(GeneralNameType.RFC822_NAME, primitive);
break;
case GeneralNameType.DNS_NAME_TAG:
name = StringName.decode(GeneralNameType.DNS_NAME, primitive);
break;
case GeneralNameType.X400_ADDRESS_TAG:
name = GenericName.decode(GeneralNameType.X400_ADDRESS, primitive);
break;
case GeneralNameType.DIRECTORY_NAME_TAG:
name = DirectoryName.decode(primitive);
break;
case GeneralNameType.EDI_PARTY_NAME_TAG:
name = GenericName.decode(GeneralNameType.EDI_PARTY_NAME, primitive);
break;
case GeneralNameType.UNIFORM_RESOURCE_IDENTIFIER_TAG:
name = StringName.decode(GeneralNameType.UNIFORM_RESOURCE_IDENTIFIER, primitive);
break;
case GeneralNameType.IP_ADDRESS_TAG:
name = IPAddressName.decode(primitive);
break;
case GeneralNameType.REGISTERED_ID_TAG:
name = RegisteredIDName.decode(primitive);
break;
default:
throw new IOException("Unsupported general name type: " + nameTypeTag);
}
return name;
}
use of org.bouncycastle.asn1.ASN1TaggedObject in project certmgr by hdecarne.
the class RegisteredIDName method decode.
/**
* Decode {@code RegisteredIDName} from an ASN.1 data object.
*
* @param primitive The ASN.1 data object to decode.
* @return The decoded registered ID object.
* @throws IOException if an I/O error occurs during decoding.
*/
public static RegisteredIDName decode(ASN1Primitive primitive) throws IOException {
decodeTagged(primitive, GeneralNameType.REGISTERED_ID_TAG);
ASN1TaggedObject taggedObject = decodePrimitive(primitive, ASN1TaggedObject.class);
String oid = ASN1ObjectIdentifier.getInstance(taggedObject, false).getId();
return new RegisteredIDName(oid);
}
use of org.bouncycastle.asn1.ASN1TaggedObject in project candlepin by candlepin.
the class X509CRLStreamWriter method offsetNextUpdate.
/**
* Write a new nextUpdate time that is the same amount of time ahead of the new thisUpdate
* time as the old nextUpdate was from the old thisUpdate.
*
* @param out
* @param tagNo
* @param oldThisUpdate
* @throws IOException
*/
protected void offsetNextUpdate(OutputStream out, int tagNo, Date oldThisUpdate) throws IOException {
int originalLength = readLength(crlIn, null);
byte[] oldBytes = new byte[originalLength];
readFullyAndTrack(crlIn, oldBytes, null);
ASN1Object oldTime = null;
if (tagNo == UTC_TIME) {
ASN1TaggedObject t = new DERTaggedObject(UTC_TIME, new DEROctetString(oldBytes));
oldTime = ASN1UTCTime.getInstance(t, false);
} else {
ASN1TaggedObject t = new DERTaggedObject(GENERALIZED_TIME, new DEROctetString(oldBytes));
oldTime = ASN1GeneralizedTime.getInstance(t, false);
}
/* Determine the time between the old thisUpdate and old nextUpdate and add it
/* to the new nextUpdate. */
Date oldNextUpdate = Time.getInstance(oldTime).getDate();
long delta = oldNextUpdate.getTime() - oldThisUpdate.getTime();
Date newNextUpdate = new Date(new Date().getTime() + delta);
ASN1Object newTime = null;
if (tagNo == UTC_TIME) {
newTime = new DERUTCTime(newNextUpdate);
} else {
newTime = new DERGeneralizedTime(newNextUpdate);
}
writeNewTime(out, newTime, originalLength);
}
use of org.bouncycastle.asn1.ASN1TaggedObject in project candlepin by candlepin.
the class X509CRLStreamWriter method updateExtensions.
/**
* This method updates the crlNumber and authorityKeyIdentifier extensions. Any
* other extensions are copied over unchanged.
* @param obj
* @return
* @throws IOException
*/
@SuppressWarnings("rawtypes")
protected byte[] updateExtensions(byte[] obj) throws IOException {
ASN1TaggedObject taggedExts = (ASN1TaggedObject) new ASN1InputStream(obj).readObject();
ASN1Sequence seq = (ASN1Sequence) taggedExts.getObject();
ASN1EncodableVector modifiedExts = new ASN1EncodableVector();
// Now we need to read the extensions and find the CRL number and increment it,
// and determine if its length changed.
Enumeration objs = seq.getObjects();
while (objs.hasMoreElements()) {
ASN1Sequence ext = (ASN1Sequence) objs.nextElement();
ASN1ObjectIdentifier oid = (ASN1ObjectIdentifier) ext.getObjectAt(0);
if (Extension.cRLNumber.equals(oid)) {
ASN1OctetString s = (ASN1OctetString) ext.getObjectAt(1);
ASN1Integer i = (ASN1Integer) new ASN1InputStream(s.getOctets()).readObject();
ASN1Integer newCrlNumber = new ASN1Integer(i.getValue().add(BigInteger.ONE));
Extension newNumberExt = new Extension(Extension.cRLNumber, false, new DEROctetString(newCrlNumber.getEncoded()));
ASN1EncodableVector crlNumber = new ASN1EncodableVector();
crlNumber.add(Extension.cRLNumber);
crlNumber.add(newNumberExt.getExtnValue());
modifiedExts.add(new DERSequence(crlNumber));
} else if (Extension.authorityKeyIdentifier.equals(oid)) {
Extension newAuthorityKeyExt = new Extension(Extension.authorityKeyIdentifier, false, aki.getEncoded());
ASN1EncodableVector aki = new ASN1EncodableVector();
aki.add(Extension.authorityKeyIdentifier);
aki.add(newAuthorityKeyExt.getExtnValue());
modifiedExts.add(new DERSequence(aki));
} else {
modifiedExts.add(ext);
}
}
ASN1Sequence seqOut = new DERSequence(modifiedExts);
ASN1TaggedObject out = new DERTaggedObject(true, 0, seqOut);
return out.getEncoded();
}
use of org.bouncycastle.asn1.ASN1TaggedObject in project candlepin by candlepin.
the class X509CRLStreamWriter method readAndReplaceTime.
/**
* Replace a time in the ASN1 with the current time.
*
* @param out
* @param tagNo
* @return the time that was replaced
* @throws IOException
*/
protected Date readAndReplaceTime(OutputStream out, int tagNo) throws IOException {
int originalLength = readLength(crlIn, null);
byte[] oldBytes = new byte[originalLength];
readFullyAndTrack(crlIn, oldBytes, null);
ASN1Object oldTime;
ASN1Object newTime;
if (tagNo == UTC_TIME) {
ASN1TaggedObject t = new DERTaggedObject(UTC_TIME, new DEROctetString(oldBytes));
oldTime = ASN1UTCTime.getInstance(t, false);
newTime = new DERUTCTime(new Date());
} else {
ASN1TaggedObject t = new DERTaggedObject(GENERALIZED_TIME, new DEROctetString(oldBytes));
oldTime = ASN1GeneralizedTime.getInstance(t, false);
newTime = new DERGeneralizedTime(new Date());
}
writeNewTime(out, newTime, originalLength);
return Time.getInstance(oldTime).getDate();
}
Aggregations