use of org.jruby.ext.openssl.impl.NetscapeCertRequest in project jruby-openssl by jruby.
the class NetscapeSPKI method verify.
@JRubyMethod
public IRubyObject verify(final IRubyObject pkey) {
final NetscapeCertRequest cert = (NetscapeCertRequest) this.cert;
cert.setPublicKey(((PKey) pkey).getPublicKey());
try {
boolean result = cert.verify(challenge.toString());
return getRuntime().newBoolean(result);
} catch (NoSuchAlgorithmException e) {
debugStackTrace(getRuntime(), e);
throw newSPKIError(e);
} catch (GeneralSecurityException e) {
throw newSPKIError(e);
}
}
use of org.jruby.ext.openssl.impl.NetscapeCertRequest in project jruby-openssl by jruby.
the class NetscapeSPKI method sign.
@JRubyMethod
public IRubyObject sign(final IRubyObject key, final IRubyObject digest) {
final String keyAlg = ((PKey) key).getAlgorithm();
final String digAlg = ((Digest) digest).getShortAlgorithm();
final String symKey = keyAlg.toLowerCase() + '-' + digAlg.toLowerCase();
try {
final ASN1ObjectIdentifier alg = ASN1.sym2Oid(getRuntime(), symKey);
final PublicKey publicKey = ((PKey) this.public_key).getPublicKey();
final String challengeStr = challenge.toString();
final NetscapeCertRequest cert;
this.cert = cert = new NetscapeCertRequest(challengeStr, new AlgorithmIdentifier(alg), publicKey);
cert.sign(((PKey) key).getPrivateKey());
} catch (NoSuchAlgorithmException e) {
debugStackTrace(getRuntime(), e);
throw newSPKIError(e);
} catch (GeneralSecurityException e) {
throw newSPKIError(e);
}
return this;
}
use of org.jruby.ext.openssl.impl.NetscapeCertRequest in project jruby-openssl by jruby.
the class NetscapeSPKI 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 (args.length > 0) {
byte[] request = args[0].convertToString().getBytes();
request = tryBase64Decode(request);
final NetscapeCertRequest cert;
try {
this.cert = cert = new NetscapeCertRequest(request);
challenge = runtime.newString(cert.getChallenge());
} catch (GeneralSecurityException e) {
throw newSPKIError(e);
} catch (IllegalArgumentException e) {
throw newSPKIError(e);
}
final PublicKey publicKey = cert.getPublicKey();
final String algorithm = publicKey.getAlgorithm();
final RubyString pub_key = RubyString.newString(runtime, publicKey.getEncoded());
if ("RSA".equalsIgnoreCase(algorithm)) {
this.public_key = _RSA(runtime).callMethod(context, "new", pub_key);
} else if ("DSA".equalsIgnoreCase(algorithm)) {
this.public_key = _DSA(runtime).callMethod(context, "new", pub_key);
} else {
throw runtime.newLoadError("not implemented algo for public key: " + algorithm);
}
}
return this;
}
Aggregations