use of com.github.zhenwei.core.asn1.DERUTF8String in project xipki by xipki.
the class Asn1GenDSAKeypairParams method toASN1Primitive.
@Override
public ASN1Primitive toASN1Primitive() {
ASN1EncodableVector vector = new ASN1EncodableVector();
vector.add(new Asn1P11SlotIdentifier(slotId));
vector.add(new DERUTF8String(label));
vector.add(new Asn1NewKeyControl(control));
vector.add(new ASN1Integer(p));
vector.add(new ASN1Integer(q));
vector.add(new ASN1Integer(g));
return new DERSequence(vector);
}
use of com.github.zhenwei.core.asn1.DERUTF8String 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 subjectDN Distinguished name for CSR
* @param publicKey Public key for CSR
* @param privateKey Private key for CSR
* @param signatureType Signature algorithm
* @param challenge Challenge, optional, pass null if not required
* @param unstructuredName An optional company name, pass null if not required
* @param extensions Optional extensions from cert for extensionRequest attribute, pass null if not required
* @param provider Optional provider (for example for PKCS11)
* @return The CSR
* @throws CryptoException If there was a problem generating the CSR
*/
public static PKCS10CertificationRequest generateCsr(X500Principal subjectDN, PublicKey publicKey, PrivateKey privateKey, SignatureType signatureType, String challenge, String unstructuredName, Extensions extensions, Provider provider) throws CryptoException {
try {
JcaPKCS10CertificationRequestBuilder csrBuilder = new JcaPKCS10CertificationRequestBuilder(subjectDN, publicKey);
// 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 (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 (OperatorCreationException e) {
throw new CryptoException(res.getString("NoGeneratePkcs10Csr.exception.message"), e);
}
}
use of com.github.zhenwei.core.asn1.DERUTF8String in project keystore-explorer by kaikramer.
the class DialogHelper method populateTextField.
private static void populateTextField(Attribute[] attrs, JTextField textField, ASN1ObjectIdentifier pkcs9Attr) {
if (attrs != null) {
for (Attribute attribute : attrs) {
ASN1ObjectIdentifier attributeOid = attribute.getAttrType();
if (attributeOid.equals(pkcs9Attr)) {
ASN1Encodable challenge = attribute.getAttributeValues()[0];
// data type can be one of IA5String or UTF8String
if (challenge instanceof DERPrintableString) {
textField.setText(((DERPrintableString) challenge).getString());
} else if (challenge instanceof DERUTF8String) {
textField.setText(((DERUTF8String) challenge).getString());
}
textField.setCaretPosition(0);
}
}
}
}
use of com.github.zhenwei.core.asn1.DERUTF8String in project xipki by xipki.
the class DemoCertprofile method getExtraExtensions.
// method initExtraExtension
@Override
public ExtensionValues getExtraExtensions(Map<ASN1ObjectIdentifier, ExtensionControl> extensionOccurences, X500Name requestedSubject, X500Name grantedSubject, Map<ASN1ObjectIdentifier, Extension> requestedExtensions, Date notBefore, Date notAfter, PublicCaInfo caInfo) throws CertprofileException, BadCertTemplateException {
ExtensionValues extnValues = new ExtensionValues();
if (addExtraWithoutConf) {
ASN1ObjectIdentifier type = id_demo_without_conf;
ExtensionControl extnControl = extensionOccurences.get(type);
if (extnControl != null) {
ConfPairs caExtraControl = caInfo.getExtraControl();
String name = "name-a";
String value = null;
if (caExtraControl != null) {
value = caExtraControl.value(name);
}
if (value == null) {
value = "UNDEF";
}
ExtensionValue extnValue = new ExtensionValue(extnControl.isCritical(), new DERUTF8String(name + ": " + value));
extnValues.addExtension(type, extnValue);
}
}
if (addExtraWithConf) {
ASN1ObjectIdentifier type = id_demo_with_conf;
ExtensionControl extnControl = extensionOccurences.get(type);
if (extnControl != null) {
if (sequence == null) {
throw new IllegalStateException("Certprofile is not initialized");
}
ExtensionValue extnValue = new ExtensionValue(extnControl.isCritical(), sequence);
extnValues.addExtension(type, extnValue);
}
}
return extnValues.size() == 0 ? null : extnValues;
}
use of com.github.zhenwei.core.asn1.DERUTF8String in project signer by demoiselle.
the class PolicyIssuerName method parse.
@Override
public void parse(ASN1Primitive primitive) {
if (primitive instanceof DLSequence) {
DLSequence sequence = (DLSequence) primitive;
ASN1Encodable asn1Encodable = sequence.getObjectAt(0);
if (asn1Encodable instanceof DERTaggedObject) {
DERTaggedObject derTaggedObject = (DERTaggedObject) asn1Encodable;
ASN1Primitive object = derTaggedObject.getObject();
if (object instanceof DEROctetString) {
OctetString octetString = new OctetString();
octetString.parse(object);
this.issuerName = octetString.getValueUTF8();
} else if (object instanceof DERSequence) {
DERSequence sequence2 = (DERSequence) object;
for (int i = 0; i < sequence2.size(); i++) {
ASN1Encodable obj = sequence2.getObjectAt(i);
if (obj instanceof DERSet) {
DERSet set = (DERSet) obj;
ASN1Encodable object2 = set.getObjectAt(0);
if (object2 instanceof DERSequence) {
DERSequence sequence3 = (DERSequence) object2;
ObjectIdentifier objectIdendifier = new ObjectIdentifier();
objectIdendifier.parse(sequence3.getObjectAt(0).toASN1Primitive());
String name = null;
ASN1Encodable object3 = sequence3.getObjectAt(1);
if (object3 instanceof DERPrintableString) {
name = ((DERPrintableString) object3).getString();
} else if (object3 instanceof DERUTF8String) {
name = ((DERUTF8String) object3).getString();
} else {
System.out.println(policyMessagesBundle.getString("error.not.recognized.object", object3.getClass(), object3.toString()));
}
if (this.issuerNames == null) {
this.issuerNames = new HashMap<ObjectIdentifier, String>();
}
this.issuerNames.put(objectIdendifier, name);
}
}
}
}
}
}
}
Aggregations