Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Mavenfile
Original file line number Diff line number Diff line change
Expand Up @@ -82,14 +82,14 @@ plugin :clean do
'failOnError' => 'false' )
end

jar 'org.jruby:jruby-core', '9.1.11.0', :scope => :provided
jar 'org.jruby:jruby-core', '9.2.19.0', :scope => :provided
# for invoker generated classes we need to add javax.annotation when on Java > 8
jar 'javax.annotation:javax.annotation-api', '1.3.1', :scope => :compile
jar 'junit:junit', '[4.13.1,)', :scope => :test

# NOTE: to build on Java 11 - installing gems fails (due old jossl) with:
# load error: jopenssl/load -- java.lang.StringIndexOutOfBoundsException
MVN_JRUBY_VERSION = ENV_JAVA['java.version'].to_i >= 9 ? '9.2.19.0' : '9.1.17.0'
MVN_JRUBY_VERSION = '9.2.19.0'

jruby_plugin! :gem do
# when installing dependent gems we want to use the built in openssl not the one from this lib directory
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ DO NOT MODIFY - GENERATED CODE
<dependency>
<groupId>org.jruby</groupId>
<artifactId>jruby-core</artifactId>
<version>9.1.11.0</version>
<version>9.2.19.0</version>
<scope>provided</scope>
</dependency>
<dependency>
Expand Down
9 changes: 9 additions & 0 deletions src/main/java/org/jruby/ext/openssl/Digest.java
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,15 @@ static MessageDigest getDigest(final Ruby runtime, final String name) {
}
}

static Digest getDigest(ThreadContext context, IRubyObject digest) {
if (digest instanceof Digest) {
return (Digest) digest;
} else {
RubyString digestString = digest.convertToString();
return newInstance(context.runtime, digestString, context.nil);
}
}

private static Digest newInstance(final Ruby runtime, final IRubyObject name, final IRubyObject data) {
final RubyClass klass = _Digest(runtime);
final Digest instance = new Digest(runtime, klass);
Expand Down
15 changes: 15 additions & 0 deletions src/main/java/org/jruby/ext/openssl/PKeyEC.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import java.math.BigInteger;
import java.security.AlgorithmParameters;
import java.security.GeneralSecurityException;
import java.security.InvalidAlgorithmParameterException;
import java.security.InvalidKeyException;
import java.security.KeyFactory;
import java.security.KeyPair;
Expand Down Expand Up @@ -438,6 +439,9 @@ public PKeyEC generate_key(final ThreadContext context) {
this.publicKey = (ECPublicKey) pair.getPublic();
this.privateKey = pair.getPrivate();
}
catch (NoSuchAlgorithmException | InvalidAlgorithmParameterException ex) {
throw newPKeyError(context.runtime, ex.getMessage());
}
catch (GeneralSecurityException ex) {
throw newECError(context.runtime, ex.toString());
}
Expand Down Expand Up @@ -558,6 +562,9 @@ public IRubyObject oid() {

private Group getGroup(boolean required) {
if (group == null) {
if (curveName == null) {
return null;
}
return group = new Group(getRuntime(), this);
}
return group;
Expand Down Expand Up @@ -857,6 +864,11 @@ public Group(Ruby runtime, RubyClass type) {
setCurveName(runtime, key.getCurveName());
}

private static RaiseException newError(final Ruby runtime, final String message) {
final RubyClass Error = _EC(runtime).getClass("Group").getClass("Error");
return Utils.newError(runtime, Error, message);
}

@JRubyMethod(rest = true, visibility = Visibility.PRIVATE)
public IRubyObject initialize(final ThreadContext context, final IRubyObject[] args) {
final Ruby runtime = context.runtime;
Expand Down Expand Up @@ -967,6 +979,9 @@ public RubyString to_pem(final ThreadContext context, final IRubyObject[] args)
}

private ECParameterSpec getParamSpec() {
if (curveName == null) {
throw newError(getRuntime(), "unsupported field: curveName is null");
}
if (paramSpec == null) {
paramSpec = PKeyEC.getParamSpec(getCurveName());
}
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/org/jruby/ext/openssl/X509Name.java
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,8 @@ static void createX509Name(final Ruby runtime, final RubyModule X509, final Ruby
final RubyFixnum IA5_STRING = runtime.newFixnum(BERTags.IA5_STRING);

final ThreadContext context = runtime.getCurrentContext();
final RubyHash hash = new RubyHash(runtime, UTF8_STRING);
final RubyHash hash = RubyHash.newHash(runtime);
hash.default_value_set(context, UTF8_STRING);
hash.op_aset(context, newString(runtime, new byte[] { 'C' }), PRINTABLE_STRING);
final byte[] countryName = { 'c','o','u','n','t','r','y','N','a','m','e' };
hash.op_aset(context, newString(runtime, countryName), PRINTABLE_STRING);
Expand Down
7 changes: 4 additions & 3 deletions src/main/java/org/jruby/ext/openssl/X509Request.java
Original file line number Diff line number Diff line change
Expand Up @@ -296,13 +296,14 @@ public IRubyObject set_public_key(final IRubyObject pkey) {

@JRubyMethod
public IRubyObject sign(final ThreadContext context,
final IRubyObject key, final IRubyObject digest) {
final IRubyObject key, final IRubyObject _digest) {
PrivateKey privateKey = ((PKey) key).getPrivateKey();
Digest digest = Digest.getDigest(context, _digest);

final Ruby runtime = context.runtime;
supportedSignatureAlgorithm(runtime, _RequestError(runtime), public_key, (Digest) digest);
supportedSignatureAlgorithm(runtime, _RequestError(runtime), public_key, digest);

final String digAlg = ((Digest) digest).getShortAlgorithm();
final String digAlg = digest.getShortAlgorithm();
try {
request = null;
getRequest().sign( privateKey, digAlg );
Expand Down
Loading