lib/motion-provisioning/certificate.rb in motion-provisioning-0.0.3 vs lib/motion-provisioning/certificate.rb in motion-provisioning-0.0.4
- old
+ new
@@ -1,19 +1,7 @@
-module Spaceship
- module Portal
- class Certificate
- # The PLIST request for the free certificate returns the certificate content
- # in the certContent variable. It's stored in this attribute for later use.
- attr_accessor :motionprovisioning_certContent,
- :motionprovisioning_serialNumber
- end
- end
-end
-
module MotionProvisioning
class Certificate
-
attr_accessor :type, :output_path, :platform
def client
MotionProvisioning.client
end
@@ -39,11 +27,11 @@
return installed_cert[:name]
else
# The certificate is not installed, so we install the cert and the key
import_file(private_key_path)
import_file(certificate_path)
- name = common_name(certificate_path)
+ name = common_name(certificate_path)
Utils.log("Info", "Using certificate '#{name}'.")
return name
end
end
@@ -51,13 +39,10 @@
FileUtils.mkdir_p(File.expand_path('./provisioning'))
# Make sure a client is created and logged in
client
- # All the certificates for the specified type
- user_certificates = certificates
-
# Lets see if any of the user certificates is in the keychain
installed_certificate = nil
if !certificates.empty?
installed_certs_sha1 = identities.map { |e| e[:fingerprint] }
installed_certificate = certificates.detect do |certificate|
@@ -65,37 +50,37 @@
installed_certs_sha1.include?(sha1.to_s.upcase)
end
end
# There are no certificates in the server so we create a new one
- if user_certificates.empty?
+ if certificates.empty?
Utils.log("Warning", "Couldn't find any existing certificates... creating a new one.")
if certificate = create_certificate
return common_name(certificate)
else
Utils.log("Error", "Something went wrong when trying to create a new certificate.")
abort
end
# There are certificates in the server, but none is installed locally. Revoke all and create a new one.
elsif installed_certificate.nil?
- Utils.log("Error", "None of the available certificates (#{user_certificates.count}) is installed on the local machine. Revoking...")
+ Utils.log("Error", "None of the available certificates (#{certificates.count}) is installed on the local machine. Revoking...")
# For distribution, ask before revoking
if self.type == :distribution
- answer = Utils.ask("Info", "There are #{user_certificates.count} distribution certificates in your account, but none installed locally.\n" \
+ answer = Utils.ask("Info", "There are #{certificates.count} distribution certificates in your account, but none installed locally.\n" \
"Before revoking and creating a new one, ask other team members who might have them installed to share them with you.\n" \
"Do you want to continue revoking the certificates? (Y/n):")
- abort if answer.downcase != "y"
+ abort if answer.no?
end
# Revoke all and create new one
if MotionProvisioning.free
- user_certificates.each do |certificate|
+ certificates.each do |certificate|
client.revoke_development_certificate(certificate.motionprovisioning_serialNumber)
end
else
- user_certificates.each(&:revoke!)
+ certificates.each(&:revoke!)
end
if certificate = create_certificate
return common_name(certificate)
else
@@ -104,24 +89,20 @@
end
# There are certificates on the server, and one of them is installed locally.
else
Utils.log("Info", "Found certificate '#{installed_certificate.name}' which is installed in the local machine.")
- path = store_certificate_raw(installed_certificate.motionprovisioning_certContent ||installed_certificate.download_raw)
+ path = store_certificate_raw(installed_certificate.motionprovisioning_certContent || installed_certificate.download_raw)
password = Utils.ask_password("Info", "Exporting private key from Keychain for certificate '#{installed_certificate.name}'. Choose a password (you will be asked for this password when importing this key into the Keychain in another machine):")
private_key_contents = private_key(common_name(path), sha1_fingerprint(path), password)
- if private_key_contents.empty?
- Utils.log("Error", "Could not export private key for certificate '#{installed_certificate.name}'.")
- abort
- end
File.write(private_key_path, private_key_contents)
# This certificate is installed on the local machine
Utils.log("Info", "Using certificate '#{installed_certificate.name}'.")
- return common_name(path)
+ common_name(path)
end
end
# All certificates of this type
def certificates
@@ -217,10 +198,10 @@
else
Utils.log("Warning", "You have just created a development certificate. If you want to use this certificate on another machine, transfer the private key (.p12) and certificate (.cer) files in your /provisioning folder and install them in the keychain.")
end
Utils.ask("Info", "Press any key to continue...")
- return cert_path
+ cert_path
end
def store_certificate_raw(raw_data)
path = File.expand_path(File.join(self.output_path, "#{platform}_#{type}_certificate.cer"))
File.write(path, raw_data)