mobile-secrets 0.0.8 → 0.0.9

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
2
  SHA256:
3
- metadata.gz: dac63b4dd181e9c103b09d3731c278027b824efd3d111df3d1bdb9ef643916c9
4
- data.tar.gz: aa9fb1acc5d381192bc6aa407e922fc3c2d07071cb881b5bcd5c8b05bb0759d6
3
+ metadata.gz: 0f4f08928281f7ec09b0f307fde69ac6a240fc006cdb398741b94b94906952f6
4
+ data.tar.gz: 2b28b5fccdd4b442bf229733eaad00e170baee9e4c5505a925761f947929bda8
5
5
  SHA512:
6
- metadata.gz: ca7520a8970dcf937921463be547a72a1a7a47d992fc3ee91926f213de358ced059694d1b479c54ff8eb43838a253f2d41f32ec3df9faddd92bc45d24fd80ca9
7
- data.tar.gz: 6bbbff40235f340cd8138ab9f33295b1f3dba98fee4cb835bd1ad299edda38b131b85766f1a563e74e31952a722fd32038a21449f0ef4be84002813a2de468fa
6
+ metadata.gz: 2f7805f87c8cf0713394b29e4f40da1654661ea736640de9fb59f95b8aff7e2928b5941a67f993af709c3b31cb62f4d1f1fbcbca88bd856303b05ddb9966ed13
7
+ data.tar.gz: 693fabe5ec237be1fcaf50ca841b60df85dccde3d017bf97e059cffe8ad6b216e8656be7ebef97688fb6e25318e93bfd36cbc09b2752fbd69ba42d39be1f72a3
@@ -20,15 +20,16 @@ module MobileSecrets
20
20
 
21
21
  def options
22
22
  opt = ""
23
- opt << "--init-gpg PATH \t\tInitialize GPG in the directory.\n"
24
- opt << "--create-template \t\tCreates a template yml file to configure the MobileSecrets\n"
25
- opt << "--import SECRETS_PATH \t\tAdds MobileSecrets to GPG secrets\n"
26
- opt << "--export PATH \t\t\tCreates source file with obfuscated secrets at given PATH\n"
27
- opt << "--encrypt-file FILE PASSWORD \tEncrypt a single file with AES\n"
28
- opt << "--usage \t\t\tManual for using MobileSecrets.\n\n"
23
+ opt << "--init-gpg PATH \t\t\tInitialize GPG in the directory.\n"
24
+ opt << "--create-template \t\t\tCreates a template yml file to configure the MobileSecrets\n"
25
+ opt << "--import SECRETS_PATH \t\t\tAdds MobileSecrets to GPG secrets\n"
26
+ opt << "--export PATH opt: ENCRYPTED_FILE_PATH \tCreates source file with obfuscated secrets at given PATH\n"
27
+ opt << "--encrypt-file FILE PASSWORD \t\tEncrypt a single file with AES\n"
28
+ opt << "--empty PATH \t\t\t\tGenerates a Secrets file without any data in it\n"
29
+ opt << "--usage \t\t\t\tManual for using MobileSecrets.\n\n"
29
30
  opt << "Examples:\n"
30
31
  opt << "--import \"./MobileSecrets.yml\"\n"
31
- opt << "--export \"./Project/Src\"\n"
32
+ opt << "--export \"./Project/Src\\n"
32
33
  opt << "--init-gpg \".\""
33
34
  opt
34
35
  end
@@ -49,22 +50,31 @@ module MobileSecrets
49
50
  FileUtils.cp("#{__dir__}/../lib/resources/example.yml", "#{Dir.pwd}#{File::SEPARATOR}MobileSecrets.yml")
50
51
  when "--export"
51
52
  return print_options if argv_1 == nil
53
+ encrypted_file_path = argv_2 ||= "secrets.gpg"
52
54
 
53
55
  secrets_handler = MobileSecrets::SecretsHandler.new
54
- secrets_handler.export_secrets argv_1
56
+ secrets_handler.export_secrets argv_1, argv_2
55
57
  when "--init-gpg"
56
58
  return print_options if argv_1 == nil
57
59
 
58
60
  Dotgpg::Cli.new.init(argv_1)
59
61
  when "--import"
60
62
  return print_options if argv_1 == nil
61
-
63
+ gpg_file = argv_2 ||= "secrets.gpg"
62
64
  file = IO.read argv_1
63
- MobileSecrets::SecretsHandler.new.encrypt "./secrets.gpg", file, nil
65
+ MobileSecrets::SecretsHandler.new.encrypt gpg_file, file, nil
64
66
  when "--encrypt-file"
65
67
  file = argv_1
66
68
  password = argv_2
67
69
  MobileSecrets::SecretsHandler.new.encrypt_file password, file, "#{file}.enc"
70
+ when "--empty"
71
+ return print_options if argv_1 == nil
72
+ file_path = argv_1
73
+
74
+ MobileSecrets::SourceRenderer.new("swift").render_empty_template "#{file_path}/secrets.swift"
75
+ when "--edit"
76
+ return print_options if argv_1 == nil
77
+ exec("dotgpg edit #{argv_1}")
68
78
  when "--usage"
69
79
  puts usage
70
80
  else
@@ -5,6 +5,7 @@
5
5
  <% if should_decrypt_files %>import CommonCrypto<% end %>
6
6
  import Foundation
7
7
 
8
+ // swiftlint:disable all
8
9
  class Secrets {
9
10
  static let standard = Secrets()
10
11
  private let bytes: [[UInt8]] = <%= secrets_array.to_s.gsub "],", "],\n "%>
@@ -0,0 +1,31 @@
1
+ //
2
+ // Autogenerated file by Mobile Secrets
3
+ //
4
+
5
+ import Foundation
6
+
7
+ // swiftlint:disable all
8
+ class Secrets {
9
+ static let standard = Secrets()
10
+ private let bytes: [[UInt8]] = [[0]]
11
+
12
+ private init() {}
13
+
14
+ func string(forKey key: String, password: String? = nil) -> String? {
15
+ let pwdBytes = password == nil ? bytes[0] : password?.map({ c in c.asciiValue ?? 0 })
16
+ guard let index = bytes.firstIndex(where: { String(data: Data($0), encoding: .utf8) == key }),
17
+ let pwd = pwdBytes,
18
+ let value = decrypt(bytes[index + 1], password: pwd) else { return nil }
19
+
20
+ return String(data: Data(value), encoding: .utf8)
21
+ }
22
+
23
+ private func decrypt(_ input: [UInt8], password: [UInt8]) -> [UInt8]? {
24
+ guard !password.isEmpty else { return nil }
25
+ var output = [UInt8]()
26
+ for byte in input.enumerated() {
27
+ output.append(byte.element ^ password[byte.offset % password.count])
28
+ }
29
+ return output
30
+ }
31
+ }
@@ -8,12 +8,13 @@ require_relative '../src/source_renderer'
8
8
  module MobileSecrets
9
9
  class SecretsHandler
10
10
 
11
- def export_secrets path
12
- decrypted_config = decrypt_secrets()
11
+ def export_secrets path, from_encrypted_file_name
12
+ decrypted_config = decrypt_secrets(from_encrypted_file_name)
13
13
  file_names_bytes, secrets_bytes = process_yaml_config decrypted_config
14
14
 
15
15
  renderer = MobileSecrets::SourceRenderer.new "swift"
16
16
  renderer.render_template secrets_bytes, file_names_bytes, "#{path}/secrets.swift"
17
+ decrypted_config
17
18
  end
18
19
 
19
20
  def process_yaml_config yaml_string
@@ -51,6 +52,7 @@ module MobileSecrets
51
52
 
52
53
  def encrypt_file password, file, output_file_path
53
54
  encryptor = FileHandler.new password
55
+ abort("Configuration contains file #{file} that cannot be found! Please check your mobile-secrets configuration or add the file into directory.") unless File.exist? file
54
56
  encrypted_content = encryptor.encrypt file
55
57
 
56
58
  File.open(output_file_path, "wb") { |f| f.write encrypted_content }
@@ -58,10 +60,10 @@ module MobileSecrets
58
60
 
59
61
  private
60
62
 
61
- def decrypt_secrets
62
- gpg = Dotgpg::Dir.new "#{Dir.pwd}/"
63
+ def decrypt_secrets encrypted_file_name
64
+ gpg = Dotgpg::Dir.closest encrypted_file_name
63
65
  output = StringIO.new
64
- gpg.decrypt "#{Dir.pwd}/secrets.gpg", output
66
+ gpg.decrypt "#{Dir.pwd}/#{encrypted_file_name}", output
65
67
  output.string
66
68
  end
67
69
 
@@ -20,6 +20,17 @@ module MobileSecrets
20
20
  end
21
21
  end
22
22
  end
23
+
24
+ def render_empty_template output_file_path
25
+ template = File.read("#{__dir__}/../resources/SecretsSwiftEmpty.erb")
26
+
27
+ case @source_type
28
+ when "swift"
29
+ File.open(output_file_path, "w") do |file|
30
+ file.puts template
31
+ end
32
+ end
33
+ end
23
34
 
24
35
  end
25
36
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mobile-secrets
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.8
4
+ version: 0.0.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Cyril Cermak
@@ -36,6 +36,7 @@ files:
36
36
  - bin/mobile-secrets
37
37
  - lib/mobile-secrets.rb
38
38
  - lib/resources/SecretsSwift.erb
39
+ - lib/resources/SecretsSwiftEmpty.erb
39
40
  - lib/resources/example.yml
40
41
  - lib/src/file_handler.rb
41
42
  - lib/src/obfuscator.rb
@@ -60,7 +61,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
60
61
  - !ruby/object:Gem::Version
61
62
  version: '0'
62
63
  requirements: []
63
- rubygems_version: 3.0.6
64
+ rubygems_version: 3.0.8
64
65
  signing_key:
65
66
  specification_version: 4
66
67
  summary: mobile-secrets tool for handling your mobile secrets