Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: jruby/jruby-openssl
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: fe55d9979d6d
Choose a base ref
...
head repository: jruby/jruby-openssl
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: cff68a0e2cd2
Choose a head ref
  • 2 commits
  • 3 files changed
  • 1 contributor

Commits on May 31, 2016

  1. cleanup/formatting at PKey's

    kares committed May 31, 2016
    Copy the full SHA
    81e451d View commit details
  2. Copy the full SHA
    cff68a0 View commit details
Showing with 24 additions and 27 deletions.
  1. +14 −19 src/main/java/org/jruby/ext/openssl/PKey.java
  2. +5 −4 src/main/java/org/jruby/ext/openssl/PKeyDSA.java
  3. +5 −4 src/main/java/org/jruby/ext/openssl/PKeyRSA.java
33 changes: 14 additions & 19 deletions src/main/java/org/jruby/ext/openssl/PKey.java
Original file line number Diff line number Diff line change
@@ -208,23 +208,10 @@ public IRubyObject sign(IRubyObject digest, IRubyObject data) {
signature.update(inp);
byte[] sigge = signature.sign();
return RubyString.newString(getRuntime(), sigge);
} catch (GeneralSecurityException gse) {
}
catch (GeneralSecurityException gse) {
throw newPKeyError(getRuntime(), gse.getMessage());
}
/*
GetPKey(self, pkey);
EVP_SignInit(&ctx, GetDigestPtr(digest));
StringValue(data);
EVP_SignUpdate(&ctx, RSTRING(data)->ptr, RSTRING(data)->len);
str = rb_str_new(0, EVP_PKEY_size(pkey)+16);
if (!EVP_SignFinal(&ctx, RSTRING(str)->ptr, &buf_len, pkey))
ossl_raise(ePKeyError, NULL);
assert(buf_len <= RSTRING(str)->len);
RSTRING(str)->len = buf_len;
RSTRING(str)->ptr[buf_len] = 0;
return str;
*/
}

@JRubyMethod(name = "verify")
@@ -247,11 +234,14 @@ public IRubyObject verify(IRubyObject digest, IRubyObject sig, IRubyObject data)
signature.initVerify(getPublicKey());
signature.update(dataBytes);
valid = signature.verify(sigBytes);
} catch (NoSuchAlgorithmException e) {
}
catch (NoSuchAlgorithmException e) {
throw newPKeyError(getRuntime(), "unsupported algorithm: " + algorithm);
} catch (SignatureException e) {
}
catch (SignatureException e) {
throw newPKeyError(getRuntime(), "invalid signature");
} catch (InvalidKeyException e) {
}
catch (InvalidKeyException e) {
throw newPKeyError(getRuntime(), "invalid key");
}
return getRuntime().newBoolean(valid);
@@ -372,9 +362,14 @@ protected static boolean ttySTDIN(final ThreadContext context) {
catch (RaiseException ex) { return false; }
}

static Object readPrivateKey(final String str, final char[] passwd)
throws PEMInputOutput.PasswordRequiredException, IOException {
return PEMInputOutput.readPrivateKey(new StringReader(str), passwd);
}

static Object readPrivateKey(final RubyString str, final char[] passwd)
throws PEMInputOutput.PasswordRequiredException, IOException {
return PEMInputOutput.readPrivateKey(new StringReader(str.toString()), passwd);
return readPrivateKey(str.toString(), passwd);
}

protected static RubyString readInitArg(final ThreadContext context, IRubyObject arg) {
9 changes: 5 additions & 4 deletions src/main/java/org/jruby/ext/openssl/PKeyDSA.java
Original file line number Diff line number Diff line change
@@ -178,6 +178,7 @@ public IRubyObject initialize(final ThreadContext context, final IRubyObject[] a

final char[] passwd = password(pass);
final RubyString str = readInitArg(context, arg);
final String strJava = str.toString();

Object key = null;
final KeyFactory dsaFactory;
@@ -194,27 +195,27 @@ public IRubyObject initialize(final ThreadContext context, final IRubyObject[] a
boolean noClassDef = false;
if ( key == null && ! noClassDef ) { // PEM_read_bio_DSAPrivateKey
try {
key = readPrivateKey(str, passwd);
key = readPrivateKey(strJava, passwd);
}
catch (NoClassDefFoundError e) { noClassDef = true; debugStackTrace(runtime, e); }
catch (PEMInputOutput.PasswordRequiredException retry) {
if ( ttySTDIN(context) ) {
try { key = readPrivateKey(str, passwordPrompt(context)); }
try { key = readPrivateKey(strJava, passwordPrompt(context)); }
catch (Exception e) { debugStackTrace(runtime, e); }
}
}
catch (Exception e) { debugStackTrace(runtime, e); }
}
if ( key == null && ! noClassDef ) { // PEM_read_bio_DSAPublicKey
try {
key = PEMInputOutput.readDSAPublicKey(new StringReader(str.toString()), passwd);
key = PEMInputOutput.readDSAPublicKey(new StringReader(strJava), passwd);
}
catch (NoClassDefFoundError e) { noClassDef = true; debugStackTrace(runtime, e); }
catch (Exception e) { debugStackTrace(runtime, e); }
}
if ( key == null && ! noClassDef ) { // PEM_read_bio_DSA_PUBKEY
try {
key = PEMInputOutput.readDSAPubKey(new StringReader(str.toString()));
key = PEMInputOutput.readDSAPubKey(new StringReader(strJava));
}
catch (NoClassDefFoundError e) { noClassDef = true; debugStackTrace(runtime, e); }
catch (Exception e) { debugStackTrace(runtime, e); }
9 changes: 5 additions & 4 deletions src/main/java/org/jruby/ext/openssl/PKeyRSA.java
Original file line number Diff line number Diff line change
@@ -217,6 +217,7 @@ public IRubyObject initialize(final ThreadContext context, final IRubyObject[] a

final char[] passwd = password(pass);
final RubyString str = readInitArg(context, arg);
final String strJava = str.toString();

Object key = null;
final KeyFactory rsaFactory;
@@ -233,27 +234,27 @@ public IRubyObject initialize(final ThreadContext context, final IRubyObject[] a
boolean noClassDef = false;
if ( key == null && ! noClassDef ) { // PEM_read_bio_RSAPrivateKey
try {
key = readPrivateKey(str, passwd);
key = readPrivateKey(strJava, passwd);
}
catch (NoClassDefFoundError e) { noClassDef = true; debugStackTrace(runtime, e); }
catch (PEMInputOutput.PasswordRequiredException retry) {
if ( ttySTDIN(context) ) {
try { key = readPrivateKey(str, passwordPrompt(context)); }
try { key = readPrivateKey(strJava, passwordPrompt(context)); }
catch (Exception e) { debugStackTrace(runtime, e); }
}
}
catch (Exception e) { debugStackTrace(runtime, e); }
}
if ( key == null && ! noClassDef ) { // PEM_read_bio_RSAPublicKey
try {
key = PEMInputOutput.readRSAPublicKey(new StringReader(str.toString()), passwd);
key = PEMInputOutput.readRSAPublicKey(new StringReader(strJava), passwd);
}
catch (NoClassDefFoundError e) { noClassDef = true; debugStackTrace(runtime, e); }
catch (Exception e) { debugStackTrace(runtime, e); }
}
if ( key == null && ! noClassDef ) { // PEM_read_bio_RSA_PUBKEY
try {
key = PEMInputOutput.readRSAPubKey(new StringReader(str.toString()));
key = PEMInputOutput.readRSAPubKey(new StringReader(strJava));
}
catch (NoClassDefFoundError e) { noClassDef = true; debugStackTrace(runtime, e); }
catch (Exception e) { debugStackTrace(runtime, e); }