use of com.android.org.bouncycastle.asn1.x509.Attribute in project JMRI by JMRI.
the class GuiLafConfigPaneXml method load.
@Override
public boolean load(Element shared, Element perNode) {
boolean result = true;
UIManager.LookAndFeelInfo[] plafs = UIManager.getInstalledLookAndFeels();
java.util.Hashtable<String, String> installedLAFs = new java.util.Hashtable<String, String>(plafs.length);
for (int i = 0; i < plafs.length; i++) {
installedLAFs.put(plafs[i].getName(), plafs[i].getClassName());
}
String name = shared.getAttribute("LAFclass").getValue();
String className = installedLAFs.get(name);
log.debug("GUI selection: " + name + " class name: " + className);
// set the GUI
if (className != null) {
InstanceManager.getDefault(GuiLafPreferencesManager.class).setLookAndFeel(name);
try {
if (!className.equals(UIManager.getLookAndFeel().getClass().getName())) {
log.debug("set GUI to " + name + "," + className);
updateLookAndFeel(name, className);
} else {
log.debug("skip updateLAF as already has className==" + className);
}
} catch (Exception ex) {
log.error("Exception while setting GUI look & feel: " + ex);
result = false;
}
}
Attribute langAttr = shared.getAttribute("LocaleLanguage");
Attribute countryAttr = shared.getAttribute("LocaleCountry");
Attribute varAttr = shared.getAttribute("LocaleVariant");
if (countryAttr != null && langAttr != null && varAttr != null) {
Locale locale = new Locale(langAttr.getValue(), countryAttr.getValue(), varAttr.getValue());
Locale.setDefault(locale);
InstanceManager.getDefault(GuiLafPreferencesManager.class).setLocale(locale);
}
Attribute clickAttr = shared.getAttribute("nonStandardMouseEvent");
if (clickAttr != null) {
boolean nonStandardMouseEvent = clickAttr.getValue().equals("yes");
jmri.util.swing.SwingSettings.setNonStandardMouseEvent(nonStandardMouseEvent);
InstanceManager.getDefault(GuiLafPreferencesManager.class).setNonStandardMouseEvent(nonStandardMouseEvent);
}
Attribute graphicAttr = shared.getAttribute("graphicTableState");
if (graphicAttr != null) {
boolean graphicTableState = graphicAttr.getValue().equals("yes");
InstanceManager.getDefault(GuiLafPreferencesManager.class).setGraphicTableState(graphicTableState);
}
GuiLafConfigPane g = new GuiLafConfigPane();
ConfigureManager cm = jmri.InstanceManager.getNullableDefault(jmri.ConfigureManager.class);
if (cm != null) {
cm.registerPref(g);
}
Attribute fontsize = shared.getAttribute("fontsize");
if (fontsize != null) {
int size = Integer.parseInt(fontsize.getValue());
InstanceManager.getDefault(GuiLafPreferencesManager.class).setFontSize(size);
this.setUIFontSize(size);
}
return result;
}
use of com.android.org.bouncycastle.asn1.x509.Attribute in project athenz by yahoo.
the class Crypto method extractX509CSREmail.
public static String extractX509CSREmail(PKCS10CertificationRequest certReq) {
String rfc822 = null;
Attribute[] attributes = certReq.getAttributes(PKCSObjectIdentifiers.pkcs_9_at_extensionRequest);
for (Attribute attribute : attributes) {
for (ASN1Encodable value : attribute.getAttributeValues()) {
Extensions extensions = Extensions.getInstance(value);
GeneralNames gns = GeneralNames.fromExtensions(extensions, Extension.subjectAlternativeName);
for (GeneralName name : gns.getNames()) {
if (name.getTagNo() == GeneralName.rfc822Name) {
rfc822 = (((DERIA5String) name.getName()).getString());
break;
}
}
}
}
return rfc822;
}
use of com.android.org.bouncycastle.asn1.x509.Attribute in project athenz by yahoo.
the class Crypto method extractX509CSRDnsNames.
public static List<String> extractX509CSRDnsNames(PKCS10CertificationRequest certReq) {
List<String> dnsNames = new ArrayList<>();
Attribute[] attributes = certReq.getAttributes(PKCSObjectIdentifiers.pkcs_9_at_extensionRequest);
for (Attribute attribute : attributes) {
for (ASN1Encodable value : attribute.getAttributeValues()) {
Extensions extensions = Extensions.getInstance(value);
GeneralNames gns = GeneralNames.fromExtensions(extensions, Extension.subjectAlternativeName);
for (GeneralName name : gns.getNames()) {
if (name.getTagNo() == GeneralName.dNSName) {
dnsNames.add(((DERIA5String) name.getName()).getString());
}
}
}
}
return dnsNames;
}
use of com.android.org.bouncycastle.asn1.x509.Attribute in project keystore-explorer by kaikramer.
the class X509Ext method getSubjectDirectoryAttributesStringValue.
private String getSubjectDirectoryAttributesStringValue(byte[] value) throws IOException {
// @formatter:off
/*
* SubjectDirectoryAttributes ::= ASN1Sequence SIZE (1..MAX) OF Attribute
*
* Attribute ::= ASN1Sequence
* {
* type AttributeType,
* values SET OF AttributeValue
* }
*/
// @formatter:on
StringBuilder sb = new StringBuilder();
SubjectDirectoryAttributes subjectDirectoryAttributes = SubjectDirectoryAttributes.getInstance(value);
for (Object attribute : subjectDirectoryAttributes.getAttributes()) {
ASN1ObjectIdentifier attributeType = ((Attribute) attribute).getAttrType();
String attributeTypeStr = attributeType.getId();
ASN1Encodable[] attributeValues = ((Attribute) attribute).getAttributeValues();
for (ASN1Encodable attributeValue : attributeValues) {
String attributeValueStr = getAttributeValueString(attributeType, attributeValue);
sb.append(MessageFormat.format("{0}={1}", attributeTypeStr, attributeValueStr));
sb.append(NEWLINE);
}
}
return sb.toString();
}
use of com.android.org.bouncycastle.asn1.x509.Attribute in project keystore-explorer by kaikramer.
the class Pkcs10Util method generateCsr.
/**
* Create a PKCS #10 certificate signing request (CSR) using the supplied
* certificate, private key and signature algorithm.
*
* @param cert
* The certificate
* @param privateKey
* The private key
* @param signatureType
* Signature
* @param challenge
* Challenge, optional, pass null if not required
* @param unstructuredName
* An optional company name, pass null if not required
* @param useExtensions
* Use extensions from cert for extensionRequest attribute?
* @throws CryptoException
* If there was a problem generating the CSR
* @return The CSR
*/
public static PKCS10CertificationRequest generateCsr(X509Certificate cert, PrivateKey privateKey, SignatureType signatureType, String challenge, String unstructuredName, boolean useExtensions, Provider provider) throws CryptoException {
try {
JcaPKCS10CertificationRequestBuilder csrBuilder = new JcaPKCS10CertificationRequestBuilder(cert.getSubjectX500Principal(), cert.getPublicKey());
// add challenge attribute
if (challenge != null) {
// PKCS#9 2.0: SHOULD use UTF8String encoding
csrBuilder.addAttribute(pkcs_9_at_challengePassword, new DERUTF8String(challenge));
}
if (unstructuredName != null) {
csrBuilder.addAttribute(pkcs_9_at_unstructuredName, new DERUTF8String(unstructuredName));
}
if (useExtensions) {
// add extensionRequest attribute with all extensions from the certificate
Certificate certificate = Certificate.getInstance(cert.getEncoded());
Extensions extensions = certificate.getTBSCertificate().getExtensions();
if (extensions != null) {
csrBuilder.addAttribute(pkcs_9_at_extensionRequest, extensions.toASN1Primitive());
}
}
// fall back to bouncy castle provider if given provider does not support the requested algorithm
if (provider != null && provider.getService("Signature", signatureType.jce()) == null) {
provider = new BouncyCastleProvider();
}
ContentSigner contentSigner = null;
if (provider == null) {
contentSigner = new JcaContentSignerBuilder(signatureType.jce()).build(privateKey);
} else {
contentSigner = new JcaContentSignerBuilder(signatureType.jce()).setProvider(provider).build(privateKey);
}
PKCS10CertificationRequest csr = csrBuilder.build(contentSigner);
if (!verifyCsr(csr)) {
throw new CryptoException(res.getString("NoVerifyGenPkcs10Csr.exception.message"));
}
return csr;
} catch (CertificateEncodingException e) {
throw new CryptoException(res.getString("NoGeneratePkcs10Csr.exception.message"), e);
} catch (OperatorCreationException e) {
throw new CryptoException(res.getString("NoGeneratePkcs10Csr.exception.message"), e);
}
}
Aggregations