obfuskit 0.3.0 → 0.4.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
  SHA256:
3
- metadata.gz: 1bf83c6351238774e0cd0f479d2aeb033d6e06bf61a0567f461951c76ea2f551
4
- data.tar.gz: b1ef6d097ab410c3266ea9ef97b7ee04dd6e9cee053f85d0cd2f3085e7dc6db0
3
+ metadata.gz: 07c3f052a3c4ff566890a9cb72099b7f2cc9f6eab79a865b58e2de901d0963c5
4
+ data.tar.gz: 93b42f3091775a71366b4f70e93ef42114f08f5eddcd0275225f0e0d14f99464
5
5
  SHA512:
6
- metadata.gz: cf47193804ca3fa28838b8d33d5f8e05965665c354b94a5651d8ca7e0ce0b9515758f84571664351efeae009116dc4fc9363bc28f1599ccdd3d1e1d0506c3e8f
7
- data.tar.gz: 0a809262ff81d7c6df8656088867f575003ff519e521bdc3db38a775295a938d9ca05d4834c3bb6432151d1fc33d169d8810a51a8013a20b76f58c893490b804
6
+ metadata.gz: 337aaf034bf4afb7d41168254472376646876aa0e30ee609256f94c3cdf7c0974e83a2853f383bcfea719aceab0c5b2cde17bf8c90e1206a9dd78329b3caae1f
7
+ data.tar.gz: 83047860687ac6ab90b77958495deb0c06f20f676730a5d53199798340ef0b0102795fe065c6ef9696183435acd29c59e936363a60505c5c1d898d390aecf3a9
data/README.md CHANGED
@@ -29,7 +29,12 @@ Common options:
29
29
 
30
30
  ### Swift
31
31
 
32
- To generate Swift code run the following command:
32
+ To generate Swift code, run the following command:
33
+
34
+ ```sh
35
+ obfuskit -l swift -k SECRET_1,SECRET_2 > generated.swift
36
+ ```
37
+
33
38
  It will create the file `generated.swift` containing an obfuscated version of the environment variables `SECRET_1` and `SECRET_2`.
34
39
  This file should be excluded from the git repository and generated at build time.
35
40
  The obfuscation salt is regenerated for each run.
@@ -49,7 +54,7 @@ enum ObfusKit {
49
54
 
50
55
  ### Kotlin
51
56
 
52
- The same concept applies for the `kotlin` language using:
57
+ The same concept applies to the Kotlin language using:
53
58
 
54
59
  ```sh
55
60
  obfuskit -l kotlin -p com.myapp.configuration.environment -k SECRET_1,SECRET_2 > generated.kt
@@ -69,23 +74,19 @@ object ObfusKit {
69
74
  // ...
70
75
  ```
71
76
 
72
- ## Customizations
73
-
74
- ### The output type name
77
+ #### Android Code shrinking and Obfuscation
78
+ Proguard/R8 changes class names and method names. This will break revealing secrets at run time.
79
+ To prevent this, add the according rules to your `proguard-rules.pro` file or use the `--keep-annotation` parameter to inject a custom annotation like `@androidx.annotation.Keep` into the generated code.
75
80
 
76
- The default generated type name in the target language is `ObfusKit``. Customize this name with the `-t` option.
77
- Which will generate the Swift type `Secrets` instead of `ObfusKit`.
81
+ For example:
78
82
 
79
- ```swift
80
- import Foundation
81
-
82
- enum Secrets {
83
- // ..
83
+ ```sh
84
+ obfuskit -l kotlin -p com.myapp.configuration.environment -k SECRET_1,SECRET_2 --keep-annotation @androidx.annotation.Keep > generated.kt
84
85
  ```
85
86
 
86
87
  ### Use a custom .env file location
87
88
 
88
- Use the `-e` option to define the path to a different `.env` file, e.g. if you want to reuse the `fastlane/.env` file.
89
+ Use the `-e` option to define the path to a different `.env` file, e.g., if you want to reuse the `fastlane/.env` file.
89
90
 
90
91
  ```sh
91
92
  obfuskit -l swift -k SECRET_3,SECRET_4 -e fastlane/.env > generated.swift
@@ -94,7 +95,7 @@ obfuskit -l swift -k SECRET_3,SECRET_4 -e fastlane/.env > generated.swift
94
95
  ## Features
95
96
  - [x] Generate Swift
96
97
  - [x] Generate Kotlin
97
- - [x] Read secrets from the Environment
98
+ - [x] Read Secrets from the Environment
98
99
  - [x] Add dynamic salt for obfuscation
99
100
  - [x] Support for .env files
100
101
  - [x] Use template engine for code generation
@@ -25,10 +25,10 @@ module Obfuskit
25
25
  values = obfuscated_values_from_env(options.env_var_keys, obfuscator)
26
26
 
27
27
  if options.output_language == :swift
28
- puts generate_with_template("swift", values, nil, options.output_type_name, obfuscator)
28
+ puts generate_with_template("swift", values, nil, options.output_type_name, obfuscator, options.keep_annotation)
29
29
 
30
30
  elsif options.output_language == :kotlin && !options.package_name.nil?
31
- puts generate_with_template("kotlin", values, options.package_name, options.output_type_name, obfuscator)
31
+ puts generate_with_template("kotlin", values, options.package_name, options.output_type_name, obfuscator, options.keep_annotation)
32
32
 
33
33
  else
34
34
  STDERR.puts parser.parse(%w[--help])
@@ -47,7 +47,7 @@ module Obfuskit
47
47
  end.compact.to_h
48
48
  end
49
49
 
50
- def generate_with_template(template_name, values, package, type_name, obfuscator)
50
+ def generate_with_template(template_name, values, package, type_name, obfuscator, keep_annotation)
51
51
  file = File.expand_path("templates/#{template_name}.erb", __dir__)
52
52
  template = ERB.new(File.read(file), trim_mode: "-")
53
53
  template.result_with_hash(
@@ -55,6 +55,7 @@ module Obfuskit
55
55
  package: package,
56
56
  type_name: type_name,
57
57
  salt: obfuscator.salt,
58
+ keep_annotation: keep_annotation
58
59
  )
59
60
  end
60
61
 
@@ -4,7 +4,7 @@ require 'optparse'
4
4
  class OptionsParser
5
5
  class ScriptOptions
6
6
 
7
- attr_accessor :output_language, :env_var_keys, :package_name, :output_type_name, :dot_env_file_path
7
+ attr_accessor :output_language, :env_var_keys, :package_name, :output_type_name, :dot_env_file_path, :keep_annotation
8
8
 
9
9
  def initialize
10
10
  self.output_language = nil
@@ -12,6 +12,7 @@ class OptionsParser
12
12
  self.package_name = nil
13
13
  self.output_type_name = "ObfusKit"
14
14
  self.dot_env_file_path = ".env"
15
+ self.keep_annotation = nil
15
16
  end
16
17
 
17
18
  def define_options(parser)
@@ -25,6 +26,7 @@ class OptionsParser
25
26
  package_name_option(parser)
26
27
  output_type_name_option(parser)
27
28
  dot_env_file_path_options(parser)
29
+ keep_annotation_options(parser)
28
30
 
29
31
  parser.separator ""
30
32
  parser.separator "Common options:"
@@ -75,6 +77,13 @@ class OptionsParser
75
77
  self.dot_env_file_path = value
76
78
  end
77
79
  end
80
+
81
+ def keep_annotation_options(parser)
82
+ parser.on("--keep-annotation [Annotation]", "Annotation to prevent key class obfuscation. e.g. @androidx.annotation.Kee
83
+ ") do |value|
84
+ self.keep_annotation = value
85
+ end
86
+ end
78
87
  end
79
88
 
80
89
  #
@@ -2,6 +2,7 @@ package <%= package %>
2
2
 
3
3
  public object <%= type_name %> {
4
4
  private val _o = O(<%= salt %>::class.java.simpleName)
5
+ <%= keep_annotation unless keep_annotation.nil? %>
5
6
  private class <%= salt %>
6
7
 
7
8
  <% values.each do |name, values| -%>
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Obfuskit
4
- VERSION = "0.3.0"
4
+ VERSION = "0.4.0"
5
5
  end
@@ -3,6 +3,7 @@ module OptionsParser
3
3
  attr_accessor dot_env_file_path: String
4
4
  attr_accessor dot_env_file_paths: [String]
5
5
  attr_accessor env_var_keys: [String]
6
+ attr_accessor keep_annotation: String?
6
7
  attr_accessor output_language: String?
7
8
  attr_accessor output_type_name: String
8
9
  attr_accessor package_name: String?
@@ -13,6 +14,7 @@ module OptionsParser
13
14
 
14
15
  def dot_env_file_path_options: -> OptionParser
15
16
  def env_var_keys_option: -> OptionParser
17
+ def keep_annotation_options: -> OptionParser
16
18
  def output_language_option: -> OptionParser
17
19
  def output_type_name_option: -> OptionParser
18
20
  def package_name_option: -> OptionParser
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: obfuskit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Martin Gratzer
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-04-02 00:00:00.000000000 Z
11
+ date: 2024-04-22 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Generate Swift and Kotlin files with obfuscated environment variables.
14
14
  email: mgratzer@gmail.com