r509 0.9.2 → 0.10.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (177) hide show
  1. checksums.yaml +7 -0
  2. checksums.yaml.gz.sig +0 -0
  3. data.tar.gz.sig +2 -0
  4. data/CONTRIBUTING.mdown +21 -0
  5. data/LICENSE +13 -0
  6. data/README.mdown +548 -0
  7. data/Rakefile +5 -0
  8. data/bin/r509 +16 -17
  9. data/doc/R509.html +42 -26
  10. data/doc/R509/ASN1.html +22 -16
  11. data/doc/R509/ASN1/GeneralName.html +180 -173
  12. data/doc/R509/ASN1/GeneralNames.html +390 -62
  13. data/doc/R509/CRL.html +9 -7
  14. data/doc/R509/CRL/Administrator.html +208 -623
  15. data/doc/R509/CRL/FileReaderWriter.html +856 -0
  16. data/doc/R509/CRL/ReaderWriter.html +524 -0
  17. data/doc/R509/CRL/SignedList.html +29 -42
  18. data/doc/R509/CSR.html +248 -333
  19. data/doc/R509/Cert.html +364 -491
  20. data/doc/R509/Cert/Extensions.html +134 -43
  21. data/doc/R509/Cert/Extensions/AuthorityInfoAccess.html +335 -65
  22. data/doc/R509/Cert/Extensions/AuthorityKeyIdentifier.html +201 -102
  23. data/doc/R509/Cert/Extensions/BasicConstraints.html +297 -68
  24. data/doc/R509/Cert/Extensions/CRLDistributionPoints.html +690 -77
  25. data/doc/R509/Cert/Extensions/CertificatePolicies.html +293 -43
  26. data/doc/R509/Cert/Extensions/ExtendedKeyUsage.html +321 -173
  27. data/doc/R509/Cert/Extensions/GeneralNamesMixin.html +656 -0
  28. data/doc/R509/Cert/Extensions/InhibitAnyPolicy.html +270 -42
  29. data/doc/R509/Cert/Extensions/KeyUsage.html +334 -184
  30. data/doc/R509/Cert/Extensions/NameConstraints.html +363 -93
  31. data/doc/R509/{ASN1 → Cert/Extensions}/NoticeReference.html +209 -48
  32. data/doc/R509/Cert/Extensions/OCSPNoCheck.html +244 -17
  33. data/doc/R509/Cert/Extensions/PolicyConstraints.html +322 -71
  34. data/doc/R509/{ASN1 → Cert/Extensions}/PolicyInformation.html +204 -43
  35. data/doc/R509/{ASN1 → Cert/Extensions}/PolicyQualifiers.html +205 -48
  36. data/doc/R509/Cert/Extensions/SubjectAlternativeName.html +348 -143
  37. data/doc/R509/Cert/Extensions/SubjectKeyIdentifier.html +165 -13
  38. data/doc/R509/{ASN1 → Cert/Extensions}/UserNotice.html +204 -43
  39. data/doc/R509/Cert/Extensions/ValidationMixin.html +120 -0
  40. data/doc/R509/CertificateAuthority.html +9 -7
  41. data/doc/R509/CertificateAuthority/OptionsBuilder.html +475 -0
  42. data/doc/R509/CertificateAuthority/Signer.html +149 -198
  43. data/doc/R509/Config.html +10 -8
  44. data/doc/R509/Config/CAConfig.html +708 -625
  45. data/doc/R509/Config/CAConfigPool.html +179 -31
  46. data/doc/R509/Config/CertProfile.html +1544 -0
  47. data/doc/R509/Config/SubjectItemPolicy.html +437 -99
  48. data/doc/R509/Engine.html +14 -28
  49. data/doc/R509/Helpers.html +1014 -0
  50. data/doc/R509/MessageDigest.html +73 -25
  51. data/doc/R509/NameSanitizer.html +39 -39
  52. data/doc/R509/OCSP.html +5 -5
  53. data/doc/R509/OCSP/Request.html +5 -5
  54. data/doc/R509/OCSP/Request/Nonce.html +5 -5
  55. data/doc/R509/OCSP/Response.html +7 -7
  56. data/doc/R509/OIDMapper.html +121 -6
  57. data/doc/R509/PrivateKey.html +226 -227
  58. data/doc/R509/R509Error.html +5 -5
  59. data/doc/R509/SPKI.html +244 -342
  60. data/doc/R509/Subject.html +241 -70
  61. data/doc/R509/Validity.html +5 -5
  62. data/doc/R509/Validity/Checker.html +5 -5
  63. data/doc/R509/Validity/DefaultChecker.html +5 -9
  64. data/doc/R509/Validity/DefaultWriter.html +5 -9
  65. data/doc/R509/Validity/Status.html +5 -5
  66. data/doc/R509/Validity/Writer.html +5 -5
  67. data/doc/_index.html +92 -30
  68. data/doc/class_list.html +2 -2
  69. data/doc/file.CONTRIBUTING.html +96 -0
  70. data/doc/file.LICENSE.html +87 -0
  71. data/doc/file.README.html +279 -389
  72. data/doc/file.YAML.html +243 -0
  73. data/doc/file.r509.html +298 -105
  74. data/doc/file_list.html +11 -2
  75. data/doc/frames.html +1 -1
  76. data/doc/index.html +279 -389
  77. data/doc/js/full_list.js +6 -1
  78. data/doc/method_list.html +869 -1139
  79. data/doc/top-level-namespace.html +103 -5
  80. data/lib/r509.rb +7 -2
  81. data/lib/r509/asn1.rb +97 -135
  82. data/lib/r509/cert.rb +17 -106
  83. data/lib/r509/cert/extensions.rb +13 -676
  84. data/lib/r509/cert/extensions/authority_info_access.rb +128 -0
  85. data/lib/r509/cert/extensions/authority_key_identifier.rb +100 -0
  86. data/lib/r509/cert/extensions/base.rb +142 -0
  87. data/lib/r509/cert/extensions/basic_constraints.rb +119 -0
  88. data/lib/r509/cert/extensions/certificate_policies.rb +262 -0
  89. data/lib/r509/cert/extensions/crl_distribution_points.rb +98 -0
  90. data/lib/r509/cert/extensions/extended_key_usage.rb +189 -0
  91. data/lib/r509/cert/extensions/inhibit_any_policy.rb +70 -0
  92. data/lib/r509/cert/extensions/key_usage.rb +209 -0
  93. data/lib/r509/cert/extensions/name_constraints.rb +179 -0
  94. data/lib/r509/cert/extensions/ocsp_no_check.rb +56 -0
  95. data/lib/r509/cert/extensions/policy_constraints.rb +122 -0
  96. data/lib/r509/cert/extensions/subject_alternative_name.rb +88 -0
  97. data/lib/r509/cert/extensions/subject_key_identifier.rb +56 -0
  98. data/lib/r509/cert/extensions/validation_mixin.rb +42 -0
  99. data/lib/r509/certificate_authority/options_builder.rb +142 -0
  100. data/lib/r509/certificate_authority/signer.rb +189 -0
  101. data/lib/r509/config.rb +3 -600
  102. data/lib/r509/config/ca_config.rb +414 -0
  103. data/lib/r509/config/cert_profile.rb +110 -0
  104. data/lib/r509/config/subject_item_policy.rb +118 -0
  105. data/lib/r509/crl/administrator.rb +169 -0
  106. data/lib/r509/crl/reader_writer.rb +109 -0
  107. data/lib/r509/crl/signed_list.rb +135 -0
  108. data/lib/r509/csr.rb +35 -116
  109. data/lib/r509/engine.rb +21 -11
  110. data/lib/r509/helpers.rb +110 -0
  111. data/lib/r509/io_helpers.rb +18 -13
  112. data/lib/r509/message_digest.rb +13 -3
  113. data/lib/r509/oid_mapper.rb +14 -0
  114. data/lib/r509/private_key.rb +74 -50
  115. data/lib/r509/spki.rb +50 -113
  116. data/lib/r509/subject.rb +24 -2
  117. data/lib/r509/trollop.rb +788 -0
  118. data/lib/r509/version.rb +1 -1
  119. data/r509.yaml +289 -96
  120. data/spec/asn1_spec.rb +171 -98
  121. data/spec/cert/extensions/authority_info_access_spec.rb +247 -0
  122. data/spec/cert/extensions/authority_key_identifier_spec.rb +85 -0
  123. data/spec/cert/extensions/base_spec.rb +172 -0
  124. data/spec/cert/extensions/basic_constraints_spec.rb +185 -0
  125. data/spec/cert/extensions/certificate_policies_spec.rb +288 -0
  126. data/spec/cert/extensions/crl_distribution_points_spec.rb +149 -0
  127. data/spec/cert/extensions/extended_key_usage_spec.rb +174 -0
  128. data/spec/cert/extensions/inhibit_any_policy_spec.rb +92 -0
  129. data/spec/cert/extensions/key_usage_spec.rb +172 -0
  130. data/spec/cert/extensions/name_constraints_spec.rb +335 -0
  131. data/spec/cert/extensions/ocsp_no_check_spec.rb +76 -0
  132. data/spec/cert/extensions/policy_constraints_spec.rb +155 -0
  133. data/spec/cert/extensions/subject_alternative_name_spec.rb +354 -0
  134. data/spec/cert/extensions/subject_key_identifier_spec.rb +64 -0
  135. data/spec/cert_spec.rb +11 -9
  136. data/spec/certificate_authority/options_builder_spec.rb +307 -0
  137. data/spec/certificate_authority/signer_spec.rb +278 -0
  138. data/spec/config/ca_config_spec.rb +405 -0
  139. data/spec/config/cert_profile_spec.rb +88 -0
  140. data/spec/config/subject_item_policy_spec.rb +81 -0
  141. data/spec/crl/administrator_spec.rb +199 -0
  142. data/spec/crl/reader_writer_spec.rb +97 -0
  143. data/spec/crl/signed_list_spec.rb +84 -0
  144. data/spec/csr_spec.rb +43 -36
  145. data/spec/engine_spec.rb +51 -0
  146. data/spec/fixtures.rb +40 -40
  147. data/spec/fixtures/cert1.pem +1 -1
  148. data/spec/fixtures/config_pool_test_minimal.yaml +11 -15
  149. data/spec/fixtures/config_test.yaml +96 -59
  150. data/spec/fixtures/config_test_dsa.yaml +29 -35
  151. data/spec/fixtures/config_test_ec.yaml +29 -35
  152. data/spec/fixtures/config_test_engine_key.yaml +7 -7
  153. data/spec/fixtures/config_test_engine_no_key_name.yaml +6 -6
  154. data/spec/fixtures/config_test_minimal.yaml +3 -5
  155. data/spec/fixtures/config_test_password.yaml +4 -6
  156. data/spec/fixtures/config_test_various.yaml +147 -137
  157. data/spec/fixtures/crl_list_file.txt +1 -1
  158. data/spec/fixtures/test_ca_crl.cer +20 -0
  159. data/spec/fixtures/test_ca_crl.key +28 -0
  160. data/spec/fixtures/test_ca_crl.p12 +0 -0
  161. data/spec/message_digest_spec.rb +6 -0
  162. data/spec/oid_mapper_spec.rb +11 -0
  163. data/spec/private_key_spec.rb +19 -18
  164. data/spec/spec_helper.rb +10 -6
  165. data/spec/spki_spec.rb +38 -19
  166. data/spec/subject_spec.rb +16 -0
  167. metadata +108 -59
  168. metadata.gz.sig +0 -0
  169. data/README.md +0 -638
  170. data/doc/R509/Config/CAProfile.html +0 -1015
  171. data/doc/R509/IOHelpers.html +0 -564
  172. data/lib/r509/certificate_authority.rb +0 -407
  173. data/lib/r509/crl.rb +0 -351
  174. data/spec/cert/extensions_spec.rb +0 -1095
  175. data/spec/certificate_authority_spec.rb +0 -681
  176. data/spec/config_spec.rb +0 -562
  177. data/spec/crl_spec.rb +0 -226
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: ca8c4fec95f6c1bfcee73da8585a30867b18e77f
4
+ data.tar.gz: a4fd0c67c5479b69f2359aaa61b11eae597c7480
5
+ SHA512:
6
+ metadata.gz: 68ca9e7f94cb8d122ad0f2ab6ec5584149f0683dc9d9ac6dcd608788db86c807b5d34b9312ea452a88960c275b30003ff8de7c90ca3b39179866acbabacc3cb7
7
+ data.tar.gz: b04daa9448a25761cb2900dc449f52056ab8d91bfef86f6fa33cbd4ca3c7c61e769fa0988e8b5a6619caad28124d55e4257a488dc2758f3e92eaf57bf861a791
Binary file
@@ -0,0 +1,2 @@
1
+ ��'
2
+ t�+���W�e0�B��c��!VG��h�}(ܯ�Z�r�����*nяv��{���_��)��e� ,x[{~�X�C�|��z�*�67A���@���b�"A��
@@ -0,0 +1,21 @@
1
+ ## Bug Reports
2
+
3
+ So you've found a bug in r509. Awesome! (Wait, that came out wrong) Go ahead and
4
+ open an [issue](https://github.com/reaperhulk/r509/issues) and answer the following questions:
5
+
6
+ - What did you do?
7
+ - What did you expect to happen?
8
+ - What happened instead?
9
+
10
+ Please also supply code that replicates the bug. If you can, a failing test would
11
+ be ideal, but a simple script demonstrating the error is acceptable.
12
+
13
+ Don't forget to specify what version of r509 you are using!
14
+
15
+ ## Pull Requests
16
+
17
+ - You must supply tests for your changes.
18
+
19
+ - All behavioral changes must be documented. Both the README and the yardoc must be kept up-to-date.
20
+
21
+ - **One pull request per feature**. If you want to do more than one thing, send multiple pull requests.
data/LICENSE ADDED
@@ -0,0 +1,13 @@
1
+ Copyright 2012 Paul Kehrer, Trustwave Holdings, Inc.
2
+
3
+ Licensed under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License.
5
+ You may obtain a copy of the License at
6
+
7
+ http://www.apache.org/licenses/LICENSE-2.0
8
+
9
+ Unless required by applicable law or agreed to in writing, software
10
+ distributed under the License is distributed on an "AS IS" BASIS,
11
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ See the License for the specific language governing permissions and
13
+ limitations under the License.
@@ -0,0 +1,548 @@
1
+ #r509 [![Build Status](https://secure.travis-ci.org/r509/r509.png)](http://travis-ci.org/r509/r509) [![Coverage Status](https://coveralls.io/repos/r509/r509/badge.png?branch=master)](https://coveralls.io/r/r509/r509?branch=master)
2
+ r509 is a Ruby gem built using OpenSSL that is designed to ease management of a public key infrastructure. The r509 API facilitates easy creation of CSRs, signing of certificates, revocation (CRL/OCSP), and much more. Together with projects like [r509-ocsp-responder](https://github.com/r509/r509-ocsp-responder) and [r509-ca-http](https://github.com/r509/r509-ca-http) it is intended to be a complete [RFC 5280](http://www.ietf.org/rfc/rfc5280.txt)-compliant certificate authority for use in production environments.
3
+
4
+ ##Why?
5
+ Certificates are hard, and the Ruby OpenSSL APIs aren't easy to use (because they hew closely to OpenSSL itself). Additionally, as SSL/TLS has aged a variety of best practices and workarounds around certificate issuance have grown up around it that are not easy to discover. r509 is an attempt to build a straightforward API that allows you to do things as simple as parsing a certificate all the way up to operating an entire certificate authority.
6
+
7
+ ##Requirements
8
+
9
+ r509 requires Ruby 1.9.3+ compiled with OpenSSL and YAML support (this is a typical default). It is recommended that you compile Ruby against OpenSSL 1.0.0+ (with elliptic curve support enabled). Red Hat-derived distributions prior to RHEL/CentOS 6.5 ship with EC disabled in OpenSSL, so if you need EC support you will need to recompile.
10
+
11
+ ##Installation
12
+ You can install via rubygems with ```gem install r509```
13
+
14
+ To install the gem from your own clone (you will need to satisfy the dependencies via ```bundle install``` or other means):
15
+
16
+ ```bash
17
+ rake gem:build
18
+ rake gem:install
19
+ ```
20
+
21
+ ##Documentation
22
+ There is documentation available for every method and class in r509 available via yardoc. You can view the latest release docs at [r509.org](http://r509.org). If you installed via gem it should be pre-generated in the doc directory. If you cloned this repo, just type ```rake yard``` with the yard gem installed. You will also need the redcarpet and github-markup gems to properly parse the README.md.
23
+
24
+ ##Support
25
+ You can [file bugs](https://github.com/r509/r509/issues), contact me directly, or join the #r509 channel on irc.freenode.net to ask questions.
26
+
27
+ ##Running Tests/Building Gem
28
+ If you want to run the tests for r509 you'll need rspec. Additionally, you should install simplecov and yard for running the code coverage and documentation tasks in the Rakefile. ```rake -T``` for a complete list of rake tasks available.
29
+
30
+ ##Continuous Integration
31
+ We run continuous integration tests (using Travis-CI) against 1.9.3, 2.0.0, 2.1.0, ruby-head, and rubinius. 1.8.7 is no longer a supported configuration due to issues with its elliptic curve methods. 0.8.1 was the last official r509 release with 1.8.7 support.
32
+
33
+ ##Executables
34
+
35
+ r509 ships with a binary named ```r509``` that can generate CSRs, keys, and create self-signed certificates. Type ```r509 -h``` to see a list of options.
36
+
37
+ ##Basic Certificate Authority Tutorial
38
+ [This guide](http://langui.sh/2012/11/02/building-a-ca-r509-howto/) provides instructions on building a basic CA using r509, [r509-ca-http](https://github.com/r509/r509-ca-http), and [r509-ocsp-responder](https://github.com/r509/r509-ocsp-responder). In it you will learn how to create a root, set up the configuration profiles, issue certificates, revoke certificates, and see responses from an OCSP responder.
39
+
40
+ ##Quick Start
41
+ ###CSR
42
+ To generate a 2048-bit RSA CSR
43
+
44
+ ```ruby
45
+ csr = R509::CSR.new(
46
+ :subject => [
47
+ ['CN','somedomain.com'],
48
+ ['O','My Org'],
49
+ ['L','City'],
50
+ ['ST','State'],
51
+ ['C','US']
52
+ ]
53
+ )
54
+ # alternately
55
+ csr = R509::CSR.new(
56
+ :subject => {
57
+ :CN => 'somedomain.com',
58
+ :O => 'My Org',
59
+ :L => 'City',
60
+ :ST => 'State',
61
+ :C => 'US'
62
+ }
63
+ )
64
+
65
+ ```
66
+
67
+ Another way to build the subject:
68
+
69
+ ```ruby
70
+ subject = R509::Subject.new
71
+ subject.CN="somedomain.com"
72
+ subject.O="My Org"
73
+ subject.L="City"
74
+ subject.ST="State"
75
+ subject.C="US"
76
+ csr = R509::CSR.new( :subject => subject )
77
+ ```
78
+
79
+ To load an existing CSR (without private key)
80
+
81
+ ```ruby
82
+ csr_pem = File.read("/path/to/csr")
83
+ csr = R509::CSR.new(:csr => csr_pem)
84
+ # or
85
+ csr = R509::CSR.load_from_file("/path/to/csr")
86
+ ```
87
+
88
+ To create a new CSR from the subject of a certificate
89
+
90
+ ```ruby
91
+ cert_pem = File.read("/path/to/cert")
92
+ csr = R509::CSR.new(:cert => cert_pem)
93
+ ```
94
+
95
+ To create a CSR with SAN names
96
+
97
+ ```ruby
98
+ csr = R509::CSR.new(
99
+ :subject => [['CN','something.com']],
100
+ :san_names => ["something2.com","something3.com"]
101
+ )
102
+ ```
103
+
104
+ ###Cert
105
+ To load an existing certificate
106
+
107
+ ```ruby
108
+ cert_pem = File.read("/path/to/cert")
109
+ cert = R509::Cert.new(:cert => cert_pem)
110
+ # or
111
+ cert = R509::Cert.load_from_file("/path/to/cert")
112
+ ```
113
+
114
+ Load a cert and key
115
+
116
+ ```ruby
117
+ cert_pem = File.read("/path/to/cert")
118
+ key_pem = File.read("/path/to/key")
119
+ cert = R509::Cert.new(
120
+ :cert => cert_pem,
121
+ :key => key_pem
122
+ )
123
+ ```
124
+
125
+ Load an encrypted private key
126
+
127
+ ```ruby
128
+ cert_pem = File.read("/path/to/cert")
129
+ key_pem = File.read("/path/to/key")
130
+ cert = R509::Cert.new(
131
+ :cert => cert_pem,
132
+ :key => key_pem,
133
+ :password => "private_key_password"
134
+ )
135
+ ```
136
+
137
+ Load a PKCS12 file
138
+
139
+ ```ruby
140
+ pkcs12_der = File.read("/path/to/p12")
141
+ cert = R509::Cert.new(
142
+ :pkcs12 => pkcs12_der,
143
+ :password => "password"
144
+ )
145
+ ```
146
+
147
+ ###PrivateKey
148
+ Generate a 1536-bit RSA key
149
+
150
+ ```ruby
151
+ key = R509::PrivateKey.new(:type => "RSA", :bit_length => 1536)
152
+ ```
153
+
154
+ Encrypt a private key
155
+
156
+ ```ruby
157
+ key = R509::PrivateKey.new(:type => "RSA", :bit_length => 2048)
158
+ encrypted_pem = key.to_encrypted_pem("aes256","my-password")
159
+ # or write it to disk
160
+ key.write_encrypted_pem("/tmp/path","aes256","my-password")
161
+ ```
162
+
163
+ ####Load Hardware Engines in PrivateKey
164
+
165
+ The engine you want to load must already be available to OpenSSL. How to compile/install OpenSSL engines is outside the scope of this document.
166
+
167
+ ```ruby
168
+ engine = R509::Engine.instance.load(:so_path => "/usr/lib64/openssl/engines/libchil.so", :id => "chil")
169
+ key = R509::PrivateKey(
170
+ :engine => engine,
171
+ :key_name => "my_key_name"
172
+ )
173
+ ```
174
+
175
+ You can then use this key for signing.
176
+
177
+ ###SPKI/SPKAC
178
+ To generate a 2048-bit RSA SPKI
179
+
180
+ ```ruby
181
+ key = R509::PrivateKey.new(:type => "RSA", :bit_length => 1024)
182
+ spki = R509::SPKI.new(:key => key)
183
+ ```
184
+
185
+ ###Self-Signed Certificate
186
+ To create a self-signed certificate
187
+
188
+ ```ruby
189
+ not_before = Time.now.to_i
190
+ not_after = Time.now.to_i+3600*24*7300
191
+ csr = R509::CSR.new(
192
+ :subject => [['C','US'],['O','r509 LLC'],['CN','r509 Self-Signed CA Test']]
193
+ )
194
+ # if you do not pass :extensions it will add basic constraints CA:TRUE, a SubjectKeyIdentifier, and an AuthorityKeyIdentifier
195
+ cert = R509::CertificateAuthority::Signer.selfsign(
196
+ :csr => csr,
197
+ :not_before => not_before,
198
+ :not_after => not_after
199
+ )
200
+ ```
201
+
202
+ ###Config
203
+
204
+ ####CAConfig
205
+ Create a basic CAConfig object
206
+
207
+ ```ruby
208
+ cert_pem = File.read("/path/to/cert")
209
+ key_pem = File.read("/path/to/key")
210
+ cert = R509::Cert.new(
211
+ :cert => cert_pem,
212
+ :key => key_pem
213
+ )
214
+ config = R509::Config::CAConfig.new(
215
+ :ca_cert => cert
216
+ )
217
+ ```
218
+
219
+ ####SubjectItemPolicy
220
+ Subject Item Policy allows you to define what subject fields are allowed in a certificate. Required means that field *must* be supplied, optional means it will be encoded if provided, and match means the field must be present and must match the value specified. The keys must match OpenSSL's short names.
221
+
222
+
223
+ ```ruby
224
+ sip = 509::Config::SubjectItemPolicy.new(
225
+ "CN" => {:policy => "required"},
226
+ "O" => {:policy => "optional"},
227
+ "OU" => {:policy => "match", :value => "Engineering" }
228
+ )
229
+ ```
230
+
231
+ ####CertProfile
232
+ Certificate profiles hold extensions you want to put in a certificate, allowed/default message digests, and subject item policies. You can build them programmatically or load them via YAML. When building programmatically you can also serialize to YAML for future use. This is the preferred way to build the YAML.
233
+
234
+ The CertProfile object can either take objects or the hash that would build those objects.
235
+
236
+ Objects:
237
+
238
+ ```ruby
239
+ profile = R509::Config::CertProfile.new(
240
+ :basic_constraints => R509::Cert::Extensions::BasicConstraints.new(
241
+ :ca => false
242
+ ),
243
+ :key_usage => R509::Cert::Extensions::KeyUsage.new(
244
+ :value => ['digitalSignature','keyEncipherment']
245
+ ),
246
+ :extended_key_usage => R509::Cert::Extensions::ExtendedKeyUsage.new(
247
+ :value => ['serverAuth','clientAuth']
248
+ ),
249
+ :authority_info_access => R509::Cert::Extensions::AuthorityInfoAccess.new(
250
+ :ocsp_location => [{:type => 'URI', :value => 'http://ocsp.myca.net'}]
251
+ ),
252
+ :certificate_policies => R509::Cert::Extensions::CertificatePolicies.new(
253
+ :value => [{:policy_identifier => '1.23.3.4.4.5.56'}]
254
+ ),
255
+ :crl_distribution_points => R509::Cert::Extensions::CRLDistributionPoints.new(
256
+ :value => [{:type => 'URI', :value => 'http://crl.myca.net/ca.crl'}]
257
+ ),
258
+ :inhibit_any_policy => R509::Cert::Extensions::InhibitAnyPolicy.new(
259
+ :value => 0
260
+ ),
261
+ :name_constraints => R509::Cert::Extensions::NameConstraints.new(
262
+ :permitted => [{:type => 'dirName', :value => { :CN => 'test' } }]
263
+ ),
264
+ :ocsp_no_check => R509::Cert::Extensions::OCSPNoCheck.new(:value => true),
265
+ :policy_constraints => R509::Cert::Extensions::PolicyConstraints.new(
266
+ :require_explicit_policy=> 1
267
+ ),
268
+ :subject_item_policy => R509::Config::SubjectItemPolicy.new(
269
+ "CN" => {:policy => "required"},
270
+ "O" => {:policy => "optional"},
271
+ "OU" => {:policy => "match", :value => "Engineering" }
272
+ ),
273
+ :default_md => "SHA256",
274
+ :allowed_mds => ["SHA256","SHA512"]
275
+ )
276
+ ```
277
+
278
+ Hashes:
279
+
280
+ ```ruby
281
+ profile = R509::Config::CertProfile.new(
282
+ :basic_constraints => {:ca => false},
283
+ :key_usage => { :value => ["digitalSignature","keyEncipherment"] },
284
+ :extended_key_usage => { :value => ["serverAuth"] },
285
+ :certificate_policies => [
286
+ { :policy_identifier => "2.16.840.1.99999.21.234",
287
+ :cps_uris => ["http://example.com/cps","http://haha.com"],
288
+ :user_notices => [ { :explicit_text => "this is a great thing", :organization => "my org", :notice_numbers => [1,2,3] } ]
289
+ }
290
+ ],
291
+ :subject_item_policy => nil,
292
+ :crl_distribution_points => {:value => [{ :type => "URI", :value => "http://crl.myca.net/ca.crl" }] },
293
+ :authority_info_access => {
294
+ :ocsp_location => [{ :type => "URI", :value => "http://ocsp.myca.net" }],
295
+ :ca_issuers_location => [{ :type => "URI", :value => "http://www.myca.net/some_ca.cer" }]
296
+ }
297
+ )
298
+ # CAConfig object from above assumed
299
+ config.set_profile("server",profile)
300
+ ```
301
+
302
+ ####CAConfigPool
303
+ Multiple CAConfigs can be loaded via CAConfigPool
304
+
305
+ ```ruby
306
+ # from objects
307
+ pool = R509::Config::CAConfigPool.new("my_ca" => config, "another_ca" => another_config)
308
+ # from yaml
309
+ pool = R509::Config::CAConfigPool.from_yaml("certificate_authorities", "config_pool.yaml")
310
+ ```
311
+
312
+ Example (Minimal) Config Pool YAML
313
+
314
+ ```yaml
315
+ certificate_authorities:
316
+ test_ca:
317
+ ca_cert:
318
+ cert: test_ca.cer
319
+ key: test_ca.key
320
+ second_ca:
321
+ ca_cert:
322
+ cert: second_ca.cer
323
+ key: second_ca.key
324
+ ```
325
+
326
+ ####Building YAML
327
+ You can serialize a CAConfig (or CAConfigPool) via ```#to_yaml```. The output of the YAML will vary depending upon what data you have supplied to the object, but the output does require the following manual configuration:
328
+
329
+ * Add paths to the requested files where you see add_path (or change the options entirely. See the YAML config section below)
330
+ * Define a name for your config and put the YAML inside it. In the example below the config has been named example_ca
331
+
332
+ ```yaml
333
+ example_ca:
334
+ # the following is the output of #to_yaml
335
+ ca_cert:
336
+ cert: <add_path>
337
+ key: <add_path>
338
+ ocsp_start_skew_seconds: 3600
339
+ ocsp_validity_hours: 168
340
+ crl_md: SHA1
341
+ profiles:
342
+ profile:
343
+ subject_item_policy:
344
+ CN:
345
+ :policy: required
346
+ O:
347
+ :policy: required
348
+ L:
349
+ :policy: required
350
+ OU:
351
+ :policy: optional
352
+ default_md: SHA512
353
+ ```
354
+
355
+ ###CertificateAuthority::Signer (sans CertProfile)
356
+
357
+ Sign a CSR
358
+
359
+ ```ruby
360
+ csr = R509::CSR.new(
361
+ :subject => {
362
+ :CN => 'somedomain.com',
363
+ :O => 'My Org',
364
+ :L => 'City',
365
+ :ST => 'State',
366
+ :C => 'US'
367
+ }
368
+ )
369
+ # assume config from yaml load above
370
+ ca = R509::CertificateAuthority::Signer.new(config)
371
+ ext = []
372
+ # you can add extensions in an array. See R509::Cert::Extensions::*
373
+ ext << R509::Cert::Extensions::BasicConstraints.new(:ca => false)
374
+
375
+ cert = ca.sign(
376
+ :csr => csr,
377
+ :extensions => ext
378
+ )
379
+ ```
380
+
381
+ Override a CSR's subject or SAN names when signing
382
+
383
+ ```ruby
384
+ csr = R509::CSR.new(
385
+ :subject => {
386
+ :CN => 'somedomain.com',
387
+ :O => 'My Org',
388
+ :L => 'City',
389
+ :ST => 'State',
390
+ :C => 'US'
391
+ }
392
+ )
393
+ subject = csr.subject.dup
394
+ san_names = [{:type=> 'DNS', :value => "domain2.com"},{:type => 'IP', :value => "128.128.128.128"}]
395
+ subject.common_name = "newdomain.com"
396
+ subject.organization = "Org 2.0"
397
+ ext = []
398
+ ext << R509::Cert::Extensions::BasicConstraints.new(:ca => false)
399
+ ext << R509::Cert::Extensions::SubjectAlternativeName.new(:names => san_names)
400
+ # assume config from yaml load above
401
+ ca = R509::CertificateAuthority::Signer.new(config)
402
+ cert = ca.sign(
403
+ :csr => csr,
404
+ :subject => subject,
405
+ :extensions => ext
406
+ )
407
+ ```
408
+
409
+ Sign an SPKI/SPKAC object
410
+
411
+ ```ruby
412
+ key = R509::PrivateKey.new(:type => "RSA", :bit_length => 2048)
413
+ spki = R509::SPKI.new(:key => key)
414
+ # SPKI objects do not contain subject or san name data so it must be specified
415
+ subject = R509::Subject.new
416
+ subject.CN = "mydomain.com"
417
+ subject.L = "Locality"
418
+ subject.ST = "State"
419
+ subject.C = "US"
420
+ san_names = [{:type=> 'DNS', :value => "domain2.com"},{:type => 'IP', :value => "128.128.128.128"}]
421
+ ext = []
422
+ ext << R509::Cert::Extensions::BasicConstraints.new(:ca => false)
423
+ ext << R509::Cert::Extensions::SubjectAlternativeName.new(:value => san_names)
424
+ # assume config from yaml load above
425
+ ca = R509::CertificateAuthority::Signer.new(config)
426
+ cert = ca.sign(
427
+ :spki => spki,
428
+ :subject => subject,
429
+ :extensions => ext
430
+ )
431
+
432
+ ```
433
+
434
+ ###CertificateAuthority::OptionsBuilder
435
+ The OptionsBuilder takes in a CAConfig with CertProfiles. You then call ```#build_and_enforce``` to have it create a hash that can be passed to ```R509::CertificateAuthority::Signer#sign```. The OptionsBuilder is responsible for enforcing restrictions on subject DN (via SubjectItemPolicy), determing allowed message digest, and adding a profile's extensions.
436
+
437
+ ```ruby
438
+ # assume config from yaml load above
439
+ csr = R509::CSR.new(
440
+ :subject => {
441
+ :CN => 'somedomain.com',
442
+ :O => 'My Org',
443
+ :L => 'City',
444
+ :ST => 'State',
445
+ :C => 'US'
446
+ }
447
+ )
448
+ builder = R509::CertificateAuthority::OptionsBuilder.new(config)
449
+ scrubbed_data = builder.build_and_enforce(
450
+ :csr => csr,
451
+ :profile_name => "server",
452
+ :subject => {:CN => 'rewritten.com'},
453
+ :san_names => ['r509.org'],
454
+ :message_digest => 'SHA256'
455
+ )
456
+ # this returns a hash with keys :csr/:pki, :subject, :extensions, and :message_digest
457
+ signer = R509::CertificateAuthority::Signer.new(config)
458
+ cert = signer.sign(scrubbed_data)
459
+
460
+ ```
461
+
462
+ You can optionally supply an array of R509::Cert::Extensions::* objects to the builder via the ```:extensions``` key. These will be merged with the extensions from the profile. If an extension in this array is also present in the profile, *the supplied extension will override the profile*.
463
+
464
+ ```ruby
465
+ # assume pre-existing config and csr from above
466
+ builder = R509::CertificateAuthority::OptionsBuilder.new(config)
467
+ scrubbed_data = builder.build_and_enforce(
468
+ :csr => csr,
469
+ :profile_name => "server",
470
+ :subject => {:CN => 'rewritten.com'},
471
+ :san_names => ['r509.org'],
472
+ :message_digest => 'SHA256',
473
+ :extensions => [R509::Cert::Extensions::BasicConstraints.new(:ca => true)]
474
+ )
475
+ ```
476
+
477
+ ###CRL Administration
478
+ The CRL administrator object takes an ```R509::Config::CAConfig``` and an optional ```R509::CRL::ReaderWriter``` subclass. By default it will use an ```R509::CRL::FileReaderWriter``` class that assumes the presence of ```crl_number_file``` and ```crl_list_file``` in the CAConfig.
479
+
480
+ ```ruby
481
+ admin = R509::CRL::Administrator.new(config)
482
+ ```
483
+
484
+ ####Revoking a certificate
485
+ To revoke a certificate and generate a new CRL
486
+
487
+ ```ruby
488
+ admin.revoke_cert(serial)
489
+ crl = admin.generate_crl
490
+ ```
491
+
492
+ This revokes on the root configured by the CAConfig that was passed into the Administrator constructor.
493
+
494
+ ###OID Mapping
495
+
496
+ Register one
497
+
498
+ ```ruby
499
+ R509::OIDMapper.register("1.3.5.6.7.8.3.23.3","short_name","optional_long_name")
500
+ ```
501
+
502
+ Register in batch
503
+
504
+ ```ruby
505
+ R509::OIDMapper.batch_register([
506
+ {:oid => "1.3.5.6.7.8.3.23.3", :short_name => "short_name", :long_name => "optional_long_name"},
507
+ {:oid => "1.3.5.6.7.8.3.23.5", :short_name => "another_name"}
508
+ ])
509
+ ```
510
+
511
+ ###Alternate Key Algorithms
512
+ In addition to the default RSA objects that are created above, r509 supports DSA and elliptic curve (EC). EC support is present only if Ruby has been linked against a version of OpenSSL compiled with EC enabled. This excludes Red Hat-based distributions at this time (unless you build it yourself). Take a look at the documentation for R509::PrivateKey, R509::Cert, and R509::CSR to see how to create DSA and EC types. You can test if elliptic curve support is available in your Ruby with:
513
+
514
+ ```ruby
515
+ R509.ec_supported?
516
+ ```
517
+
518
+ ####NIST Recommended Elliptic Curves
519
+ These curves are set via ```:curve_name```. The system defaults to using ```secp384r1```
520
+
521
+ * secp224r1 -- NIST/SECG curve over a 224 bit prime field
522
+ * secp384r1 -- NIST/SECG curve over a 384 bit prime field
523
+ * secp521r1 -- NIST/SECG curve over a 521 bit prime field
524
+ * prime192v1 -- NIST/X9.62/SECG curve over a 192 bit prime field
525
+ * sect163k1 -- NIST/SECG/WTLS curve over a 163 bit binary field
526
+ * sect163r2 -- NIST/SECG curve over a 163 bit binary field
527
+ * sect233k1 -- NIST/SECG/WTLS curve over a 233 bit binary field
528
+ * sect233r1 -- NIST/SECG/WTLS curve over a 233 bit binary field
529
+ * sect283k1 -- NIST/SECG curve over a 283 bit binary field
530
+ * sect283r1 -- NIST/SECG curve over a 283 bit binary field
531
+ * sect409k1 -- NIST/SECG curve over a 409 bit binary field
532
+ * sect409r1 -- NIST/SECG curve over a 409 bit binary field
533
+ * sect571k1 -- NIST/SECG curve over a 571 bit binary field
534
+ * sect571r1 -- NIST/SECG curve over a 571 bit binary field
535
+
536
+
537
+ ##Created by...
538
+ __Paul Kehrer__ ([Twitter](https://twitter.com/reaperhulk) | [GitHub](https://github.com/reaperhulk))
539
+
540
+ ##Contributors
541
+ * [Sean Schulte](https://github.com/sirsean)
542
+ * [Mike Ryan](https://github.com/justfalter)
543
+ * [Chris Woodbury](https://github.com/woodbusy)
544
+
545
+ ##License
546
+ See the LICENSE file. Licensed under the Apache 2.0 License.
547
+
548
+ ##[YAML Documentation](YAML.mdown)