use of org.jruby.runtime.ThreadContext in project gocd by gocd.
the class NokogiriHandler method call.
private void call(String methodName) {
ThreadContext context = ruby.getCurrentContext();
RuntimeHelpers.invoke(context, document(context), methodName);
}
use of org.jruby.runtime.ThreadContext in project jruby-openssl by jruby.
the class ASN1 method createASN1.
public static void createASN1(final Ruby runtime, final RubyModule OpenSSL) {
final RubyModule ASN1 = OpenSSL.defineModuleUnder("ASN1");
final RubyClass OpenSSLError = OpenSSL.getClass("OpenSSLError");
ASN1.defineClassUnder("ASN1Error", OpenSSLError, OpenSSLError.getAllocator());
ASN1.defineAnnotatedMethods(ASN1.class);
final RubyArray UNIVERSAL_TAG_NAME = runtime.newArray(ASN1_INFO.length);
for (int i = 0; i < ASN1_INFO.length; i++) {
final String name = (String) ASN1_INFO[i][0];
if (name.charAt(0) != '[') {
UNIVERSAL_TAG_NAME.append(runtime.newString(name));
ASN1.setConstant(name, runtime.newFixnum(i));
} else {
UNIVERSAL_TAG_NAME.append(runtime.getNil());
}
}
ASN1.setConstant("UNIVERSAL_TAG_NAME", UNIVERSAL_TAG_NAME);
final ThreadContext context = runtime.getCurrentContext();
final ObjectAllocator asn1DataAllocator = ASN1Data.ALLOCATOR;
RubyClass _ASN1Data = ASN1.defineClassUnder("ASN1Data", runtime.getObject(), asn1DataAllocator);
_ASN1Data.addReadWriteAttribute(context, "value");
_ASN1Data.addReadWriteAttribute(context, "tag");
_ASN1Data.addReadWriteAttribute(context, "tag_class");
_ASN1Data.defineAnnotatedMethods(ASN1Data.class);
final ObjectAllocator primitiveAllocator = Primitive.ALLOCATOR;
RubyClass Primitive = ASN1.defineClassUnder("Primitive", _ASN1Data, primitiveAllocator);
Primitive.addReadWriteAttribute(context, "tagging");
Primitive.addReadAttribute(context, "infinite_length");
Primitive.defineAnnotatedMethods(Primitive.class);
final ObjectAllocator constructiveAllocator = Constructive.ALLOCATOR;
RubyClass Constructive = ASN1.defineClassUnder("Constructive", _ASN1Data, constructiveAllocator);
Constructive.includeModule(runtime.getModule("Enumerable"));
Constructive.addReadWriteAttribute(context, "tagging");
Constructive.addReadWriteAttribute(context, "infinite_length");
Constructive.defineAnnotatedMethods(Constructive.class);
// OpenSSL::ASN1::Boolean <=> value is a Boolean
ASN1.defineClassUnder("Boolean", Primitive, primitiveAllocator);
// OpenSSL::ASN1::Integer <=> value is a Number
ASN1.defineClassUnder("Integer", Primitive, primitiveAllocator);
// OpenSSL::ASN1::Null <=> value is always nil
ASN1.defineClassUnder("Null", Primitive, primitiveAllocator);
// OpenSSL::ASN1::Object <=> value is a String
ASN1.defineClassUnder("Object", Primitive, primitiveAllocator);
// OpenSSL::ASN1::Enumerated <=> value is a Number
ASN1.defineClassUnder("Enumerated", Primitive, primitiveAllocator);
RubyClass BitString = ASN1.defineClassUnder("BitString", Primitive, primitiveAllocator);
BitString.addReadWriteAttribute(context, "unused_bits");
ASN1.defineClassUnder("OctetString", Primitive, primitiveAllocator);
ASN1.defineClassUnder("UTF8String", Primitive, primitiveAllocator);
ASN1.defineClassUnder("NumericString", Primitive, primitiveAllocator);
ASN1.defineClassUnder("PrintableString", Primitive, primitiveAllocator);
ASN1.defineClassUnder("T61String", Primitive, primitiveAllocator);
ASN1.defineClassUnder("VideotexString", Primitive, primitiveAllocator);
ASN1.defineClassUnder("IA5String", Primitive, primitiveAllocator);
ASN1.defineClassUnder("GraphicString", Primitive, primitiveAllocator);
ASN1.defineClassUnder("ISO64String", Primitive, primitiveAllocator);
ASN1.defineClassUnder("GeneralString", Primitive, primitiveAllocator);
ASN1.defineClassUnder("UniversalString", Primitive, primitiveAllocator);
ASN1.defineClassUnder("BMPString", Primitive, primitiveAllocator);
// OpenSSL::ASN1::UTCTime <=> value is a Time
ASN1.defineClassUnder("UTCTime", Primitive, primitiveAllocator);
// OpenSSL::ASN1::GeneralizedTime <=> value is a Time
ASN1.defineClassUnder("GeneralizedTime", Primitive, primitiveAllocator);
// OpenSSL::ASN1::EndOfContent <=> value is always nil
ASN1.defineClassUnder("EndOfContent", Primitive, primitiveAllocator);
RubyClass ObjectId = ASN1.defineClassUnder("ObjectId", Primitive, primitiveAllocator);
ObjectId.defineAnnotatedMethods(ObjectId.class);
ASN1.defineClassUnder("Sequence", Constructive, Constructive.getAllocator());
ASN1.defineClassUnder("Set", Constructive, Constructive.getAllocator());
}
use of org.jruby.runtime.ThreadContext in project jruby-openssl by jruby.
the class SSLContext method convertToAuxCerts.
private static List<X509AuxCertificate> convertToAuxCerts(final ThreadContext context, IRubyObject value) {
final RubyModule SSLContext = _SSLContext(context.runtime);
final RubyModule Certificate = _Certificate(context.runtime);
if (value instanceof RubyArray) {
final RubyArray val = (RubyArray) value;
final int size = val.size();
final ArrayList<X509AuxCertificate> result = new ArrayList<X509AuxCertificate>(size);
for (int i = 0; i < size; i++) result.add(assureCertificate(context, Certificate, val.eltInternal(i)).getAuxCert());
return result;
}
if (value instanceof List) {
final List<X509Cert> val = (List) value;
final int size = val.size();
final ArrayList<X509AuxCertificate> result = new ArrayList<X509AuxCertificate>(size);
for (int i = 0; i < size; i++) result.add(assureCertificate(context, Certificate, val.get(i)).getAuxCert());
return result;
}
// else :
final ArrayList<X509AuxCertificate> result = new ArrayList<X509AuxCertificate>();
Utils.invoke(context, value, "each", CallBlock.newCallClosure(value, SSLContext, Arity.NO_ARGUMENTS, new BlockCallback() {
public IRubyObject call(ThreadContext context, IRubyObject[] args, Block block) {
result.add(assureCertificate(context, Certificate, args[0]).getAuxCert());
return context.nil;
}
}, context));
return result;
}
use of org.jruby.runtime.ThreadContext in project jruby-openssl by jruby.
the class X509Extension method getValue.
private IRubyObject getValue(final Ruby runtime) throws IOException {
if (value instanceof RubyString) {
// explicitly set value
return (RubyString) value;
}
final ThreadContext context = runtime.getCurrentContext();
final byte[] enc = getRealValueEncoded();
IRubyObject extValue = runtime.newString(new ByteList(enc, false));
extValue = ASN1.decodeImpl(context, _ASN1(runtime), extValue);
return extValue.callMethod(context, "value");
}
use of org.jruby.runtime.ThreadContext in project jruby-openssl by jruby.
the class OCSPRequest method verify.
@JRubyMethod(name = "verify", rest = true)
public IRubyObject verify(IRubyObject[] args) {
Ruby runtime = getRuntime();
ThreadContext context = runtime.getCurrentContext();
int flags = 0;
boolean ret = false;
if (Arity.checkArgumentCount(runtime, args, 2, 3) == 3) {
flags = RubyFixnum.fix2int((RubyFixnum) args[2]);
}
IRubyObject certificates = args[0];
IRubyObject store = args[1];
OCSPReq bcOCSPReq = getBCOCSPReq();
if (bcOCSPReq == null) {
throw newOCSPError(runtime, new NullPointerException("Missing BC asn1bcReq. Missing certIDs or signature?"));
}
if (!bcOCSPReq.isSigned()) {
return RubyBoolean.newBoolean(runtime, ret);
}
GeneralName genName = bcOCSPReq.getRequestorName();
if (genName.getTagNo() != 4) {
return RubyBoolean.newBoolean(runtime, ret);
}
X500Name genX500Name = X500Name.getInstance(genName.getName());
X509StoreContext storeContext = null;
JcaContentVerifierProviderBuilder jcacvpb = new JcaContentVerifierProviderBuilder();
jcacvpb.setProvider("BC");
try {
java.security.cert.Certificate signer = findCertByName(genX500Name, certificates, flags);
if (signer == null)
return RubyBoolean.newBoolean(runtime, ret);
if ((flags & RubyFixnum.fix2int(_OCSP(runtime).getConstant(OCSP_NOINTERN))) > 0 && ((flags & RubyFixnum.fix2int(_OCSP(runtime).getConstant(OCSP_TRUSTOTHER))) > 0))
flags |= RubyFixnum.fix2int(_OCSP(runtime).getConstant(OCSP_NOVERIFY));
if ((flags & RubyFixnum.fix2int(_OCSP(runtime).getConstant(OCSP_NOSIGS))) == 0) {
PublicKey signerPubKey = signer.getPublicKey();
ContentVerifierProvider cvp = jcacvpb.build(signerPubKey);
ret = bcOCSPReq.isSignatureValid(cvp);
if (!ret) {
return RubyBoolean.newBoolean(runtime, ret);
}
}
if ((flags & RubyFixnum.fix2int(_OCSP(runtime).getConstant(OCSP_NOVERIFY))) == 0) {
if ((flags & RubyFixnum.fix2int(_OCSP(runtime).getConstant(OCSP_NOCHAIN))) > 0) {
storeContext = X509StoreContext.newStoreContext(context, (X509Store) store, X509Cert.wrap(runtime, signer), context.nil);
} else {
RubyArray certs = RubyArray.newEmptyArray(runtime);
ASN1Sequence bcCerts = asn1bcReq.getOptionalSignature().getCerts();
if (bcCerts != null) {
Iterator<ASN1Encodable> it = bcCerts.iterator();
while (it.hasNext()) {
Certificate cert = Certificate.getInstance(it.next());
certs.add(X509Cert.wrap(runtime, new X509AuxCertificate(cert)));
}
}
storeContext = X509StoreContext.newStoreContext(context, (X509Store) store, X509Cert.wrap(runtime, signer), certs);
}
storeContext.set_purpose(context, _X509(runtime).getConstant("PURPOSE_OCSP_HELPER"));
storeContext.set_trust(context, _X509(runtime).getConstant("TRUST_OCSP_REQUEST"));
ret = storeContext.verify(context).isTrue();
if (!ret)
return RubyBoolean.newBoolean(runtime, false);
}
} catch (Exception e) {
debugStackTrace(e);
throw newOCSPError(runtime, e);
}
return RubyBoolean.newBoolean(getRuntime(), ret);
}
Aggregations