aspis 0.1.0 → 0.1.1

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
  SHA256:
3
- metadata.gz: 185a743d7eac9bf51be9f4fe226230f1f80c40a62a4bb0f0369220225df4b1ce
4
- data.tar.gz: ae52af9fd222c6d38c749e0c768bc27f33f141e0dd628e750b689ed31e10eabd
3
+ metadata.gz: 978a70410af727b8fa5742fa96cd055b9cb767e38fbfdb837b654145afbb44cf
4
+ data.tar.gz: 48521856c3b2878674692c9ed81fdb50b3de4eb2966ff16af6115ef431b8e0d1
5
5
  SHA512:
6
- metadata.gz: 36b039f303d773fef53aeeaef29d0991a30d7c4093d9e52e6d755e4876ce1c5836efdbfa3b348329b7d1101f6b9c6aa27853009ee2a353885a1c14af161cf22e
7
- data.tar.gz: 2a987e228220b1996b5de171e05f1bdc91ad7f10892b65903df24c3ea30ae5f4153506421f562f336f19310a551042cc2e1e512ca4516e7a88feb5164db96021
6
+ metadata.gz: 82fd12f2436e209fb0a506995f13bff752b7decc46b2d4fd9d5bacefd0a3d65002e8366f9360ab4957988e560fc5034ec98c858422fdd7dae910791d3a6edad0
7
+ data.tar.gz: 980065d8833495225ed8bae2d7b4058ded99b1fe249f3ee2eb1c3476beebf1bc48144d146655433d6e043abac40e5f5706437b3f0e77012349125e92c1d56547
Binary file
data.tar.gz.sig CHANGED
Binary file
@@ -1,10 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'aspis/version'
4
- require 'aspis/asymmetric_encrypt'
5
- require 'aspis/asymmetric_decrypt'
6
- require 'aspis/symmetric_encrypt'
7
- require 'aspis/symmetric_decrypt'
4
+ require 'aspis/asymmetric'
5
+ require 'aspis/symmetric'
8
6
  require 'aspis/generate_keys'
9
7
  require 'aspis/aspis_init'
10
8
 
@@ -15,10 +15,8 @@
15
15
  # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16
16
  require 'optparse'
17
17
 
18
- require_relative 'asymmetric_encrypt.rb'
19
- require_relative 'asymmetric_decrypt.rb'
20
- require_relative 'symmetric_encrypt.rb'
21
- require_relative 'symmetric_decrypt.rb'
18
+ require_relative 'asymmetric.rb'
19
+ require_relative 'symmetric.rb'
22
20
  require_relative 'generate_keys.rb'
23
21
  require_relative 'version.rb'
24
22
 
@@ -84,15 +82,15 @@ module AspisInit
84
82
  case options[:mode]
85
83
  when 'encrypt'
86
84
  if options[:public_key]
87
- puts AsymmetricEncrypt.encrypt(ARGF.read, options[:public_key], options[:private_key], options[:ask_pass])
85
+ puts Asymmetric.encrypt(ARGF.read, options[:public_key], options[:private_key], options[:ask_pass])
88
86
  else
89
- puts SymmetricEncrypt.encrypt(ARGF.read, options[:opslimit], options[:memlimit], options[:ask_pass])
87
+ puts Symmetric.encrypt(ARGF.read, options[:opslimit], options[:memlimit], options[:ask_pass])
90
88
  end
91
89
  when 'decrypt'
92
90
  if options[:public_key]
93
- puts AsymmetricDecrypt.decrypt(ARGF.read, options[:public_key], options[:private_key], options[:ask_pass])
91
+ puts Asymmetric.decrypt(ARGF.read, options[:public_key], options[:private_key], options[:ask_pass])
94
92
  else
95
- puts SymmetricDecrypt.decrypt(ARGF.read, options[:ask_pass])
93
+ puts Symmetric.decrypt(ARGF.read, options[:ask_pass])
96
94
  end
97
95
  when 'generate'
98
96
  GenerateKeys.generate(options[:opslimit], options[:memlimit], options[:ask_pass])
@@ -5,16 +5,16 @@ require 'fileutils'
5
5
  require 'base64'
6
6
  require 'json'
7
7
 
8
- require_relative 'symmetric_decrypt.rb'
8
+ require_relative 'symmetric.rb'
9
9
  require_relative 'version.rb'
10
10
 
11
- module AsymmetricEncrypt
11
+ module Asymmetric
12
12
  def self.encrypt(plaintext, public_key, private_key, ask_pass)
13
13
  recipient_public_key = File.read(public_key)
14
14
  recipient_public_key = Base64.decode64(recipient_public_key)
15
15
 
16
16
  sender_private_key = File.read(private_key)
17
- sender_private_key = SymmetricDecrypt.decrypt(sender_private_key, ask_pass)
17
+ sender_private_key = Symmetric.decrypt(sender_private_key, ask_pass)
18
18
 
19
19
  box = RbNaCl::SimpleBox.from_keypair(recipient_public_key, sender_private_key)
20
20
  ciphertext = box.encrypt(plaintext)
@@ -23,5 +23,20 @@ module AsymmetricEncrypt
23
23
  output = { version: Aspis::VERSION,
24
24
  ciphertext: ciphertext }
25
25
  JSON.generate(output)
26
+ end
27
+
28
+ def self.decrypt(input, public_key, private_key, ask_pass)
29
+ sender_public_key = File.read(public_key)
30
+ sender_public_key = Base64.decode64(sender_public_key)
31
+
32
+ recipient_private_key = File.read(private_key)
33
+ recipient_private_key = Symmetric.decrypt(recipient_private_key, ask_pass)
34
+
35
+ box = RbNaCl::SimpleBox.from_keypair(sender_public_key, recipient_private_key)
36
+
37
+ input = JSON.parse(input)
38
+ ciphertext = input['ciphertext']
39
+ ciphertext = Base64.decode64(ciphertext)
40
+ box.decrypt(ciphertext)
26
41
  end
27
42
  end
@@ -4,7 +4,7 @@ require 'rbnacl'
4
4
  require 'fileutils'
5
5
  require 'base64'
6
6
 
7
- require_relative 'symmetric_encrypt.rb'
7
+ require_relative 'symmetric.rb'
8
8
 
9
9
  module GenerateKeys
10
10
  def self.generate(opslimit, memlimit, ask_pass)
@@ -16,7 +16,7 @@ module GenerateKeys
16
16
  public_key = Base64.strict_encode64(public_key)
17
17
 
18
18
  # Encrypt private key before writing to disk
19
- private_key = SymmetricEncrypt.encrypt(private_key, opslimit, memlimit, ask_pass)
19
+ private_key = Symmetric.encrypt(private_key, opslimit, memlimit, ask_pass)
20
20
 
21
21
  File.write(aspis_dir + '/private_key', private_key)
22
22
  File.write(aspis_dir + '/public_key', public_key)
@@ -5,7 +5,7 @@ require 'json'
5
5
  require 'base64'
6
6
  require 'io/console'
7
7
 
8
- module SymmetricEncrypt
8
+ module Symmetric
9
9
  def self.timingsafe_compare(secret1, secret2)
10
10
  check = secret1.bytesize ^ secret2.bytesize
11
11
  secret1.bytes.zip(secret2.bytes) { |x, y| check |= x ^ y.to_i }
@@ -59,4 +59,35 @@ module SymmetricEncrypt
59
59
 
60
60
  JSON.generate(output)
61
61
  end
62
+
63
+ def self.decrypt(input, ask_pass)
64
+ input = JSON.parse(input)
65
+
66
+ salt = input['salt']
67
+ salt = Base64.decode64(salt)
68
+
69
+ ops = input['ops']
70
+ mem = input['mem']
71
+ key_size = input['key_size']
72
+
73
+ ciphertext = input['ciphertext']
74
+ ciphertext = Base64.decode64(ciphertext)
75
+
76
+ password = if ask_pass == false
77
+ ENV['ASPIS_PASS']
78
+ else
79
+ IO.console.getpass 'Enter passphrase: '
80
+ end
81
+
82
+ key = RbNaCl::PasswordHash.argon2i(
83
+ password,
84
+ salt,
85
+ ops,
86
+ mem,
87
+ key_size
88
+ )
89
+
90
+ box = RbNaCl::SimpleBox.from_secret_key(key)
91
+ box.decrypt(ciphertext)
92
+ end
62
93
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Aspis
4
- VERSION = '0.1.0'
4
+ VERSION = '0.1.1'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: aspis
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joseph Fierro
@@ -100,11 +100,9 @@ files:
100
100
  - exe/aspis
101
101
  - lib/aspis.rb
102
102
  - lib/aspis/aspis_init.rb
103
- - lib/aspis/asymmetric_decrypt.rb
104
- - lib/aspis/asymmetric_encrypt.rb
103
+ - lib/aspis/asymmetric.rb
105
104
  - lib/aspis/generate_keys.rb
106
- - lib/aspis/symmetric_decrypt.rb
107
- - lib/aspis/symmetric_encrypt.rb
105
+ - lib/aspis/symmetric.rb
108
106
  - lib/aspis/version.rb
109
107
  homepage: https://github.com/jsfierro/aspis
110
108
  licenses:
metadata.gz.sig CHANGED
Binary file
@@ -1,25 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'rbnacl'
4
- require 'fileutils'
5
- require 'base64'
6
- require 'json'
7
-
8
- require_relative 'symmetric_decrypt.rb'
9
-
10
- module AsymmetricDecrypt
11
- def self.decrypt(input, public_key, private_key, ask_pass)
12
- sender_public_key = File.read(public_key)
13
- sender_public_key = Base64.decode64(sender_public_key)
14
-
15
- recipient_private_key = File.read(private_key)
16
- recipient_private_key = SymmetricDecrypt.decrypt(recipient_private_key, ask_pass)
17
-
18
- box = RbNaCl::SimpleBox.from_keypair(sender_public_key, recipient_private_key)
19
-
20
- input = JSON.parse(input)
21
- ciphertext = input['ciphertext']
22
- ciphertext = Base64.decode64(ciphertext)
23
- box.decrypt(ciphertext)
24
- end
25
- end
@@ -1,38 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'rbnacl'
4
- require 'json'
5
- require 'base64'
6
-
7
- module SymmetricDecrypt
8
- def self.decrypt(input, ask_pass)
9
- input = JSON.parse(input)
10
-
11
- salt = input['salt']
12
- salt = Base64.decode64(salt)
13
-
14
- ops = input['ops']
15
- mem = input['mem']
16
- key_size = input['key_size']
17
-
18
- ciphertext = input['ciphertext']
19
- ciphertext = Base64.decode64(ciphertext)
20
-
21
- password = if ask_pass == false
22
- ENV['ASPIS_PASS']
23
- else
24
- IO.console.getpass 'Enter passphrase: '
25
- end
26
-
27
- key = RbNaCl::PasswordHash.argon2i(
28
- password,
29
- salt,
30
- ops,
31
- mem,
32
- key_size
33
- )
34
-
35
- box = RbNaCl::SimpleBox.from_secret_key(key)
36
- box.decrypt(ciphertext)
37
- end
38
- end