use of org.openecard.bouncycastle.asn1.x500.RDN in project robovm by robovm.
the class IETFUtils method rDNsFromString.
public static RDN[] rDNsFromString(String name, X500NameStyle x500Style) {
X500NameTokenizer nTok = new X500NameTokenizer(name);
X500NameBuilder builder = new X500NameBuilder(x500Style);
while (nTok.hasMoreTokens()) {
String token = nTok.nextToken();
if (token.indexOf('+') > 0) {
X500NameTokenizer pTok = new X500NameTokenizer(token, '+');
X500NameTokenizer vTok = new X500NameTokenizer(pTok.nextToken(), '=');
String attr = vTok.nextToken();
if (!vTok.hasMoreTokens()) {
throw new IllegalArgumentException("badly formatted directory string");
}
String value = vTok.nextToken();
ASN1ObjectIdentifier oid = x500Style.attrNameToOID(attr.trim());
if (pTok.hasMoreTokens()) {
Vector oids = new Vector();
Vector values = new Vector();
oids.addElement(oid);
values.addElement(unescape(value));
while (pTok.hasMoreTokens()) {
vTok = new X500NameTokenizer(pTok.nextToken(), '=');
attr = vTok.nextToken();
if (!vTok.hasMoreTokens()) {
throw new IllegalArgumentException("badly formatted directory string");
}
value = vTok.nextToken();
oid = x500Style.attrNameToOID(attr.trim());
oids.addElement(oid);
values.addElement(unescape(value));
}
builder.addMultiValuedRDN(toOIDArray(oids), toValueArray(values));
} else {
builder.addRDN(oid, unescape(value));
}
} else {
X500NameTokenizer vTok = new X500NameTokenizer(token, '=');
String attr = vTok.nextToken();
if (!vTok.hasMoreTokens()) {
throw new IllegalArgumentException("badly formatted directory string");
}
String value = vTok.nextToken();
ASN1ObjectIdentifier oid = x500Style.attrNameToOID(attr.trim());
builder.addRDN(oid, unescape(value));
}
}
return builder.build().getRDNs();
}
use of org.openecard.bouncycastle.asn1.x500.RDN in project jmeter by apache.
the class SMIMEAssertion method getEmailFromCert.
/**
* Extract email addresses from a certificate
*
* @param cert the X509 certificate holder
* @return a List of all email addresses found
* @throws CertificateException
*/
private static List<String> getEmailFromCert(X509CertificateHolder cert) throws CertificateException {
List<String> res = new ArrayList<>();
X500Name subject = cert.getSubject();
for (RDN emails : subject.getRDNs(BCStyle.EmailAddress)) {
for (AttributeTypeAndValue emailAttr : emails.getTypesAndValues()) {
if (log.isDebugEnabled()) {
log.debug("Add email from RDN: {}", IETFUtils.valueToString(emailAttr.getValue()));
}
res.add(IETFUtils.valueToString(emailAttr.getValue()));
}
}
Extension subjectAlternativeNames = cert.getExtension(Extension.subjectAlternativeName);
if (subjectAlternativeNames != null) {
for (GeneralName name : GeneralNames.getInstance(subjectAlternativeNames.getParsedValue()).getNames()) {
if (name.getTagNo() == GeneralName.rfc822Name) {
String email = IETFUtils.valueToString(name.getName());
log.debug("Add email from subjectAlternativeName: {}", email);
res.add(email);
}
}
}
return res;
}
use of org.openecard.bouncycastle.asn1.x500.RDN in project ddf by codice.
the class SubjectUtilsTest method testFilterDNKeepOne.
@Test
public void testFilterDNKeepOne() {
Predicate<RDN> predicate = rdn -> rdn.getTypesAndValues()[0].getType().equals(BCStyle.CN);
String baseDN = SubjectUtils.filterDN(dnPrincipal, predicate);
assertThat(baseDN, is("CN=Foo"));
}
use of org.openecard.bouncycastle.asn1.x500.RDN in project ddf by codice.
the class SubjectUtilsTest method testFilterDNDropOne.
@Test
public void testFilterDNDropOne() {
Predicate<RDN> predicate = rdn -> !rdn.getTypesAndValues()[0].getType().equals(BCStyle.CN);
String baseDN = SubjectUtils.filterDN(dnPrincipal, predicate);
assertThat(baseDN, is("OU=Engineering,OU=Dev,O=DDF,ST=AZ,C=US"));
}
use of org.openecard.bouncycastle.asn1.x500.RDN in project ddf by codice.
the class SubjectUtilsTest method testFilterDNDropMultivalue.
@Test
public void testFilterDNDropMultivalue() {
Predicate<RDN> predicate = rdn -> !rdn.getTypesAndValues()[0].getType().equals(BCStyle.OU);
String baseDN = SubjectUtils.filterDN(dnPrincipal, predicate);
assertThat(baseDN, is("CN=Foo,O=DDF,ST=AZ,C=US"));
}
Aggregations