use of org.jruby.ext.openssl.x509store.X509AuxCertificate in project jruby-openssl by jruby.
the class X509StoreContext method initialize.
@JRubyMethod(name = "initialize", rest = true, visibility = Visibility.PRIVATE)
public IRubyObject initialize(final ThreadContext context, final IRubyObject[] args) {
X509Store store;
IRubyObject cert, chain;
cert = chain = context.nil;
store = (X509Store) args[0];
if (Arity.checkArgumentCount(context.runtime, args, 1, 3) > 1) {
cert = args[1];
if (args.length > 2)
chain = args[2];
}
final X509AuxCertificate _cert;
if (cert.isNil()) {
_cert = null;
} else {
if (!(cert instanceof X509Cert)) {
throw context.runtime.newTypeError(cert, "OpenSSL::X509::Certificate");
}
_cert = ((X509Cert) cert).getAuxCert();
}
final List<X509AuxCertificate> _chain;
if (!chain.isNil()) {
@SuppressWarnings("unchecked") final RubyArray certs = (RubyArray) chain;
_chain = new ArrayList<X509AuxCertificate>(certs.size());
for (int i = 0; i < certs.size(); i++) {
// NOTE: if we use the normal java syntax for iterating over this
// RubyArray, the `toJava` method of the X509Cert class will be
// implicitly called, and that will return the BC certificate object
// rather than the JRuby one.
X509Cert c = (X509Cert) certs.eltOk(i);
_chain.add(c.getAuxCert());
}
} else {
_chain = new ArrayList<X509AuxCertificate>(4);
}
this.storeContext = new StoreContext(store.getStore());
if (storeContext.init(_cert, _chain) != 1) {
throw newStoreError(context.runtime, null);
}
IRubyObject time = store.getInstanceVariables().getInstanceVariable("@time");
if (!time.isNil())
set_time(time);
this.setInstanceVariable("@verify_callback", store.verify_callback());
this.setInstanceVariable("@cert", cert);
return this;
}
use of org.jruby.ext.openssl.x509store.X509AuxCertificate in project jruby-openssl by jruby.
the class X509StoreContext method chain.
@JRubyMethod
public IRubyObject chain(final ThreadContext context) {
final Ruby runtime = context.runtime;
final List<X509AuxCertificate> chain = storeContext.getChain();
if (chain == null)
return runtime.getNil();
final RubyArray result = runtime.newArray(chain.size());
final RubyClass _Certificate = _Certificate(runtime);
try {
for (X509AuxCertificate x509 : chain) {
RubyString encoded = StringHelper.newString(runtime, x509.getEncoded());
result.append(_Certificate.callMethod(context, "new", encoded));
}
} catch (CertificateEncodingException e) {
throw newStoreError(runtime, e.getMessage());
}
return result;
}
Aggregations