Skip to content

Commit

Permalink
feat: fastlane command to create voip push certificates
Browse files Browse the repository at this point in the history
  • Loading branch information
glouvigny committed Jan 30, 2019
1 parent 7f0e849 commit b498b81
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 0 deletions.
4 changes: 4 additions & 0 deletions client/react-native/Makefile
Expand Up @@ -314,19 +314,23 @@ fastlane.match.enterprise:
fastlane.match.all: fastlane.match.development fastlane.match.appstore fastlane.match.adhoc fastlane.match.enterprise

fastlane.pem.development:
time bundle exec fastlane voip_cert app_identifier:$(IOS_BUNDLE_ID_DEBUG) team_id:$(PEM_COMPANY_TEAM_ID) pem_name:$(IOS_BUNDLE_ID_DEBUG)-voip.pem
time bundle exec fastlane pem --app_identifier $(IOS_BUNDLE_ID_DEBUG) --team_id $(PEM_COMPANY_TEAM_ID) --pem_name $(IOS_BUNDLE_ID_DEBUG)-dev.pem --development

fastlane.pem.appstore:
time bundle exec fastlane voip_cert app_identifier:$(IOS_BUNDLE_ID_RELEASE) team_id:$(PEM_COMPANY_TEAM_ID) pem_name:$(IOS_BUNDLE_ID_RELEASE)-voip.pem
time bundle exec fastlane pem --app_identifier $(IOS_BUNDLE_ID_RELEASE) --team_id $(PEM_COMPANY_TEAM_ID) --pem_name $(IOS_BUNDLE_ID_RELEASE).pem
time bundle exec fastlane pem --app_identifier $(IOS_BUNDLE_ID_RELEASE) --team_id $(PEM_COMPANY_TEAM_ID) --pem_name $(IOS_BUNDLE_ID_RELEASE)-dev.pem --development

fastlane.pem.adhoc:
time bundle exec fastlane pem --app_identifier $(IOS_BUNDLE_ID_ADHOC) --team_id $(PEM_COMPANY_TEAM_ID) --pem_name $(IOS_BUNDLE_ID_ADHOC).pem
time bundle exec fastlane pem --app_identifier $(IOS_BUNDLE_ID_ADHOC) --team_id $(PEM_COMPANY_TEAM_ID) --pem_name $(IOS_BUNDLE_ID_ADHOC)-dev.pem --development
time bundle exec fastlane voip_cert app_identifier:$(IOS_BUNDLE_ID_ADHOC) team_id:$(PEM_COMPANY_TEAM_ID) pem_name:$(IOS_BUNDLE_ID_ADHOC)-voip.pem

fastlane.pem.enterprise:
time bundle exec fastlane pem --app_identifier $(IOS_BUNDLE_ID_HOUSE) --team_id $(PEM_ENTERPRISE_TEAM_ID) --pem_name $(IOS_BUNDLE_ID_HOUSE).pem
time bundle exec fastlane pem --app_identifier $(IOS_BUNDLE_ID_HOUSE) --team_id $(PEM_ENTERPRISE_TEAM_ID) --pem_name $(IOS_BUNDLE_ID_HOUSE)-dev.pem --development
time bundle exec fastlane voip_cert app_identifier:$(IOS_BUNDLE_ID_HOUSE) team_id:$(PEM_ENTERPRISE_TEAM_ID) pem_name:$(IOS_BUNDLE_ID_HOUSE)-voip.pem

fastlane.setup_circle:
bundle exec fastlane run create_keychain timeout:3600 default_keychain:true unlock:true add_to_search_list:true
Expand Down
47 changes: 47 additions & 0 deletions client/react-native/fastlane/Fastfile
Expand Up @@ -13,6 +13,8 @@
# # Uncomment the line if you want fastlane to automatically update itself
# # update_fastlane

fastlane_require 'spaceship'

fastlane_version "2.76.1"

default_platform :ios
Expand All @@ -36,4 +38,49 @@ platform :ios do
end

end

lane :voip_cert do |options|
app_identifier = options[:app_identifier]
apple_id = ENV['PEM_USERNAME']
team_id = options[:team_id]
output_path = ENV['PEM_OUTPUT_PATH']
p12_password = options[:p12_password]
filename_base = options[:pem_name].gsub('.pem', '')
p12_cert_path = File.absolute_path(File.join(output_path, "#{filename_base}.p12"), File.expand_path('../..', __FILE__))
x509_cert_path = File.absolute_path(File.join(output_path, "#{filename_base}.pem"), File.expand_path('../..', __FILE__))
certificate_type = "voippush"
active_days_limit = 30

UI.important "Creating a new voip certificate for app '#{app_identifier}'."

Spaceship.login(apple_id, nil)
Spaceship.select_team(team_id: team_id)

certificate_sorted = Spaceship.certificate.voip_push.all.sort { |x, y| y.expires <=> x.expires }

existing_certificate = certificate_sorted.detect do |c|
c.owner_name == app_identifier
end

if existing_certificate.nil? == false
remaining_days = (existing_certificate.expires - Time.now) / 60 / 60 / 24
UI.message("Existing push notification profile for '#{existing_certificate.owner_name}' is valid for #{remaining_days.round} more days.")
if remaining_days > active_days_limit
UI.success("You already have a push certificate, which is active for more than #{active_days_limit} more days. No need to create a new one")
exit!
end
end

csr, pkey = Spaceship::Certificate.create_certificate_signing_request
cert = Spaceship::Certificate::VoipPush.create!(csr:csr,bundle_id:app_identifier)

x509_certificate = cert.download

p12 = OpenSSL::PKCS12.create(p12_password, certificate_type, pkey, x509_certificate)
File.write(p12_cert_path, p12.to_der)
UI.message("p12 certificate: ".green + Pathname.new(p12_cert_path).realpath.to_s)

File.write(x509_cert_path, x509_certificate.to_pem + pkey.to_pem)
UI.message("PEM: ".green + Pathname.new(x509_cert_path).realpath.to_s)
end
end
5 changes: 5 additions & 0 deletions client/react-native/fastlane/README.md
Expand Up @@ -21,6 +21,11 @@ or alternatively using `brew cask install fastlane`
fastlane ios build
```

### ios voip_cert
```
fastlane ios voip_cert
```


----

Expand Down

0 comments on commit b498b81

Please sign in to comment.