apns-key-convert 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +7 -0
  2. data/bin/apns-key-convert +66 -0
  3. metadata +48 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 8cc726d7b423be7e3fd365708e376ba1cc6da7dd
4
+ data.tar.gz: 3665076edb6c69e9bd0e8a2c4f8f73573f36c398
5
+ SHA512:
6
+ metadata.gz: 778e8cc8a1dc8cf2d3e841f7d4c517ef909b6c1e303415b7e497709a3d88e935f0bf87da544e7a863ec82ca58463f3b57d50d08b6f643344091ad81278daff36
7
+ data.tar.gz: 8420fbee610edd53c154962306ba2647c33306c2638f05bcd53f4993a00dd5cc0d67a2231794c5fd78c8381146b70a160c4e28fea45a3c7deb09f9392fe0b813
@@ -0,0 +1,66 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ class String
4
+ def red
5
+ "\e[31m#{self}\e[0m"
6
+ end
7
+ end
8
+
9
+ raw_private_key_path = ARGV[0]
10
+ raw_certificate_path = ARGV[1]
11
+
12
+ if raw_certificate_path.nil? && raw_certificate_path.nil?
13
+ STDERR.puts "usage: apns-key-convert [path/to/privatekey.p12] [path/to/certificate.cer]".red
14
+ Process.exit(1)
15
+ end
16
+
17
+ unless raw_private_key_path =~ /\.p12\z/
18
+ STDERR.puts "Expected private key to end with .p12.".red
19
+ STDERR.puts "You should pass the key as you exported it from keychain access."
20
+ Process.exit(1)
21
+ end
22
+
23
+ unless File.file?(raw_private_key_path)
24
+ STDERR.puts "Private key does not exist at #{raw_private_key_path}".red
25
+ Process.exit(1)
26
+ end
27
+
28
+ unless raw_certificate_path =~ /\.cer\z/
29
+ STDERR.puts "Expected certificate to end with .cer.".red
30
+ STDERR.puts "You should pass the certificate as downloaded from Apple developer tools."
31
+ Process.exit(1)
32
+ end
33
+
34
+ unless File.file?(raw_certificate_path)
35
+ STDERR.puts "Private key does not exist at #{raw_certificate_path}".red
36
+ Process.exit(1)
37
+ end
38
+
39
+ require 'openssl'
40
+ require 'io/console'
41
+
42
+ #
43
+ # Convert the p12 to pem
44
+ #
45
+
46
+ STDERR.puts "Enter the passphrase for this key: "
47
+ passphrase = STDIN.noecho(&:gets)
48
+
49
+ begin
50
+ private_key = OpenSSL::PKCS12.new(File.read(raw_private_key_path), passphrase.chomp)
51
+ rescue OpenSSL::PKCS12::PKCS12Error
52
+ STDERR.puts "The passphase entered is incorrect. Please check and try again.".red
53
+ Process.exit(1)
54
+ end
55
+
56
+ #
57
+ # Convert the certificate to pem
58
+ #
59
+ certificate = OpenSSL::X509::Certificate.new(File.read(raw_certificate_path))
60
+
61
+ #
62
+ # Puts the resulting file
63
+ #
64
+
65
+ puts private_key.key.to_s
66
+ puts certificate.to_s
metadata ADDED
@@ -0,0 +1,48 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: apns-key-convert
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Adam Cooke
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-06-20 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: This script will take a P12 and CER file and generate a PEM file for
14
+ use when sending notifications.
15
+ email:
16
+ - me@adamcooke.io
17
+ executables:
18
+ - apns-key-convert
19
+ extensions: []
20
+ extra_rdoc_files: []
21
+ files:
22
+ - bin/apns-key-convert
23
+ homepage: http://adamcooke.io
24
+ licenses:
25
+ - MIT
26
+ metadata: {}
27
+ post_install_message:
28
+ rdoc_options: []
29
+ require_paths:
30
+ - lib
31
+ required_ruby_version: !ruby/object:Gem::Requirement
32
+ requirements:
33
+ - - ">="
34
+ - !ruby/object:Gem::Version
35
+ version: '0'
36
+ required_rubygems_version: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ requirements: []
42
+ rubyforge_project:
43
+ rubygems_version: 2.2.0
44
+ signing_key:
45
+ specification_version: 4
46
+ summary: A quick script for generating APNS key PEM files.
47
+ test_files: []
48
+ has_rdoc: