Modified: trunk/jopenssl/src/java/org/jruby/ext/openssl/ASN1.java (1101 => 1102)
--- trunk/jopenssl/src/java/org/jruby/ext/openssl/ASN1.java 2008-08-11 12:36:58 UTC (rev 1101)
+++ trunk/jopenssl/src/java/org/jruby/ext/openssl/ASN1.java 2008-08-11 12:37:02 UTC (rev 1102)
@@ -581,7 +581,6 @@
IRubyObject ret = decodeObj(asnM, asis.readObject());
return ret;
} catch(IOException e) {
- System.err.println("gah" + e);
throw recv.getRuntime().newIOErrorFromException(e);
} catch(Exception e) {
throw recv.getRuntime().newArgumentError(e.getMessage());
Modified: trunk/jopenssl/src/java/org/jruby/ext/openssl/OpenSSLReal.java (1101 => 1102)
--- trunk/jopenssl/src/java/org/jruby/ext/openssl/OpenSSLReal.java 2008-08-11 12:36:58 UTC (rev 1101)
+++ trunk/jopenssl/src/java/org/jruby/ext/openssl/OpenSSLReal.java 2008-08-11 12:37:02 UTC (rev 1102)
@@ -35,9 +35,17 @@
* @author <a href="" PROTECTED]">Ola Bini</a>
*/
public class OpenSSLReal {
-
public static java.security.Provider PROVIDER;
+ static {
+ try {
+ PROVIDER = (java.security.Provider)
+ Class.forName("org.bouncycastle.jce.provider.BouncyCastleProvider").newInstance();
+ } catch (Exception exception) {
+ // no bouncy castle available
+ }
+ }
+
public static void doWithBCProvider(final Runnable toRun) {
getWithBCProvider(new Callable() {
@@ -64,15 +72,6 @@
}
public static void createOpenSSL(Ruby runtime) {
- if (PROVIDER == null) {
- try {
- PROVIDER = (java.security.Provider)
- Class.forName("org.bouncycastle.jce.provider.BouncyCastleProvider").newInstance();
- } catch (Exception exception) {
- // no bouncy castle available
- }
- }
-
RubyModule ossl = runtime.getOrCreateModule("OpenSSL");
RubyClass standardError = runtime.getClass("StandardError");
ossl.defineClassUnder("OpenSSLError", standardError, standardError.getAllocator());
Modified: trunk/jopenssl/src/java/org/jruby/ext/openssl/impl/CipherBIOFilter.java (1101 => 1102)
--- trunk/jopenssl/src/java/org/jruby/ext/openssl/impl/CipherBIOFilter.java 2008-08-11 12:36:58 UTC (rev 1101)
+++ trunk/jopenssl/src/java/org/jruby/ext/openssl/impl/CipherBIOFilter.java 2008-08-11 12:37:02 UTC (rev 1102)
@@ -39,6 +39,14 @@
public class CipherBIOFilter extends BIOFilter {
private Cipher cipher;
+ private byte[] bufRead = new byte[4096];
+ private int fillLen = 0;
+ private int fillOffset = 0;
+
+ private byte[] tmpBuf = new byte[1024];
+
+ private boolean finalized = false;
+
public CipherBIOFilter(Cipher cipher) {
this.cipher = cipher;
}
@@ -57,6 +65,83 @@
}
}
+ public int read(byte[] into, int offset, int len) throws IOException {
+ try {
+ int read = 0;
+ if(fillLen > 0) {
+ read = Math.min(fillLen, len);
+ System.arraycopy(bufRead, fillOffset, into, offset, read);
+ fillOffset += read;
+ fillLen -= read;
+ if(fillLen == 0) {
+ fillOffset = 0;
+ }
+ if(read == len) {
+ return read;
+ }
+ }
+
+ int req = len - read;
+ int off = offset + read;
+
+ if(finalized) {
+ return 0;
+ }
+
+ while(req > 0) {
+ int readFromNext = next().read(tmpBuf, 0, 1024);
+ if(readFromNext > 0) {
+ int required = cipher.getOutputSize(readFromNext);
+ if(required > (bufRead.length - (fillOffset + fillLen))) {
+ byte[] newBuf = new byte[required + fillOffset + fillLen];
+ System.arraycopy(bufRead, fillOffset, newBuf, 0, fillLen);
+ fillOffset = 0;
+ bufRead = newBuf;
+ }
+ int outputted = cipher.update(tmpBuf, 0, readFromNext, bufRead, fillOffset + fillLen);
+ fillLen += outputted;
+
+ read = Math.min(fillLen, req);
+ System.arraycopy(bufRead, fillOffset, into, off, read);
+ fillOffset += read;
+ fillLen -= read;
+ if(fillLen == 0) {
+ fillOffset = 0;
+ }
+
+ req -= read;
+ off += read;
+ } else {
+ int required = cipher.getOutputSize(0);
+ if(required > (bufRead.length - (fillOffset + fillLen))) {
+ byte[] newBuf = new byte[required + fillOffset + fillLen];
+ System.arraycopy(bufRead, fillOffset, newBuf, 0, fillLen);
+ fillOffset = 0;
+ bufRead = newBuf;
+ }
+ int outputted = cipher.doFinal(bufRead, fillOffset + fillLen);
+ finalized = true;
+ fillLen += outputted;
+
+ read = Math.min(fillLen, req);
+ System.arraycopy(bufRead, fillOffset, into, off, read);
+ fillOffset += read;
+ fillLen -= read;
+ if(fillLen == 0) {
+ fillOffset = 0;
+ }
+
+ req -= read;
+ return len-req;
+ }
+ }
+
+ return len;
+ } catch(Exception e) {
+ throw new IllegalArgumentException(e);
+ }
+ }
+
public int write(byte[] out, int offset, int len) throws IOException {
byte[] result = cipher.update(out, offset, len);
if(result == null) {
Modified: trunk/jopenssl/test/openssl/utils.rb (1101 => 1102)
--- trunk/jopenssl/test/openssl/utils.rb 2008-08-11 12:36:58 UTC (rev 1101)
+++ trunk/jopenssl/test/openssl/utils.rb 2008-08-11 12:37:02 UTC (rev 1102)
@@ -121,9 +121,6 @@
crl.add_extension(ef.create_extension(oid, value, critical))
}
crl.sign(issuer_key, digest)
- File.open("crls", "a") do |f|
- f.puts crl
- end
crl
end
Modified: trunk/jopenssl/test/test_openssl.rb (1101 => 1102)
--- trunk/jopenssl/test/test_openssl.rb 2008-08-11 12:36:58 UTC (rev 1101)
+++ trunk/jopenssl/test/test_openssl.rb 2008-08-11 12:37:02 UTC (rev 1102)
@@ -1,5 +1,10 @@
-require 'java' if RUBY_PLATFORM =~ /java/
+if defined?(JRUBY_VERSION)
+ require "java"
+ base = File.join(File.dirname(__FILE__), '..')
+ $CLASSPATH << File.join(base, 'pkg', 'classes')
+ $CLASSPATH << File.join(base, 'lib', 'bcprov-jdk14-139.jar')
+end
def protect_require(name)
require name
@@ -24,3 +29,4 @@
protect_require 'openssl/test_x509req'
protect_require 'openssl/test_x509store'
protect_require 'test_cipher'
+protect_require 'test_java'