Skip to content
Open
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
3 changes: 1 addition & 2 deletions jruby-pgp.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 2 additions & 2 deletions lib/pgp.rb
Original file line number Diff line number Diff line change
@@ -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'
Expand Down
3 changes: 2 additions & 1 deletion lib/pgp/encryptor.rb
Original file line number Diff line number Diff line change
@@ -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()
Expand Down Expand Up @@ -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
Expand Down
Binary file not shown.
Binary file not shown.
9 changes: 5 additions & 4 deletions lib/pgp/private_key.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down
12 changes: 7 additions & 5 deletions lib/pgp/ruby_decryptor.rb
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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

Expand Down
5 changes: 3 additions & 2 deletions lib/pgp/verifier.rb
Original file line number Diff line number Diff line change
@@ -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)
Expand Down Expand Up @@ -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
end
2 changes: 1 addition & 1 deletion lib/pgp/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module PGP
VERSION = '0.4.0'
VERSION = '0.4.2-plxis'
end
6 changes: 2 additions & 4 deletions spec/lib/pgp/cli_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
require 'rspec'
require 'bundler'
require 'jruby-pgp'
require 'pry'

Fixtures_Path = Bundler.root + 'spec/support/fixtures/'

Expand Down