ece 0.2.1 → 0.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 2e947d1704ffb9c3b8df64b1e1086b0cb6ccc582
4
- data.tar.gz: a3106fb907ef7f8be5e16b9bbbd48230e8065dfd
2
+ SHA256:
3
+ metadata.gz: e83a743e5e15a8603358906d330f2152763bcdc48d0bb7793ccbb7a8f30cc86c
4
+ data.tar.gz: 2251ca33088306a752a496d2e5204658daee8a7c2ef7782f119f6840a8fb7d78
5
5
  SHA512:
6
- metadata.gz: e715f1010c9d164946d1764c413fbf220387bbf579a32cfac29590a797ace9a8455b5d8d7ca820ae54c45399f7431cb4eb0c5060356be0c2603e49db8b7d7dba
7
- data.tar.gz: 3b1e07649a250825e1cb0b078006519fc19023306784566c4b889fe368906b86446167271f797885d9ec7e268798fbf5e7e41f2bf4bd106d1544def73d247dac
6
+ metadata.gz: 47e9b83318a4e511dc962b8ab1a42e45b351e2d2961a392ae9096425337b55d7df583d05a54c798cfffa0a3294aba0e6fe1426a3cd47725cad155c548ae2b5f6
7
+ data.tar.gz: '09ac0852fbb993ffa142a1ccfb5d4de2f7c45ea8dc93c0c4d8fe46f07d8b7c3f8024a62c5314ebd7d6fc4e20293eddc385a2b609a6ce88b79e2496388e42551d'
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # ECE
2
2
 
3
- Ruby implementation of encrypted content-encoding.
3
+ Ruby implementation of encrypted content-encoding.
4
4
 
5
5
  https://tools.ietf.org/html/draft-thomson-http-encryption-02
6
6
 
@@ -34,11 +34,35 @@ data = "Your very private data"
34
34
  encrypted_data = ECE.encrypt(data, key: key, salt: salt)
35
35
  ```
36
36
  Decrypting:
37
+
37
38
  ```ruby
38
39
  ECE.decrypt(encrypted_data, key: key, salt: salt)
39
40
  ```
40
41
  Data can be bytestring as well.
42
+
43
+ Encrypting data with elliptical curve Diffie-Hellman (ECDH) key agreement
44
+ protocol using client keys providing by a [Web Push subscription](https://developer.mozilla.org/en-US/docs/Web/API/PushSubscription/getKey):
45
+
46
+ ```ruby
47
+ user_public_key # Provided by the browser, effectively: Random.new.bytes(65)
48
+ user_auth # Provided by the browser, effectively: Random.new.bytes(16)
49
+
50
+ local_curve = OpenSSL::PKey::EC.new("prime256v1")
51
+ local_curve.generate_key
52
+ user_public_key_point = OpenSSL::PKey::EC::Point.new(local_curve.group, OpenSSL::BN.new(user_public_key, 2))
53
+
54
+ key = local_curve.dh_compute_key(user_public_key_point)
55
+ server_public_key = local_curve.public_key.to_bn.to_s(2)
56
+ salt = Random.new.bytes(16)
57
+
58
+ encrypted_data = ECE.encrypt(data,
59
+ key: key,
60
+ salt: salt
61
+ server_public_key: server_public_key,
62
+ user_public_key: user_public_key,
63
+ auth: user_auth)
64
+ ```
65
+
41
66
  ## Contributing
42
67
 
43
68
  Bug reports and pull requests are welcome on GitHub at https://github.com/randomlogin/ece.
44
-
data/Rakefile CHANGED
@@ -1,2 +1,10 @@
1
1
  require "bundler/gem_tasks"
2
- task :default => :spec
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList["test/**/*_test.rb"]
8
+ end
9
+
10
+ task :default => :test
data/ece.gemspec CHANGED
@@ -18,6 +18,6 @@ Gem::Specification.new do |spec|
18
18
  spec.require_paths = ["lib"]
19
19
 
20
20
  spec.add_development_dependency "bundler", "~> 1.11"
21
- spec.add_development_dependency "rake", "~> 10.0"
21
+ spec.add_development_dependency "rake", "~> 12.3.3"
22
22
  spec.add_dependency 'hkdf'
23
23
  end
data/lib/ece.rb CHANGED
@@ -1,3 +1,2 @@
1
1
  require 'ece/version'
2
2
  require 'ece/ece'
3
-
data/lib/ece/ece.rb CHANGED
@@ -19,7 +19,7 @@ class ECE
19
19
  def self.hkdf_extract(salt, ikm) #ikm stays for input keying material
20
20
  hmac_hash(salt,ikm)
21
21
  end
22
-
22
+
23
23
  def self.get_info(type, client_public, server_public)
24
24
  cl_len_no = [client_public.size].pack('n')
25
25
  sv_len_no = [server_public.size].pack('n')
@@ -104,7 +104,7 @@ class ECE
104
104
  raise "Block is too small" if buffer.length <= TAG_LENGTH+pad_bytes
105
105
  gcm.auth_tag = buffer[-TAG_LENGTH..-1]
106
106
  decrypted = gcm.update(buffer[0..-TAG_LENGTH-1]) + gcm.final
107
-
107
+
108
108
  if params[:auth]
109
109
  padding_length = decrypted[0..1].unpack("n")[0]
110
110
  raise "Padding is too big" if padding_length+2 > decrypted.length
@@ -117,7 +117,7 @@ class ECE
117
117
  padding = decrypted[1..padding_length]
118
118
  raise "Wrong padding" unless padding = "\x00"*padding_length
119
119
  return decrypted[1..-1]
120
- end
120
+ end
121
121
  end
122
122
 
123
123
  def self.encrypt_record(params, counter, buffer, pad=0)
@@ -125,7 +125,7 @@ class ECE
125
125
  gcm.encrypt
126
126
  gcm.key = params[:key]
127
127
  gcm.iv = generate_nonce(params[:nonce], counter)
128
- gcm.auth_data = ""
128
+ gcm.auth_data = ""
129
129
  padding = ""
130
130
  if params[:auth]
131
131
  padding = [pad].pack('n') + "\x00"*pad # 2 bytes, big endian, then n zero bytes of padding
@@ -134,9 +134,8 @@ class ECE
134
134
  else
135
135
  record = gcm.update("\x00"+buffer) # 1 padding byte, not fully implemented
136
136
  end
137
- enc = record + gcm.final + gcm.auth_tag
137
+ enc = record + gcm.final + gcm.auth_tag
138
138
  enc
139
139
  end
140
140
 
141
-
142
141
  end
data/lib/ece/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  class ECE
2
- VERSION = "0.2.1"
2
+ VERSION = "0.2.2"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ece
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexander Shevtsov
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-03-15 00:00:00.000000000 Z
11
+ date: 2021-04-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -30,14 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '10.0'
33
+ version: 12.3.3
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '10.0'
40
+ version: 12.3.3
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: hkdf
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -87,8 +87,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
87
87
  - !ruby/object:Gem::Version
88
88
  version: '0'
89
89
  requirements: []
90
- rubyforge_project:
91
- rubygems_version: 2.4.8
90
+ rubygems_version: 3.1.2
92
91
  signing_key:
93
92
  specification_version: 4
94
93
  summary: Ruby implementation of encrypted content-encoding