fastlane-plugin-match_android_v2 0.3.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 21c9a6b307d4eb38474e48cc59175cb038d9ca3427e1adb27d6866cea9f44287
4
+ data.tar.gz: c62facda96c00553ccd265e76cad21b9dfcee7118768a85df36dd860b1c7dfa8
5
+ SHA512:
6
+ metadata.gz: 8df42d0fecbf4cc632c85b248ce5edab3a0ad66fe535583dded75e52f53e8dac118a45b1aa6d0eafabf388d7ebf2ec61a8da56a82d4e3bd395dca4e94d92cc4c
7
+ data.tar.gz: 1ae140e38c1b30c54dae4d25b56eff879944346fe3d93b923219d2f9280e1b3dcadeef9792f11d6b08aca262114105561774d005ae96d688f932eb1d1cc5df01
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2020 Christopher NEY <christopher.ney@gmail.com>
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,90 @@
1
+ # match_android plugin
2
+
3
+ [![fastlane Plugin Badge](https://rawcdn.githack.com/fastlane/fastlane/master/fastlane/assets/plugin-badge.svg)](https://rubygems.org/gems/fastlane-plugin-match_android)
4
+
5
+ ## Machine requirements
6
+
7
+ * OpenSSL 1.1.1 min OR LibreSSL 2.9 min installed
8
+ * Git installed
9
+ * Android SDK & Build-tools installed
10
+ * ANDROID_HOME environment variable defined
11
+
12
+ ## Getting Started
13
+
14
+ This project is a [_fastlane_](https://github.com/fastlane/fastlane) plugin. To get started with `fastlane-plugin-match_android`, add it to your project by running:
15
+
16
+ ```bash
17
+ fastlane add_plugin match_android
18
+ ```
19
+
20
+ ## About match_android
21
+
22
+ *This repo is a fork of [fastlane-plugin-match_keystore](https://github.com/christopherney/fastlane-plugin-match_keystore) with some improvements and bug fixes. The original plugin was not maintained anymore. This updated package is published under a new name to be able to publish & install the plugin.*
23
+
24
+ Easily sync your Android keystores across your team.
25
+
26
+ This plugin was design based on the 'match' plugin and code signing concept: https://codesigning.guide/
27
+
28
+ With **match_android** you can store all your Android Keystores in secured private repository and share it to your team and your CI system.
29
+
30
+ The keystore properties are encrypted with AES in order to secure sensitive data in the Git repository itself.
31
+
32
+ ## How to use
33
+
34
+ ```ruby
35
+ lane :release_and_sign do |options|
36
+ gradle(task: "clean")
37
+ gradle(task: 'assemble', build_type: 'Release')
38
+
39
+ signed_apk_path = match_android(
40
+ git_url: "https://github.com/<GITHUB_USERNAME>/keystores.git", # Please use a private Git repository !
41
+ package_name: "com.your.package.name",
42
+ apk_path: "/app/build/outputs/apk/app-release.apk" # Or path without APK: /app/build/outputs/apk/
43
+ # Optional:
44
+ match_secret: "A-very-str0ng-password!", # The secret use to encrypt/decrypt Keystore passwords on Git repo (for CI)
45
+ existing_keystore: "assets/existing-keystore.jks", # Optional, if needed to import an existing keystore
46
+ override_keystore: true, # Optional, override an existing Keystore on Git repo
47
+ keystore_data: "assets/keystore.json" # Optional, all data required to create a new Keystore (use to bypass prompt)
48
+ )
49
+
50
+ # Return the path of signed APK (useful for other lanes such as `publish_to_firebase`, `upload_to_play_store`)
51
+ puts signed_apk_path
52
+ end
53
+ ```
54
+
55
+ You can build aab files as well by providing an `aab_path` instead of an `apk_path`.
56
+
57
+ ## Example
58
+
59
+ Check out the [example `Fastfile`](fastlane/Fastfile) to see how to use this plugin. Try it by cloning the repo, running `fastlane install_plugins` and `bundle exec fastlane test`.
60
+
61
+ **Note to author:** Please set up a sample project to make it easy for users to explore what your plugin does. Provide everything that is necessary to try out the plugin in this project (including a sample Xcode/Android project if necessary)
62
+
63
+ ## Run tests for this plugin
64
+
65
+ To run both the tests, and code style validation, run
66
+
67
+ ```
68
+ rake
69
+ ```
70
+
71
+ To automatically fix many of the styling issues, use
72
+ ```
73
+ rubocop -a
74
+ ```
75
+
76
+ ## Issues and Feedback
77
+
78
+ For any other issues and feedback about this plugin, please submit it to this repository.
79
+
80
+ ## Troubleshooting
81
+
82
+ If you have trouble using plugins, check out the [Plugins Troubleshooting](https://docs.fastlane.tools/plugins/plugins-troubleshooting/) guide.
83
+
84
+ ## Using _fastlane_ Plugins
85
+
86
+ For more information about how the `fastlane` plugin system works, check out the [Plugins documentation](https://docs.fastlane.tools/plugins/create-plugin/).
87
+
88
+ ## About _fastlane_
89
+
90
+ _fastlane_ is the easiest way to automate beta deployments and releases for your iOS and Android apps. To learn more, check out [fastlane.tools](https://fastlane.tools).
@@ -0,0 +1,800 @@
1
+ require 'fastlane/action'
2
+ require 'fileutils'
3
+ require 'os'
4
+ require 'json'
5
+ require 'digest'
6
+ require_relative '../helper/match_android_helper'
7
+
8
+ module Fastlane
9
+ module Actions
10
+ module SharedValues
11
+ MATCH_ANDROID_PATH = :MATCH_ANDROID_PATH
12
+ MATCH_ANDROID_ALIAS_NAME = :MATCH_ANDROID_ALIAS_NAME
13
+ MATCH_ANDROID_APK_SIGNED = :MATCH_ANDROID_APK_SIGNED
14
+ MATCH_ANDROID_AAB_SIGNED = :MATCH_ANDROID_AAB_SIGNED
15
+ end
16
+
17
+ class MatchAndroidAction < Action
18
+
19
+ KEY_VERSION = "2"
20
+ OPENSSL_BIN_PATH_MAC = "/usr/local/opt/openssl@1.1/bin"
21
+
22
+ def self.to_md5(value)
23
+ hash_value = Digest::MD5.hexdigest value
24
+ hash_value
25
+ end
26
+
27
+ def self.sha512(value)
28
+ hash_value = Digest::SHA512.hexdigest value
29
+ hash_value
30
+ end
31
+
32
+ def self.load_json(json_path)
33
+ file = File.read(json_path)
34
+ data_hash = JSON.parse(file)
35
+ data_hash
36
+ end
37
+
38
+ def self.load_properties(properties_filename)
39
+ properties = {}
40
+ File.open(properties_filename, 'r') do |properties_file|
41
+ properties_file.read.each_line do |line|
42
+ line.strip!
43
+ if (line[0] != ?# and line[0] != ?=)
44
+ i = line.index('=')
45
+ if (i)
46
+ properties[line[0..i - 1].strip] = line[i + 1..-1].strip
47
+ else
48
+ properties[line] = ''
49
+ end
50
+ end
51
+ end
52
+ end
53
+ properties
54
+ end
55
+
56
+ def self.get_android_home
57
+ `rm -f android_home.txt`
58
+ `echo $ANDROID_HOME > android_home.txt`
59
+ data = File.read("android_home.txt")
60
+ android_home = data.strip
61
+ `rm -f android_home.txt`
62
+ android_home
63
+ end
64
+
65
+ def self.get_build_tools_version(targeted_version)
66
+ path = self.get_build_tools(targeted_version)
67
+ version = path.split('/').last
68
+ version
69
+ end
70
+
71
+ def self.get_build_tools(targeted_version)
72
+ android_home = self.get_android_home()
73
+ build_tools_root = File.join(android_home, '/build-tools')
74
+
75
+ build_tools_path = ""
76
+ if !targeted_version.to_s.strip.empty?
77
+ build_tools_path = File.join(build_tools_root, "/#{targeted_version}/")
78
+ end
79
+
80
+ if !File.directory?(build_tools_path)
81
+ sub_dirs = Dir.glob(File.join(build_tools_root, '*', ''))
82
+ build_tools_last_version = ''
83
+ for sub_dir in sub_dirs
84
+ build_tools_last_version = sub_dir
85
+ end
86
+ build_tools_path = build_tools_last_version
87
+ end
88
+
89
+ build_tools_path
90
+ end
91
+
92
+ def self.check_ssl_version(forceOpenSSL)
93
+ libressl_min = '2.9'
94
+ openssl_min = '1.1.1'
95
+
96
+ openssl = self.openssl(forceOpenSSL)
97
+ output = `#{openssl} version`
98
+ if !output.start_with?("LibreSSL") && !output.start_with?("OpenSSL")
99
+ raise "Please install OpenSSL '#{openssl_min}' at least OR LibreSSL #{libressl_min}' at least"
100
+ end
101
+ UI.message("SSL/TLS protocol library: '#{output.strip!}'")
102
+
103
+ # Check minimum verion:
104
+ version = output.to_str.scan(/[0-9\.]{1,}/).first
105
+ UI.message("SSL/TLS protocol version: '#{version}'")
106
+ if self.is_libre_ssl(forceOpenSSL)
107
+ if Gem::Version.new(version) < Gem::Version.new(libressl_min)
108
+ raise "Minimum version for LibreSSL is '#{libressl_min}' (you're on '#{version}'), please update it."
109
+ end
110
+ else
111
+ if Gem::Version.new(version) < Gem::Version.new(openssl_min)
112
+ raise "Minimum version for OpenSSL is '#{openssl_min}' (you're on '#{version}'), please update it."
113
+ end
114
+ end
115
+
116
+ output.strip
117
+ end
118
+
119
+ def self.openssl(forceOpenSSL)
120
+ if forceOpenSSL
121
+ output = "#{self::OPENSSL_BIN_PATH_MAC}/openssl"
122
+ else
123
+ output = "openssl"
124
+ end
125
+ output
126
+ end
127
+
128
+ def self.is_libre_ssl(forceOpenSSL)
129
+ result = false
130
+ openssl = self.openssl(forceOpenSSL)
131
+ output = `#{openssl} version`
132
+ if output.start_with?("LibreSSL")
133
+ result = true
134
+ end
135
+ result
136
+ end
137
+
138
+ def self.gen_key(key_path, password, compat_key)
139
+ `rm -f '#{key_path}'`
140
+ shaValue = self.sha512(password)
141
+ # Backward-compatibility
142
+ if compat_key == "1"
143
+ `echo "#{password}" | openssl dgst -sha512 | awk '{print $2}' | cut -c1-128 > '#{key_path}'`
144
+ else
145
+ `echo "#{shaValue}" > '#{key_path}'`
146
+ end
147
+ end
148
+
149
+ def self.encrypt_file(clear_file, encrypt_file, key_path, forceOpenSSL)
150
+ `rm -f '#{encrypt_file}'`
151
+ libre_ssl = self.is_libre_ssl(forceOpenSSL)
152
+ openssl_bin = self.openssl(forceOpenSSL)
153
+ `#{openssl_bin} enc -aes-256-cbc -salt -pbkdf2 -in '#{clear_file}' -out '#{encrypt_file}' -pass file:'#{key_path}'`
154
+ end
155
+
156
+ def self.decrypt_file(encrypt_file, clear_file, key_path, forceOpenSSL)
157
+ `rm -f '#{clear_file}'`
158
+ libre_ssl = self.is_libre_ssl(forceOpenSSL)
159
+ openssl_bin = self.openssl(forceOpenSSL)
160
+ `#{openssl_bin} enc -d -aes-256-cbc -pbkdf2 -in '#{encrypt_file}' -out '#{clear_file}' -pass file:'#{key_path}'`
161
+ end
162
+
163
+ def self.assert_equals(test_name, excepted, value)
164
+ puts "Unit Test: #{test_name}"
165
+ if value != excepted
166
+ puts " - Excepted: #{excepted}"
167
+ puts " - Returned: #{value}"
168
+ raise "Unit Test - #{test_name} error!"
169
+ else
170
+ puts " - OK"
171
+ end
172
+ end
173
+
174
+ def self.test_security
175
+
176
+ self.check_ssl_version(false)
177
+
178
+ # Clear temp files
179
+ temp_dir = File.join(Dir.pwd, '/temp/')
180
+ FileUtils.rm_rf(temp_dir)
181
+ Dir.mkdir(temp_dir)
182
+
183
+ fakeValue = "4esfsf4dsfds!efs5ZDOJF"
184
+ # Check MD5
185
+ md5value = self.to_md5(fakeValue)
186
+ excepted = "1c815cd208fe08076c9e7b6595d121d1"
187
+ self.assert_equals("MD5", excepted, md5value)
188
+
189
+ # Check SHA-512
190
+ shaValue = self.sha512(fakeValue)
191
+ excepted = "cc6a7b0d89cc61c053f7018a305672bdb82bc07e5015f64bb063d9662be4ec81ec8afa819b009de266482b6bd56b7068def2524c32f5b5d4d9db49ee4578499d"
192
+ self.assert_equals("SHA-512", excepted, shaValue)
193
+
194
+ # Check SHA-512-File
195
+ key_path = File.join(Dir.pwd, '/temp/key.txt')
196
+ self.gen_key(key_path, fakeValue, false)
197
+ shaValue = self.get_file_content(key_path).strip!
198
+ excepted = "cc6a7b0d89cc61c053f7018a305672bdb82bc07e5015f64bb063d9662be4ec81ec8afa819b009de266482b6bd56b7068def2524c32f5b5d4d9db49ee4578499d"
199
+ self.assert_equals("SHA-512-File", excepted, shaValue)
200
+
201
+
202
+ # Check LibreSSL
203
+ result = self.is_libre_ssl(false)
204
+ self.assert_equals("Is-LibreSSL", true, result)
205
+ result = self.is_libre_ssl(true)
206
+ self.assert_equals("Is-LibreSSL", false, result)
207
+
208
+ # Encrypt OpenSSL
209
+ clear_file = File.join(Dir.pwd, '/temp/clear.txt')
210
+ openssl_encrypt_file = File.join(Dir.pwd, '/temp/openssl_encrypted.txt')
211
+ self.content_to_file(clear_file, fakeValue)
212
+ self.encrypt_file(clear_file, openssl_encrypt_file, key_path, true)
213
+ result = File.file?(openssl_encrypt_file) && File.size(openssl_encrypt_file) > 10
214
+ self.assert_equals("Encrypt-OpenSSL", true, result)
215
+
216
+ # Encrypt LibreSSL
217
+ encrypt_file_libre = File.join(Dir.pwd, '/temp/libressl_encrypted.txt')
218
+ self.content_to_file(clear_file, fakeValue)
219
+ self.encrypt_file(clear_file, encrypt_file_libre, key_path, false)
220
+ result = File.file?(encrypt_file_libre) && File.size(encrypt_file_libre) > 10
221
+ self.assert_equals("Encrypt-LibreSSL", true, result)
222
+
223
+ # exit!
224
+
225
+ # Decrypt OpenSSL (from OpenSSL)
226
+ openssl_clear_file = File.join(Dir.pwd, '/temp/openssl_clear.txt')
227
+ self.decrypt_file(openssl_encrypt_file, openssl_clear_file, key_path, true)
228
+ decrypted = self.get_file_content(openssl_clear_file).strip!
229
+ self.assert_equals("Decrypt-OpenSSL", fakeValue, decrypted)
230
+
231
+ # Decrypt LibreSSL (from LibreSSL)
232
+ libressl_clear_file = File.join(Dir.pwd, '/temp/libressl_clear.txt')
233
+ self.decrypt_file(encrypt_file_libre, libressl_clear_file, key_path, false)
234
+ decrypted = self.get_file_content(libressl_clear_file).strip!
235
+ self.assert_equals("Decrypt-LibreSSL", fakeValue, decrypted)
236
+
237
+ # Decrypt LibreSSL (from OpenSSL)
238
+ libressl_clear_file = File.join(Dir.pwd, '/temp/libressl_from_openssl_clear.txt')
239
+ self.decrypt_file(openssl_encrypt_file, libressl_clear_file, key_path, false)
240
+ decrypted = self.get_file_content(libressl_clear_file).strip!
241
+ self.assert_equals("Decrypt-LibreSSL-from-OpenSSL", fakeValue, decrypted)
242
+
243
+ # Decrypt OpenSSL (from LibreSSL)
244
+ openssl_clear_file = File.join(Dir.pwd, '/temp/openssl_from_libressl_clear.txt')
245
+ self.decrypt_file(encrypt_file_libre, openssl_clear_file, key_path, true)
246
+ decrypted = self.get_file_content(openssl_clear_file).strip!
247
+ self.assert_equals("Decrypt-OpenSSL-from-LibreSSL", fakeValue, decrypted)
248
+
249
+ end
250
+
251
+ def self.sign_apk(apk_path, keystore_path, key_password, alias_name, alias_password, zip_align, version_targeted)
252
+
253
+ build_tools_path = self.get_build_tools(version_targeted)
254
+ UI.message("Build-tools path: #{build_tools_path}")
255
+
256
+ # https://developer.android.com/studio/command-line/apksigner
257
+ apk_path_signed = apk_path.gsub(".apk", "-signed.apk")
258
+ apk_path_signed = apk_path_signed.gsub("unsigned", "")
259
+ apk_path_signed = apk_path_signed.gsub("--", "-")
260
+ `rm -f '#{apk_path_signed}'`
261
+
262
+ UI.message("Signing APK (input): #{apk_path}")
263
+ apksigner_opts = ""
264
+ build_tools_version = self.get_build_tools_version(version_targeted)
265
+ UI.message("Build-tools version: #{build_tools_version}")
266
+ if Gem::Version.new(build_tools_version) >= Gem::Version.new('30')
267
+ apksigner_opts = "--v4-signing-enabled false "
268
+ end
269
+ output = `#{build_tools_path}apksigner sign --ks '#{keystore_path}' --ks-key-alias '#{alias_name}' --ks-pass pass:'#{key_password}' --key-pass pass:'#{alias_password}' --v1-signing-enabled true --v2-signing-enabled true #{apksigner_opts}--out '#{apk_path_signed}' '#{apk_path}'`
270
+ puts ""
271
+ puts output
272
+
273
+ UI.message("Verifing APK signature (output): #{apk_path_signed}")
274
+ output = `#{build_tools_path}apksigner verify '#{apk_path_signed}'`
275
+ puts ""
276
+ puts output
277
+
278
+
279
+ # https://developer.android.com/studio/command-line/zipalign
280
+ if zip_align != false
281
+ apk_path_aligned = apk_path_signed.gsub(".apk", "-aligned.apk")
282
+ `rm -f '#{apk_path_aligned}'`
283
+ UI.message("Aligning APK (zipalign): #{apk_path_signed}")
284
+ output = `#{build_tools_path}zipalign -v 4 '#{apk_path_signed}' '#{apk_path_aligned}'`
285
+ puts ""
286
+ puts output
287
+
288
+ if !File.file?(apk_path_aligned)
289
+ raise "Aligned APK not exists!"
290
+ end
291
+
292
+ `rm -f '#{apk_path_signed}'`
293
+ apk_path_signed = apk_path_aligned
294
+
295
+ else
296
+ UI.message("No zip align - deactivated via parameter!")
297
+ end
298
+
299
+ apk_path_signed
300
+ end
301
+
302
+ def self.sign_aab(aab_path, keystore_path, key_password, alias_name, alias_password)
303
+
304
+ aab_path_signed = aab_path.gsub('.aab', '-signed.aab')
305
+ aab_path_signed = aab_path_signed.gsub('unsigned', '')
306
+ aab_path_signed = aab_path_signed.gsub('--', '-')
307
+ `rm -f '#{aab_path_signed}'`
308
+
309
+ UI.message("Signing AAB (input): #{aab_path}")
310
+ aabsigner_opts = ""
311
+ output = `jarsigner -keystore '#{keystore_path}' -storepass '#{key_password}' -keypass '#{alias_password}' -signedjar '#{aab_path_signed}' '#{aab_path}' '#{alias_name}'`
312
+ puts ""
313
+ puts output
314
+
315
+ aab_path_signed
316
+ end
317
+
318
+ def self.resolve_dir(path)
319
+ if !File.directory?(path)
320
+ path = File.join(Dir.pwd, path)
321
+ end
322
+ path
323
+ end
324
+
325
+ def self.resolve_file(path)
326
+ if !File.file?(path)
327
+ path = File.join(Dir.pwd, path)
328
+ end
329
+ path
330
+ end
331
+
332
+ def self.content_to_file(file_path, content)
333
+ `echo #{content} > #{file_path}`
334
+ end
335
+
336
+ def self.get_file_content(file_path)
337
+ data = File.read(file_path)
338
+ data
339
+ end
340
+
341
+ def self.resolve_aab_path(aab_path)
342
+
343
+ # Set default AAB path if not set:
344
+ if aab_path.to_s.strip.empty?
345
+ aab_path = '/app/build/outputs/bundle/release/'
346
+ end
347
+
348
+ if !aab_path.to_s.end_with?('.aab')
349
+
350
+ aab_path = self.resolve_dir(aab_path)
351
+
352
+ pattern = File.join(aab_path, '*.aab')
353
+ files = Dir[pattern]
354
+
355
+ for file in files
356
+ if file.to_s.end_with?('.aab') && !file.to_s.end_with?("-signed.aab")
357
+ apk_path = file
358
+ break
359
+ end
360
+ end
361
+
362
+ else
363
+ aab_path = self.resolve_file(aab_path)
364
+ end
365
+
366
+ aab_path
367
+ end
368
+
369
+ def self.resolve_apk_path(apk_path)
370
+
371
+ # Set default APK path if not set:
372
+ if apk_path.to_s.strip.empty?
373
+ apk_path = '/app/build/outputs/apk/'
374
+ end
375
+
376
+ if !apk_path.to_s.end_with?(".apk")
377
+
378
+ apk_path = self.resolve_dir(apk_path)
379
+
380
+ pattern = File.join(apk_path, '*.apk')
381
+ files = Dir[pattern]
382
+
383
+ for file in files
384
+ if file.to_s.end_with?(".apk") && !file.to_s.end_with?("-signed.apk")
385
+ apk_path = file
386
+ break
387
+ end
388
+ end
389
+
390
+ else
391
+ apk_path = self.resolve_file(apk_path)
392
+ end
393
+
394
+ apk_path
395
+ end
396
+
397
+ def self.prompt2(params)
398
+ # UI.message("prompt2: #{params[:value]}")
399
+ if params[:value].to_s.empty?
400
+ return_value = other_action.prompt(text: params[:text], secure_text: params[:secure_text], ci_input: params[:ci_input])
401
+ else
402
+ return_value = params[:value]
403
+ end
404
+ return_value
405
+ end
406
+
407
+ def self.run(params)
408
+
409
+ # Get input parameters:
410
+ git_url = params[:git_url]
411
+ package_name = params[:package_name]
412
+ apk_path = params[:apk_path]
413
+ aab_path = params[:aab_path]
414
+ existing_keystore = params[:existing_keystore]
415
+ match_secret = params[:match_secret]
416
+ override_keystore = params[:override_keystore]
417
+ keystore_data = params[:keystore_data]
418
+ clear_keystore = params[:clear_keystore]
419
+ unit_test = params[:unit_test]
420
+ build_tools_version = params[:build_tools_version]
421
+ zip_align = params[:zip_align]
422
+ compat_key = params[:compat_key]
423
+ ci_mode = params[:ci_mode]
424
+
425
+ # Test OpenSSL/LibreSSL
426
+ if unit_test
427
+ result_test = self.test_security
428
+ exit!
429
+ end
430
+
431
+ # Init constants:
432
+ keystore_name = 'keystore.jks'
433
+ properties_name = 'keystore.properties'
434
+ keystore_info_name = 'keystore.txt'
435
+ properties_encrypt_name = 'keystore.properties.enc'
436
+
437
+ # Check Android Home env:
438
+ android_home = self.get_android_home()
439
+ UI.message("Android SDK: #{android_home}")
440
+ if android_home.to_s.strip.empty?
441
+ raise "The environment variable ANDROID_HOME is not defined, or Android SDK is not installed!"
442
+ end
443
+
444
+ # Check OpenSSL:
445
+ self.check_ssl_version(false)
446
+
447
+ # Check is backward-compatibility is required:
448
+ if !compat_key.to_s.strip.empty?
449
+ UI.message("Compatiblity version: #{compat_key}")
450
+ end
451
+
452
+ # Init workign local directory:
453
+ dir_name = ENV['HOME'] + '/.match_android'
454
+ unless File.directory?(dir_name)
455
+ UI.message("Creating '.match_android' working directory...")
456
+ FileUtils.mkdir_p(dir_name)
457
+ end
458
+
459
+ # Init 'security password' for AES encryption:
460
+ if compat_key == "1"
461
+ key_name = "#{self.to_md5(git_url)}.hex"
462
+ else
463
+ key_name = "#{self.to_md5(git_url)}-#{self::KEY_VERSION}.hex"
464
+ end
465
+ key_path = File.join(dir_name, key_name)
466
+ # UI.message(key_path)
467
+ if !File.file?(key_path)
468
+ security_password = self.prompt2(text: "Security password: ", secure_text: true, value: match_secret)
469
+ if security_password.to_s.strip.empty?
470
+ raise "Security password is not defined! Please use 'match_secret' parameter for CI."
471
+ end
472
+ UI.message "Generating security key '#{key_name}'..."
473
+ self.gen_key(key_path, security_password, compat_key)
474
+ end
475
+
476
+ # Check is 'security password' is well initialized:
477
+ tmpkey = self.get_file_content(key_path).strip
478
+ if tmpkey.length == 128
479
+ UI.message "Security key '#{key_name}' initialized"
480
+ else
481
+ raise "The security key '#{key_name}' is malformed, or not initialized!"
482
+ end
483
+
484
+ # Clear repo Keystore (local) - mostly for testing:
485
+ repo_dir = File.join(dir_name, self.to_md5(git_url))
486
+ if clear_keystore && File.directory?(repo_dir)
487
+ FileUtils.rm_rf(repo_dir)
488
+ UI.message("Local repo keystore (#{repo_dir}) directory deleted!")
489
+ end
490
+
491
+ # Create repo directory to sync remote Keystores repository:
492
+ unless File.directory?(repo_dir)
493
+ UI.message("Creating 'repo' directory...")
494
+ FileUtils.mkdir_p(repo_dir)
495
+ end
496
+
497
+ # Check if package name defined:
498
+ if package_name.to_s.strip.empty?
499
+ raise "Package name is not defined!"
500
+ end
501
+
502
+ # Define paths:
503
+ keystoreAppDir = File.join(repo_dir, package_name)
504
+ keystore_path = File.join(keystoreAppDir, keystore_name)
505
+ properties_path = File.join(keystoreAppDir, properties_name)
506
+ properties_encrypt_path = File.join(keystoreAppDir, properties_encrypt_name)
507
+
508
+ # Cloning/pulling GIT remote repository:
509
+ gitDir = File.join(repo_dir, '/.git')
510
+ if !File.directory?(gitDir)
511
+ UI.message("Cloning remote Keystores repository...")
512
+ `git clone #{git_url} #{repo_dir}`
513
+ else
514
+ UI.message("Pulling remote Keystores repository...")
515
+ `cd #{repo_dir} && git pull`
516
+ end
517
+
518
+ # Load parameters from JSON for CI or Unit Tests:
519
+ if keystore_data != nil && File.file?(keystore_data)
520
+ data_json = self.load_json(keystore_data)
521
+ data_key_password = data_json['key_password']
522
+ data_alias_name = data_json['alias_name']
523
+ data_alias_password = data_json['alias_password']
524
+ data_full_name = data_json['full_name']
525
+ data_org_unit = data_json['org_unit']
526
+ data_org = data_json['org']
527
+ data_city_locality = data_json['city_locality']
528
+ data_state_province = data_json['state_province']
529
+ data_country = data_json['country']
530
+ end
531
+
532
+ # Create keystore with command
533
+ override_keystore = !existing_keystore.to_s.strip.empty? && File.file?(existing_keystore)
534
+ UI.message("Existing Keystore: #{existing_keystore}")
535
+ if !File.file?(keystore_path) || override_keystore
536
+
537
+ if File.file?(keystore_path)
538
+ FileUtils.remove_dir(keystore_path)
539
+ end
540
+
541
+ key_password = self.prompt2(text: "Keystore Password: ", value: data_key_password)
542
+ if key_password.to_s.strip.empty?
543
+ raise "Keystore Password is not definined!"
544
+ end
545
+ alias_name = self.prompt2(text: "Keystore Alias name: ", value: data_alias_name)
546
+ if alias_name.to_s.strip.empty?
547
+ raise "Keystore Alias name is not definined!"
548
+ end
549
+ alias_password = self.prompt2(text: "Keystore Alias password: ", value: data_alias_password)
550
+ if alias_password.to_s.strip.empty?
551
+ raise "Keystore Alias password is not definined!"
552
+ end
553
+
554
+ # https://developer.android.com/studio/publish/app-signing
555
+ if existing_keystore.to_s.strip.empty? || !File.file?(existing_keystore)
556
+ UI.message("Generating Android Keystore...")
557
+
558
+ full_name = self.prompt2(text: "Certificate First and Last Name: ", value: data_full_name)
559
+ org_unit = self.prompt2(text: "Certificate Organisation Unit: ", value: data_org_unit)
560
+ org = self.prompt2(text: "Certificate Organisation: ", value: data_org)
561
+ city_locality = self.prompt2(text: "Certificate City or Locality: ", value: data_city_locality)
562
+ state_province = self.prompt2(text: "Certificate State or Province: ", value: data_state_province)
563
+ country = self.prompt2(text: "Certificate Country Code (XX): ", value: data_country)
564
+
565
+ # Make sure the directory exists
566
+ FileUtils.mkdir_p keystoreAppDir
567
+
568
+ keytool_parts = [
569
+ "keytool -genkey -v",
570
+ "-keystore '#{keystore_path}'",
571
+ "-alias '#{alias_name}'",
572
+ "-keyalg RSA -keysize 2048 -validity 10000",
573
+ "-storepass '#{alias_password}'",
574
+ "-keypass '#{key_password}'",
575
+ "-dname \"CN=#{full_name}, OU=#{org_unit}, O=#{org}, L=#{city_locality}, S=#{state_province}, C=#{country}\"",
576
+ ]
577
+ sh keytool_parts.join(" ")
578
+ else
579
+ UI.message("Copy existing keystore to match_android repository...")
580
+ `cp #{existing_keystore} #{keystore_path}`
581
+ end
582
+
583
+ UI.message("Generating Keystore properties...")
584
+
585
+ if File.file?(properties_path)
586
+ FileUtils.remove_dir(properties_path)
587
+ end
588
+
589
+ # Build URL:
590
+ store_file = git_url + '/' + package_name + '/' + keystore_name
591
+
592
+ out_file = File.new(properties_path, "w")
593
+ out_file.puts("keyFile=#{store_file}")
594
+ out_file.puts("keyPassword=#{key_password}")
595
+ out_file.puts("aliasName=#{alias_name}")
596
+ out_file.puts("aliasPassword=#{alias_password}")
597
+ out_file.close
598
+
599
+ self.encrypt_file(properties_path, properties_encrypt_path, key_path, false)
600
+ File.delete(properties_path)
601
+
602
+ # Print Keystore data in repo:
603
+ keystore_info_path = File.join(keystoreAppDir, keystore_info_name)
604
+ `yes "" | keytool -list -v -keystore '#{keystore_path}' -storepass '#{key_password}' > '#{keystore_info_path}'`
605
+
606
+ if !ci_mode
607
+ UI.message("Upload new Keystore to remote repository...")
608
+ puts ''
609
+ `cd '#{repo_dir}' && git add .`
610
+ `cd '#{repo_dir}' && git commit -m "[ADD] Keystore for app '#{package_name}'."`
611
+ `cd '#{repo_dir}' && git push`
612
+ puts ''
613
+ end
614
+
615
+ else
616
+ UI.message "Keystore file already exists, continue..."
617
+
618
+ self.decrypt_file(properties_encrypt_path, properties_path, key_path, false)
619
+
620
+ properties = self.load_properties(properties_path)
621
+ # Pry::ColorPrinter.pp(properties)
622
+ key_password = properties['keyPassword']
623
+ alias_name = properties['aliasName']
624
+ alias_password = properties['aliasPassword']
625
+
626
+ File.delete(properties_path)
627
+ end
628
+
629
+ # Sign APK:
630
+ if apk_path && File.file?(apk_path)
631
+ UI.message("APK to sign: " + apk_path)
632
+
633
+ # Resolve path to the APK to sign:
634
+ output_signed_apk = ''
635
+ apk_path = self.resolve_apk_path(apk_path)
636
+
637
+ if File.file?(keystore_path)
638
+
639
+ UI.message("Signing the APK...")
640
+ puts ''
641
+ output_signed_apk = self.sign_apk(
642
+ apk_path,
643
+ keystore_path,
644
+ key_password,
645
+ alias_name,
646
+ alias_password,
647
+ zip_align, # Zip align
648
+ build_tools_version # Buil-tools version
649
+ )
650
+ puts ''
651
+ end
652
+
653
+ # Prepare contect shared values for next lanes:
654
+ Actions.lane_context[SharedValues::MATCH_ANDROID_PATH] = keystore_path
655
+ Actions.lane_context[SharedValues::MATCH_ANDROID_ALIAS_NAME] = alias_name
656
+ Actions.lane_context[SharedValues::MATCH_ANDROID_APK_SIGNED] = output_signed_apk
657
+
658
+ output_signed_apk
659
+ # Sign AAB
660
+ elsif aab_path && File.file?(aab_path)
661
+ UI.message('AAB to sign: '+ aab_path)
662
+
663
+ # Resolve path to the AAB to sign:
664
+ output_signed_aab = ''
665
+ aab_path = self.resolve_aab_path(aab_path)
666
+
667
+ if File.file?(keystore_path)
668
+
669
+ UI.message("Signing the AAB...")
670
+ puts ''
671
+ output_signed_aab = self.sign_aab(
672
+ aab_path,
673
+ keystore_path,
674
+ key_password,
675
+ alias_name,
676
+ alias_password
677
+ )
678
+ puts ''
679
+ end
680
+
681
+ # Prepare contect shared values for next lanes:
682
+ Actions.lane_context[SharedValues::MATCH_ANDROID_PATH] = keystore_path
683
+ Actions.lane_context[SharedValues::MATCH_ANDROID_ALIAS_NAME] = alias_name
684
+ Actions.lane_context[SharedValues::MATCH_ANDROID_AAB_SIGNED] = output_signed_aab
685
+
686
+ output_signed_aab
687
+ else
688
+ UI.message("No APK or AAB file found")
689
+ end
690
+ end
691
+
692
+ def self.description
693
+ "Easily sync your Android keystores across your team"
694
+ end
695
+
696
+ def self.authors
697
+ ["Christopher NEY", "Simon Scherzinger"]
698
+ end
699
+
700
+ def self.return_value
701
+ "Prepare Keystore local path, alias name, and passwords for the specified App."
702
+ end
703
+
704
+ def self.output
705
+ [
706
+ ['MATCH_ANDROID_PATH', 'File path of the Keystore fot the App.'],
707
+ ['MATCH_ANDROID_ALIAS_NAME', 'Keystore Alias Name.'],
708
+ ['MATCH_ANDROID_APK_SIGNED', 'Path of the signed APK.'],
709
+ ['MATCH_ANDROID_AAB_SIGNED', 'Path of the signed AAB.']
710
+ ]
711
+ end
712
+
713
+ def self.details
714
+ # Optional:
715
+ "This way, your entire team can use the same account and have one code signing identity without any manual work or confusion."
716
+ end
717
+
718
+ def self.available_options
719
+ [
720
+ FastlaneCore::ConfigItem.new(key: :git_url,
721
+ env_name: "MATCH_ANDROID_GIT_URL",
722
+ description: "The URL of the Git repository (Github, BitBucket...)",
723
+ optional: false,
724
+ type: String),
725
+ FastlaneCore::ConfigItem.new(key: :package_name,
726
+ env_name: "MATCH_ANDROID_PACKAGE_NAME",
727
+ description: "The package name of the App",
728
+ optional: false,
729
+ type: String),
730
+ FastlaneCore::ConfigItem.new(key: :apk_path,
731
+ env_name: "MATCH_ANDROID_APK_PATH",
732
+ description: "Path of the APK file to sign",
733
+ optional: true,
734
+ type: String),
735
+ FastlaneCore::ConfigItem.new(key: :aab_path,
736
+ env_name: "MATCH_ANDROID_AAB_PATH",
737
+ description: "Path of the AAB file to sign",
738
+ optional: true,
739
+ type: String),
740
+ FastlaneCore::ConfigItem.new(key: :match_secret,
741
+ env_name: "MATCH_ANDROID_SECRET",
742
+ description: "Secret to decrypt keystore.properties file (CI)",
743
+ optional: true,
744
+ type: String),
745
+ FastlaneCore::ConfigItem.new(key: :existing_keystore,
746
+ env_name: "MATCH_ANDROID_EXISTING",
747
+ description: "Path of an existing Keystore",
748
+ optional: true,
749
+ type: String),
750
+ FastlaneCore::ConfigItem.new(key: :override_keystore,
751
+ env_name: "MATCH_ANDROID_OVERRIDE",
752
+ description: "Override an existing Keystore (false by default)",
753
+ optional: true,
754
+ type: Boolean),
755
+ FastlaneCore::ConfigItem.new(key: :keystore_data,
756
+ env_name: "MATCH_ANDROID_JSON_PATH",
757
+ description: "Required data to import an existing keystore, or create a new one",
758
+ optional: true,
759
+ type: String),
760
+ FastlaneCore::ConfigItem.new(key: :build_tools_version,
761
+ env_name: "MATCH_ANDROID_BUILD_TOOLS_VERSION",
762
+ description: "Set built-tools version (by default latest available on machine)",
763
+ optional: true,
764
+ type: String),
765
+ FastlaneCore::ConfigItem.new(key: :zip_align,
766
+ env_name: "MATCH_ANDROID_ZIPALIGN",
767
+ description: "Define if plugin will run zipalign on APK before sign it (true by default)",
768
+ optional: true,
769
+ type: Boolean),
770
+ FastlaneCore::ConfigItem.new(key: :compat_key,
771
+ env_name: "MATCH_ANDROID_COMPAT_KEY",
772
+ description: "Define the compatibility key version used on local machine (nil by default)",
773
+ optional: true,
774
+ type: String),
775
+ FastlaneCore::ConfigItem.new(key: :clear_keystore,
776
+ env_name: "MATCH_ANDROID_CLEAR",
777
+ description: "Clear the local keystore (false by default)",
778
+ optional: true,
779
+ type: Boolean),
780
+ FastlaneCore::ConfigItem.new(key: :unit_test,
781
+ env_name: "MATCH_ANDROID_UNIT_TESTS",
782
+ description: "launch Unit Tests (false by default)",
783
+ optional: true,
784
+ type: Boolean),
785
+ FastlaneCore::ConfigItem.new(key: :ci_mode,
786
+ env_name: "CI_MODE",
787
+ description: "Don't push the keys to repository even if they don't exist (false by default)",
788
+ optional: true,
789
+ type: Boolean)
790
+ ]
791
+ end
792
+
793
+ def self.is_supported?(platform)
794
+ # Adjust this if your plugin only works for a particular platform (iOS vs. Android, for example)
795
+ # See: https://docs.fastlane.tools/advanced/#control-configuration-by-lane-and-by-platform
796
+ [:android].include?(platform)
797
+ end
798
+ end
799
+ end
800
+ end
@@ -0,0 +1,16 @@
1
+ require 'fastlane_core/ui/ui'
2
+
3
+ module Fastlane
4
+ UI = FastlaneCore::UI unless Fastlane.const_defined?("UI")
5
+
6
+ module Helper
7
+ class MatchAndroidHelper
8
+ # class methods that you define here become available in your action
9
+ # as `Helper::MatchAndroidHelper.your_method`
10
+ #
11
+ def self.show_message
12
+ UI.message("Hello from the match_android plugin helper!")
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,5 @@
1
+ module Fastlane
2
+ module MatchAndroid
3
+ VERSION = "0.3.4"
4
+ end
5
+ end
@@ -0,0 +1,16 @@
1
+ require 'fastlane/plugin/match_android/version'
2
+
3
+ module Fastlane
4
+ module MatchAndroid
5
+ # Return all .rb files inside the "actions" and "helper" directory
6
+ def self.all_classes
7
+ Dir[File.expand_path('**/{actions,helper}/*.rb', File.dirname(__FILE__))]
8
+ end
9
+ end
10
+ end
11
+
12
+ # By default we want to import all available actions and helpers
13
+ # A plugin can contain any number of actions and plugins
14
+ Fastlane::MatchAndroid.all_classes.each do |current|
15
+ require current
16
+ end
metadata ADDED
@@ -0,0 +1,174 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fastlane-plugin-match_android_v2
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.3.4
5
+ platform: ruby
6
+ authors:
7
+ - Maikel Stuivenberg
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2025-05-23 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: pry
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec_junit_formatter
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rubocop
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '='
88
+ - !ruby/object:Gem::Version
89
+ version: 0.49.1
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - '='
95
+ - !ruby/object:Gem::Version
96
+ version: 0.49.1
97
+ - !ruby/object:Gem::Dependency
98
+ name: rubocop-require_tools
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: simplecov
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: fastlane
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: 2.144.0
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: 2.144.0
139
+ description:
140
+ email: maikel.stuivenberg@gmail.com
141
+ executables: []
142
+ extensions: []
143
+ extra_rdoc_files: []
144
+ files:
145
+ - LICENSE
146
+ - README.md
147
+ - lib/fastlane/plugin/match_android.rb
148
+ - lib/fastlane/plugin/match_android/actions/match_android_action.rb
149
+ - lib/fastlane/plugin/match_android/helper/match_android_helper.rb
150
+ - lib/fastlane/plugin/match_android/version.rb
151
+ homepage: https://github.com/CursedMun/fastlane-plugin-match_android
152
+ licenses:
153
+ - MIT
154
+ metadata: {}
155
+ post_install_message:
156
+ rdoc_options: []
157
+ require_paths:
158
+ - lib
159
+ required_ruby_version: !ruby/object:Gem::Requirement
160
+ requirements:
161
+ - - ">="
162
+ - !ruby/object:Gem::Version
163
+ version: '0'
164
+ required_rubygems_version: !ruby/object:Gem::Requirement
165
+ requirements:
166
+ - - ">="
167
+ - !ruby/object:Gem::Version
168
+ version: '0'
169
+ requirements: []
170
+ rubygems_version: 3.4.1
171
+ signing_key:
172
+ specification_version: 4
173
+ summary: Share your Android keystore with your team in a secure way
174
+ test_files: []