linecook-gem 0.3.4 → 0.3.5

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: e87d1bca24ab425a96ef4108ca9e08a97f9b51b5
4
- data.tar.gz: 6bbfde16379fdac23f86c9abe03874eebace8312
3
+ metadata.gz: 436f7b18965a42d51257b1f278f5b3bae0154afa
4
+ data.tar.gz: 9a77064dbb23155c0108494498201a8540e67638
5
5
  SHA512:
6
- metadata.gz: f77aa1056e1025fc365153944fe86e31fc5fb25356ac0b56a27d185be86281c16e827b374eb395d6a30e8a0e6366b3666d8dd9d4517714880f9f454d49d32f99
7
- data.tar.gz: 0040f73516143aa687dcdd174ade3d5107b1657f2165493163641f41d16878b7290f9b827ac7c90f553eefbdef91f6b79ca350f35497a858afe5a8a7d701aab7
6
+ metadata.gz: 546c9bf9d9dbbea383122473f40d888fd4021943357e69ee3492dcbe6b21ff4fc5ed3c38eabea2edd2f632d7e3d9c2a436aaaf74a9f67bf269272c33746711d9
7
+ data.tar.gz: 45d28706131eba971a94b145f5f2a74c4bda5d0f2d0bf4b255acbecae3a57c5539f3d50d4a93c6ee6ad54299639987ae77bf2c731bec04e92de48d6ef4a456a9
@@ -4,13 +4,9 @@ require 'linecook/image/manager'
4
4
  require 'linecook/util/executor'
5
5
  require 'linecook/util/config'
6
6
 
7
- require 'encryptor'
8
7
  module Linecook
9
8
  class Crypto
10
9
  include Executor
11
- CIPHER = 'aes-256-cbc'
12
- KEY_BYTES = 32 # 256 bits
13
- attr_reader :iv, :secret_key
14
10
 
15
11
  def initialize(remote: nil)
16
12
  @remote = remote
@@ -22,36 +18,42 @@ module Linecook
22
18
  encrypt_file(image_path)
23
19
  end
24
20
 
25
- def encrypt_file(source, dest: nil, keypath: nil)
21
+ def encrypt_file(source, dest: nil)
26
22
  dest ||= "/tmp/#{File.basename(source)}"
27
- Tempfile.open('key') do |key|
28
- key.write(@secret_key)
29
- key.flush
30
- capture("openssl enc -#{CIPHER} -out #{dest} -in #{source} -kfile #{key.path}", sudo: false)
31
- end
23
+ File.write(dest, box.encrypt(File.read(source)))
32
24
  dest
33
25
  end
34
26
 
35
- def decrypt_file(source, dest: nil, keypath: nil)
27
+ def decrypt_file(source, dest: nil)
36
28
  dest ||= "/tmp/#{File.basename(source)}-decrypted"
37
- Tempfile.open('key') do |key|
38
- key.write(@secret_key)
39
- key.flush
40
- @remote.upload(@secret_key, key.path) if @remote
41
- capture("openssl enc -#{CIPHER} -out #{dest} -in #{source} -kfile #{key.path} -d", sudo: false)
42
- @remote.run("rm #{key.path}") if @remote
29
+ if @remote
30
+ Tempfile.open('key') do |key|
31
+ @remote.upload(decryptor_script(source, dest), key.path)
32
+ @remote.run("bash #{key.path}")
33
+ @remote.run("rm #{key.path}")
34
+ end
35
+ else
36
+ File.write(dest, box.decrypt(File.read(source)))
43
37
  end
44
38
  dest
45
39
  end
46
40
 
47
41
  def self.keygen
48
- secret_key = Base64.encode64(OpenSSL::Random.random_bytes(KEY_BYTES)).unpack('H*').first
42
+ RbNaCl::Random.random_bytes(RbNaCl::SecretBox.key_bytes).unpack('H*').first
49
43
  end
50
44
 
51
45
  private
52
46
 
47
+ def decryptor_script(source, dest)
48
+ "ruby -e \"require 'rbnacl/libsodium'; box = RbNaCl::SimpleBox.from_secret_key(['#{@secret_key}'].pack('H*')); File.write('#{dest}', box.decrypt(File.read('#{source}')))\""
49
+ end
50
+
51
+ def box
52
+ @box ||= RbNaCl::SimpleBox.from_secret_key([@secret_key].pack('H*'))
53
+ end
54
+
53
55
  def load_key
54
- @secret_key = Linecook.config[:aeskey]
56
+ @secret_key = Linecook.config[:imagekey]
55
57
  end
56
58
  end
57
59
  end
@@ -289,6 +289,9 @@ module Linecook
289
289
  @remote.upload("exec shutdown -h 60 'Delayed shutdown started'", '/tmp/delay-shutdown')
290
290
  execute('mv /tmp/delay-shutdown /etc/init/delay-shutdown.conf') # ubuntism is ok, since the temporary host can always be ubuntu
291
291
  execute('start delay-shutdown')
292
+ # Install crypto deps
293
+ execute('apt-get install -y --force-yes build-essential ruby ruby-dev')
294
+ execute('gem install rbnacl rbnacl-libsodium')
292
295
  end
293
296
 
294
297
  def find_ami
@@ -1,3 +1,3 @@
1
1
  module Linecook
2
- VERSION = '0.3.4'
2
+ VERSION = '0.3.5'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: linecook-gem
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.4
4
+ version: 0.3.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dale Hamel