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: f76ec2f196a0
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: 412bbe512eaa
Choose a head ref
  • 2 commits
  • 3 files changed
  • 1 contributor

Commits on Apr 6, 2018

  1. Verified

    This commit was signed with the committer’s verified signature.
    wyattjoh Wyatt Johnson
    Copy the full SHA
    08ae555 View commit details
  2. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    412bbe5 View commit details
23 changes: 15 additions & 8 deletions src/main/java/org/jruby/ext/openssl/Cipher.java
Original file line number Diff line number Diff line change
@@ -253,7 +253,7 @@ public static final class Algorithm {
};

static {
KNOWN_BLOCK_MODES = new HashSet<String>();
KNOWN_BLOCK_MODES = new HashSet<>(10, 1);
for ( String mode : OPENSSL_BLOCK_MODES ) KNOWN_BLOCK_MODES.add(mode);
KNOWN_BLOCK_MODES.add("CTR");
KNOWN_BLOCK_MODES.add("CTS"); // not supported by OpenSSL
@@ -262,8 +262,15 @@ public static final class Algorithm {
}

// Subset of KNOWN_BLOCK_MODES that do not require padding (and shouldn't have it by default).
private static final List<String> NO_PADDING_BLOCK_MODES = Arrays.asList(
"CFB", "CFB8", "OFB", "CTR", "GCM");
private static final Set<String> NO_PADDING_BLOCK_MODES;
static {
NO_PADDING_BLOCK_MODES = new HashSet<>(6, 1);
NO_PADDING_BLOCK_MODES.add("CFB");
NO_PADDING_BLOCK_MODES.add("CFB8");
NO_PADDING_BLOCK_MODES.add("OFB");
NO_PADDING_BLOCK_MODES.add("CTR");
NO_PADDING_BLOCK_MODES.add("GCM");
}

// Ruby to Java name String (or FALSE)
static final HashMap<String, String[]> supportedCiphers = new LinkedHashMap<String, String[]>(120, 1);
@@ -834,7 +841,7 @@ public IRubyObject set_key(final ThreadContext context, final IRubyObject key) {
debugStackTrace(runtime, e);
throw newCipherError(runtime, e);
}
if ( keyBytes.length() < keyLength ) {
if ( keyBytes.getRealSize() < keyLength ) {
throw newCipherError(context.runtime, "key length too short");
}

@@ -856,7 +863,7 @@ public IRubyObject set_iv(final ThreadContext context, final IRubyObject iv) {
debugStackTrace(runtime, e);
throw newCipherError(runtime, e);
}
if ( ivBytes.length() < ivLength ) {
if ( ivBytes.getRealSize() < ivLength ) {
throw newCipherError(context.runtime, "iv length too short");
}
// EVP_CipherInit_ex uses leading IV length of given sequence.
@@ -1102,7 +1109,7 @@ public IRubyObject update(final ThreadContext context, final IRubyObject arg) {
checkAuthTag(runtime);

final ByteList data = arg.asString().getByteList();
final int length = data.length();
final int length = data.getRealSize();
if ( length == 0 ) {
throw runtime.newArgumentError("data must not be empty");
}
@@ -1221,7 +1228,7 @@ private ByteList do_final_with_auth(final Ruby runtime) throws GeneralSecurityEx
final byte[] out;
if ( auth_tag != null ) {
final byte[] tag = auth_tag.getUnsafeBytes();
out = cipher.doFinal(tag, auth_tag.begin(), auth_tag.length());
out = cipher.doFinal(tag, auth_tag.getBegin(), auth_tag.getRealSize());
}
else {
out = cipher.doFinal();
@@ -1303,7 +1310,7 @@ private boolean updateAuthData(final Ruby runtime) {
if ( auth_data == null ) return false; // only to be set if auth-mode
//try {
final byte[] data = auth_data.getUnsafeBytes();
cipher.updateAAD(data, auth_data.begin(), auth_data.length());
cipher.updateAAD(data, auth_data.getBegin(), auth_data.getRealSize());
//}
//catch (RuntimeException e) {
// debugStackTrace( runtime, e );
2 changes: 1 addition & 1 deletion src/main/java/org/jruby/ext/openssl/OpenSSL.java
Original file line number Diff line number Diff line change
@@ -106,7 +106,7 @@ public static void createOpenSSL(final Ruby runtime) {
final byte[] JRuby_OpenSSL_ = { 'J','R','u','b','y','-','O','p','e','n','S','S','L',' ' };
final int OPENSSL_VERSION_NUMBER = 999999999; // NOTE: smt more useful?

ByteList OPENSSL_VERSION = new ByteList( jVERSION.getByteList().length() + JRuby_OpenSSL_.length );
ByteList OPENSSL_VERSION = new ByteList( jVERSION.getByteList().getRealSize() + JRuby_OpenSSL_.length );
OPENSSL_VERSION.setEncoding( jVERSION.getEncoding() );
OPENSSL_VERSION.append( JRuby_OpenSSL_ );
OPENSSL_VERSION.append( jVERSION.getByteList() );
Original file line number Diff line number Diff line change
@@ -573,7 +573,7 @@ private DEROctetString parseSubjectKeyIdentifier(final ThreadContext context, fi
i++;
}
}
final byte[] hexBytes = new byte[hex.length()];
final byte[] hexBytes = new byte[hex.getRealSize()];
System.arraycopy(hex.getUnsafeBytes(), hex.getBegin(), hexBytes, 0, hexBytes.length);
return new DEROctetString(hexBytes);
}