mdmCSR 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: a3986054f88377ae0608af729006bf0b27e20532
4
+ data.tar.gz: a31ab262c1e74936cfcf4bd37723bd77b0fb645c
5
+ SHA512:
6
+ metadata.gz: 89aaf21c0c42f0ac3b5a411934f4e50826f8112067b797507ff2d238435aba345c01e7e604e63eece4cc9822f5ae846f22388c16a018cc33b70639853f3b4eac
7
+ data.tar.gz: f9f2286fd3abc74765ce2a989b0c0785c0faa08b1a24bdf9fb1f279ce9b2c0bbb493b6f6c91eee8df07511295c914d5e0f788c389be0fd769596a81228846f36
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in mdmCSR.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,45 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ mdmCSR (0.1.0)
5
+ nokogiri
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ coderay (1.1.1)
11
+ diff-lcs (1.2.5)
12
+ method_source (0.8.2)
13
+ mini_portile2 (2.0.0)
14
+ nokogiri (1.6.7.2)
15
+ mini_portile2 (~> 2.0.0.rc2)
16
+ pry (0.10.3)
17
+ coderay (~> 1.1.0)
18
+ method_source (~> 0.8.1)
19
+ slop (~> 3.4)
20
+ rspec (3.4.0)
21
+ rspec-core (~> 3.4.0)
22
+ rspec-expectations (~> 3.4.0)
23
+ rspec-mocks (~> 3.4.0)
24
+ rspec-core (3.4.4)
25
+ rspec-support (~> 3.4.0)
26
+ rspec-expectations (3.4.0)
27
+ diff-lcs (>= 1.2.0, < 2.0)
28
+ rspec-support (~> 3.4.0)
29
+ rspec-mocks (3.4.1)
30
+ diff-lcs (>= 1.2.0, < 2.0)
31
+ rspec-support (~> 3.4.0)
32
+ rspec-support (3.4.1)
33
+ slop (3.6.0)
34
+
35
+ PLATFORMS
36
+ ruby
37
+
38
+ DEPENDENCIES
39
+ bundler (~> 1.11)
40
+ mdmCSR!
41
+ pry
42
+ rspec (~> 3.0)
43
+
44
+ BUNDLED WITH
45
+ 1.11.2
data/README.md ADDED
@@ -0,0 +1,39 @@
1
+ # MdmCSR
2
+
3
+ Generate apple MDM vendor CSR signing file to upload to https://identity.apple.com/pushcert/
4
+
5
+
6
+ ## Installation
7
+
8
+ Add this line to your application's Gemfile:
9
+
10
+ ```ruby
11
+ gem 'mdmCSR'
12
+ ```
13
+
14
+ And then execute:
15
+
16
+ $ bundle
17
+
18
+ Or install it yourself as:
19
+
20
+ $ gem install mdmCSR
21
+
22
+ ## Usage
23
+
24
+ ```ruby
25
+ params = {
26
+ country: 'CL',
27
+ state: 'RM',
28
+ city: 'Santiago',
29
+ department: 'Web',
30
+ organization: 'Example Inc.',
31
+ common_name: 'example.com',
32
+ email: 'example@email.com'
33
+ }
34
+
35
+ @certificate = MdmCSR::Certificate.new(params)
36
+ ```
37
+
38
+ this will create the certificate_signing_request.plist that you need upload to https://identity.apple.com/pushcert/
39
+
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "mdmCSR"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,25 @@
1
+ -----BEGIN CERTIFICATE-----
2
+ MIIEIjCCAwqgAwIBAgIIAd68xDltoBAwDQ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J4V9T0mZyCKM2r3DYLP3uujL/lTaltkwGMzd/c6ByxW69oP
26
+ IQ7aunMZT7XZNn/Bh1XZp5m5MkL72NVxnn6hUrcbvZNCJBIqxw8dtk2cXmPIS4AX
27
+ UKqK1drk/NAJBzewdXUh
28
+ -----END CERTIFICATE-----
@@ -0,0 +1 @@
1
+ your vendor.p12 file
data/lib/mdmCSR.rb ADDED
@@ -0,0 +1,100 @@
1
+ require "mdmCSR/version"
2
+ require 'nokogiri'
3
+ require 'base64'
4
+
5
+ module MdmCSR
6
+ class Certificate
7
+
8
+ attr_reader :country, :state, :city, :department, :organization,
9
+ :common_name, :email
10
+
11
+ def initialize(country:, state:, city:, department:, organization:,
12
+ common_name:, email:)
13
+
14
+ @country = country
15
+ @state = state
16
+ @city = city
17
+ @department = department
18
+ @organization = organization
19
+ @common_name = common_name
20
+ @email = email
21
+
22
+ generate_csr
23
+ end
24
+
25
+ private
26
+
27
+ def generate_csr
28
+
29
+ rsa_key = OpenSSL::PKey::RSA.new(2048)
30
+
31
+ digest = OpenSSL::Digest::SHA256.new
32
+ request = OpenSSL::X509::Request.new.tap do |r|
33
+ r.version = 0
34
+ r.subject = OpenSSL::X509::Name.new([
35
+ ["C", @country, OpenSSL::ASN1::PRINTABLESTRING],
36
+ ["ST", @state, OpenSSL::ASN1::PRINTABLESTRING],
37
+ ["L", @city, OpenSSL::ASN1::PRINTABLESTRING],
38
+ ["O", @organization, OpenSSL::ASN1::UTF8STRING],
39
+ ["OU", @department, OpenSSL::ASN1::UTF8STRING],
40
+ ["CN", @common_name, OpenSSL::ASN1::UTF8STRING],
41
+ ["emailAddress", @email, OpenSSL::ASN1::UTF8STRING]
42
+ ])
43
+
44
+ r.public_key = rsa_key.public_key
45
+ r.sign(rsa_key, digest)
46
+ end
47
+
48
+ csr_64 = Base64.encode64(request.to_der)
49
+
50
+ signature = sign_csr(request.to_der)
51
+
52
+ create_plist(csr_64, signature)
53
+ end
54
+
55
+ def create_plist(csr_64, signature)
56
+
57
+ load_certificates
58
+
59
+ builder = Nokogiri::XML::Builder.new do |xml|
60
+ xml.doc.create_internal_subset(
61
+ 'plist',
62
+ "-//Apple//DTD PLIST 1.0//EN",
63
+ "http://www.apple.com/DTDs/PropertyList-1.0.dtd"
64
+ )
65
+ xml.plist('version' => '1.0') do
66
+ xml.dict do
67
+ xml.key "PushCertRequestCSR"
68
+ xml.string csr_64
69
+ xml.key "PushCertSignature"
70
+ xml.string signature
71
+ xml.key "PushCertCertificateChain"
72
+ xml.string "#{@mdm_cert}#{@apple_cert}#{@apple_root_cert}"
73
+ end
74
+ end
75
+ end
76
+
77
+ plist_file = File.new("certificate_signing_request.plist", "w")
78
+ plist_file.puts(Base64.encode64(builder.to_xml))
79
+ plist_file.close
80
+ end
81
+
82
+ def load_private_key
83
+ vendor = OpenSSL::PKCS12.new(File.read "certificates/vendor.p12")
84
+ vendor.key
85
+ end
86
+
87
+ def load_certificates
88
+ @apple_root_cert = File.read "certificates/root.pem"
89
+ @apple_cert = File.read "certificates/intermediate.pem"
90
+ @mdm_cert = File.read "certificates/mdm.pem"
91
+ end
92
+
93
+ def sign_csr(csr_content)
94
+ digest = OpenSSL::Digest::SHA1.new
95
+ private_key = load_private_key
96
+ Base64.encode64(private_key.sign(digest, csr_content))
97
+ end
98
+
99
+ end
100
+ end
@@ -0,0 +1,3 @@
1
+ module MdmCSR
2
+ VERSION = "0.1.0"
3
+ end
data/mdmCSR.gemspec ADDED
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'mdmCSR/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "mdmCSR"
8
+ spec.version = MdmCSR::VERSION
9
+ spec.authors = ["patricio jofre"]
10
+ spec.email = ["luis.jofre.g@gmail.com"]
11
+
12
+ spec.summary = "Apple MDM vendor CSR signing"
13
+ spec.description = "Apple MDM vendor CSR signing"
14
+ spec.homepage = "https://github.com/patriciojofre"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
+ spec.bindir = "exe"
18
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency "nokogiri"
22
+
23
+ spec.add_development_dependency "pry"
24
+ spec.add_development_dependency "bundler", "~> 1.11"
25
+ spec.add_development_dependency "rspec", "~> 3.0"
26
+ end
metadata ADDED
@@ -0,0 +1,111 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mdmCSR
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - patricio jofre
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-05-19 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: nokogiri
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: pry
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.11'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.11'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.0'
69
+ description: Apple MDM vendor CSR signing
70
+ email:
71
+ - luis.jofre.g@gmail.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - Gemfile
77
+ - Gemfile.lock
78
+ - README.md
79
+ - bin/console
80
+ - bin/setup
81
+ - certificates/intermediate.pem
82
+ - certificates/mdm.pem
83
+ - certificates/root.pem
84
+ - certificates/vendor.p12
85
+ - lib/mdmCSR.rb
86
+ - lib/mdmCSR/version.rb
87
+ - mdmCSR.gemspec
88
+ homepage: https://github.com/patriciojofre
89
+ licenses: []
90
+ metadata: {}
91
+ post_install_message:
92
+ rdoc_options: []
93
+ require_paths:
94
+ - lib
95
+ required_ruby_version: !ruby/object:Gem::Requirement
96
+ requirements:
97
+ - - ">="
98
+ - !ruby/object:Gem::Version
99
+ version: '0'
100
+ required_rubygems_version: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ requirements: []
106
+ rubyforge_project:
107
+ rubygems_version: 2.4.6
108
+ signing_key:
109
+ specification_version: 4
110
+ summary: Apple MDM vendor CSR signing
111
+ test_files: []