secure-keys 1.1.2 → 1.1.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 +4 -4
- data/README.md +75 -5
- data/bin/secure-keys +1 -1
- data/lib/core/console/arguments/handler.rb +21 -2
- data/lib/core/console/arguments/parser.rb +14 -1
- data/lib/core/console/arguments/xcframework/handler.rb +23 -0
- data/lib/core/console/arguments/xcframework/parser.rb +42 -0
- data/lib/core/console/logger.rb +123 -0
- data/lib/core/console/shell.rb +61 -0
- data/lib/core/environment/ci.rb +1 -10
- data/lib/core/generator.rb +81 -0
- data/lib/core/globals/globals.rb +55 -1
- data/lib/core/utils/extensions/kernel.rb +13 -0
- data/lib/core/utils/extensions/string/camelize.rb +11 -0
- data/lib/core/utils/extensions/string/to_bool.rb +16 -0
- data/lib/core/utils/swift/package.rb +2 -1
- data/lib/core/utils/swift/writer.rb +81 -52
- data/lib/core/utils/swift/xcframework.rb +45 -4
- data/lib/core/utils/swift/xcodeproj.rb +135 -0
- data/lib/keys.rb +9 -75
- data/lib/version.rb +2 -2
- metadata +129 -8
@@ -0,0 +1,16 @@
|
|
1
|
+
# Adds some useful methods to the String class
|
2
|
+
module BooleanCasting
|
3
|
+
# Casts a string to a boolean
|
4
|
+
# @return [Boolean] the boolean value of the string
|
5
|
+
def to_bool
|
6
|
+
return self if [true, false].include?(self)
|
7
|
+
return false if nil? || empty?
|
8
|
+
return false if self =~ /^(false|f|no|n|0)$/i
|
9
|
+
return true if self =~ /^(true|t|yes|y|1)$/i
|
10
|
+
|
11
|
+
# If the string is not a boolean, return false by default
|
12
|
+
false
|
13
|
+
end
|
14
|
+
alias to_b to_bool
|
15
|
+
alias to_boolean to_bool
|
16
|
+
end
|
@@ -1,6 +1,7 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
3
|
require_relative './swift'
|
4
|
+
require_relative '../../console/shell'
|
4
5
|
|
5
6
|
module SecureKeys
|
6
7
|
module Swift
|
@@ -14,7 +15,7 @@ module SecureKeys
|
|
14
15
|
swift package init --name #{SWIFT_PACKAGE_NAME} --type library
|
15
16
|
BASH
|
16
17
|
|
17
|
-
|
18
|
+
Core::Console::Shell.sh(command:)
|
18
19
|
end
|
19
20
|
end
|
20
21
|
end
|
@@ -30,8 +30,6 @@ module SecureKeys
|
|
30
30
|
end
|
31
31
|
end
|
32
32
|
|
33
|
-
private
|
34
|
-
|
35
33
|
# Generate the formatted keys content using Swift code format
|
36
34
|
# @return [String] The formatted keys content
|
37
35
|
def formatted_keys
|
@@ -44,7 +42,7 @@ module SecureKeys
|
|
44
42
|
/// The decrypted value of the key
|
45
43
|
public var decryptedValue: String {
|
46
44
|
switch self {
|
47
|
-
#{mapped_keys.map { |key| switch_case_key_declaration_template(name: key[:name], value: key[:value], iv: key[:iv], tag: key[:tag]) }.join("\t\t
|
45
|
+
#{mapped_keys.map { |key| switch_case_key_declaration_template(name: key[:name], value: key[:value], iv: key[:iv], tag: key[:tag]) }.join("\t\t")}
|
48
46
|
case .unknown: fatalError("Unknown key \\(rawValue)")
|
49
47
|
}
|
50
48
|
}
|
@@ -61,25 +59,7 @@ module SecureKeys
|
|
61
59
|
import Foundation
|
62
60
|
import CryptoKit
|
63
61
|
|
64
|
-
|
65
|
-
|
66
|
-
/// Fetch the decrypted value of the key
|
67
|
-
///
|
68
|
-
/// - Parameter:
|
69
|
-
/// - key: The key to fetch the decrypted value for
|
70
|
-
///
|
71
|
-
/// - Returns: The decrypted value of the key
|
72
|
-
@available(iOS 13.0, *)
|
73
|
-
public func key(for key: SecureKey) -> String { key.decryptedValue }
|
74
|
-
|
75
|
-
/// Fetch the decrypted value of the key
|
76
|
-
///
|
77
|
-
/// - Parameter:
|
78
|
-
/// - key: The key to fetch the decrypted value for
|
79
|
-
///
|
80
|
-
/// - Returns: The decrypted value of the key
|
81
|
-
@available(iOS 13.0, *)
|
82
|
-
public func key(_ key: SecureKey) -> String { key.decryptedValue }
|
62
|
+
#{key_swift_global_helper_functions}
|
83
63
|
|
84
64
|
// MARK: - SecureKey enum
|
85
65
|
|
@@ -92,50 +72,95 @@ module SecureKeys
|
|
92
72
|
#{content}
|
93
73
|
}
|
94
74
|
|
95
|
-
|
75
|
+
#{key_array_decrypt_swift_extension}
|
96
76
|
|
97
|
-
|
98
|
-
extension Array where Element == UInt8 {
|
77
|
+
#{key_string_swift_extension}
|
99
78
|
|
100
|
-
|
79
|
+
// swiftlint:enable all
|
80
|
+
SWIFT
|
81
|
+
end
|
101
82
|
|
102
|
-
|
103
|
-
guard let sealedBox = try? AES.GCM.SealedBox(nonce: AES.GCM.Nonce(data: Data(iv)),
|
104
|
-
ciphertext: Data(self),
|
105
|
-
tag: Data(tag)),
|
106
|
-
let decryptedData = try? AES.GCM.open(sealedBox, using: SymmetricKey(data: Data(key))),
|
107
|
-
let decryptedKey = String(data: decryptedData, encoding: .utf8) else {
|
108
|
-
fatalError("Failed to decrypt the key")
|
109
|
-
}
|
110
|
-
return decryptedKey
|
111
|
-
}
|
112
|
-
}
|
83
|
+
private
|
113
84
|
|
114
|
-
|
85
|
+
# Generate the key global helper functions
|
86
|
+
# @return [String] The key global helper functions
|
87
|
+
def key_swift_global_helper_functions
|
88
|
+
<<~SWIFT
|
89
|
+
// MARK: - Global methods
|
90
|
+
|
91
|
+
/// Fetch the decrypted value of the key
|
92
|
+
///
|
93
|
+
/// - Parameter:
|
94
|
+
/// - key: The key to fetch the decrypted value for
|
95
|
+
///
|
96
|
+
/// - Returns: The decrypted value of the key
|
97
|
+
@available(iOS 13.0, *)
|
98
|
+
public func key(for key: SecureKey) -> String { key.decryptedValue }
|
99
|
+
|
100
|
+
/// Fetch the decrypted value of the key
|
101
|
+
///
|
102
|
+
/// - Parameter:
|
103
|
+
/// - key: The key to fetch the decrypted value for
|
104
|
+
///
|
105
|
+
/// - Returns: The decrypted value of the key
|
106
|
+
@available(iOS 13.0, *)
|
107
|
+
public func key(_ key: SecureKey) -> String { key.decryptedValue }
|
108
|
+
SWIFT
|
109
|
+
end
|
115
110
|
|
116
|
-
|
117
|
-
|
111
|
+
# Generate the key array decrypt extension
|
112
|
+
# @return [String] The key array decrypt extension
|
113
|
+
def key_array_decrypt_swift_extension
|
114
|
+
<<~SWIFT
|
115
|
+
// MARK: - Decrypt keys from array extension
|
116
|
+
|
117
|
+
@available(iOS 13.0, *)
|
118
|
+
extension Array where Element == UInt8 {
|
119
|
+
|
120
|
+
// MARK: - Methods
|
121
|
+
|
122
|
+
func decrypt(key: [UInt8], iv: [UInt8], tag: [UInt8]) -> String {
|
123
|
+
guard let sealedBox = try? AES.GCM.SealedBox(nonce: AES.GCM.Nonce(data: Data(iv)),
|
124
|
+
ciphertext: Data(self),
|
125
|
+
tag: Data(tag)),
|
126
|
+
let decryptedData = try? AES.GCM.open(sealedBox, using: SymmetricKey(data: Data(key))),
|
127
|
+
let decryptedKey = String(data: decryptedData, encoding: .utf8) else {
|
128
|
+
fatalError("Failed to decrypt the key")
|
129
|
+
}
|
130
|
+
return decryptedKey
|
131
|
+
}
|
132
|
+
}
|
133
|
+
SWIFT
|
134
|
+
end
|
135
|
+
|
136
|
+
# Generate the key string extension
|
137
|
+
# @return [String] The key string extension
|
138
|
+
def key_string_swift_extension
|
139
|
+
<<~SWIFT
|
140
|
+
// MARK: - String extension for secure keys
|
118
141
|
|
119
|
-
|
142
|
+
@available(iOS 13.0, *)
|
143
|
+
extension String {
|
120
144
|
|
121
|
-
|
122
|
-
public var secretKey: SecureKey { SecureKey(rawValue: self) ?? .unknown }
|
145
|
+
// MARK: - Methods
|
123
146
|
|
124
|
-
|
125
|
-
|
126
|
-
/// - Parameters:
|
127
|
-
/// - key: The key to fetch the decrypted value for
|
128
|
-
///
|
129
|
-
/// - Returns: The decrypted value of the key
|
130
|
-
public static func key(for key: SecureKey) -> String { key.decryptedValue }
|
131
|
-
}
|
147
|
+
/// Fetch the key from the secure keys enum
|
148
|
+
public var secretKey: SecureKey { SecureKey(rawValue: self) ?? .unknown }
|
132
149
|
|
133
|
-
|
150
|
+
/// Fetch the decrypted value of the key
|
151
|
+
///
|
152
|
+
/// - Parameters:
|
153
|
+
/// - key: The key to fetch the decrypted value for
|
154
|
+
///
|
155
|
+
/// - Returns: The decrypted value of the key
|
156
|
+
public static func key(for key: SecureKey) -> String { key.decryptedValue }
|
157
|
+
}
|
134
158
|
SWIFT
|
135
159
|
end
|
136
160
|
|
137
161
|
# Generate the case key declaration template
|
138
162
|
# @param name [String] The name of the key
|
163
|
+
# @return [String] The case key declaration template
|
139
164
|
def case_key_declaration_template(name:)
|
140
165
|
<<~SWIFT
|
141
166
|
case #{name}
|
@@ -144,6 +169,10 @@ module SecureKeys
|
|
144
169
|
|
145
170
|
# Generate the switch case key declaration template
|
146
171
|
# @param name [String] The name of the key
|
172
|
+
# @param value [String] The value of the key
|
173
|
+
# @param iv [String] The IV of the key
|
174
|
+
# @param tag [String] The tag of the key
|
175
|
+
# @return [String] The switch case key declaration template
|
147
176
|
def switch_case_key_declaration_template(name:, value:, iv:, tag:) # rubocop:disable Naming/MethodParameterName
|
148
177
|
<<~SWIFT
|
149
178
|
case .#{name}: #{value}.decrypt(key: #{secure_key_bytes}, iv: #{iv}, tag: #{tag})
|
@@ -2,6 +2,10 @@
|
|
2
2
|
|
3
3
|
require_relative './swift'
|
4
4
|
require_relative '../../globals/globals'
|
5
|
+
require_relative '../../console/shell'
|
6
|
+
require_relative '../../console/logger'
|
7
|
+
require_relative '../../console/arguments/handler'
|
8
|
+
require_relative '../swift/xcodeproj'
|
5
9
|
|
6
10
|
module SecureKeys
|
7
11
|
module Swift
|
@@ -12,7 +16,7 @@ module SecureKeys
|
|
12
16
|
# Currently this is failling with the following error:
|
13
17
|
# "library with the identifier 'ios-arm64' already exists."
|
14
18
|
%w[Release].each do |configuration|
|
15
|
-
|
19
|
+
Globals.ios_platforms.each do |platform|
|
16
20
|
generate_key_modules(configuration:, platform:)
|
17
21
|
generate_key_libraries(configuration:, platform: platform[:path])
|
18
22
|
end
|
@@ -20,6 +24,12 @@ module SecureKeys
|
|
20
24
|
generate_key_xcframework
|
21
25
|
end
|
22
26
|
|
27
|
+
# Configure the XCFramework to the Xcode project
|
28
|
+
def configure_xcframework_to_xcodeproj
|
29
|
+
remove_xcframework_from_xcodeproj_target_if_needed if Globals.replace_xcframework?
|
30
|
+
add_xcframework_to_xcodeproj_target_if_needed if Globals.replace_xcframework? || Globals.add_xcframework?
|
31
|
+
end
|
32
|
+
|
23
33
|
private
|
24
34
|
|
25
35
|
# Generate the Swift package modules
|
@@ -35,7 +45,7 @@ module SecureKeys
|
|
35
45
|
ARCHS="arm64" BUILD_DIR="../#{BUILD_DIRECTORY}"
|
36
46
|
BASH
|
37
47
|
|
38
|
-
|
48
|
+
Core::Console::Shell.sh(command:)
|
39
49
|
end
|
40
50
|
|
41
51
|
# Generate the Swift package libraries
|
@@ -48,7 +58,7 @@ module SecureKeys
|
|
48
58
|
#{BUILD_DIRECTORY}/#{configuration}-#{platform}/#{SWIFT_PACKAGE_NAME}.o
|
49
59
|
BASH
|
50
60
|
|
51
|
-
|
61
|
+
Core::Console::Shell.sh(command:)
|
52
62
|
end
|
53
63
|
|
54
64
|
# Generate the XCFramework from the Swift package libraries
|
@@ -61,7 +71,7 @@ module SecureKeys
|
|
61
71
|
-output #{XCFRAMEWORK_DIRECTORY}
|
62
72
|
BASH
|
63
73
|
|
64
|
-
|
74
|
+
Core::Console::Shell.sh(command:)
|
65
75
|
end
|
66
76
|
|
67
77
|
# Generate the XCFramework library command
|
@@ -76,6 +86,37 @@ module SecureKeys
|
|
76
86
|
end.join(' ')
|
77
87
|
end.join(' ')
|
78
88
|
end
|
89
|
+
|
90
|
+
# Add the XCFramework to the Xcode project target if needed
|
91
|
+
# @param target_name [String] The target name to add the XCFramework
|
92
|
+
def add_xcframework_to_xcodeproj_target_if_needed(target_name: nil)
|
93
|
+
target_name ||= Core::Console::Argument::Handler.fetch(key: %i[xcframework target])
|
94
|
+
return if target_name.to_s.empty?
|
95
|
+
|
96
|
+
Core::Console::Logger.important(message: "Adding the XCFramework to the target '#{target_name}'")
|
97
|
+
xcodeproj = Xcodeproj.xcodeproj
|
98
|
+
xcodeproj_target = Xcodeproj.xcodeproj_target_by_target_name(xcodeproj:, target_name:)
|
99
|
+
Xcodeproj.add_framework_search_path(xcodeproj_target:)
|
100
|
+
Xcodeproj.add_xcframework_to_build_phases(xcodeproj:, xcodeproj_target:)
|
101
|
+
|
102
|
+
xcodeproj.save
|
103
|
+
Core::Console::Logger.success(message: "The XCFramework was added to the target '#{target_name}'")
|
104
|
+
end
|
105
|
+
|
106
|
+
# Remove the XCFramework from the Xcode project target if needed
|
107
|
+
# @param target_name [String] The target name to remove the XCFramework
|
108
|
+
def remove_xcframework_from_xcodeproj_target_if_needed(target_name: nil)
|
109
|
+
target_name ||= Core::Console::Argument::Handler.fetch(key: %i[xcframework target])
|
110
|
+
return if target_name.to_s.empty?
|
111
|
+
|
112
|
+
Core::Console::Logger.important(message: "Removing the XCFramework from the target '#{target_name}'")
|
113
|
+
xcodeproj = Xcodeproj.xcodeproj
|
114
|
+
xcodeproj_target = Xcodeproj.xcodeproj_target_by_target_name(xcodeproj:, target_name:)
|
115
|
+
Xcodeproj.remove_xcframework(xcodeproj:, xcodeproj_target:, xcframework_path: Xcodeproj.xcframework_relative_path)
|
116
|
+
|
117
|
+
xcodeproj.save
|
118
|
+
Core::Console::Logger.success(message: "The XCFramework was removed from the target '#{target_name}'")
|
119
|
+
end
|
79
120
|
end
|
80
121
|
end
|
81
122
|
end
|
@@ -0,0 +1,135 @@
|
|
1
|
+
require 'xcodeproj'
|
2
|
+
require_relative '../../globals/globals'
|
3
|
+
require_relative '../../utils/swift/swift'
|
4
|
+
require_relative '../../console/logger'
|
5
|
+
|
6
|
+
module SecureKeys
|
7
|
+
module Swift
|
8
|
+
module Xcodeproj
|
9
|
+
module_function
|
10
|
+
|
11
|
+
# Add the SecureKeys XCFramework to the Xcodeproj target build settings
|
12
|
+
# @param target_name [String] The target name to add the XCFramework
|
13
|
+
# @param configurations [Array<String>] The configurations to add the XCFramework
|
14
|
+
def add_framework_search_path(xcodeproj_target:, configurations: %w[Debug Release])
|
15
|
+
configurations.each do |config|
|
16
|
+
paths = ['$(inherited)', "$(SRCROOT)/#{xcframework_relative_path}"]
|
17
|
+
xcodeproj_target.build_settings(config)['FRAMEWORK_SEARCH_PATHS'] = paths
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
# Add the SecureKeys XCFramework to the Xcodeproj target build phases
|
22
|
+
# @param xcodeproj [Xcodeproj::Project] The Xcodeproj to add the XCFramework
|
23
|
+
# @param xcodeproj_target [Xcodeproj] The Xcodeproj target to add the XCFramework
|
24
|
+
def add_xcframework_to_build_phases(xcodeproj:, xcodeproj_target:)
|
25
|
+
Core::Console::Logger.crash!(message: "The xcodeproj #{xcodeproj} already have the #{XCFRAMEWORK_DIRECTORY}") if xcodeproj_has_secure_keys_xcframework?(xcodeproj:)
|
26
|
+
xcframework_reference = xcodeproj.frameworks_group.new_file(xcframework_relative_path)
|
27
|
+
xcodeproj_target.frameworks_build_phase.add_file_reference(xcframework_reference)
|
28
|
+
end
|
29
|
+
|
30
|
+
# Get the Xcodeproj target by target name
|
31
|
+
# @param xcodeproj [Xcodeproj::Project] The Xcodeproj to get the target
|
32
|
+
# @param target_name [String] The target name to get
|
33
|
+
# @return [Xcodeproj] The Xcodeproj target
|
34
|
+
# @raise [StandardError] If the target was not found
|
35
|
+
def xcodeproj_target_by_target_name(xcodeproj:, target_name:)
|
36
|
+
xcodeproj_target = xcodeproj.targets.find { |target| target.name.eql?(target_name) }
|
37
|
+
Core::Console::Logger.crash!(message: "The target #{target_name} was not found") if xcodeproj_target.nil?
|
38
|
+
|
39
|
+
xcodeproj_target
|
40
|
+
end
|
41
|
+
|
42
|
+
# Get the Xcodeproj
|
43
|
+
# @return [Xcodeproj] The Xcodeproj
|
44
|
+
def xcodeproj
|
45
|
+
::Xcodeproj::Project.open(Globals.xcodeproj_path)
|
46
|
+
end
|
47
|
+
|
48
|
+
# Remove all references to SecureKeys.xcframework from the Xcodeproj
|
49
|
+
# @param xcodeproj [Xcodeproj::Project] The Xcodeproj to remove the XCFramework
|
50
|
+
# @param xcodeproj_target [Xcodeproj::Project::Object::PBXNativeTarget] The target where the XCFramework is linked
|
51
|
+
# @param xcframework_path [String] The XCFramework path to remove
|
52
|
+
def remove_xcframework(xcodeproj:, xcodeproj_target:, xcframework_path:)
|
53
|
+
xcframework_filename = File.basename(xcframework_path)
|
54
|
+
|
55
|
+
remove_xcframework_from_build_phase(xcodeproj_target:, xcframework_filename:)
|
56
|
+
remove_xcframework_file_references(xcodeproj:, xcframework_filename:)
|
57
|
+
remove_xcframework_from_groups(xcodeproj:, xcframework_filename:)
|
58
|
+
remove_xcframework_from_search_paths(xcodeproj_target:, xcframework_filename:)
|
59
|
+
end
|
60
|
+
|
61
|
+
# Get the XCFramework relative path
|
62
|
+
# @return [Pathname] The XCFramework relative path
|
63
|
+
def xcframework_relative_path
|
64
|
+
Pathname.new(Globals.secure_keys_xcframework_path)
|
65
|
+
.relative_path_from(Pathname.new(Globals.xcodeproj_path).dirname)
|
66
|
+
end
|
67
|
+
|
68
|
+
# Check if the Xcode project has the secure keys XCFramework
|
69
|
+
# @param xcodeproj [Xcodeproj::Project] The Xcode project
|
70
|
+
# @return [Bool] true if the Xcode project has the secure keys XCFramework
|
71
|
+
def xcodeproj_has_secure_keys_xcframework?(xcodeproj:)
|
72
|
+
xcodeproj.targets.any? do |target|
|
73
|
+
target.frameworks_build_phase.files.any? do |file|
|
74
|
+
return false if file.file_ref.nil?
|
75
|
+
|
76
|
+
file.file_ref.path.include?(Globals.secure_keys_xcframework_path)
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
# Remove the XCFramework from the "Link Binary With Libraries" build phase
|
82
|
+
# @param xcodeproj_target [Xcodeproj::Project::Object::PBXNativeTarget] The target where the XCFramework is linked
|
83
|
+
# @param xcframework_filename [String] The XCFramework filename to remove
|
84
|
+
def remove_xcframework_from_build_phase(xcodeproj_target:, xcframework_filename:)
|
85
|
+
build_phase_files = xcodeproj_target.frameworks_build_phase.files.select do |file|
|
86
|
+
file.file_ref&.path&.include?(xcframework_filename)
|
87
|
+
end
|
88
|
+
|
89
|
+
build_phase_files.each do |file|
|
90
|
+
file.remove_from_project
|
91
|
+
Core::Console::Logger.verbose(message: "Removed #{xcframework_filename} from Link Binary With Libraries in target #{xcodeproj_target.name}")
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
# Remove the XCFramework from the file references
|
96
|
+
# @param xcodeproj [Xcodeproj::Project] The Xcodeproj to remove the XCFramework
|
97
|
+
# @param xcframework_filename [String] The XCFramework filename to remove
|
98
|
+
def remove_xcframework_file_references(xcodeproj:, xcframework_filename:)
|
99
|
+
file_references = xcodeproj.files.select { |file| file.path&.include?(xcframework_filename) }
|
100
|
+
file_references.each do |file_ref|
|
101
|
+
file_ref.remove_from_project
|
102
|
+
Core::Console::Logger.verbose(message: "Removed #{xcframework_filename} file reference")
|
103
|
+
end
|
104
|
+
|
105
|
+
# Ensure no orphaned references remain
|
106
|
+
xcodeproj.objects.select { |obj| obj.isa == 'PBXFileReference' && obj.path&.include?(xcframework_filename) }.each(&:remove_from_project)
|
107
|
+
xcodeproj.objects.select { |obj| obj.isa == 'PBXBuildFile' && obj.file_ref&.path&.include?(xcframework_filename) }.each(&:remove_from_project)
|
108
|
+
end
|
109
|
+
|
110
|
+
# Remove the XCFramework from groups (e.g., Frameworks Group)
|
111
|
+
# @param xcodeproj [Xcodeproj::Project] The Xcodeproj to remove the XCFramework
|
112
|
+
# @param xcframework_filename [String] The XCFramework filename to remove
|
113
|
+
def remove_xcframework_from_groups(xcodeproj:, xcframework_filename:)
|
114
|
+
frameworks_group = xcodeproj.frameworks_group
|
115
|
+
group_references = frameworks_group.files.select { |file| file.path&.include?(xcframework_filename) }
|
116
|
+
|
117
|
+
group_references.each do |file_ref|
|
118
|
+
frameworks_group.remove_reference(file_ref)
|
119
|
+
Core::Console::Logger.verbose(message: "Removed #{xcframework_filename} from Frameworks group")
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
# Remove the XCFramework from FRAMEWORK_SEARCH_PATHS
|
124
|
+
# @param xcodeproj_target [Xcodeproj::Project::Object::PBXNativeTarget] The target where the XCFramework is linked
|
125
|
+
# @param xcframework_filename [String] The XCFramework filename to remove
|
126
|
+
def remove_xcframework_from_search_paths(xcodeproj_target:, xcframework_filename:)
|
127
|
+
xcodeproj_target.build_configurations.each do |config|
|
128
|
+
framework_search_paths = config.build_settings['FRAMEWORK_SEARCH_PATHS'] || []
|
129
|
+
new_search_paths = framework_search_paths.reject { |path| path.include?(xcframework_filename) }
|
130
|
+
config.build_settings['FRAMEWORK_SEARCH_PATHS'] = new_search_paths unless framework_search_paths == new_search_paths
|
131
|
+
end
|
132
|
+
end
|
133
|
+
end
|
134
|
+
end
|
135
|
+
end
|
data/lib/keys.rb
CHANGED
@@ -1,84 +1,18 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
+
require_relative './core/utils/extensions/kernel'
|
4
|
+
require_relative './core/generator'
|
3
5
|
require_relative './core/globals/globals'
|
4
|
-
require_relative './core/
|
5
|
-
require_relative './core/environment/keychain'
|
6
|
-
require_relative './core/utils/swift/writer'
|
7
|
-
require_relative './core/utils/swift/package'
|
8
|
-
require_relative './core/utils/swift/swift'
|
9
|
-
require_relative './core/utils/swift/xcframework'
|
10
|
-
require_relative './core/utils/openssl/cipher'
|
6
|
+
require_relative './core/console/logger'
|
11
7
|
require_relative './core/console/arguments/parser'
|
8
|
+
require_relative './core/utils/swift/xcframework'
|
12
9
|
|
13
10
|
module SecureKeys
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
attr_accessor :cipher, :secrets_source, :secret_keys, :mapped_keys
|
18
|
-
|
19
|
-
public
|
20
|
-
|
21
|
-
def initialize
|
22
|
-
# Configure the argument parser
|
23
|
-
SecureKeys::Core::Console::Argument::Parser.new
|
24
|
-
|
25
|
-
puts "🔔 You're using a custom delimiter '#{SecureKeys::Globals.key_delimiter}'" unless SecureKeys::Globals.key_delimiter.eql?(SecureKeys::Globals.default_key_delimiter)
|
26
|
-
puts "🔔 You're using a custom key access identifier '#{SecureKeys::Globals.key_access_identifier}'" unless SecureKeys::Globals.key_access_identifier.eql?(SecureKeys::Globals.default_key_access_identifier)
|
27
|
-
|
28
|
-
# Configure cipher
|
29
|
-
self.cipher = SecureKeys::OpenSSL::Cipher.new
|
30
|
-
|
31
|
-
# Configure the secret source based on the environment
|
32
|
-
if SecureKeys::Globals.ci?
|
33
|
-
self.secrets_source = SecureKeys::Core::Environment::CI.new
|
34
|
-
else
|
35
|
-
self.secrets_source = SecureKeys::Core::Environment::Keychain.new
|
36
|
-
end
|
37
|
-
|
38
|
-
# Define the keys that we want to map
|
39
|
-
self.secret_keys = secrets_source.fetch(key: SecureKeys::Globals.key_access_identifier)
|
40
|
-
.to_s
|
41
|
-
.split(SecureKeys::Globals.key_delimiter)
|
42
|
-
.map(&:strip)
|
43
|
-
|
44
|
-
# Add the keys that we want to map
|
45
|
-
self.mapped_keys = secret_keys.map do |key|
|
46
|
-
encrypted_data = cipher.encrypt(value: secrets_source.fetch(key:))
|
47
|
-
# Convert the first key chart to downcase
|
48
|
-
key[0] = key[0].downcase
|
49
|
-
{ name: key, **encrypted_data }
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
def setup
|
54
|
-
pre_actions
|
55
|
-
|
56
|
-
package = SecureKeys::Swift::Package.new
|
57
|
-
package.generate
|
58
|
-
|
59
|
-
writer = SecureKeys::Swift::Writer.new(mapped_keys: mapped_keys,
|
60
|
-
secure_key_bytes: cipher.secure_key_bytes)
|
61
|
-
writer.write
|
62
|
-
|
63
|
-
xcframework = SecureKeys::Swift::XCFramework.new
|
64
|
-
xcframework.generate
|
65
|
-
|
66
|
-
post_actions
|
67
|
-
end
|
68
|
-
|
69
|
-
private
|
70
|
-
|
71
|
-
def pre_actions
|
72
|
-
# Remove the keys directory
|
73
|
-
system("rm -rf #{SecureKeys::Swift::KEYS_DIRECTORY}")
|
74
|
-
end
|
75
|
-
|
76
|
-
def post_actions
|
77
|
-
# Remove the keys directory
|
78
|
-
system("rm -rf #{SecureKeys::Swift::SWIFT_PACKAGE_DIRECTORY}")
|
11
|
+
def self.run
|
12
|
+
# Configure the argument parser
|
13
|
+
Core::Console::Argument::Parser.new
|
79
14
|
|
80
|
-
|
81
|
-
|
82
|
-
end
|
15
|
+
# Generate the keys
|
16
|
+
Core::Generator.new.generate
|
83
17
|
end
|
84
18
|
end
|
data/lib/version.rb
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
3
|
module SecureKeys
|
4
|
-
VERSION = '1.1.
|
4
|
+
VERSION = '1.1.4'.freeze
|
5
5
|
SUMMARY = 'Secure Keys is a simple tool for managing your secret keys'.freeze
|
6
6
|
DESCRIPTION = 'Secure Keys is a simple tool to manage your secret keys in your iOS project'.freeze
|
7
|
-
HOMEPAGE_URI = 'https://github.com/
|
7
|
+
HOMEPAGE_URI = 'https://github.com/derian-cordoba/secure-keys'.freeze
|
8
8
|
end
|