Search in sources :

Example 21 with RubyString

use of org.jruby.RubyString 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;
}
Also used : PKCS10Request(org.jruby.ext.openssl.impl.PKCS10Request) Attribute(org.bouncycastle.asn1.pkcs.Attribute) PublicKey(java.security.PublicKey) GeneralSecurityException(java.security.GeneralSecurityException) RubyString(org.jruby.RubyString) RubyString(org.jruby.RubyString) IOException(java.io.IOException) ASN1Set(org.bouncycastle.asn1.ASN1Set) Ruby(org.jruby.Ruby) ASN1ObjectIdentifier(org.bouncycastle.asn1.ASN1ObjectIdentifier) JRubyMethod(org.jruby.anno.JRubyMethod)

Example 22 with RubyString

use of org.jruby.RubyString in project jruby-openssl by jruby.

the class OCSPRequest method add_nonce.

@JRubyMethod(name = "add_nonce", rest = true)
public IRubyObject add_nonce(IRubyObject[] args) {
    Ruby runtime = getRuntime();
    if (Arity.checkArgumentCount(runtime, args, 0, 1) == 0) {
        nonce = generateNonce();
    } else {
        RubyString input = (RubyString) args[0];
        nonce = input.getBytes();
    }
    addNonceImpl();
    return this;
}
Also used : RubyString(org.jruby.RubyString) Ruby(org.jruby.Ruby) JRubyMethod(org.jruby.anno.JRubyMethod)

Example 23 with RubyString

use of org.jruby.RubyString in project jruby-openssl by jruby.

the class OCSPRequest method initialize.

@JRubyMethod(name = "initialize", rest = true, visibility = Visibility.PRIVATE)
public IRubyObject initialize(final ThreadContext context, IRubyObject[] args) {
    Ruby runtime = context.getRuntime();
    if (Arity.checkArgumentCount(runtime, args, 0, 1) == 0)
        return this;
    RubyString derString = StringHelper.readPossibleDERInput(context, args[0]);
    asn1bcReq = org.bouncycastle.asn1.ocsp.OCSPRequest.getInstance(derString.getBytes());
    return this;
}
Also used : RubyString(org.jruby.RubyString) Ruby(org.jruby.Ruby) JRubyMethod(org.jruby.anno.JRubyMethod)

Example 24 with RubyString

use of org.jruby.RubyString in project jruby-openssl by jruby.

the class OCSPResponse method initialize.

@JRubyMethod(name = "initialize", rest = true, visibility = Visibility.PRIVATE)
public IRubyObject initialize(final ThreadContext context, IRubyObject[] args) {
    Ruby runtime = context.getRuntime();
    if (Arity.checkArgumentCount(runtime, args, 0, 1) == 0)
        return this;
    RubyString derString = (RubyString) args[0];
    try {
        bcResp = org.bouncycastle.asn1.ocsp.OCSPResponse.getInstance(ASN1TaggedObject.fromByteArray(derString.getBytes()));
    } catch (IOException e) {
        throw newOCSPError(runtime, e);
    }
    return this;
}
Also used : RubyString(org.jruby.RubyString) IOException(java.io.IOException) Ruby(org.jruby.Ruby) JRubyMethod(org.jruby.anno.JRubyMethod)

Example 25 with RubyString

use of org.jruby.RubyString in project jruby-openssl by jruby.

the class OCSPSingleResponse method initialize.

@JRubyMethod(name = "initialize", visibility = Visibility.PRIVATE)
public IRubyObject initialize(final ThreadContext context, IRubyObject derStr) {
    Ruby runtime = context.getRuntime();
    RubyString rubyDerStr = (RubyString) derStr;
    try {
        bcSingleResponse = SingleResponse.getInstance(DERTaggedObject.fromByteArray(rubyDerStr.getBytes()));
    } catch (IOException e) {
        throw newOCSPError(runtime, e);
    }
    return this;
}
Also used : RubyString(org.jruby.RubyString) IOException(java.io.IOException) Ruby(org.jruby.Ruby) JRubyMethod(org.jruby.anno.JRubyMethod)

Aggregations

RubyString (org.jruby.RubyString)49 JRubyMethod (org.jruby.anno.JRubyMethod)32 Ruby (org.jruby.Ruby)28 IRubyObject (org.jruby.runtime.builtin.IRubyObject)18 IOException (java.io.IOException)15 ByteList (org.jruby.util.ByteList)12 StringReader (java.io.StringReader)8 ByteArrayInputStream (java.io.ByteArrayInputStream)5 GeneralSecurityException (java.security.GeneralSecurityException)5 RaiseException (org.jruby.exceptions.RaiseException)5 BigInteger (java.math.BigInteger)4 PublicKey (java.security.PublicKey)4 NokogiriHelpers.rubyStringToString (nokogiri.internals.NokogiriHelpers.rubyStringToString)4 ASN1ObjectIdentifier (org.bouncycastle.asn1.ASN1ObjectIdentifier)4 RubyArray (org.jruby.RubyArray)4 Charset (java.nio.charset.Charset)3 InvalidKeySpecException (java.security.spec.InvalidKeySpecException)3 RubyInteger (org.jruby.RubyInteger)3 ThreadContext (org.jruby.runtime.ThreadContext)3 InputSource (org.xml.sax.InputSource)3