cryptor 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGES.md +4 -0
- data/cryptor.gemspec +1 -1
- data/lib/cryptor.rb +8 -0
- data/lib/cryptor/ciphers/message_encryptor.rb +2 -0
- data/lib/cryptor/ciphers/xsalsa20poly1305.rb +2 -0
- data/lib/cryptor/symmetric_encryption.rb +7 -15
- data/lib/cryptor/version.rb +1 -1
- data/spec/symmetric_encryption_spec.rb +36 -0
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7e231e81835f4ec4b64c603b597b38266d505cd8
|
4
|
+
data.tar.gz: 0843bf2d906c77f5824d75c187d30d2d28bf246c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 46ecd69eebc0ab266b699f978bc934f03fd7211414eb55a8147e9cdc14a1a999424fd266c66d2db211b4ce9a0734cb6799d7e45beba2927167cd40579d835c36
|
7
|
+
data.tar.gz: 3da93938f00f68a5e7b3d968e7628a09d788b3838142a48945ae14437150c5849bae15da751002ba205b70c5c90bf399ca6f80793315ce6e4a90a4f02ed48e21
|
data/CHANGES.md
CHANGED
data/cryptor.gemspec
CHANGED
@@ -19,7 +19,7 @@ Gem::Specification.new do |spec|
|
|
19
19
|
spec.test_files = spec.files.grep(/^(test|spec|features)\//)
|
20
20
|
spec.require_paths = ['lib']
|
21
21
|
|
22
|
-
spec.add_runtime_dependency 'ordo', '>= 0.0.
|
22
|
+
spec.add_runtime_dependency 'ordo', '>= 0.0.2'
|
23
23
|
|
24
24
|
spec.add_development_dependency 'rake'
|
25
25
|
spec.add_development_dependency 'rubocop'
|
data/lib/cryptor.rb
CHANGED
@@ -4,3 +4,11 @@ require 'cryptor/cipher'
|
|
4
4
|
require 'cryptor/encoding'
|
5
5
|
require 'cryptor/secret_key'
|
6
6
|
require 'cryptor/symmetric_encryption'
|
7
|
+
|
8
|
+
# Multi-backend high-level encryption library
|
9
|
+
module Cryptor
|
10
|
+
CryptoError = Class.new(StandardError)
|
11
|
+
|
12
|
+
InvalidMessageError = Class.new(CryptoError)
|
13
|
+
CorruptedMessageError = Class.new(CryptoError)
|
14
|
+
end
|
@@ -28,24 +28,16 @@ module Cryptor
|
|
28
28
|
end
|
29
29
|
|
30
30
|
def decrypt(ciphertext)
|
31
|
-
|
32
|
-
|
31
|
+
begin
|
32
|
+
message = ORDO::Message.parse(ciphertext)
|
33
|
+
rescue ORDO::ParseError => ex
|
34
|
+
raise InvalidMessageError, ex.to_s
|
35
|
+
end
|
33
36
|
|
37
|
+
fingerprint = message['Key-Fingerprint']
|
34
38
|
fail ArgumentError, "no key configured for: #{fingerprint}" if @key.fingerprint != fingerprint
|
35
39
|
|
36
|
-
@key.decrypt
|
37
|
-
end
|
38
|
-
|
39
|
-
private
|
40
|
-
|
41
|
-
def decode(message)
|
42
|
-
encoding = message['Content-Transfer-Encoding']
|
43
|
-
|
44
|
-
case encoding
|
45
|
-
when 'base64' then Base64.strict_decode64(message.body)
|
46
|
-
when 'binary' then message.body
|
47
|
-
else fail ArgumentError, "invalid message encoding: #{encoding}"
|
48
|
-
end
|
40
|
+
@key.decrypt message.body
|
49
41
|
end
|
50
42
|
end
|
51
43
|
end
|
data/lib/cryptor/version.rb
CHANGED
@@ -2,6 +2,14 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe Cryptor::SymmetricEncryption do
|
4
4
|
let(:plaintext) { 'THE MAGIC WORDS ARE SQUEAMISH OSSIFRAGE' }
|
5
|
+
|
6
|
+
let(:garbage) do
|
7
|
+
'Timely and accurate information about the activities, capabilities, ' \
|
8
|
+
'plans, and intentions of foreign powers, organizations, and persons ' \
|
9
|
+
'and their agents, is essential to the national security of the ' \
|
10
|
+
'United States.'
|
11
|
+
end
|
12
|
+
|
5
13
|
subject { described_class.new(secret_key) }
|
6
14
|
|
7
15
|
context 'xsalsa20poly1305' do
|
@@ -13,6 +21,20 @@ describe Cryptor::SymmetricEncryption do
|
|
13
21
|
ciphertext = subject.encrypt(plaintext)
|
14
22
|
expect(subject.decrypt(ciphertext)).to eq plaintext
|
15
23
|
end
|
24
|
+
|
25
|
+
it 'raises InvalidMessageError if asked to decrypt garbage' do
|
26
|
+
expect { subject.decrypt(garbage) }.to raise_exception(Cryptor::InvalidMessageError)
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'raises CorruptedMessageError if the message is corrupt' do
|
30
|
+
valid_message = subject.encrypt(plaintext)
|
31
|
+
munged_message = ORDO::Message.parse(valid_message)
|
32
|
+
munged_message.body.replace Base64.strict_encode64(munged_message.body + "\0")
|
33
|
+
|
34
|
+
expect do
|
35
|
+
subject.decrypt(munged_message.to_string)
|
36
|
+
end.to raise_exception(Cryptor::CorruptedMessageError)
|
37
|
+
end
|
16
38
|
end
|
17
39
|
|
18
40
|
context 'message_encryptor' do
|
@@ -24,5 +46,19 @@ describe Cryptor::SymmetricEncryption do
|
|
24
46
|
ciphertext = subject.encrypt(plaintext)
|
25
47
|
expect(subject.decrypt(ciphertext)).to eq plaintext
|
26
48
|
end
|
49
|
+
|
50
|
+
it 'raises InvalidMessageError if asked to decrypt garbage' do
|
51
|
+
expect { subject.decrypt(garbage) }.to raise_exception(Cryptor::InvalidMessageError)
|
52
|
+
end
|
53
|
+
|
54
|
+
it 'raises CorruptedMessageError if the message is corrupt' do
|
55
|
+
valid_message = subject.encrypt(plaintext)
|
56
|
+
munged_message = ORDO::Message.parse(valid_message)
|
57
|
+
munged_message.body.replace Base64.strict_encode64(munged_message.body + "\0")
|
58
|
+
|
59
|
+
expect do
|
60
|
+
subject.decrypt(munged_message.to_string)
|
61
|
+
end.to raise_exception(Cryptor::CorruptedMessageError)
|
62
|
+
end
|
27
63
|
end
|
28
64
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cryptor
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tony Arcieri
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-06-
|
11
|
+
date: 2014-06-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ordo
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 0.0.
|
19
|
+
version: 0.0.2
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 0.0.
|
26
|
+
version: 0.0.2
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|