Module: CertStepper

Defined in:
lib/certstepper.rb

Defined Under Namespace

Classes: Cert

Class Method Summary collapse

Class Method Details

.copyToClipboard(content) ⇒ Object



171
172
173
# File 'lib/certstepper.rb', line 171

def self.copyToClipboard(content)
  system  ("echo #{content} | pbcopy")
end

.createDir(filePath) ⇒ Object



175
176
177
# File 'lib/certstepper.rb', line 175

def self.createDir(filePath)
   Dir.mkdir filePath if !Dir.exist?  filePath
end

.dealCert(cert) ⇒ Object



187
188
189
190
191
192
# File 'lib/certstepper.rb', line 187

def self.dealCert(cert)
  system "security create-keychain -P 123456"
  system "security add-trusted-cert -r unspecified -k 123456 #{File.expand_path('~')}/Downloads/ios_development.cer"
  system "security export -k 123456 -t certs -f pkcs12 -o #{@@root_path}/#{cert.profile_name}/cert.p12"
  system "security delete-keychain 123456"
end

.dealCertByChrome(root_path, profile_name) ⇒ Object



194
195
196
197
198
199
# File 'lib/certstepper.rb', line 194

def self.dealCertByChrome(root_path , profile_name)
  system "security create-keychain -P 123456"
  system "security add-trusted-cert -r unspecified -k 123456 #{File.expand_path('~')}/Downloads/ios_development.cer"
  system "security export -k 123456 -t certs -f pkcs12 -o #{root_path}/#{profile_name}/cert.p12"
  system "security delete-keychain 123456"
end

.getUserInputObject



179
180
181
182
183
184
185
# File 'lib/certstepper.rb', line 179

def self.getUserInput 
      begin
        return $stdin.gets
       rescue  => e
         
      end
end

.parseData(start_path) ⇒ Object



136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
# File 'lib/certstepper.rb', line 136

def self.parseData(start_path)
  @@certs = Array.new
  index = 0
  file_name = start_path
  @@root_path = Pathname.new(file_name).parent.to_s
  @@file_path 
  new_cert = nil
 file = File.open(file_name , "r")
  line_array = file.readlines
  file_content= line_array.join
  file_content = file_content.gsub /[\r]/,"\n"
  file_content.each_line do |line|
     cert_prop_index = index%3
     line_content = line.gsub! /[\s\n\t\r]/ ,""
     if  line_content !=nil && !line_content.empty?
        case cert_prop_index
        when 0
          new_cert = Cert.new
          @@certs << new_cert
          new_cert.email = line_content.strip
        when 1
          new_cert.password = line_content.strip
        when 2
          new_cert.profile_id = line_content.strip
          line_content.strip.split(".").each do |comp|
            new_cert.profile_name = comp if comp =~ /\b\w?\d+\b/ 
          end
        end
        index+=1
     end 
  end
 file.close

end

.startStepObject



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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/certstepper.rb', line 30

def self.startStep
  # if ARGV.length==0 || ARGV == nil
 #      puts "error: Parameter does not match,there is not any parameter"
 #      return nil
 #    end
  

    file = File.open("#{File.expand_path('~')}/certstepper.log", "w")
    file.write("#{ARGV}\n")

     begin
       if ARGV[0].start_with? "chrome-extension:"
         finished = false
         while !finished do 
           str = self.getUserInput[1..-1]
           str =str.strip_control_characters

           file.write("#{str}\n")


           file.write "start parse #{str.class}\n"
           my_hash = JSON.parse str
           file.write("end parse#{my_hash}\n")

           start_path = my_hash["start_path"] 
           profile_name = my_hash["name"]
           if start_path 
             file.write("#start work \n")
             self.startWorkByChromeExtension start_path , profile_name
             finished = true
           end
         end
       else 
         self.parseData ARGV[0]
         self.startWork
       end

     rescue => e 
       f.write e.backtrace 
     end
     

    file.close
end

.startWorkObject



90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
# File 'lib/certstepper.rb', line 90

def self.startWork
              
      console_root_path = @@root_path.gsub /[\s]/ , "\\ "
      open_dir ="open #{console_root_path}"
      system("open #{console_root_path}")
      puts "Apple Cert Create Stepper\n"
      @@certs.each do |cert|
         puts "----------- begin  #{cert.profile_id} Cert ----------- \n"
         self.createDir @@root_path + "/#{cert.profile_name}"
         puts "1. copy email. <press enter>"
         self.getUserInput
         self.copyToClipboard cert.email
         puts "email coppied : #{cert.email}\n"
         puts "2. copy password. <press enter>"
         self.getUserInput
         self.copyToClipboard cert.password
         puts "password coppied : #{cert.password}\n"
         puts "3.import and export cert"
         self.dealCert cert
         puts "4. copy profile name. <press enter>"
         self.getUserInput
         self.copyToClipboard cert.profile_name
         puts "name coppied : #{cert.profile_name}\n"
         puts "\n5. copy profile id. <press enter>"
         self.getUserInput
         self.copyToClipboard  cert.profile_id
         puts "id coppied : #{cert.profile_id}"
         puts "\n6. copy profile name. <press enter>"
         self.getUserInput
         self.copyToClipboard cert.profile_name
         puts "name coppied : #{cert.profile_name}\n"
         puts "\n7. move profile to destination from download. <press enter>"
         self.getUserInput
         mobileprovision_name = "#{cert.profile_name}.mobileprovision"
         source_file = "#{File.expand_path('~')}/Downloads/#{mobileprovision_name}" 
         dest_file = "#{@@root_path}/#{cert.profile_name}/#{mobileprovision_name}"
         if File.exist? source_file
           FileUtils.mv source_file , dest_file 
           puts "#{mobileprovision_name} moved\n\n"
         else 
           puts "#{mobileprovision_name} doesn't exist. Please download and move by yourself !\n\n"
         end

      end 
end

.startWorkByChromeExtension(root_path, profile_name) ⇒ Object



75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/certstepper.rb', line 75

def self.startWorkByChromeExtension(root_path,profile_name)
  file = File.open("/Users/mac/Desktop/CertSimplify/some_file", "a")
  console_root_path = root_path.gsub /[\s]/ , "\\ "
  system("open #{console_root_path}")
  self.createDir root_path + "/#{profile_name}"
  self.dealCertByChrome root_path , profile_name
  mobileprovision_name = "#{profile_name}.mobileprovision"
  source_file = "#{File.expand_path('~')}/Downloads/#{mobileprovision_name}" 
  dest_file = "#{root_path}/#{profile_name}/#{mobileprovision_name}"
  if File.exist? source_file
     FileUtils.mv source_file , dest_file 
  end

end