-
Notifications
You must be signed in to change notification settings - Fork 0
/
decrypt.rb
executable file
·46 lines (34 loc) · 1.35 KB
/
decrypt.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/usr/bin/env ruby
def error(*msg)
msg.each { |m| puts "Decrypt Error: #{m}" }
exit 1
end
def log(*msg)
msg.each { |m| puts "Decrypt: #{m}" }
end
def require_or_error(gem_name)
error("plist gem is not installed, please do ") unless require(gem_name)
end
require_or_error 'json'
require_or_error 'plist'
keydir = ENV.fetch("EJSON_KEYS_PATH", "~/.ejson_keys")
ejson_path = ENV.fetch("EJSON_SECRETS_FILE", "secrets.ejson")
ejson_full_path = File.exist?(ejson_path) && File.absolute_path(ejson_path)
built_products_dir = ENV.fetch("BUILT_PRODUCTS_DIR")
app_product = "#{ENV.fetch("PRODUCT_NAME")}.app"
secrets_plist = "Fidelius.plist"
secrets_plist_path = [built_products_dir, app_product, secrets_plist].join("/")
error("#{ejson_full_path} does not exist") unless ejson_full_path
error("Key directory #{keydir} not found") unless Dir.exists? keydir
log("Found secrets at #{ejson_full_path}")
# Decrypt secrets
secrets = `ejson -keydir #{keydir} decrypt #{ejson_full_path}`.strip
# Parse secrets
json_secrets = begin
JSON.parse(secrets)
rescue JSON::ParserError
error("#{ejson_path} file is not parseable. Please check it and confirm it is in the proper format")
end
json_secrets.delete("_public_key")
log("Writing secrets to #{secrets_plist_path}")
File.write(secrets_plist_path, json_secrets.to_plist)