diff --git a/jruby-pgp.gemspec b/jruby-pgp.gemspec index 0abdc9c..e7bd0dc 100644 --- a/jruby-pgp.gemspec +++ b/jruby-pgp.gemspec @@ -18,9 +18,8 @@ Gem::Specification.new do |gem| gem.test_files = gem.files.grep(%r{^(test|spec|features)/}) gem.require_paths = ['lib'] - gem.add_dependency 'jruby-openssl' - gem.add_development_dependency 'rake' gem.add_development_dependency 'rspec' + gem.add_development_dependency 'pry' gem.add_development_dependency 'rake-compiler' end diff --git a/lib/pgp.rb b/lib/pgp.rb index e26166c..789c6dd 100644 --- a/lib/pgp.rb +++ b/lib/pgp.rb @@ -1,6 +1,6 @@ require 'java' -require 'pgp/jars/bcprov-jdk15on-153.jar' -require 'pgp/jars/bcpg-jdk15on-153.jar' +require 'pgp/jars/bcprov-jdk15on-158.jar' +require 'pgp/jars/bcpg-jdk15on-158.jar' require 'pgp/jruby-pgp.jar' require 'pgp/decryptor' diff --git a/lib/pgp/encryptor.rb b/lib/pgp/encryptor.rb index 0e000df..e362f3f 100644 --- a/lib/pgp/encryptor.rb +++ b/lib/pgp/encryptor.rb @@ -1,6 +1,7 @@ module PGP class Encryptor < org.sgonyea.pgp.Encryptor include_package "org.bouncycastle.openpgp" + java_import "org.bouncycastle.openpgp.operator.jcajce.JcaKeyFingerprintCalculator" def initialize(key_string=nil) super() @@ -61,7 +62,7 @@ def keyring_from_string(key_string) def keyring_from_stream(stream) yafs = PGPUtil.get_decoder_stream(stream) - PGPPublicKeyRingCollection.new(yafs) + PGPPublicKeyRingCollection.new(yafs, JcaKeyFingerprintCalculator.new) end end diff --git a/lib/pgp/jars/bcpg-jdk15on-153.jar b/lib/pgp/jars/bcpg-jdk15on-158.jar similarity index 57% rename from lib/pgp/jars/bcpg-jdk15on-153.jar rename to lib/pgp/jars/bcpg-jdk15on-158.jar index f89d659..e3c15e5 100644 Binary files a/lib/pgp/jars/bcpg-jdk15on-153.jar and b/lib/pgp/jars/bcpg-jdk15on-158.jar differ diff --git a/lib/pgp/jars/bcprov-jdk15on-153.jar b/lib/pgp/jars/bcprov-jdk15on-158.jar similarity index 50% rename from lib/pgp/jars/bcprov-jdk15on-153.jar rename to lib/pgp/jars/bcprov-jdk15on-158.jar index c9fbafb..dae02cb 100644 Binary files a/lib/pgp/jars/bcprov-jdk15on-153.jar and b/lib/pgp/jars/bcprov-jdk15on-158.jar differ diff --git a/lib/pgp/private_key.rb b/lib/pgp/private_key.rb index aa19ef0..d958a6c 100644 --- a/lib/pgp/private_key.rb +++ b/lib/pgp/private_key.rb @@ -3,20 +3,21 @@ module PGP # the PGPPrivateKey class and make using it less ghoulish. class PrivateKey include_package "org.bouncycastle.openpgp" + java_import "org.bouncycastle.openpgp.operator.jcajce.JcaKeyFingerprintCalculator" + java_import "org.bouncycastle.openpgp.operator.jcajce.JcePBESecretKeyDecryptorBuilder" def self.from_string(string, key_id) stream = PGP.string_to_bais(string) pgp_sec = keyring_from_stream(stream) sec_key = pgp_sec.get_secret_key(key_id) - sec_key.extract_private_key(nil, BC_Provider_Code) if sec_key + sec_key.extract_private_key(JcePBESecretKeyDecryptorBuilder.new.set_provider("BC").build(nil)) if sec_key end def self.from_file(filename, key_id) pgp_sec = keyring_from_file(filename) sec_key = pgp_sec.get_secret_key(key_id) - - sec_key.extract_private_key(nil, BC_Provider_Code) if sec_key + sec_key.extract_private_key(JcePBESecretKeyDecryptorBuilder.new.set_provider("BC").build(nil)) if sec_key end def self.keyring_from_file(filename) @@ -26,7 +27,7 @@ def self.keyring_from_file(filename) def self.keyring_from_stream(stream) yafs = PGPUtil.get_decoder_stream(stream) - PGPSecretKeyRingCollection.new(yafs) + PGPSecretKeyRingCollection.new(yafs, JcaKeyFingerprintCalculator.new) end end diff --git a/lib/pgp/ruby_decryptor.rb b/lib/pgp/ruby_decryptor.rb index dad9efb..401d1a9 100644 --- a/lib/pgp/ruby_decryptor.rb +++ b/lib/pgp/ruby_decryptor.rb @@ -1,13 +1,16 @@ module PGP class RubyDecryptor include_package "org.bouncycastle.openpgp" + include_package "org.bouncycastle.openpgp.jcajce" + java_import "org.bouncycastle.openpgp.operator.jcajce.JcePublicKeyDataDecryptorFactoryBuilder" + java_import "org.bouncycastle.openpgp.operator.jcajce.JcaKeyFingerprintCalculator" java_import 'java.io.ByteArrayOutputStream' def self.decrypt(encrypted_text, private_key_file) bytes = PGP.string_to_bais(encrypted_text) dec_s = PGPUtil.get_decoder_stream(bytes) - pgp_f = PGPObjectFactory.new(dec_s) + pgp_f = JcaPGPObjectFactory.new(dec_s) enc_data = pgp_f.next_object enc_data = pgp_f.next_object unless PGPEncryptedDataList === enc_data @@ -30,14 +33,13 @@ def self.decrypt(encrypted_text, private_key_file) end end - clear = pbe.get_data_stream(sec_key, BC_Provider_Code) - - plain_fact = PGPObjectFactory.new(clear) + clear = pbe.get_data_stream(JcePublicKeyDataDecryptorFactoryBuilder.new.set_provider("BC").build(sec_key)) + plain_fact = JcaPGPObjectFactory.new(clear) message = plain_fact.next_object if(PGPCompressedData === message) - pgp_fact = PGPObjectFactory.new(message.get_data_stream) + pgp_fact = JcaPGPObjectFactory.new(message.get_data_stream) message = pgp_fact.next_object end diff --git a/lib/pgp/verifier.rb b/lib/pgp/verifier.rb index e856ffb..26cb81f 100644 --- a/lib/pgp/verifier.rb +++ b/lib/pgp/verifier.rb @@ -1,6 +1,7 @@ module PGP class Verifier < org.sgonyea.pgp.Verifier include_package "org.bouncycastle.openpgp" + java_import "org.bouncycastle.openpgp.operator.jcajce.JcaKeyFingerprintCalculator" def add_keys(key_string) self.public_keys = keyring_from_string(key_string) @@ -31,8 +32,8 @@ def keyring_from_string(key_string) def keyring_from_stream(stream) yafs = PGPUtil.get_decoder_stream(stream) - PGPPublicKeyRingCollection.new(yafs) + PGPPublicKeyRingCollection.new(yafs, JcaKeyFingerprintCalculator.new) end end -end \ No newline at end of file +end diff --git a/lib/pgp/version.rb b/lib/pgp/version.rb index 7e1a7ca..9f0470c 100644 --- a/lib/pgp/version.rb +++ b/lib/pgp/version.rb @@ -1,3 +1,3 @@ module PGP - VERSION = '0.4.0' + VERSION = '0.4.2-plxis' end diff --git a/spec/lib/pgp/cli_spec.rb b/spec/lib/pgp/cli_spec.rb index 885a23c..299b20a 100644 --- a/spec/lib/pgp/cli_spec.rb +++ b/spec/lib/pgp/cli_spec.rb @@ -18,16 +18,14 @@ describe 'Encrypting' do it "should encrypt a given file to the given public key" do PGP::CLI::Runner.go!([decrypted_file, "-p", "spec/support/fixtures/public_key.asc"]) - - File.exist?('unencrypted_file.txt.gpg').should be_true + File.exist?('unencrypted_file.txt.gpg').should be_truthy end end describe 'Decrypting' do it "should decrypt a given file to the given private key" do PGP::CLI::Runner.go!([encrypted_file, "-P", "spec/support/fixtures/private_key.asc", "-d"]) - - File.exist?('unencrypted_file.txt').should be_true + File.exist?('unencrypted_file.txt').should be_truthy end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index c4e8c3d..81f097b 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,6 +1,7 @@ require 'rspec' require 'bundler' require 'jruby-pgp' +require 'pry' Fixtures_Path = Bundler.root + 'spec/support/fixtures/'