use of org.openecard.bouncycastle.asn1.x509.Extension in project robovm by robovm.
the class RFC3280CertPathUtilities method processCRLC.
/**
* If use-deltas is set, verify the issuer and scope of the delta CRL.
*
* @param deltaCRL The delta CRL.
* @param completeCRL The complete CRL.
* @param pkixParams The PKIX paramaters.
* @throws AnnotatedException if an exception occurs.
*/
protected static void processCRLC(X509CRL deltaCRL, X509CRL completeCRL, ExtendedPKIXParameters pkixParams) throws AnnotatedException {
if (deltaCRL == null) {
return;
}
IssuingDistributionPoint completeidp = null;
try {
completeidp = IssuingDistributionPoint.getInstance(CertPathValidatorUtilities.getExtensionValue(completeCRL, RFC3280CertPathUtilities.ISSUING_DISTRIBUTION_POINT));
} catch (Exception e) {
throw new AnnotatedException("Issuing distribution point extension could not be decoded.", e);
}
if (pkixParams.isUseDeltasEnabled()) {
// (c) (1)
if (!deltaCRL.getIssuerX500Principal().equals(completeCRL.getIssuerX500Principal())) {
throw new AnnotatedException("Complete CRL issuer does not match delta CRL issuer.");
}
// (c) (2)
IssuingDistributionPoint deltaidp = null;
try {
deltaidp = IssuingDistributionPoint.getInstance(CertPathValidatorUtilities.getExtensionValue(deltaCRL, ISSUING_DISTRIBUTION_POINT));
} catch (Exception e) {
throw new AnnotatedException("Issuing distribution point extension from delta CRL could not be decoded.", e);
}
boolean match = false;
if (completeidp == null) {
if (deltaidp == null) {
match = true;
}
} else {
if (completeidp.equals(deltaidp)) {
match = true;
}
}
if (!match) {
throw new AnnotatedException("Issuing distribution point extension from delta CRL and complete CRL does not match.");
}
// (c) (3)
ASN1Primitive completeKeyIdentifier = null;
try {
completeKeyIdentifier = CertPathValidatorUtilities.getExtensionValue(completeCRL, AUTHORITY_KEY_IDENTIFIER);
} catch (AnnotatedException e) {
throw new AnnotatedException("Authority key identifier extension could not be extracted from complete CRL.", e);
}
ASN1Primitive deltaKeyIdentifier = null;
try {
deltaKeyIdentifier = CertPathValidatorUtilities.getExtensionValue(deltaCRL, AUTHORITY_KEY_IDENTIFIER);
} catch (AnnotatedException e) {
throw new AnnotatedException("Authority key identifier extension could not be extracted from delta CRL.", e);
}
if (completeKeyIdentifier == null) {
throw new AnnotatedException("CRL authority key identifier is null.");
}
if (deltaKeyIdentifier == null) {
throw new AnnotatedException("Delta CRL authority key identifier is null.");
}
if (!completeKeyIdentifier.equals(deltaKeyIdentifier)) {
throw new AnnotatedException("Delta CRL authority key identifier does not match complete CRL authority key identifier.");
}
}
}
use of org.openecard.bouncycastle.asn1.x509.Extension in project zm-mailbox by Zimbra.
the class CertUtil method printCRLDistributionPoints.
private void printCRLDistributionPoints(PrintStream outStream) throws Exception {
outStream.format("X509v3 CRL Distribution Points: \n");
// 2.5.29.31
String extOid = X509Extension.cRLDistributionPoints.getId();
byte[] extVal = cert.getExtensionValue(extOid);
if (extVal == null) {
return;
}
/* http://download.oracle.com/javase/6/docs/api/java/security/cert/X509Extension.html#getExtensionValue(java.lang.String)
*
The ASN.1 definition for this is:
Extensions ::= SEQUENCE SIZE (1..MAX) OF Extension
Extension ::= SEQUENCE {
extnId OBJECT IDENTIFIER,
critical BOOLEAN DEFAULT FALSE,
extnValue OCTET STRING
-- contains a DER encoding of a value
-- of the type registered for use with
-- the extnId object identifier value
}
*/
byte[] extnValue = DEROctetString.getInstance(ASN1Object.fromByteArray(extVal)).getOctets();
CRLDistPoint crlDistPoint = CRLDistPoint.getInstance(ASN1Object.fromByteArray(extnValue));
DistributionPoint[] distPoints = crlDistPoint.getDistributionPoints();
for (DistributionPoint distPoint : distPoints) {
DistributionPointName distPointName = distPoint.getDistributionPoint();
int type = distPointName.getType();
if (DistributionPointName.FULL_NAME == type) {
outStream.format("Full Name: \n");
GeneralNames generalNames = GeneralNames.getInstance(distPointName.getName());
GeneralName[] names = generalNames.getNames();
for (GeneralName generalname : names) {
int tag = generalname.getTagNo();
if (GeneralName.uniformResourceIdentifier == tag) {
DEREncodable name = generalname.getName();
DERIA5String str = DERIA5String.getInstance(name);
String value = str.getString();
outStream.format(" %s\n", value);
} else {
outStream.format("tag %d not yet implemented", tag);
}
}
} else {
outStream.format("type %d not yet implemented", type);
}
}
}
use of org.openecard.bouncycastle.asn1.x509.Extension in project oxTrust by GluuFederation.
the class ExtensionDeserializer method deserialize.
@Override
public Extension deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException {
log.info(" deserialize() ");
try {
if (id == null || id.isEmpty()) {
throw new IllegalArgumentException("The URN cannot be null or empty");
}
JsonNode rootNode = jsonParser.readValueAsTree();
if (!rootNode.isObject()) {
throw new IllegalArgumentException("Extension is of wrong JSON type");
}
Extension.Builder extensionBuilder = new Extension.Builder(id);
Iterator<Map.Entry<String, JsonNode>> fieldIterator = rootNode.getFields();
while (fieldIterator.hasNext()) {
Map.Entry<String, JsonNode> entry = fieldIterator.next();
GluuAttribute gluuAttribute = attributeService.getAttributeByName(entry.getKey());
if (gluuAttribute != null) {
if (!(gluuAttribute.getOxSCIMCustomAttribute() != null && gluuAttribute.getOxSCIMCustomAttribute().equals(ScimCustomAtribute.TRUE))) {
log.info(" NOT A CUSTOM ATTRIBUTE: " + gluuAttribute.getName());
throw new IllegalArgumentException("NOT A CUSTOM ATTRIBUTE: " + gluuAttribute.getName());
}
GluuAttributeDataType attributeDataType = gluuAttribute.getDataType();
if ((gluuAttribute.getOxMultivaluedAttribute() != null) && gluuAttribute.getOxMultivaluedAttribute().equals(OxMultivalued.TRUE)) {
if (entry.getValue() instanceof ArrayNode) {
ArrayNode arrayNode = (ArrayNode) entry.getValue();
ObjectMapper mapper = new ObjectMapper();
mapper.disable(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES);
if (attributeDataType.equals(GluuAttributeDataType.STRING) || attributeDataType.equals(GluuAttributeDataType.PHOTO)) {
List<String> stringList = Arrays.asList(mapper.readValue(arrayNode, String[].class));
extensionBuilder.setFieldAsList(entry.getKey(), stringList);
} else if (attributeDataType.equals(GluuAttributeDataType.DATE)) {
// For validation
List<Date> dateList = Arrays.asList(mapper.readValue(arrayNode, Date[].class));
extensionBuilder.setFieldAsList(entry.getKey(), Arrays.asList(mapper.readValue(arrayNode, String[].class)));
} else if (attributeDataType.equals(GluuAttributeDataType.NUMERIC)) {
List<BigDecimal> numberList = Arrays.asList(mapper.readValue(arrayNode, BigDecimal[].class));
extensionBuilder.setFieldAsList(entry.getKey(), numberList);
} else {
log.info(" NO MATCH: attributeDataType.getDisplayName() = " + attributeDataType.getDisplayName());
throw new IllegalArgumentException("JSON type not supported: " + entry.getValue().toString());
}
} else {
throw new IllegalArgumentException("Attribute \"" + entry.getKey() + "\" is multi-valued but passed value is not of array type.");
}
} else {
if (entry.getValue() instanceof ArrayNode) {
throw new IllegalArgumentException("Attribute \"" + entry.getKey() + "\" is not multi-valued but passed value is of array type.");
} else {
if (attributeDataType.equals(GluuAttributeDataType.STRING) || attributeDataType.equals(GluuAttributeDataType.PHOTO)) {
handleString(extensionBuilder, entry);
} else if (attributeDataType.equals(GluuAttributeDataType.DATE)) {
handleDateTime(extensionBuilder, entry);
} else if (attributeDataType.equals(GluuAttributeDataType.NUMERIC)) {
handleNumber(extensionBuilder, entry);
} else {
log.info(" NO MATCH: attributeDataType.getDisplayName() = " + attributeDataType.getDisplayName());
throw new IllegalArgumentException("JSON type not supported: " + entry.getValue().toString());
}
}
}
} else {
throw new IllegalArgumentException("NOT FOUND: custom attribute = " + entry.getKey());
}
}
return extensionBuilder.build();
} catch (Exception e) {
e.printStackTrace();
throw new IOException(INTERNAL_SERVER_ERROR_MESSAGE);
}
}
use of org.openecard.bouncycastle.asn1.x509.Extension in project oxTrust by GluuFederation.
the class GluuCustomPerson method setExtensions.
public void setExtensions(Map<String, Extension> extensions) throws Exception {
this.extensions = extensions;
for (Map.Entry<String, Extension> extensionEntry : extensions.entrySet()) {
Extension extension = extensionEntry.getValue();
for (Map.Entry<String, Extension.Field> fieldEntry : extension.getFields().entrySet()) {
if (fieldEntry.getValue().isMultiValued() && (fieldEntry.getValue().getValue() != null)) {
ObjectMapper mapper = new ObjectMapper();
mapper.disable(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES);
String[] values = mapper.readValue(fieldEntry.getValue().getValue(), String[].class);
setAttribute(fieldEntry.getKey(), values);
} else {
setAttribute(fieldEntry.getKey(), fieldEntry.getValue().getValue());
}
}
}
}
use of org.openecard.bouncycastle.asn1.x509.Extension in project oxTrust by GluuFederation.
the class UserExtensionsTest method testCreatePersonFromJsonString.
@Test
@Parameters({ "test.scim2.userext.create_json" })
public void testCreatePersonFromJsonString(final String createJson) throws Exception {
System.out.println(" testCreatePersonFromJsonString() ");
// Create custom attributes
// String, not
GluuAttribute scimCustomFirst = null;
// multi-valued
if (attributeService.getAttributeByName("scimCustomFirst") == null) {
scimCustomFirst = createCustomAttribute(attributeService, schemaService, appConfiguration, "scimCustomFirst", "Custom First", "First custom attribute", GluuAttributeDataType.STRING, OxMultivalued.FALSE);
}
// Date, multi-valued
GluuAttribute scimCustomSecond = null;
if (attributeService.getAttributeByName("scimCustomSecond") == null) {
scimCustomSecond = createCustomAttribute(attributeService, schemaService, appConfiguration, "scimCustomSecond", "Custom Second", "Second custom attribute", GluuAttributeDataType.DATE, OxMultivalued.TRUE);
}
// Numeric, not
GluuAttribute scimCustomThird = null;
// multi-valued
if (attributeService.getAttributeByName("scimCustomThird") == null) {
scimCustomThird = createCustomAttribute(attributeService, schemaService, appConfiguration, "scimCustomThird", "Custom Third", "Third custom attribute", GluuAttributeDataType.NUMERIC, OxMultivalued.FALSE);
}
// String CREATEJSON =
// "{\"schemas\":[\"urn:ietf:params:scim:schemas:core:2.0:User\",\"urn:ietf:params:scim:schemas:extension:gluu:2.0:User\"],\"urn:ietf:params:scim:schemas:extension:gluu:2.0:User\":
// {\"scimCustomFirst\":\"[1000,2000]\",\"scimCustomSecond\":[\"2016-02-23T15:35:22Z\"],\"scimCustomThird\":3000},\"externalId\":\"scimclient\",\"userName\":\"userjson.add.username\",\"name\":{\"givenName\":\"json\",\"familyName\":\"json\",\"middleName\":\"N/A\",\"honorificPrefix\":\"N/A\",\"honorificSuffix\":\"N/A\"},\"displayName\":\"json
// json\",\"nickName\":\"json\",\"profileUrl\":\"http://www.gluu.org/\",\"emails\":[{\"value\":\"json@gluu.org\",\"type\":\"work\",\"primary\":\"true\"},{\"value\":\"json2@gluu.org\",\"type\":\"home\",\"primary\":\"false\"}],\"addresses\":[{\"type\":\"work\",\"streetAddress\":\"621
// East 6th Street Suite
// 200\",\"locality\":\"Austin\",\"region\":\"TX\",\"postalCode\":\"78701\",\"country\":\"US\",\"formatted\":\"621
// East 6th Street Suite 200 Austin , TX 78701
// US\",\"primary\":\"true\"}],\"phoneNumbers\":[{\"value\":\"646-345-2346\",\"type\":\"work\"}],\"ims\":[{\"value\":\"nynytest_user\",\"type\":\"Skype\"}],\"userType\":\"CEO\",\"title\":\"CEO\",\"preferredLanguage\":\"en-us\",\"locale\":\"en_US\",\"active\":\"true\",\"password\":\"secret\",\"roles\":[{\"value\":\"Owner\"}],\"entitlements\":[{\"value\":\"full
// access\"}],\"x509Certificates\":[{\"value\":\"MIIDQzCCAqygAwIBAgICEAAwDQYJKoZIhvcNAQEFBQAwTjELMAkGA1UEBhMCVVMxEzARBgNVBAgMCkNhbGlmb3JuaWExFDASBgNVBAoMC2V4YW1wbGUuY29tMRQwEgYDVQQDDAtleGFtcGxlLmNvbTAeFw0xMTEwMjIwNjI0MzFaFw0xMjEwMDQwNjI0MzFa
// MH8xCzAJBgNVBAYTAlVTMRMwEQYDVQQIDApDYWxpZm9ybmlhMRQwEgYDVQQKDAtleGFtcGxlLmNvbTEhMB8GA1UEAwwYTXMuIEJhcmJhcmEgSiBKZW5zZW4gSUlJMSIwIAYJKoZIhvcNAQkBFhNiamVuc2VuQGV4YW1wbGUuY29tMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA7Kr+Dcds/JQ5GwejJFcBIP682X3xpjis56AK02bc1FLgzdLI8auoR+cC9/Vrh5t66HkQIOdA4unHh0AaZ4xL5PhVbXIPMB5vAPKpzz5iPSi8xO8SL7I7SDhcBVJhqVqr3HgllEG6UClDdHO7nkLuwXq8HcISKkbT5WFTVfFZzidPl8HZ7DhXkZIRtJwBweq4bvm3hM1Os7UQH05ZS6cVDgweKNwdLLrT51ikSQG3DYrl+ft781UQRIqxgwqCfXEuDiinPh0kkvIi5jivVu1Z9QiwlYEdRbLJ4zJQBmDrSGTMYn4lRc2HgHO4DqB/bnMVorHB0CC6AV1QoFK4GPe1LwIDAQABo3sweTAJBgNVHRMEAjAAMCwGCWCGSAGG+EIBDQQfFh1PcGVuU1NMIEdlbmVyYXRlZCBDZXJ0aWZpY2F0ZTAdBgNVHQ4EFgQU8pD0U0vsZIsaA16lL8En8bx0F/gwHwYDVR0jBBgwFoAUdGeKitcaF7gnzsNwDx708kqaVt0wDQYJKoZIhvcNAQEFBQADgYEAA81SsFnOdYJtNg5Tcq+/ByEDrBgnusx0jloUhByPMEVkoMZ3J7j1ZgI8rAbOkNngX8+pKfTiDz1RC4+dx8oU6Za+4NJXUjlL5CvV6BEYb1+QAEJwitTVvxB/A67g42/vzgAtoRUeDov1+GFiBZ+GNF/cAYKcMtGcrs2i97ZkJMo=\"}],\"meta\":{\"created\":\"2010-01-23T04:56:22Z\",\"lastModified\":\"2011-05-13T04:42:34Z\",\"version\":\"aversion\",\"location\":\"http://localhost:8080/identity/seam/resource/restv1/Users/8c4b6c26-efaf-4840-bddf-c0146a8eb2a9\"}}";
ObjectMapper mapper = new ObjectMapper();
mapper.disable(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES);
SimpleModule simpleModule = new SimpleModule("SimpleModule", new Version(1, 0, 0, ""));
simpleModule.addDeserializer(User.class, new UserDeserializer());
mapper.registerModule(simpleModule);
User user = mapper.readValue(createJson, User.class);
String testUserName = user.getUserName() + " (" + System.currentTimeMillis() + ")";
user.setUserName(testUserName);
Extension extension = user.getExtension(Constants.USER_EXT_SCHEMA_ID);
assertNotNull(extension, "(Deserialization) Custom extension not deserialized.");
Extension.Field customFirstField = extension.getFields().get("scimCustomFirst");
assertNotNull(customFirstField, "(Deserialization) \"scimCustomFirst\" field not deserialized.");
assertEquals(customFirstField.getValue(), "[1000,2000]");
System.out.println("##### (Deserialization) customFirstField.getValue() = " + customFirstField.getValue());
Extension.Field customSecondField = extension.getFields().get("scimCustomSecond");
assertNotNull(customSecondField, "(Deserialization) \"scimCustomSecond\" field not deserialized.");
List<Date> dateList = Arrays.asList(mapper.readValue(customSecondField.getValue(), Date[].class));
assertEquals(dateList.size(), 1);
System.out.println("##### (Deserialization) dateList.get(0) = " + dateList.get(0));
Extension.Field customThirdField = extension.getFields().get("scimCustomThird");
assertNotNull(customThirdField, "(Deserialization) \"scimCustomThird\" field not deserialized.");
assertEquals(new BigDecimal(customThirdField.getValue()), new BigDecimal(3000));
System.out.println("##### (Deserialization) customThirdField.getValue() = " + customThirdField.getValue());
// Create Person
GluuCustomPerson gluuPerson = copyUtils2.copy(user, null, false);
assertNotNull(gluuPerson, "gluuPerson is null!");
System.out.println(">>>>> gluuPerson.getUid() = " + gluuPerson.getUid());
String inum = personService.generateInumForNewPerson();
String dn = personService.getDnForPerson(inum);
String iname = personService.generateInameForNewPerson(user.getUserName());
gluuPerson.setDn(dn);
gluuPerson.setInum(inum);
gluuPerson.setIname(iname);
gluuPerson.setCommonName(gluuPerson.getGivenName() + " " + gluuPerson.getSurname());
personService.addPerson(gluuPerson);
// Retrieve Person
GluuCustomPerson retrievedPerson = personService.getPersonByUid(gluuPerson.getUid());
assertNotNull(retrievedPerson, "Failed to find person.");
User newPerson = copyUtils2.copy(retrievedPerson, null);
extension = newPerson.getExtension(Constants.USER_EXT_SCHEMA_ID);
assertNotNull(extension, "(Persistence) Custom extension not persisted.");
customFirstField = extension.getFields().get("scimCustomFirst");
assertNotNull(customFirstField, "(Persistence) \"scimCustomFirst\" field not persisted.");
assertEquals(customFirstField.getValue(), "[1000,2000]");
System.out.println("##### (Persistence) customFirstField.getValue() = " + customFirstField.getValue());
customSecondField = extension.getFields().get("scimCustomSecond");
assertNotNull(customSecondField, "(Persistence) \"scimCustomSecond\" field not persisted.");
dateList = Arrays.asList(mapper.readValue(customSecondField.getValue(), Date[].class));
assertEquals(dateList.size(), 1);
System.out.println("##### (Persistence) dateList.get(0) = " + dateList.get(0));
customThirdField = extension.getFields().get("scimCustomThird");
assertNotNull(customThirdField, "(Persistence) \"scimCustomThird\" field not persisted.");
assertEquals(new BigDecimal(customThirdField.getValue()), new BigDecimal(3000));
System.out.println("##### (Persistence) customThirdField.getValue() = " + customThirdField.getValue());
// Remove Person
memberService.removePerson(retrievedPerson);
// Remove custom attributes
// schemaService.removeAttributeTypeFromObjectClass(scimCustomFirst.getOrigin(),
// scimCustomFirst.getName());
// schemaService.removeStringAttribute(scimCustomFirst.getName());
// attributeService.removeAttribute(scimCustomFirst);
// schemaService.removeAttributeTypeFromObjectClass(scimCustomSecond.getOrigin(),
// scimCustomSecond.getName());
// schemaService.removeStringAttribute(scimCustomSecond.getName());
// attributeService.removeAttribute(scimCustomSecond);
// schemaService.removeAttributeTypeFromObjectClass(scimCustomThird.getOrigin(),
// scimCustomThird.getName());
// schemaService.removeStringAttribute(scimCustomThird.getName());
// attributeService.removeAttribute(scimCustomThird);
}
Aggregations