classifieds 0.1.0 → 0.2.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: f7a28ed7dd95a4865ff0f44347b3bd6c569e7286
4
- data.tar.gz: 228092b3aaca67a48753c77d59540cb093a7b455
3
+ metadata.gz: be21a9b90c90cb9033fb3d083fbdfe046f088214
4
+ data.tar.gz: 1105c72dbc850ae727fd72a8726fedd550e78f76
5
5
  SHA512:
6
- metadata.gz: fd48a3b29771b3e2153e58a740e156b09a3943303f0b70677e5a99b0e1f8f531a86e50ecaef7c2f63e30dab6357a88e1452ba7ef15444b7e7da4a6991916017d
7
- data.tar.gz: 487ec5bbc7a0a70350189cceb1fcc7d0d8fa5482fd47a8a67ddae34a6d3bcba186fdbe0ee981ada576c1215d0707d70649ac7f5010dacd038f9c3f4ad5ed3ec1
6
+ metadata.gz: 9fd490542826ca9d4ad8e8a72aff680b8b97f41a4c2cd05848fd8d8ce44ce786f2f885fd527289aae1aa312de29ae46da75fad8da9a267e6b9ef38c6a9ade351
7
+ data.tar.gz: dbe2f6c2de67696c56252d893c9b1445e1293e05ee767108af49a4a02f1cc3e8ba9321a21a9cf5899d34f49cbc80d92f0a9401772b2db79eec28b91c139bf6bd
data/.gitignore CHANGED
@@ -7,3 +7,5 @@
7
7
  /pkg/
8
8
  /spec/reports/
9
9
  /tmp/
10
+
11
+ vendor
data/README.md CHANGED
@@ -16,28 +16,28 @@ $ gem install classifieds
16
16
 
17
17
  ## Usage
18
18
 
19
- Initialize classifieds.
19
+ Generate identity files using by public key encryption.
20
20
 
21
21
  ```
22
- $ classifieds init
22
+ $ classifieds keygen
23
23
  ```
24
24
 
25
- Encrypt files which were described in .classifieds.
25
+ Show a status of the encryption of this repository.
26
26
 
27
27
  ```
28
- $ classifieds encrypt
28
+ $ classifieds status
29
29
  ```
30
30
 
31
- Decrypt files which were described in .classifieds.
31
+ Encrypt files which were described in .classifieds.
32
32
 
33
33
  ```
34
- $ classifieds decrypt
34
+ $ classifieds encrypt
35
35
  ```
36
36
 
37
- Show a status of the encryption of this repository.
37
+ Decrypt files which were described in .classifieds.
38
38
 
39
39
  ```
40
- $ classifieds status
40
+ $ classifieds decrypt
41
41
  ```
42
42
 
43
43
  ## Example
@@ -60,8 +60,7 @@ In your repository:
60
60
  First, initialize classifieds.
61
61
 
62
62
  ```
63
- $ classifieds init
64
- .classifieds was created
63
+ $ touch .classifieds
65
64
 
66
65
  $ ls -a
67
66
  .classifieds bar/ foo fuga/ hoge/
@@ -90,6 +89,8 @@ Unencrypted:
90
89
  /path/to/fuga/fuga2
91
90
  ```
92
91
 
92
+ ### Password Encryption
93
+
93
94
  Encrypt files.
94
95
 
95
96
  ```
@@ -116,7 +117,73 @@ Encrypted:
116
117
  /path/to/fuga/fuga2
117
118
 
118
119
  $ cat foo
119
- 65c0ec273963aacc69af593b03d1710ff90f75da¢É™¸
120
+ 65c0ec273963aacc69af593b03d1710ff90f75daB5KyfrnkTXz/K6+SeNkapA==
121
+ ```
122
+
123
+ Decrypt files.
124
+
125
+ ```
126
+ $ classifieds decrypt
127
+ Password:
128
+ Decrypted:
129
+ /path/to/foo
130
+ /path/to/bar/bar2
131
+ /path/to/hoge/hoge1.rb
132
+ /path/to/fuga/fuga1
133
+ /path/to/fuga/fuga2
134
+ ```
135
+
136
+ Check the status.
137
+
138
+ ```
139
+ $ classifieds status
140
+ Unencrypted:
141
+ /path/to/foo
142
+ /path/to/bar/bar2
143
+ /path/to/hoge/hoge1.rb
144
+ /path/to/fuga/fuga1
145
+ /path/to/fuga/fuga2
146
+
147
+ $ cat foo
148
+ foo
149
+ ```
150
+
151
+ ### Public Key Encryption
152
+
153
+ Generate keys.
154
+
155
+ ```
156
+ $ classifieds keygen > ~/classifieds_private_key
157
+ $ ls .classifieds.d/*
158
+ .classifieds.d/common_key
159
+ .classifieds.d/public_key
160
+ ```
161
+
162
+ Encrypt files.
163
+
164
+ ```
165
+ $ classifieds encrypt -i ~/classifieds_private_key
166
+ Encrypted:
167
+ /path/to/foo
168
+ /path/to/bar/bar2
169
+ /path/to/hoge/hoge1.rb
170
+ /path/to/fuga/fuga1
171
+ /path/to/fuga/fuga2
172
+ ```
173
+
174
+ Check the status.
175
+
176
+ ```
177
+ $ classifieds status
178
+ Encrypted:
179
+ /path/to/foo
180
+ /path/to/bar/bar2
181
+ /path/to/hoge/hoge1.rb
182
+ /path/to/fuga/fuga1
183
+ /path/to/fuga/fuga2
184
+
185
+ $ cat foo
186
+ 65c0ec273963aacc69af593b03d1710ff90f75daB5KyfrnkTXz/K6+SeNkapA==
120
187
  ```
121
188
 
122
189
  Decrypt files.
@@ -1,5 +1,6 @@
1
1
  require 'digest/sha1'
2
2
  require 'openssl'
3
+ require 'base64'
3
4
  require 'fileutils'
4
5
 
5
6
  require 'safe_colorize'
@@ -11,24 +12,46 @@ module Classifieds
11
12
  using SafeColorize
12
13
 
13
14
  def initialize(*args)
15
+ unless File.exists?(SOURCE_FILE)
16
+ STDERR.puts "#{SOURCE_FILE} is not found".color(:red)
17
+ exit 1
18
+ end
19
+
20
+ FileUtils.mkdir_p(SOURCE_DIRECTORY) unless Dir.exists?(SOURCE_DIRECTORY)
14
21
  @prefix = Digest::SHA1.hexdigest('classifieds')
15
22
  super
16
23
  end
17
24
 
18
- desc 'init', 'Initialize classifieds'
19
- def init
20
- if File.exists?(SOURCE_FILE)
21
- puts 'Classifieds already initialized'.color(:red)
25
+ desc 'keygen', 'Generate identity files using by public key encryption'
26
+ option :force, type: :boolean, aliases: '-f'
27
+ def keygen
28
+ if !options[:force] && (File.exists?(PUBLIC_KEY_PATH) && File.exists?(COMMON_KEY_PATH))
29
+ STDERR.puts 'Already exists'.color(:red)
30
+ exit 1
22
31
  else
23
- FileUtils.touch(SOURCE_FILE)
24
- puts "#{SOURCE_FILE} was created".color(:green)
32
+ OpenSSL::Random.seed(File.read('/dev/random', 16))
33
+ rsa = OpenSSL::PKey::RSA.new(2048)
34
+ pub = rsa.public_key
35
+ File.open(PUBLIC_KEY_PATH, 'w') do |f|
36
+ f.puts pub.to_pem
37
+ end
38
+ File.open(COMMON_KEY_PATH, 'w') do |f|
39
+ f.puts pub.public_encrypt(OpenSSL::Random.random_bytes(16))
40
+ end
41
+ puts rsa
25
42
  end
26
43
  end
27
44
 
28
45
  desc 'encrypt', 'Encrypt files which were described in .classifieds'
46
+ option :identity_file, type: 'string', aliases: '-i'
29
47
  def encrypt
30
- @password ||= ask_password
31
- retype_password
48
+ if identity_file = options[:identity_file]
49
+ rsa = OpenSSL::PKey::RSA.new(File.read(identity_file).chomp)
50
+ @password = rsa.private_decrypt(File.read(COMMON_KEY_PATH).chomp)
51
+ else
52
+ @password = ask_password
53
+ retype_password
54
+ end
32
55
 
33
56
  encrypted_files = classifieds.each_with_object([]) do |file_path, array|
34
57
  next if encrypted?(file_path)
@@ -56,8 +79,14 @@ module Classifieds
56
79
  end
57
80
 
58
81
  desc 'decrypt', 'Decrypt files which were described in .classifieds'
82
+ option :identity_file, type: 'string', aliases: '-i'
59
83
  def decrypt
60
- @password ||= ask_password
84
+ if identity_file = options[:identity_file]
85
+ rsa = OpenSSL::PKey::RSA.new(File.read(identity_file).chomp)
86
+ @password = rsa.private_decrypt(File.read(COMMON_KEY_PATH).chomp)
87
+ else
88
+ @password = ask_password
89
+ end
61
90
 
62
91
  decrypted_files = classifieds.each_with_object([]) do |file_path, array|
63
92
  next if decrypted?(file_path)
@@ -99,9 +128,9 @@ module Classifieds
99
128
  end
100
129
  end
101
130
  puts 'Encrypted:'.color(:green) unless encrypted_files.empty?
102
- encrypted_files.each {|file| puts "\t" + file }
131
+ encrypted_files.each {|encrypted_file| puts "\t" + encrypted_file }
103
132
  puts 'Unencrypted:'.color(:red) unless unencrypted_files.empty?
104
- unencrypted_files.each {|file| puts "\t" + file }
133
+ unencrypted_files.each {|unencrypted_file| puts "\t" + unencrypted_file }
105
134
  end
106
135
 
107
136
  private
@@ -127,26 +156,35 @@ module Classifieds
127
156
  end
128
157
 
129
158
  def classifieds
130
- File.open(SOURCE_FILE) do |f|
131
- Parser.parse(f.read)
132
- end
133
- rescue Errno::ENOENT
134
- STDERR.puts "#{SOURCE_FILE} is not found".color(:red)
135
- exit 1
159
+ Parser.parse(File.read(SOURCE_FILE).chomp)
136
160
  end
137
161
 
138
162
  def encrypt_data(data)
139
163
  cipher = OpenSSL::Cipher.new('AES-256-CBC')
140
164
  cipher.encrypt
141
- cipher.pkcs5_keyivgen(@password)
142
- cipher.update(data) + cipher.final
165
+ key_iv = OpenSSL::PKCS5.pbkdf2_hmac_sha1(
166
+ @password,
167
+ File.expand_path(File.dirname(__FILE__)).split('/').pop,
168
+ 1000,
169
+ cipher.key_len + cipher.iv_len
170
+ )
171
+ cipher.key = key_iv[0, cipher.key_len]
172
+ cipher.iv = key_iv[cipher.key_len, cipher.iv_len]
173
+ Base64.encode64(cipher.update(data) + cipher.final)
143
174
  end
144
175
 
145
176
  def decrypt_data(data)
146
177
  cipher = OpenSSL::Cipher.new('AES-256-CBC')
147
178
  cipher.decrypt
148
- cipher.pkcs5_keyivgen(@password)
149
- cipher.update(data) + cipher.final
179
+ key_iv = OpenSSL::PKCS5.pbkdf2_hmac_sha1(
180
+ @password,
181
+ File.expand_path(File.dirname(__FILE__)).split('/').pop,
182
+ 1000,
183
+ cipher.key_len + cipher.iv_len
184
+ )
185
+ cipher.key = key_iv[0, cipher.key_len]
186
+ cipher.iv = key_iv[cipher.key_len, cipher.iv_len]
187
+ cipher.update(Base64.decode64(data)) + cipher.final
150
188
  end
151
189
 
152
190
  def encrypted?(file)
@@ -1,3 +1,3 @@
1
1
  module Classifieds
2
- VERSION = "0.1.0"
2
+ VERSION = '0.2.0'
3
3
  end
data/lib/classifieds.rb CHANGED
@@ -4,4 +4,7 @@ require 'classifieds/main'
4
4
 
5
5
  module Classifieds
6
6
  SOURCE_FILE = '.classifieds'
7
+ SOURCE_DIRECTORY = '.classifieds.d'
8
+ PUBLIC_KEY_PATH = File.join(SOURCE_DIRECTORY, 'public_key')
9
+ COMMON_KEY_PATH = File.join(SOURCE_DIRECTORY, 'common_key')
7
10
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: classifieds
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - kaihar4
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-06-21 00:00:00.000000000 Z
11
+ date: 2015-10-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -108,7 +108,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
108
108
  version: '0'
109
109
  requirements: []
110
110
  rubyforge_project:
111
- rubygems_version: 2.4.5
111
+ rubygems_version: 2.4.5.1
112
112
  signing_key:
113
113
  specification_version: 4
114
114
  summary: File Encryption Manager