use of com.github.zhenwei.core.asn1.pkcs.Attribute in project jruby-openssl by jruby.
the class SignerInfoWithPkey method addAttribute.
/**
* c: static add_attribute
*/
private ASN1Set addAttribute(ASN1Set base, int atrType, ASN1Encodable value) {
ASN1EncodableVector vector = new ASN1EncodableVector();
if (base == null)
base = new DERSet();
Attribute attr;
for (Enumeration e = base.getObjects(); e.hasMoreElements(); ) {
attr = Attribute.getInstance(e.nextElement());
if (ASN1Registry.oid2nid(attr.getAttrType()) != atrType) {
vector.add(attr);
}
}
ASN1ObjectIdentifier ident = ASN1Registry.nid2obj(atrType);
attr = new Attribute(ident, new DERSet(value));
vector.add(attr);
return new DERSet(vector);
}
use of com.github.zhenwei.core.asn1.pkcs.Attribute in project jruby-openssl by jruby.
the class X509Request method initialize.
@JRubyMethod(name = "initialize", rest = true, visibility = Visibility.PRIVATE)
public IRubyObject initialize(final ThreadContext context, final IRubyObject[] args) {
final Ruby runtime = context.runtime;
if (Arity.checkArgumentCount(runtime, args, 0, 1) == 0)
return this;
try {
request = new PKCS10Request(StringHelper.readX509PEM(context, args[0]));
} catch (RuntimeException e) {
debugStackTrace(runtime, e);
throw newRequestError(runtime, "invalid certificate request data", e);
}
final String algorithm;
final byte[] encoded;
try {
final PublicKey pkey = request.generatePublicKey();
algorithm = pkey.getAlgorithm();
encoded = pkey.getEncoded();
} catch (IOException e) {
throw newRequestError(runtime, e);
} catch (GeneralSecurityException e) {
throw newRequestError(runtime, e);
}
final RubyString enc = RubyString.newString(runtime, encoded);
if ("RSA".equalsIgnoreCase(algorithm)) {
this.public_key = newPKeyImplInstance(context, "RSA", enc);
} else if ("DSA".equalsIgnoreCase(algorithm)) {
this.public_key = newPKeyImplInstance(context, "DSA", enc);
} else {
throw runtime.newNotImplementedError("public key algorithm: " + algorithm);
}
this.subject = newName(context, request.getSubject());
final Attribute[] attrs = request.getAttributes();
try {
// final RubyModule _ASN1 = _ASN1(runtime);
if (attrs != null) {
for (final Attribute attr : attrs) {
final ASN1ObjectIdentifier type = attr.getAttrType();
final ASN1Set values = attr.getAttrValues();
attributes.add(newAttribute(context, type, values));
}
}
} catch (IOException e) {
throw newRequestError(runtime, e);
}
return this;
}
use of com.github.zhenwei.core.asn1.pkcs.Attribute in project xipki by xipki.
the class CaUtil method getExtensions.
public static Extensions getExtensions(CertificationRequestInfo csr) {
notNull(csr, "csr");
ASN1Set attrs = csr.getAttributes();
for (int i = 0; i < attrs.size(); i++) {
Attribute attr = Attribute.getInstance(attrs.getObjectAt(i));
if (PKCSObjectIdentifiers.pkcs_9_at_extensionRequest.equals(attr.getAttrType())) {
return Extensions.getInstance(attr.getAttributeValues()[0]);
}
}
return null;
}
use of com.github.zhenwei.core.asn1.pkcs.Attribute in project xipki by xipki.
the class CaUtil method getChallengePassword.
// method getExtensions
public static String getChallengePassword(CertificationRequestInfo csr) {
notNull(csr, "csr");
ASN1Set attrs = csr.getAttributes();
for (int i = 0; i < attrs.size(); i++) {
Attribute attr = Attribute.getInstance(attrs.getObjectAt(i));
if (PKCSObjectIdentifiers.pkcs_9_at_challengePassword.equals(attr.getAttrType())) {
ASN1String str = (ASN1String) attr.getAttributeValues()[0];
return str.getString();
}
}
return null;
}
use of com.github.zhenwei.core.asn1.pkcs.Attribute in project athenz by AthenZ.
the class Crypto method extractX509CSRIPAddresses.
public static List<String> extractX509CSRIPAddresses(PKCS10CertificationRequest certReq) {
List<String> ipAddresses = 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);
if (gns == null) {
continue;
}
for (GeneralName name : gns.getNames()) {
if (name.getTagNo() == GeneralName.iPAddress) {
try {
InetAddress addr = InetAddress.getByAddress(((DEROctetString) name.getName()).getOctets());
ipAddresses.add(addr.getHostAddress());
} catch (UnknownHostException ignored) {
}
}
}
}
}
return ipAddresses;
}
Aggregations