mobile-secrets 0.0.3 → 0.0.4

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: f5ec8b140d8737e4f56e955ebac3fc11a2fbf48c
4
- data.tar.gz: 2cdeeadf7afcdbda9f675deea2009c85a25a5ff2
2
+ SHA256:
3
+ metadata.gz: 96bdba0202a6a478beea1f412bbac5e8abd333af7f3f605dfb7ca6e09fb892de
4
+ data.tar.gz: 20545830edba12a31d17e141fe4330790fce4110eb401756c497d64c93ea28d5
5
5
  SHA512:
6
- metadata.gz: 49a4fa417ef9a4d27a05d33f67893d6f7b8cdcb59a0311ed403d1511539d43abb269a7e9774a92796d7b937be196aa2b0495fc4e5e16a83d922363193fb3fe59
7
- data.tar.gz: 42180819686313ce6427f36a28e16391cbaeaf940d524d30cd7d2f8236148a377e32ca8f2e6d8955df05fb6073941db580a754e02749a4cb599f7715d0ad33b2
6
+ metadata.gz: 8563eabd178ac86fd1b65da16a1686c275f364e0033b6801536069039a00f66285273629b34f1fb3eda32156d8166155dc43fa0df746880d80d5cc7578b2153f
7
+ data.tar.gz: 1c5ed3422664c6c8139053994fc7cf6f7f1c43baf0f3e687e581421478bb6a052334befa76c783e71410758d503c5ec0b78ad710fe2ab3e43f61280ef7817b6d
data/bin/mobile-secrets CHANGED
@@ -1,79 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
- require_relative '../lib/src/secrets_handler'
2
+ require_relative '../lib/mobile-secrets'
3
3
  require "dotgpg"
4
4
 
5
- module MobileSecrets
6
- class Cli
7
-
8
- def header
9
- "Mobile Secrets HELP:
10
- ##############################################################################################################################
11
- ## %# #%%%( ##% ,%%% (%%/ *%%%% ,%%%/ .%%( (%%, #%%%#.(%%# #%%*.#%%% ,%%%%%.%%%%. #%%%%.#%%%.*%% %%%%*#%% ##
12
- ## % #%%%( % *%%%# /%%%( *%%%% %%%%, %%%* %, (%%%# #( .%%%( %% (%%%# %%%% %%%%. .%.*% %%%%* #% ##
13
- ## #%%%( %%%%# /%%%% *%%%% %%%%. .%%%%%%#. (%%%( ,% %%%%( ,# (%%%# .%%%% .%%%%. (* ,( %%%%* .# ##
14
- ## #%%%( %%%%# /%%%% /%%%% *%%%* *%%%%%%%% (%%%((%% %%%%( (%%%#.#%#, .%%%%.%%* %%%%, ##
15
- ## #%%%( #%%%# /%%%% /%%%% .( (%%%%%# (%%%( ,% %%%%( (%%%# *%%%# .%%%%. #* %%%%, ##
16
- ## %%%%( %%%# /%%%. /%%%% ,%, %%%/ (%%%( (# (%%%( *# #%%%# .%%%% .%%%% #, %%%%, ##
17
- ## %%%%%%( /%%**%%( ,%%%%%( ,%%#. /%%* #%%%(./%%# *%%# .## #%%%# .%%%%#/ .%%%% ,%%, %%%%, ##
18
- ##############################################################################################################################"
19
- end
20
-
21
- def options
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 \tAdds MobileSecrets to GPG secrets\n"
26
- opt << "--export PATH \t\t\tCreates source file with obfuscated secrets at given PATH\n"
27
- opt << "--usage \t\t\tManual for using MobileSecrets.\n\n"
28
- opt << "Examples:\n"
29
- opt << "--import \"./MobileSecrets.yml\"\n"
30
- opt << "--export \"./Project/Src\"\n"
31
- opt << "--init-gpg \".\""
32
- opt
33
- end
34
-
35
- def usage
36
- usage = ""
37
- usage << "1) Create gpg first with --init-gpg \".\"\n"
38
- usage << "2) Create a template for MobileSecrets with --create-template\n"
39
- usage << "3) Configure MobileSecrets.yml with your hash key, secrets etc\n"
40
- usage << "4) Import edited template to encrypted secret.gpg with --import\n"
41
- usage << "5) Export secrets from secrets.gpg to source file with --export and PATH to project\n"
42
- usage << "6) Add exported source file to the project\n"
43
- end
44
-
45
- def perform_action command, argv_1, argv_2
46
- case command
47
- when "--create-template"
48
- FileUtils.cp("#{__dir__}/../lib/resources/example.yml", "#{Dir.pwd}#{File::SEPARATOR}MobileSecrets.yml")
49
- when "--export"
50
- return print_options if argv_1 == nil
51
-
52
- secrets_handler = MobileSecrets::SecretsHandler.new
53
- secrets_handler.export_secrets argv_1
54
- when "--init-gpg"
55
- return print_options if argv_1 == nil
56
-
57
- Dotgpg::Cli.new.init(argv_1)
58
- when "--import"
59
- return print_options if argv_1 == nil
60
-
61
- dotgpg = Dotgpg::Dir.new("#{Dir.pwd}/")
62
- file = IO.read argv_1
63
- dotgpg.encrypt "./secrets.gpg", file
64
- when "--usage"
65
- puts usage
66
- else
67
- print_options
68
- end
69
- end
70
-
71
- def print_options
72
- puts "#{header}\n\n#{options}" #Wrong action selected
73
- end
74
-
75
- end
76
- end
77
-
78
5
  cmd, argv_1, argv_2 = ARGV[0], ARGV[1], ARGV[2]
79
6
  MobileSecrets::Cli.new.perform_action cmd, argv_1, argv_2
@@ -0,0 +1,75 @@
1
+ #!/usr/bin/env ruby
2
+ require_relative 'src/secrets_handler'
3
+ require "dotgpg"
4
+
5
+ module MobileSecrets
6
+ class Cli
7
+
8
+ def header
9
+ "Mobile Secrets HELP:
10
+ ##############################################################################################################################
11
+ ## %# #%%%( ##% ,%%% (%%/ *%%%% ,%%%/ .%%( (%%, #%%%#.(%%# #%%*.#%%% ,%%%%%.%%%%. #%%%%.#%%%.*%% %%%%*#%% ##
12
+ ## % #%%%( % *%%%# /%%%( *%%%% %%%%, %%%* %, (%%%# #( .%%%( %% (%%%# %%%% %%%%. .%.*% %%%%* #% ##
13
+ ## #%%%( %%%%# /%%%% *%%%% %%%%. .%%%%%%#. (%%%( ,% %%%%( ,# (%%%# .%%%% .%%%%. (* ,( %%%%* .# ##
14
+ ## #%%%( %%%%# /%%%% /%%%% *%%%* *%%%%%%%% (%%%((%% %%%%( (%%%#.#%#, .%%%%.%%* %%%%, ##
15
+ ## #%%%( #%%%# /%%%% /%%%% .( (%%%%%# (%%%( ,% %%%%( (%%%# *%%%# .%%%%. #* %%%%, ##
16
+ ## %%%%( %%%# /%%%. /%%%% ,%, %%%/ (%%%( (# (%%%( *# #%%%# .%%%% .%%%% #, %%%%, ##
17
+ ## %%%%%%( /%%**%%( ,%%%%%( ,%%#. /%%* #%%%(./%%# *%%# .## #%%%# .%%%%#/ .%%%% ,%%, %%%%, ##
18
+ ##############################################################################################################################"
19
+ end
20
+
21
+ def options
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 \tAdds MobileSecrets to GPG secrets\n"
26
+ opt << "--export PATH \t\t\tCreates source file with obfuscated secrets at given PATH\n"
27
+ opt << "--usage \t\t\tManual for using MobileSecrets.\n\n"
28
+ opt << "Examples:\n"
29
+ opt << "--import \"./MobileSecrets.yml\"\n"
30
+ opt << "--export \"./Project/Src\"\n"
31
+ opt << "--init-gpg \".\""
32
+ opt
33
+ end
34
+
35
+ def usage
36
+ usage = ""
37
+ usage << "1) Create gpg first with --init-gpg \".\"\n"
38
+ usage << "2) Create a template for MobileSecrets with --create-template\n"
39
+ usage << "3) Configure MobileSecrets.yml with your hash key, secrets etc\n"
40
+ usage << "4) Import edited template to encrypted secret.gpg with --import\n"
41
+ usage << "5) Export secrets from secrets.gpg to source file with --export and PATH to project\n"
42
+ usage << "6) Add exported source file to the project\n"
43
+ end
44
+
45
+ def perform_action command, argv_1, argv_2
46
+ case command
47
+ when "--create-template"
48
+ FileUtils.cp("#{__dir__}/../lib/resources/example.yml", "#{Dir.pwd}#{File::SEPARATOR}MobileSecrets.yml")
49
+ when "--export"
50
+ return print_options if argv_1 == nil
51
+
52
+ secrets_handler = MobileSecrets::SecretsHandler.new
53
+ secrets_handler.export_secrets argv_1
54
+ when "--init-gpg"
55
+ return print_options if argv_1 == nil
56
+
57
+ Dotgpg::Cli.new.init(argv_1)
58
+ when "--import"
59
+ return print_options if argv_1 == nil
60
+
61
+ file = IO.read argv_1
62
+ MobileSecrets::SecretsHandler.new.encrypt "./secrets.gpg", file, nil
63
+ when "--usage"
64
+ puts usage
65
+ else
66
+ print_options
67
+ end
68
+ end
69
+
70
+ def print_options
71
+ puts "#{header}\n\n#{options}" #Wrong action selected
72
+ end
73
+
74
+ end
75
+ end
@@ -6,8 +6,13 @@ module MobileSecrets
6
6
  class SecretsHandler
7
7
 
8
8
  def export_secrets path
9
- decrypted_secrets = decrypt_secrets()
10
- config = YAML.load(decrypted_secrets)["MobileSecrets"]
9
+ decrypted_config = decrypt_secrets()
10
+ bytes = process_yaml_config decrypted_config
11
+ inject_secrets(bytes, "#{path}/secrets.swift")
12
+ end
13
+
14
+ def process_yaml_config yaml_string
15
+ config = YAML.load(yaml_string)["MobileSecrets"]
11
16
  hash_key = config["hashKey"]
12
17
  obfuscator = MobileSecrets::Obfuscator.new hash_key
13
18
 
@@ -19,10 +24,10 @@ module MobileSecrets
19
24
  bytes << key.bytes << encrypted.bytes
20
25
  end
21
26
 
22
- inject_secrets(bytes, "#{path}/secrets.swift")
27
+ bytes
23
28
  end
24
29
 
25
- def inject_secrets(secret_bytes, file)
30
+ def inject_secrets secret_bytes, file
26
31
  template = IO.read "#{__dir__}/../resources/SecretsTemplate.swift"
27
32
  secret_bytes = "#{secret_bytes}".gsub "],", "],\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t"
28
33
  bytes_variable = "private let bytes: [[UInt8]] = #{secret_bytes}"
@@ -31,6 +36,13 @@ module MobileSecrets
31
36
  File.open(file, "w") { |f| f.puts swift_secrets }
32
37
  end
33
38
 
39
+ def encrypt output_file_path, string, gpg_path
40
+ gpg_path = "." unless gpg_path
41
+ gpg_path = "#{Dir.pwd}/#{gpg_path}"
42
+ dotgpg = Dotgpg::Dir.new(gpg_path)
43
+ dotgpg.encrypt output_file_path, string
44
+ end
45
+
34
46
  private
35
47
 
36
48
  def decrypt_secrets
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.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Cyril Cermak
@@ -34,6 +34,7 @@ extra_rdoc_files: []
34
34
  files:
35
35
  - Rakefile
36
36
  - bin/mobile-secrets
37
+ - lib/mobile-secrets.rb
37
38
  - lib/resources/SecretsTemplate.swift
38
39
  - lib/resources/example.yml
39
40
  - lib/src/obfuscator.rb
@@ -58,8 +59,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
58
59
  - !ruby/object:Gem::Version
59
60
  version: '0'
60
61
  requirements: []
61
- rubyforge_project:
62
- rubygems_version: 2.6.12
62
+ rubygems_version: 3.0.6
63
63
  signing_key:
64
64
  specification_version: 4
65
65
  summary: mobile-secrets tool for handling your mobile secrets