Class: Cert::DeveloperCenter

Inherits:
FastlaneCore::DeveloperCenter
  • Object
show all
Defined in:
lib/cert/developer_center.rb

Constant Summary collapse

DISTRIBUTION =
"Distribution"
DEVELOPMENT =
"Development"
CERTS_URL =
"https://developer.apple.com/account/ios/certificate/certificateList.action?type=distribution"
CERTS_URL_DEV =
"https://developer.apple.com/account/ios/certificate/certificateList.action?type=development"
CREATE_CERT_URL =
"https://developer.apple.com/account/ios/certificate/certificateCreate.action"

Instance Method Summary collapse

Instance Method Details

#create_certificateObject

This will actually create a new certificate



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# File 'lib/cert/developer_center.rb', line 58

def create_certificate
  visit CREATE_CERT_URL
  wait_for_elements("form[name='certificateSave']")

  Helper.log.info "Creating a new code signing certificate"

  # select certificate type
  toggle_value = 'type-iosNoOCSP'
  toggle_value = 'type-development' if @type == DEVELOPMENT
  app_store_toggle = first("input##{toggle_value}")
  if !!app_store_toggle['disabled']
    # Limit of certificates already reached
    raise "Could not create another certificate, reached the maximum number of available certificates.".red
  end

  app_store_toggle.click

  click_next # submit the certificate type
  sleep 2
  click_next # information about how to upload the file (no action required on this step)

  cert_signing_request = Cert::SigningRequest.get_path
  Helper.log.info "Uploading the cert signing request '#{cert_signing_request}'"

  wait_for_elements("input[name='upload']").first.set cert_signing_request # upload the cert signing request
  sleep 1
  click_next

  sleep 3

  while all(:css, '.loadingMessage').count > 0
    Helper.log.debug "Waiting for iTC to generate the profile"
    sleep 2
  end

  Helper.log.info "Downloading newly generated certificate"
  sleep 2

  # Now download the certificate
  download_button = wait_for_elements(".button.small.blue").first
  url = download_button['href']

  path = File.join(TMP_FOLDER, "certificate.cer")
  download_url(url, path)

  certificate_id = url.match(/.*displayId=(.*)&type.*/)[1]

  ENV["CER_FILE_PATH"] = path
  ENV["CER_CERTIFICATE_ID"] = certificate_id
  Helper.log.info "Successfully downloaded latest .cer file to '#{path}' (#{certificate_id})".green

  Cert::KeychainImporter::import_file(path)
rescue => ex
  error_occured(ex)
end

#find_existing_certObject



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/cert/developer_center.rb', line 27

def find_existing_cert
  if @type == DEVELOPMENT
    visit CERTS_URL_DEV
  else
    visit CERTS_URL
  end

  # Download all available certs to check if they are installed using the SHA1 hash
  certs = code_signing_certificate
  certs.each do |current|
    display_id = current['certificateId']
    type_id = current['certificateTypeDisplayId']
    url = "/account/ios/certificate/certificateContentDownload.action?displayId=#{display_id}&type=#{type_id}"

    output = File.join(TMP_FOLDER, "#{display_id}-#{type_id}.cer")
    download_url(url, output)
    if Cert::CertChecker.is_installed?output
      # We'll use this one, since it's installed on the local machine
      ENV["CER_CERTIFICATE_ID"] = display_id
      Helper.log.info "Found the certificate #{display_id}-#{type_id} which is installed on the local machine. Using this one.".green
      return output
    end
  end

  Helper.log.info "Couldn't find an existing certificate... creating a new one"
  return false
rescue => ex
  error_occured(ex)
end

#runObject

This will check if there is at least one of the certificates already installed on the local machine This will store the resulting file name in ENV ‘CER_FILE_PATH’ and the Cert ID in ‘CER_CERTIFICATE_ID’



14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/cert/developer_center.rb', line 14

def run
  @type = (Cert.config[:development] ? DEVELOPMENT : DISTRIBUTION)
  file = find_existing_cert
  if file
    # We don't need to do anything :)
    ENV["CER_FILE_PATH"] = file
  else
    create_certificate
  end
rescue => ex
  error_occured(ex)
end