rbnacl 2.0.0.pre → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2ba5a3248fe87dd5d2f784f29857ff1d7d26e631
4
- data.tar.gz: b61bd66e86e6b2bce75ed52d87d0a706df5626b6
3
+ metadata.gz: 4868c75138fed2d13cc2c2e101961e5149a2f950
4
+ data.tar.gz: 9b2bc9e35ff45cf67715ae49a86f3667dff2609a
5
5
  SHA512:
6
- metadata.gz: ed12ef065cb24120b4ff6329026ea69bb560736f6ae6df76534fd064fb862251f29d137b8a8506ed35be67965d610b2cd3b70196253a72da645d3001a3cb7ceb
7
- data.tar.gz: ea66f56eadd856e610761ecb031b95a5163e7e99d6127b2798126fa2dbf9998bfd53fd9c6cf9d245511f3ba65d70d3af91313f7f01f19bd35a642f212a45ca12
6
+ metadata.gz: 6667126547e0562e40b3d653b998058a4cc2f4dab18063d636285ca957d5b3c500eac93966946bcf9989bcad24c312208edbb856b34d53391d6ce7d2eec97932
7
+ data.tar.gz: 4e2d2f6ac34fa25972361afa81e8d0ae1c08f6b344e3fba43cdba92790daf1b00c824b564f4c5a3a64070fb2b7a6f9698e546ede8ec9088295a43355528958cd
Binary file
@@ -0,0 +1,2 @@
1
+ ��aA�˥�P�$��9�~��b+;�w[!,�fƬ@Iս��a]s8�R�Fu�X|�K��va�a���! œ8���"��aŶ�K��kp�_�HĊ؜�?^n�e���b
2
+ �I��,*����00�?=���@]�w$K6g�L)F�G��e�>u�`�W:�Z�x�ʖ��@���!Cf�q'�^���Ȏ�mX�@|�C���%��kߑr��3���Q�O��(fUw�*��vr�R��z�_ƒ<�K��o
data/CHANGES.md CHANGED
@@ -1,10 +1,22 @@
1
- 2.0.0.pre
2
- ---------
3
- * ZOMG LOTS OF STUFF! We should make we get it all added to this file!
1
+ 2.0.0 (2013-11-07)
2
+ ------------------
4
3
  * Add encrypt/decrypt aliases for Crypto::RandomNonceBox
5
4
  * Rename Crypto module to RbNaCl module
6
5
  * RbNaCl::VerifyKey#verify operand order was reversed. New operand order is
7
6
  signature, message instead of message, signature
7
+ * RbNaCL::SecretBox#open, RbNaCl::Box#open, Auth#verify and VerifyKey#verify
8
+ all now raise a (descendent of) CryptoError if the check fails. This ensures
9
+ failures are handled by the program.
10
+ * RbNaCl::SecretBox, Box, etc. are all now aliases for the real implementations,
11
+ which are named after the primitives they provide
12
+ * Encoders have now gone.
13
+ * Add support for the Blake2b cryptographic hash algorithm.
14
+ * Add checks that we have a sufficiently recent version of libsodium (0.4.3+)
15
+ * Dropped ruby-1.8 support
16
+ * Call the `sodium_init()` function, to select the best algorithms.
17
+ * Fix some typos in the documentation
18
+ * Changes in the low level binding for libsodium and removal of the NaCl module
19
+ * Add a mutex around calls to randombytes in libsodium
8
20
 
9
21
  1.1.0 (2013-04-19)
10
22
  ------------------
@@ -1,6 +1,7 @@
1
1
  # encoding: binary
2
2
  require "rbnacl/version"
3
3
  require "rbnacl/sodium"
4
+ require "rbnacl/sodium/version"
4
5
  require "rbnacl/serializable"
5
6
  require "rbnacl/key_comparator"
6
7
  require "rbnacl/auth"
@@ -11,12 +12,6 @@ require "rbnacl/test_vectors"
11
12
  require "rbnacl/init"
12
13
 
13
14
  module RbNaCl
14
- REQUIRED_LIBSODIUM_VERSION = "0.4.5"
15
-
16
- if Util.sodium_version_string < REQUIRED_LIBSODIUM_VERSION
17
- raise "Sorry, you need to install libsodium #{REQUIRED_LIBSODIUM_VERSION}+. You have #{Util.sodium_version_string} installed"
18
- end
19
-
20
15
  # Oh no, something went wrong!
21
16
  #
22
17
  # This indicates a failure in the operation of a cryptographic primitive such
@@ -39,6 +34,10 @@ module RbNaCl
39
34
  # The signature was forged or otherwise corrupt
40
35
  class BadSignatureError < CryptoError; end
41
36
 
37
+ # The authenticator was forged or otherwise corrupt
38
+ class BadAuthenticatorError < CryptoError; end
39
+
40
+
42
41
  # Public Key Encryption (Box): Curve25519XSalsa20Poly1305
43
42
  require "rbnacl/boxes/curve25519xsalsa20poly1305"
44
43
  require "rbnacl/boxes/curve25519xsalsa20poly1305/private_key"
@@ -1,5 +1,6 @@
1
1
  # encoding: binary
2
2
  module RbNaCl
3
+
3
4
  # Secret Key Authenticators
4
5
  #
5
6
  # These provide a means of verifying the integrity of a message, but only
@@ -38,6 +39,9 @@ module RbNaCl
38
39
  # @param [#to_str] authenticator to be checked
39
40
  # @param [#to_str] message the message to be authenticated
40
41
  #
42
+ # @raise [BadAuthenticatorError] if the tag isn't valid
43
+ # @raise [LengthError] if the tag is of the wrong length
44
+ #
41
45
  # @return [Boolean] Was it valid?
42
46
  def self.verify(key, authenticator, message)
43
47
  new(key).verify(authenticator, message)
@@ -60,11 +64,14 @@ module RbNaCl
60
64
  # @param [#to_str] authenticator to be checked
61
65
  # @param [#to_str] message the message to be authenticated
62
66
  #
67
+ # @raise [BadAuthenticatorError] if the tag isn't valid
68
+ # @raise [LengthError] if the tag is of the wrong length
69
+ #
63
70
  # @return [Boolean] Was it valid?
64
71
  def verify(authenticator, message)
65
72
  auth = authenticator.to_s
66
- return false unless auth.bytesize == tag_bytes
67
- verify_message(auth, message)
73
+ Util.check_length(auth, tag_bytes, "Provided authenticator")
74
+ verify_message(auth, message) || raise(BadAuthenticatorError, "Invalid authenticator provided, message is corrupt")
68
75
  end
69
76
 
70
77
  # The crypto primitive for this authenticator instance
@@ -35,11 +35,18 @@ module RbNaCl
35
35
  # @return [RbNaCl::Hash::Blake2b] A Blake2b hasher object
36
36
  def initialize(opts = {})
37
37
  @key = opts.fetch(:key, nil)
38
- @key_size = @key ? @key.bytesize : 0
39
- raise LengthError, "Invalid key size" if (@key_size != 0) && (@key_size < KEYBYTES_MIN || @key_size > KEYBYTES_MAX)
38
+
39
+ if @key
40
+ @key_size = @key.bytesize
41
+ raise LengthError, "key too short" if @key_size < KEYBYTES_MIN
42
+ raise LengthError, "key too long" if @key_size > KEYBYTES_MAX
43
+ else
44
+ @key_size = 0
45
+ end
40
46
 
41
47
  @digest_size = opts.fetch(:digest_size, BYTES_MAX)
42
- raise LengthError, "Invalid digest size" if @digest_size < BYTES_MIN || @digest_size > BYTES_MAX
48
+ raise LengthError, "digest size too short" if @digest_size < BYTES_MIN
49
+ raise LengthError, "digest size too long" if @digest_size > BYTES_MAX
43
50
  end
44
51
 
45
52
  # Calculate a Blake2b digest
@@ -1,3 +1,5 @@
1
+ require 'thread'
2
+
1
3
  # encoding: binary
2
4
  module RbNaCl
3
5
  # Functions for random number generation
@@ -7,6 +9,8 @@ module RbNaCl
7
9
  module Random
8
10
  extend Sodium
9
11
 
12
+ @mutex = Mutex.new
13
+
10
14
  sodium_function :c_random_bytes,
11
15
  :randombytes_buf,
12
16
  [:pointer, :ulong_long]
@@ -17,7 +21,7 @@ module RbNaCl
17
21
  # @return [String] random bytes.
18
22
  def self.random_bytes(n=32)
19
23
  buf = RbNaCl::Util.zeros(n)
20
- c_random_bytes(buf, n)
24
+ @mutex.synchronize { c_random_bytes(buf, n) }
21
25
  buf
22
26
  end
23
27
  end
@@ -80,12 +80,14 @@ module RbNaCl
80
80
  #:nocov:
81
81
  end
82
82
 
83
- bad_signature = signature[0,63] + '0'
84
-
85
- unless verify_key.verify(bad_signature, message) == false
86
- #:nocov:
87
- raise SelfTestFailure, "failed to detect an invalid signature"
88
- #:nocov:
83
+ begin
84
+ passed = false
85
+ bad_signature = signature[0,63] + '0'
86
+ verify_key.verify(bad_signature, message)
87
+ rescue CryptoError
88
+ passed = true
89
+ ensure
90
+ passed or raise SelfTestFailure, "failed to detect corrupt ciphertext"
89
91
  end
90
92
  end
91
93
 
@@ -117,10 +119,13 @@ module RbNaCl
117
119
  #:nocov:
118
120
  end
119
121
 
120
- if authenticator.verify(vector(tag), message + ' ')
121
- #:nocov:
122
- raise SelfTestFailure, "#{klass} failed to detect invalid authentication tag"
123
- #:nocov:
122
+ begin
123
+ passed = false
124
+ authenticator.verify(vector(tag), message + ' ')
125
+ rescue CryptoError
126
+ passed = true
127
+ ensure
128
+ passed or raise SelfTestFailure, "failed to detect corrupt ciphertext"
124
129
  end
125
130
  end
126
131
  end
@@ -33,9 +33,14 @@ module RbNaCl
33
33
 
34
34
  # Verify a signature for a given message
35
35
  #
36
+ # Raises if the signature is invalid.
37
+ #
36
38
  # @param signature [String] Alleged signature to be checked
37
39
  # @param message [String] Message to be authenticated
38
40
  #
41
+ # @raise [BadSignatureError] if the signature check fails
42
+ # @raise [LengthError] if the signature is of the wrong length
43
+ #
39
44
  # @return [Boolean] was the signature authentic?
40
45
  def verify(signature, message)
41
46
  signature = signature.to_str
@@ -45,25 +50,7 @@ module RbNaCl
45
50
  buffer = Util.zeros(sig_and_msg.bytesize)
46
51
  buffer_len = Util.zeros(FFI::Type::LONG_LONG.size)
47
52
 
48
- self.class.sign_ed25519_open(buffer, buffer_len, sig_and_msg, sig_and_msg.bytesize, @key)
49
- end
50
-
51
- # Verify a signature for a given message or raise exception
52
- #
53
- # "Dangerous" (but really safer) verify that raises an exception if a
54
- # signature check fails. This is probably less likely to go unnoticed than
55
- # an improperly checked verify, as you are forced to deal with the
56
- # exception explicitly (and failing signature checks are certainly an
57
- # exceptional condition!)
58
- #
59
- # The arguments are otherwise the same as the verify method.
60
- #
61
- # @param message [String] Message to be authenticated
62
- # @param signature [String] Alleged signature to be checked
63
- #
64
- # @return [true] Will raise BadSignatureError if signature check fails
65
- def verify!(message, signature)
66
- verify(message, signature) or raise BadSignatureError, "signature was forged/corrupt"
53
+ self.class.sign_ed25519_open(buffer, buffer_len, sig_and_msg, sig_and_msg.bytesize, @key) || raise(BadSignatureError, "signature was forged/corrupt")
67
54
  end
68
55
 
69
56
  # Return the raw key in byte format
@@ -0,0 +1,23 @@
1
+ require 'rbnacl/sodium'
2
+
3
+ module RbNaCl
4
+ module Sodium
5
+ module Version
6
+ MINIMUM_LIBSODIUM_VERSION = "0.4.3"
7
+
8
+ extend Sodium
9
+ attach_function :sodium_version_string, [], :string
10
+
11
+ STRING = sodium_version_string
12
+ MAJOR, MINOR, PATCH = STRING.split(".").map(&:to_i)
13
+
14
+ installed_version = [MAJOR, MINOR, PATCH]
15
+ minimum_version = MINIMUM_LIBSODIUM_VERSION.split(".").map(&:to_i)
16
+
17
+ case installed_version <=> minimum_version
18
+ when -1
19
+ raise "Sorry, you need to install libsodium #{MINIMUM_LIBSODIUM_VERSION}+. You have #{Version::STRING} installed"
20
+ end
21
+ end
22
+ end
23
+ end
@@ -4,8 +4,6 @@ module RbNaCl
4
4
  module Util
5
5
  extend Sodium
6
6
 
7
- attach_function :sodium_version_string, [], :string
8
-
9
7
  sodium_function :c_verify16, :crypto_verify_16, [:pointer, :pointer]
10
8
  sodium_function :c_verify32, :crypto_verify_32, [:pointer, :pointer]
11
9
  module_function
@@ -1,5 +1,5 @@
1
1
  # encoding: binary
2
2
  module RbNaCl
3
3
  # The library's version
4
- VERSION = "2.0.0.pre"
4
+ VERSION = "2.0.0"
5
5
  end
@@ -11,6 +11,7 @@ Gem::Specification.new do |gem|
11
11
  gem.description = "Ruby binding to the Networking and Cryptography (NaCl) library"
12
12
  gem.summary = "The Networking and Cryptography (NaCl) library provides a high-level toolkit for building cryptographic systems and protocols"
13
13
  gem.homepage = "https://github.com/cryptosphere/rbnacl"
14
+ gem.licenses = ["MIT"]
14
15
 
15
16
  gem.files = `git ls-files`.split($/)
16
17
  gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
@@ -25,4 +26,7 @@ Gem::Specification.new do |gem|
25
26
 
26
27
  gem.add_development_dependency "rake"
27
28
  gem.add_development_dependency "rspec", ">= 2.14"
29
+
30
+ gem.signing_key = "../.sekretz/gem-private_key.pem"
31
+ gem.cert_chain = ["bascule.cert"]
28
32
  end
@@ -7,11 +7,11 @@ describe RbNaCl::Hash::Blake2b do
7
7
  let(:empty_string_hash) { vector :blake2b_empty }
8
8
 
9
9
  it "calculates the correct hash for a reference string" do
10
- RbNaCl::Hash.blake2b(reference_string).should eq reference_string_hash
10
+ expect(RbNaCl::Hash.blake2b(reference_string)).to eq reference_string_hash
11
11
  end
12
12
 
13
13
  it "calculates the correct hash for an empty string" do
14
- RbNaCl::Hash.blake2b("").should eq empty_string_hash
14
+ expect(RbNaCl::Hash.blake2b("")).to eq empty_string_hash
15
15
  end
16
16
 
17
17
  context "keyed" do
@@ -20,7 +20,11 @@ describe RbNaCl::Hash::Blake2b do
20
20
  let(:reference_string_hash) { vector :blake2b_keyed_digest }
21
21
 
22
22
  it "calculates keyed hashes correctly" do
23
- RbNaCl::Hash.blake2b(reference_string, :key => reference_key).should eq reference_string_hash
23
+ expect(RbNaCl::Hash.blake2b(reference_string, key: reference_key)).to eq reference_string_hash
24
+ end
25
+
26
+ it "doesn't accept empty strings as a key" do
27
+ expect { RbNaCl::Hash.blake2b(reference_string, key: "") }.to raise_exception
24
28
  end
25
29
  end
26
30
  end
@@ -13,12 +13,12 @@ describe RbNaCl::VerifyKey do
13
13
  subject.verify(signature, message).should be_true
14
14
  end
15
15
 
16
- it "detects bad signatures" do
17
- subject.verify(bad_signature, message).should be_false
16
+ it "raises when asked to verify a bad signature" do
17
+ expect { subject.verify(bad_signature, message) }.to raise_exception RbNaCl::BadSignatureError
18
18
  end
19
19
 
20
- it "raises when asked to verify with a bang" do
21
- expect { subject.verify!(bad_signature, message) }.to raise_exception RbNaCl::BadSignatureError
20
+ it "raises when asked to verify a short signature" do
21
+ expect { subject.verify(bad_signature[0,63], message) }.to raise_exception RbNaCl::LengthError
22
22
  end
23
23
 
24
24
  it "serializes to bytes" do
@@ -53,19 +53,18 @@ shared_examples "authenticator" do
53
53
  end
54
54
 
55
55
  it "fails to validate an invalid authenticator" do
56
- described_class.verify(key, tag, message+"\0").should be false
56
+ expect { described_class.verify(key, tag, message+"\0") }.to raise_error(RbNaCl::BadAuthenticatorError)
57
57
  end
58
58
 
59
59
  it "fails to validate a short authenticator" do
60
- described_class.verify(key, tag[0,tag.bytesize - 2], message).should be false
60
+ expect { described_class.verify(key, tag[0,tag.bytesize - 2], message) }.to raise_error(RbNaCl::LengthError)
61
61
  end
62
62
 
63
63
  it "fails to validate a long authenticator" do
64
- described_class.verify(key, tag+"\0", message).should be false
64
+ expect { described_class.verify(key, tag+"\0", message) }.to raise_error(RbNaCl::LengthError)
65
65
  end
66
66
  end
67
67
 
68
-
69
68
  context "Instance methods" do
70
69
  let(:authenticator) { described_class.new(key) }
71
70
 
@@ -81,15 +80,15 @@ shared_examples "authenticator" do
81
80
  end
82
81
 
83
82
  it "fails to validate an invalid authenticator" do
84
- authenticator.verify(tag, message+"\0").should be false
83
+ expect { authenticator.verify(tag, message+"\0") }.to raise_error(RbNaCl::BadAuthenticatorError)
85
84
  end
86
85
 
87
86
  it "fails to validate a short authenticator" do
88
- authenticator.verify(tag[0,tag.bytesize - 2], message).should be false
87
+ expect { authenticator.verify(tag[0,tag.bytesize - 2], message) }.to raise_error(RbNaCl::LengthError)
89
88
  end
90
89
 
91
90
  it "fails to validate a long authenticator" do
92
- authenticator.verify(tag+"\0", message).should be false
91
+ expect { authenticator.verify(tag+"\0", message) }.to raise_error(RbNaCl::LengthError)
93
92
  end
94
93
  end
95
94
  end
@@ -1,4 +1,5 @@
1
1
  # encoding: binary
2
+ require 'json'
2
3
  require 'coveralls'
3
4
  Coveralls.wear!
4
5
 
metadata CHANGED
@@ -1,15 +1,37 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rbnacl
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0.pre
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tony Arcieri
8
8
  - Jonathan Stott
9
9
  autorequire:
10
10
  bindir: bin
11
- cert_chain: []
12
- date: 2013-10-24 00:00:00.000000000 Z
11
+ cert_chain:
12
+ - |
13
+ -----BEGIN CERTIFICATE-----
14
+ MIIDbDCCAlSgAwIBAgIBATANBgkqhkiG9w0BAQUFADA+MRAwDgYDVQQDDAdiYXNj
15
+ dWxlMRUwEwYKCZImiZPyLGQBGRYFZ21haWwxEzARBgoJkiaJk/IsZAEZFg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eCjpomboQMP36GRIZ30SoOVPMGvZ/+QpW52QU7mJW5
32
+ GzWyf92p0uscgUZVTYixjg==
33
+ -----END CERTIFICATE-----
34
+ date: 2013-11-07 00:00:00.000000000 Z
13
35
  dependencies:
14
36
  - !ruby/object:Gem::Dependency
15
37
  name: ffi
@@ -102,6 +124,7 @@ files:
102
124
  - lib/rbnacl/signatures/ed25519/signing_key.rb
103
125
  - lib/rbnacl/signatures/ed25519/verify_key.rb
104
126
  - lib/rbnacl/sodium.rb
127
+ - lib/rbnacl/sodium/version.rb
105
128
  - lib/rbnacl/test_vectors.rb
106
129
  - lib/rbnacl/util.rb
107
130
  - lib/rbnacl/version.rb
@@ -130,7 +153,8 @@ files:
130
153
  - tasks/ci.rake
131
154
  - tasks/rspec.rake
132
155
  homepage: https://github.com/cryptosphere/rbnacl
133
- licenses: []
156
+ licenses:
157
+ - MIT
134
158
  metadata: {}
135
159
  post_install_message:
136
160
  rdoc_options: []
@@ -143,12 +167,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
143
167
  version: '0'
144
168
  required_rubygems_version: !ruby/object:Gem::Requirement
145
169
  requirements:
146
- - - '>'
170
+ - - '>='
147
171
  - !ruby/object:Gem::Version
148
- version: 1.3.1
172
+ version: '0'
149
173
  requirements: []
150
174
  rubyforge_project:
151
- rubygems_version: 2.0.6
175
+ rubygems_version: 2.0.2
152
176
  signing_key:
153
177
  specification_version: 4
154
178
  summary: The Networking and Cryptography (NaCl) library provides a high-level toolkit
@@ -0,0 +1,2 @@
1
+ �. �r_Q���; �|��A�;e�(�zX#�u?���ݛ�Zܻ�@c�ךk�����ɛ�ID>����ߣg�J����4
2
+ %Wh���h�o�ҟ�����,�W�,��˥�{�tw{#�B؄k\�