while (iter.hasNext()) {
ASN1EncodableVector v = new ASN1EncodableVector();
v.add(new DERObjectIdentifier(CertTools.UPN_OBJECTID));
v.add(new DERTaggedObject(true, 0, new DERUTF8String((String)iter.next())));
//GeneralName gn = new GeneralName(new DERSequence(v), 0);
DERObject gn = new DERTaggedObject(false, 0, new DERSequence(v));
vec.add(gn);
}
}
ArrayList<String> guid = CertTools.getPartsFromDN(altName, CertTools.GUID);
if (!guid.isEmpty()) {
Iterator<String> iter = guid.iterator();
while (iter.hasNext()) {
ASN1EncodableVector v = new ASN1EncodableVector();
byte[] guidbytes = Hex.decode((String)iter.next());
if (guidbytes != null) {
v.add(new DERObjectIdentifier(CertTools.GUID_OBJECTID));
v.add(new DERTaggedObject(true, 0, new DEROctetString(guidbytes)));
DERObject gn = new DERTaggedObject(false, 0, new DERSequence(v));
vec.add(gn);
} else {
log.error("Cannot decode hexadecimal guid: "+guid);
}
}
}
// Krb5PrincipalName is an OtherName, see method getKrb5Principal...for ASN.1 definition
ArrayList<String> krb5principalname = CertTools.getPartsFromDN(altName, CertTools.KRB5PRINCIPAL);
if (!krb5principalname.isEmpty()) {
Iterator<String> iter = krb5principalname.iterator();
while (iter.hasNext()) {
// Start by parsing the input string to separate it in different parts
String principalString = (String)iter.next();
if (log.isDebugEnabled()) {
log.debug("principalString: "+principalString);
}
// The realm is the last part moving back until an @
int index = principalString.lastIndexOf('@');
String realm = "";
if (index > 0) {
realm = principalString.substring(index+1);
}
if (log.isDebugEnabled()) {
log.debug("realm: "+realm);
}
// Now we can have several principals separated by /
ArrayList<String> principalarr = new ArrayList<String>();
int jndex = 0;
int bindex = 0;
while (jndex < index) {
// Loop and add all strings separated by /
jndex = principalString.indexOf('/', bindex);
if (jndex == -1) {
jndex = index;
}
String s = principalString.substring(bindex, jndex);
if (log.isDebugEnabled()) {
log.debug("adding principal name: "+s);
}
principalarr.add(s);
bindex = jndex+1;
}
// Now we must construct the rather complex asn.1...
ASN1EncodableVector v = new ASN1EncodableVector(); // this is the OtherName
v.add(new DERObjectIdentifier(CertTools.KRB5PRINCIPAL_OBJECTID));
// First the Krb5PrincipalName sequence
ASN1EncodableVector krb5p = new ASN1EncodableVector();
// The realm is the first tagged GeneralString
krb5p.add(new DERTaggedObject(true, 0, new DERGeneralString(realm)));
// Second is the sequence of principal names, which is at tagged position 1 in the krb5p
ASN1EncodableVector principals = new ASN1EncodableVector();
// According to rfc4210 the type NT-UNKNOWN is 0, and according to some other rfc this type should be used...
principals.add(new DERTaggedObject(true, 0, new DERInteger(0)));
// The names themselves are yet another sequence
Iterator<String> i = principalarr.iterator();
ASN1EncodableVector names = new ASN1EncodableVector();
while (i.hasNext()) {
String principalName = (String)i.next();
names.add(new DERGeneralString(principalName));
}
principals.add(new DERTaggedObject(true, 1, new DERSequence(names)));
krb5p.add(new DERTaggedObject(true, 1, new DERSequence(principals)));
v.add(new DERTaggedObject(true, 0, new DERSequence(krb5p)));
DERObject gn = new DERTaggedObject(false, 0, new DERSequence(v));
vec.add(gn);
}
}
// To support custom OIDs in altNames, they must be added as an OtherName of plain type UTF8String
ArrayList<String> customoids = CertTools.getCustomOids(altName);
if (!customoids.isEmpty()) {
Iterator<String> iter = customoids.iterator();
while (iter.hasNext()) {
String oid = (String)iter.next();
ArrayList<String> oidval = CertTools.getPartsFromDN(altName, oid);
if (!oidval.isEmpty()) {
Iterator<String> valiter = oidval.iterator();
while (valiter.hasNext()) {
ASN1EncodableVector v = new ASN1EncodableVector();
v.add(new DERObjectIdentifier(oid));
v.add(new DERTaggedObject(true, 0, new DERUTF8String((String)valiter.next())));
DERObject gn = new DERTaggedObject(false, 0, new DERSequence(v));
vec.add(gn);
}
}
}
}