List of usage examples for org.bouncycastle.asn1 DERGeneralString getInstance
public static DERGeneralString getInstance(Object obj)
From source file:AAModulePackage.ACHelper.java
/** * This method takes in an AC and wraps it up in the wrapper class. * @param ac - X509AttributeCertificateHold that we want to wrap. * @return wrapped up AC.// ww w. ja v a 2 s . com */ public static AttributeCertificateWrapper extractAttributes(X509AttributeCertificateHolder ac) { AttributeCertificateWrapper wrapper = new AttributeCertificateWrapper(ac); for (Attribute a : ac.getAttributes(NewAttributeIdentifiers.role)) { ASN1Set set = a.getAttrValues(); String s = DERGeneralString.getInstance(set.getObjectAt(0)).getString(); wrapper.setRole(s); } for (Attribute a : ac.getAttributes(NewAttributeIdentifiers.record_id)) { ASN1Set set = a.getAttrValues(); String s = DERGeneralString.getInstance(set.getObjectAt(0)).getString(); wrapper.setRecordId(s); } for (Attribute a : ac.getAttributes(NewAttributeIdentifiers.time_stamp)) { ASN1Set set = a.getAttrValues(); Time t = new Time(set.getObjectAt(0).toASN1Primitive()); wrapper.setTimeStamp(t); } for (Attribute a : ac.getAttributes(NewAttributeIdentifiers.record_type)) { ASN1Set set = a.getAttrValues(); String[] arr = new String[set.size()]; for (int i = 0; i < set.size(); ++i) { arr[i] = DERGeneralString.getInstance(set.getObjectAt(i)).getString(); } wrapper.setRecordTypes(arr); } for (Attribute a : ac.getAttributes(NewAttributeIdentifiers.record_subject)) { ASN1Set set = a.getAttrValues(); String s = DERGeneralString.getInstance(set.getObjectAt(0)).getString(); wrapper.setRecord_subject(s); } for (Attribute a : ac.getAttributes(NewAttributeIdentifiers.actions_taken)) { ASN1Set set = a.getAttrValues(); String[] arr = new String[set.size()]; for (int i = 0; i < set.size(); ++i) { arr[i] = DERGeneralString.getInstance(set.getObjectAt(i)).getString(); } wrapper.setActions_taken(arr); } return wrapper; }
From source file:org.cesecore.util.CertTools.java
License:Open Source License
/** * Helper method for getting kerberos 5 principal name (altName, OtherName) * // w ww. ja v a2 s.com * Krb5PrincipalName is an OtherName Subject Alternative Name * * String representation is in form "principalname1/principalname2@realm" * * KRB5PrincipalName ::= SEQUENCE { realm [0] Realm, principalName [1] PrincipalName } * * Realm ::= KerberosString * * PrincipalName ::= SEQUENCE { name-type [0] Int32, name-string [1] SEQUENCE OF KerberosString } * * The new (post-RFC 1510) type KerberosString, defined below, is a GeneralString that is constrained to contain only characters in IA5String. * * KerberosString ::= GeneralString (IA5String) * * Int32 ::= INTEGER (-2147483648..2147483647) -- signed values representable in 32 bits * * @param seq the OtherName sequence * @return String with the krb5 name in the form of "principal1/principal2@realm" or null if the altName does not exist */ @SuppressWarnings("unchecked") protected static String getKrb5PrincipalNameFromSequence(ASN1Sequence seq) { String ret = null; if (seq != null) { // First in sequence is the object identifier, that we must check ASN1ObjectIdentifier id = ASN1ObjectIdentifier.getInstance(seq.getObjectAt(0)); if (id.getId().equals(CertTools.KRB5PRINCIPAL_OBJECTID)) { // Get the KRB5PrincipalName sequence ASN1TaggedObject oobj = (ASN1TaggedObject) seq.getObjectAt(1); // Due to bug in java cert.getSubjectAltName regarding OtherName, it can be tagged an extra time... ASN1Primitive obj = oobj.getObject(); if (obj instanceof ASN1TaggedObject) { obj = ASN1TaggedObject.getInstance(obj).getObject(); } ASN1Sequence krb5Seq = ASN1Sequence.getInstance(obj); // Get the Realm tagged as 0 ASN1TaggedObject robj = (ASN1TaggedObject) krb5Seq.getObjectAt(0); DERGeneralString realmObj = DERGeneralString.getInstance(robj.getObject()); String realm = realmObj.getString(); // Get the PrincipalName tagged as 1 ASN1TaggedObject pobj = (ASN1TaggedObject) krb5Seq.getObjectAt(1); // This is another sequence of type and name ASN1Sequence nseq = ASN1Sequence.getInstance(pobj.getObject()); // Get the name tagged as 1 ASN1TaggedObject nobj = (ASN1TaggedObject) nseq.getObjectAt(1); // The name is yet another sequence of GeneralString ASN1Sequence sseq = ASN1Sequence.getInstance(nobj.getObject()); Enumeration<ASN1Object> en = sseq.getObjects(); while (en.hasMoreElements()) { ASN1Primitive o = (ASN1Primitive) en.nextElement(); DERGeneralString str = DERGeneralString.getInstance(o); if (ret != null) { ret += "/" + str.getString(); } else { ret = str.getString(); } } // Add the realm in the end so we have "principal@realm" ret += "@" + realm; } } return ret; }
From source file:org.ejbca.util.CertTools.java
License:Open Source License
/** Helper method for getting kerberos 5 principal name (altName, OtherName) * /* w ww. j ava 2 s .com*/ * Krb5PrincipalName is an OtherName Subject Alternative Name * * String representation is in form "principalname1/principalname2@realm" * * KRB5PrincipalName ::= SEQUENCE { * realm [0] Realm, * principalName [1] PrincipalName * } * * Realm ::= KerberosString * * PrincipalName ::= SEQUENCE { * name-type [0] Int32, * name-string [1] SEQUENCE OF KerberosString * } * * The new (post-RFC 1510) type KerberosString, defined below, is a * GeneralString that is constrained to contain only characters in IA5String. * * KerberosString ::= GeneralString (IA5String) * * Int32 ::= INTEGER (-2147483648..2147483647) * -- signed values representable in 32 bits * * @param seq the OtherName sequence * @return String with the krb5 name in the form of "principal1/principal2@realm" or null if the altName does not exist */ @SuppressWarnings("unchecked") protected static String getKrb5PrincipalNameFromSequence(ASN1Sequence seq) { String ret = null; if (seq != null) { // First in sequence is the object identifier, that we must check DERObjectIdentifier id = DERObjectIdentifier.getInstance(seq.getObjectAt(0)); if (id.getId().equals(CertTools.KRB5PRINCIPAL_OBJECTID)) { // Get the KRB5PrincipalName sequence ASN1TaggedObject oobj = (ASN1TaggedObject) seq.getObjectAt(1); // After encoding in a cert, it is tagged an extra time... DERObject obj = oobj.getObject(); if (obj instanceof ASN1TaggedObject) { obj = ASN1TaggedObject.getInstance(obj).getObject(); } ASN1Sequence krb5Seq = ASN1Sequence.getInstance(obj); // Get the Realm tagged as 0 ASN1TaggedObject robj = (ASN1TaggedObject) krb5Seq.getObjectAt(0); DERGeneralString realmObj = DERGeneralString.getInstance(robj.getObject()); String realm = realmObj.getString(); // Get the PrincipalName tagged as 1 ASN1TaggedObject pobj = (ASN1TaggedObject) krb5Seq.getObjectAt(1); // This is another sequence of type and name ASN1Sequence nseq = ASN1Sequence.getInstance(pobj.getObject()); // Get the name tagged as 1 ASN1TaggedObject nobj = (ASN1TaggedObject) nseq.getObjectAt(1); // The name is yet another sequence of GeneralString ASN1Sequence sseq = ASN1Sequence.getInstance(nobj.getObject()); Enumeration<ASN1Object> en = sseq.getObjects(); while (en.hasMoreElements()) { ASN1Object o = (ASN1Object) en.nextElement(); DERGeneralString str = DERGeneralString.getInstance(o); if (ret != null) { ret += "/" + str.getString(); } else { ret = str.getString(); } } // Add the realm in the end so we have "principal@realm" ret += "@" + realm; } } return ret; }