use of org.bouncycastle.asn1.x509.Attribute in project keystore-explorer by kaikramer.
the class DViewCsr method populatePkcs10CsrDetails.
private void populatePkcs10CsrDetails() throws CryptoException {
jtfFormat.setText(res.getString("DViewCsr.jtfFormat.Pkcs10.text"));
jtfFormat.setCaretPosition(0);
jdnSubject.setDistinguishedName(pkcs10Csr.getSubject());
jbPem.setEnabled(true);
jbAsn1.setEnabled(true);
Attribute[] extReqAttr = pkcs10Csr.getAttributes(pkcs_9_at_extensionRequest);
if (extReqAttr != null && extReqAttr.length > 0) {
jbExtensions.setEnabled(true);
} else {
jbExtensions.setEnabled(false);
}
DialogHelper.populatePkcs10Challenge(pkcs10Csr.getAttributes(), jtfChallenge);
DialogHelper.populatePkcs10UnstructuredName(pkcs10Csr.getAttributes(), jtfUnstructuredName);
populatePublicKey(getPkcs10PublicKey());
String sigAlgId = pkcs10Csr.getSignatureAlgorithm().getAlgorithm().getId();
SignatureType sigAlg = SignatureType.resolveOid(sigAlgId);
if (sigAlg != null) {
jtfSignatureAlgorithm.setText(sigAlg.friendly());
} else {
jtfSignatureAlgorithm.setText(sigAlgId);
}
jtfSignatureAlgorithm.setCaretPosition(0);
}
use of org.bouncycastle.asn1.x509.Attribute in project keystore-explorer by kaikramer.
the class DialogHelper method populatePkcs10UnstructuredName.
/**
* Populates a JTextField with PKCS#10/#9 unstructuredName
*
* @param attributes
* Attributes from CSR
* @param textField
* Text field to be populated with the unstructuredName
*/
public static void populatePkcs10UnstructuredName(Attribute[] attributes, JTextField textField) {
ASN1ObjectIdentifier pkcs9UnstructureName = PKCSObjectIdentifiers.pkcs_9_at_unstructuredName;
populateTextField(attributes, textField, pkcs9UnstructureName);
}
use of org.bouncycastle.asn1.x509.Attribute in project pwm by pwm-project.
the class StoredConfigurationImpl method writeConfigProperty.
@Override
public void writeConfigProperty(final ConfigurationProperty propertyName, final String value) {
domModifyLock.writeLock().lock();
try {
final XPathExpression xp = XPathBuilder.xpathForConfigProperty(propertyName);
final List<Element> propertyElements = xp.evaluate(document);
for (final Element propertyElement : propertyElements) {
propertyElement.detach();
}
final Element propertyElement = new Element(XML_ELEMENT_PROPERTY);
propertyElement.setAttribute(new Attribute(XML_ATTRIBUTE_KEY, propertyName.getKey()));
propertyElement.setContent(new Text(value));
if (null == XPathBuilder.xpathForConfigProperties().evaluateFirst(document)) {
final Element configProperties = new Element(XML_ELEMENT_PROPERTIES);
configProperties.setAttribute(new Attribute(XML_ATTRIBUTE_TYPE, XML_ATTRIBUTE_VALUE_CONFIG));
document.getRootElement().addContent(configProperties);
}
final XPathExpression xp2 = XPathBuilder.xpathForConfigProperties();
final Element propertiesElement = (Element) xp2.evaluateFirst(document);
propertyElement.setAttribute(XML_ATTRIBUTE_MODIFY_TIME, JavaHelper.toIsoDate(Instant.now()));
propertiesElement.setAttribute(XML_ATTRIBUTE_MODIFY_TIME, JavaHelper.toIsoDate(Instant.now()));
propertiesElement.addContent(propertyElement);
} finally {
domModifyLock.writeLock().unlock();
}
}
use of org.bouncycastle.asn1.x509.Attribute in project fabric-sdk-java by hyperledger.
the class HFCAClientIT method testCertificateRevoke.
// Tests revoking a certificate
@Test
public void testCertificateRevoke() throws Exception {
SampleUser user = getTestUser(TEST_USER1_ORG);
if (!user.isRegistered()) {
RegistrationRequest rr = new RegistrationRequest(user.getName(), TEST_USER1_AFFILIATION);
String password = "testUserRevoke";
rr.setSecret(password);
rr.addAttribute(new Attribute("user.role", "department lead"));
rr.addAttribute(new Attribute(HFCAClient.HFCA_ATTRIBUTE_HFREVOKER, "true"));
// Admin can register other users.
user.setEnrollmentSecret(client.register(rr, admin));
if (!user.getEnrollmentSecret().equals(password)) {
fail("Secret returned from RegistrationRequest not match : " + user.getEnrollmentSecret());
}
}
if (!user.isEnrolled()) {
EnrollmentRequest req = new EnrollmentRequest(DEFAULT_PROFILE_NAME, "label 2", null);
req.addHost("example3.ibm.com");
user.setEnrollment(client.enroll(user.getName(), user.getEnrollmentSecret(), req));
}
// verify
String cert = user.getEnrollment().getCert();
BufferedInputStream pem = new BufferedInputStream(new ByteArrayInputStream(cert.getBytes()));
CertificateFactory certFactory = CertificateFactory.getInstance(Config.getConfig().getCertificateFormat());
X509Certificate certificate = (X509Certificate) certFactory.generateCertificate(pem);
// get its serial number
String serial = DatatypeConverter.printHexBinary(certificate.getSerialNumber().toByteArray());
// get its aki
// 2.5.29.35 : AuthorityKeyIdentifier
byte[] extensionValue = certificate.getExtensionValue(Extension.authorityKeyIdentifier.getId());
ASN1OctetString akiOc = ASN1OctetString.getInstance(extensionValue);
String aki = DatatypeConverter.printHexBinary(AuthorityKeyIdentifier.getInstance(akiOc.getOctets()).getKeyIdentifier());
int startedWithRevokes = -1;
if (!testConfig.isRunningAgainstFabric10()) {
// prevent clock skewing. make sure we request started with revokes.
Thread.sleep(1000);
// one more after we do this revoke.
startedWithRevokes = getRevokes(null).length;
// prevent clock skewing. make sure we request started with revokes.
Thread.sleep(1000);
}
// revoke all enrollment of this user
client.revoke(admin, serial, aki, "revoke certificate");
if (!testConfig.isRunningAgainstFabric10()) {
final int newRevokes = getRevokes(null).length;
assertEquals(format("Expected one more revocation %d, but got %d", startedWithRevokes + 1, newRevokes), startedWithRevokes + 1, newRevokes);
}
}
use of org.bouncycastle.asn1.x509.Attribute in project fabric-sdk-java by hyperledger.
the class HFCAClientIT method testRegisterAttributes.
// Tests attributes
@Test
public void testRegisterAttributes() throws Exception {
if (testConfig.isRunningAgainstFabric10()) {
// needs v1.1
return;
}
SampleUser user = new SampleUser("mrAttributes", TEST_ADMIN_ORG, sampleStore);
RegistrationRequest rr = new RegistrationRequest(user.getName(), TEST_USER1_AFFILIATION);
String password = "mrAttributespassword";
rr.setSecret(password);
rr.addAttribute(new Attribute("testattr1", "mrAttributesValue1"));
rr.addAttribute(new Attribute("testattr2", "mrAttributesValue2"));
rr.addAttribute(new Attribute("testattrDEFAULTATTR", "mrAttributesValueDEFAULTATTR", true));
user.setEnrollmentSecret(client.register(rr, admin));
if (!user.getEnrollmentSecret().equals(password)) {
fail("Secret returned from RegistrationRequest not match : " + user.getEnrollmentSecret());
}
EnrollmentRequest req = new EnrollmentRequest();
req.addAttrReq("testattr2").setOptional(false);
user.setEnrollment(client.enroll(user.getName(), user.getEnrollmentSecret(), req));
Enrollment enrollment = user.getEnrollment();
String cert = enrollment.getCert();
String certdec = getStringCert(cert);
assertTrue(format("Missing testattr2 in certficate decoded: %s", certdec), certdec.contains("\"testattr2\":\"mrAttributesValue2\""));
// Since request had specific attributes don't expect defaults.
assertFalse(format("Contains testattrDEFAULTATTR in certificate decoded: %s", certdec), certdec.contains("\"testattrDEFAULTATTR\"") || certdec.contains("\"mrAttributesValueDEFAULTATTR\""));
assertFalse(format("Contains testattr1 in certificate decoded: %s", certdec), certdec.contains("\"testattr1\"") || certdec.contains("\"mrAttributesValue1\""));
}
Aggregations