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
Binary file
data/README.md DELETED
@@ -1,638 +0,0 @@
1
- #r509 [![Build Status](https://secure.travis-ci.org/reaperhulk/r509.png)](http://travis-ci.org/reaperhulk/r509)
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/reaperhulk/r509-ocsp-responder) and [r509-ca-http](https://github.com/sirsean/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
- ##Requirements
5
-
6
- r509 requires the Ruby OpenSSL bindings as well as yaml support (present by default in modern Ruby builds). It is recommended that you compile Ruby against OpenSSL 1.0.0+ (with elliptic curve support enabled). Red Hat-derived distributions ship with EC disabled in OpenSSL, so if you need EC support you will need to recompile.
7
-
8
- ##Installation
9
- You can install via rubygems with ```gem install r509```
10
-
11
- To install the gem from your own clone (you will need to satisfy the dependencies via ```bundle install``` or other means):
12
-
13
- ```bash
14
- rake gem:build
15
- rake gem:install
16
- ```
17
-
18
- ##Running Tests/Building Gem
19
- If you want to run the tests for r509 you'll need rspec. Additionally, you may want to install rcov/simplecov (ruby 1.8/1.9 respectively) and yard for running the code coverage and documentation tasks in the Rakefile. ```rake -T``` for a complete list of rake tasks available.
20
-
21
- ##Continuous Integration
22
- We run continuous integration tests (using Travis-CI) against 1.9.3, 2.0.0, ruby-head, and rubinius(rbx) 2.0 in 1.9 mode. 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.
23
-
24
- ##Executable
25
-
26
- Inside the gem there is a binary named ```r509```. Type ```r509 -h``` to see a list of options.
27
-
28
- ##Basic Certificate Authority Howto
29
- [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/sirsean/r509-ca-http), and [r509-ocsp-responder](https://github.com/reaperhulk/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.
30
-
31
- ##Usage
32
- ###CSR
33
- To generate a 2048-bit RSA CSR
34
-
35
- ```ruby
36
- csr = R509::CSR.new(
37
- :subject => [
38
- ['CN','somedomain.com'],
39
- ['O','My Org'],
40
- ['L','City'],
41
- ['ST','State'],
42
- ['C','US']
43
- ]
44
- )
45
- ```
46
-
47
- Another way to build the subject:
48
-
49
- ```ruby
50
- subject = R509::Subject.new
51
- subject.CN="somedomain.com"
52
- subject.O="My Org"
53
- subject.L="City"
54
- subject.ST="State"
55
- subject.C="US"
56
- csr = R509::CSR.new( :subject => subject )
57
- ```
58
-
59
- To load an existing CSR (without private key)
60
-
61
- ```ruby
62
- csr_pem = File.read("/path/to/csr")
63
- csr = R509::CSR.new(:csr => csr_pem)
64
- # or
65
- csr = R509::CSR.load_from_file("/path/to/csr")
66
- ```
67
-
68
- To create a new CSR from the subject of a certificate
69
-
70
- ```ruby
71
- cert_pem = File.read("/path/to/cert")
72
- csr = R509::CSR.new(:cert => cert_pem)
73
- ```
74
-
75
- To create a CSR with SAN names
76
-
77
- ```ruby
78
- csr = R509::CSR.new(
79
- :subject => [['CN','something.com']],
80
- :san_names => ["something2.com","something3.com"]
81
- )
82
- ```
83
-
84
- ###Cert
85
- To load an existing certificate
86
-
87
- ```ruby
88
- cert_pem = File.read("/path/to/cert")
89
- cert = R509::Cert.new(:cert => cert_pem)
90
- # or
91
- cert = R509::Cert.load_from_file("/path/to/cert")
92
- ```
93
-
94
- Load a cert and key
95
-
96
- ```ruby
97
- cert_pem = File.read("/path/to/cert")
98
- key_pem = File.read("/path/to/key")
99
- cert = R509::Cert.new(
100
- :cert => cert_pem,
101
- :key => key_pem
102
- )
103
- ```
104
-
105
- Load an encrypted private key
106
-
107
- ```ruby
108
- cert_pem = File.read("/path/to/cert")
109
- key_pem = File.read("/path/to/key")
110
- cert = R509::Cert.new(
111
- :cert => cert_pem,
112
- :key => key_pem,
113
- :password => "private_key_password"
114
- )
115
- ```
116
-
117
- Load a PKCS12 file
118
-
119
- ```ruby
120
- pkcs12_der = File.read("/path/to/p12")
121
- cert = R509::Cert.new(
122
- :pkcs12 => pkcs12_der,
123
- :password => "password"
124
- )
125
- ```
126
-
127
- ###PrivateKey
128
- Generate a 1536-bit RSA key
129
-
130
- ```ruby
131
- key = R509::PrivateKey.new(:type => :rsa, :bit_strength => 1536)
132
- ```
133
-
134
- Encrypt the private key
135
-
136
- ```ruby
137
- key = R509::PrivateKey.new(:type => :rsa, :bit_strength => 2048)
138
- encrypted_pem = key.to_encrypted_pem("aes256","my-password")
139
- # or write it to disk
140
- key.write_encrypted_pem("/tmp/path","aes256","my-password")
141
- ```
142
-
143
- ####Load Hardware Engines in PrivateKey
144
-
145
- 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.
146
-
147
- ```ruby
148
- engine = R509::Engine.load("SO_PATH" => "/usr/lib64/openssl/engines/libchil.so", "ID" => "chil")
149
- key = R509::PrivateKey(
150
- :engine => engine,
151
- :key_name => "my_key_name"
152
- )
153
- ```
154
-
155
- You can then use this key for signing.
156
-
157
- ###SPKI/SPKAC
158
- To generate a 2048-bit RSA SPKI
159
-
160
- ```ruby
161
- key = R509::PrivateKey.new(:type => :rsa, :bit_strength => 1024)
162
- spki = R509::SPKI.new(:key => key)
163
- ```
164
-
165
- ###Self-Signed Certificate
166
- To create a self-signed certificate
167
-
168
- ```ruby
169
- not_before = Time.now.to_i
170
- not_after = Time.now.to_i+3600*24*7300
171
- csr = R509::CSR.new(
172
- :subject => [['C','US'],['O','r509 LLC'],['CN','r509 Self-Signed CA Test']]
173
- )
174
- ca = R509::CertificateAuthority::Signer.new
175
- cert = ca.selfsign(
176
- :csr => csr,
177
- :not_before => not_before,
178
- :not_after => not_after
179
- )
180
- ```
181
-
182
- ###Config
183
-
184
- Create a basic CAConfig object
185
-
186
- ```ruby
187
- cert_pem = File.read("/path/to/cert")
188
- key_pem = File.read("/path/to/key")
189
- cert = R509::Cert.new(
190
- :cert => cert_pem,
191
- :key => key_pem
192
- )
193
- config = R509::Config::CAConfig.new(
194
- :ca_cert => cert
195
- )
196
- ```
197
-
198
- Add a signing profile named "server" (CAProfile) to a config object
199
-
200
- ```ruby
201
- profile = R509::Config::CAProfile.new(
202
- :basic_constraints => {"ca" : false},
203
- :key_usage => ["digitalSignature","keyEncipherment"],
204
- :extended_key_usage => ["serverAuth"],
205
- :certificate_policies => [
206
- { "policy_identifier" => "2.16.840.1.99999.21.234",
207
- "cps_uris" => ["http://example.com/cps","http://haha.com"],
208
- "user_notices" => [ { "explicit_text" => "this is a great thing", "organization" => "my org", "notice_numbers" => "1,2,3" } ]
209
- }
210
- ],
211
- :subject_item_policy => nil,
212
- :ocsp_no_check => false # this should only be true if you are setting OCSPSigning EKU
213
- )
214
- # config object from above assumed
215
- config.set_profile("server",profile)
216
- ```
217
-
218
- Set up a subject item policy (required/optional). The keys must match OpenSSL's shortnames!
219
-
220
- ```ruby
221
- profile = R509::Config::CAProfile.new(
222
- :basic_constraints => {"ca" : false},
223
- :key_usage => ["digitalSignature","keyEncipherment"],
224
- :extended_key_usage => ["serverAuth"],
225
- :subject_item_policy => {
226
- "CN" => "required",
227
- "O" => "optional"
228
- }
229
- )
230
- # config object from above assumed
231
- config.set_profile("server",profile)
232
- ```
233
-
234
- Load CAConfig + Profile from YAML
235
-
236
- ```ruby
237
- config = R509::Config::CAConfig.from_yaml("test_ca", "config_test.yaml")
238
- ```
239
-
240
- Example YAML (more options are supported than this example)
241
-
242
- ```yaml
243
- test_ca: {
244
- ca_cert: {
245
- cert: '/path/to/test_ca.cer',
246
- key: '/path/to/test_ca.key'
247
- },
248
- crl_list: "crl_list_file.txt",
249
- crl_number: "crl_number_file.txt",
250
- cdp_location: ['http://crl.domain.com/test_ca.crl'],
251
- crl_validity_hours: 168, #7 days
252
- ocsp_location: ['http://ocsp.domain.com'],
253
- ca_issuers_location: ['http://www.domain.com/my_roots.html'],
254
- message_digest: 'SHA1', #SHA1, SHA224, SHA256, SHA384, SHA512 supported. MD5 too, but you really shouldn't use that unless you have a good reason
255
- profiles: {
256
- server: {
257
- basic_constraints: {"ca" : false},
258
- key_usage: [digitalSignature,keyEncipherment],
259
- extended_key_usage: [serverAuth],
260
- certificate_policies: [
261
- { policy_identifier: "2.16.840.1.99999.21.234",
262
- cps_uris: ["http://example.com/cps","http://haha.com"],
263
- user_notices: [ { explicit_text: "this is a great thing", organization: "my org", notice_numbers: "1,2,3" } ]
264
- },
265
- { policy_identifier: "2.16.840.1.99999.21.235",
266
- cps_uris: ["http://example.com/cps2"],
267
- user_notices: [ { explicit_text: "this is a bad thing", organization: "another org", notice_numbers: "3,2,1" },{ explicit_text: "another user notice"} ]
268
- }
269
- ],
270
- subject_item_policy: {
271
- "CN" : "required",
272
- "O" : "optional",
273
- "ST" : "required",
274
- "C" : "required",
275
- "OU" : "optional" }
276
- }
277
- }
278
- }
279
- ```
280
-
281
- Load multiple CAConfigs using a CAConfigPool
282
-
283
- ```ruby
284
- pool = R509::Config::CAConfigPool.from_yaml("certificate_authorities", "config_pool.yaml")
285
- ```
286
-
287
- Example (Minimal) Config Pool YAML
288
-
289
- ```yaml
290
- certificate_authorities: {
291
- test_ca: {
292
- ca_cert: {
293
- cert: 'test_ca.cer',
294
- key: 'test_ca.key'
295
- }
296
- },
297
- second_ca: {
298
- ca_cert: {
299
- cert: 'second_ca.cer',
300
- key: 'second_ca.key'
301
- }
302
- }
303
- }
304
- ```
305
-
306
- ###CertificateAuthority
307
-
308
- Sign a CSR
309
-
310
- ```ruby
311
- csr = R509::CSR.new(
312
- :subject => [
313
- ['CN','somedomain.com'],
314
- ['O','My Org'],
315
- ['L','City'],
316
- ['ST','State'],
317
- ['C','US']
318
- ]
319
- )
320
- # assume config from yaml load above
321
- ca = R509::CertificateAuthority::Signer.new(config)
322
- cert = ca.sign(
323
- :profile_name => "server",
324
- :csr => csr
325
- )
326
- ```
327
-
328
- Override a CSR's subject or SAN names when signing
329
-
330
- ```ruby
331
- csr = R509::CSR.new(
332
- :subject => [
333
- ['CN','somedomain.com'],
334
- ['O','My Org'],
335
- ['L','City'],
336
- ['ST','State'],
337
- ['C','US']
338
- ]
339
- )
340
- subject = csr.subject.dup
341
- san_names = ["sannames.com","domain2.com","128.128.128.128"]
342
- subject.common_name = "newdomain.com"
343
- subject.organization = "Org 2.0"
344
- # assume config from yaml load above
345
- ca = R509::CertificateAuthority::Signer.new(config)
346
- cert = ca.sign(
347
- :profile_name => "server",
348
- :csr => csr,
349
- :subject => subject,
350
- :san_names => san_names
351
- )
352
- ```
353
-
354
- Sign an SPKI/SPKAC object
355
-
356
- ```ruby
357
- key = R509::PrivateKey.new(:type => :rsa, :bit_strength => 2048)
358
- spki = R509::SPKI.new(:key => key)
359
- # SPKI objects do not contain subject or san name data so it must be specified
360
- subject = R509::Subject.new
361
- subject.CN = "mydomain.com"
362
- subject.L = "Locality"
363
- subject.ST = "State"
364
- subject.C = "US"
365
- san_names = ["domain2.com","128.128.128.128"]
366
- # assume config from yaml load above
367
- ca = R509::CertificateAuthority::Signer.new(config)
368
- cert = ca.sign(
369
- :profile_name => "server",
370
- :spki => spki,
371
- :subject => subject,
372
- :san_names => san_names
373
- )
374
-
375
- ```
376
-
377
- ###OID Mapping
378
-
379
- Register one
380
-
381
- ```ruby
382
- R509::OIDMapper.register("1.3.5.6.7.8.3.23.3","short_name","optional_long_name")
383
- ```
384
-
385
- Register in batch
386
-
387
- ```ruby
388
- R509::OIDMapper.batch_register([
389
- {:oid => "1.3.5.6.7.8.3.23.3", :short_name => "short_name", :long_name => "optional_long_name"},
390
- {:oid => "1.3.5.6.7.8.3.23.5", :short_name => "another_name"}
391
- ])
392
- ```
393
-
394
- ###Alternate Key Algorithms
395
- 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:
396
-
397
- ```ruby
398
- R509.ec_supported?
399
- ```
400
-
401
- ####NIST Recommended Elliptic Curves
402
- These curves are set via ```:curve_name```. The system defaults to using ```secp384r1```
403
-
404
- * secp224r1 -- NIST/SECG curve over a 224 bit prime field
405
- * secp384r1 -- NIST/SECG curve over a 384 bit prime field
406
- * secp521r1 -- NIST/SECG curve over a 521 bit prime field
407
- * prime192v1 -- NIST/X9.62/SECG curve over a 192 bit prime field
408
- * sect163k1 -- NIST/SECG/WTLS curve over a 163 bit binary field
409
- * sect163r2 -- NIST/SECG curve over a 163 bit binary field
410
- * sect233k1 -- NIST/SECG/WTLS curve over a 233 bit binary field
411
- * sect233r1 -- NIST/SECG/WTLS curve over a 233 bit binary field
412
- * sect283k1 -- NIST/SECG curve over a 283 bit binary field
413
- * sect283r1 -- NIST/SECG curve over a 283 bit binary field
414
- * sect409k1 -- NIST/SECG curve over a 409 bit binary field
415
- * sect409r1 -- NIST/SECG curve over a 409 bit binary field
416
- * sect571k1 -- NIST/SECG curve over a 571 bit binary field
417
- * sect571r1 -- NIST/SECG curve over a 571 bit binary field
418
-
419
- ##Documentation
420
- There is documentation available for every method and class in r509 available via yardoc. 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. Alternately you can view pre-generated documentation at [r509.org](http://r509.org)
421
-
422
- ##Created by...
423
- [Paul Kehrer](https://github.com/reaperhulk)
424
-
425
- ##Thanks to...
426
- * [Sean Schulte](https://github.com/sirsean)
427
- * [Mike Ryan](https://github.com/justfalter)
428
-
429
- ##License
430
- See the LICENSE file. Licensed under the Apache 2.0 License.
431
-
432
- #YAML Config Options
433
- r509 configs are nested hashes of key:values that define the behavior of each CA. See r509.yaml for a full example config. These options can also be defined programmatically via R509::CAConfig and R509::CAProfile.
434
-
435
- ##ca\_name
436
- ###ca\_cert
437
- This hash defines the certificate + key that will be used to sign for the ca\_name. Depending on desired configuration various elements are optional. You can even supply just __cert__ (for example, if you are using an ocsp\_cert hash and only using the configured CA for OCSP responses)
438
-
439
- * cert (cannot use with pkcs12)
440
- * key (optional, cannot use with pkcs12)
441
- * engine (optional, cannot be used with key or pkcs12. Must be a hash with SO_PATH and ID keys)
442
- * key\_name (required when using engine)
443
- * pkcs12 (optional, cannot be used with key or cert)
444
- * password (optional, used for pkcs12 or passworded private key)
445
-
446
- ###ocsp\_cert
447
- This hash defines the certificate + key that will be used to sign for OCSP responses. OCSP responses cannot be directly created with r509, but require the ancillary gem [r509-ocsp-responder](https://github.com/reaperhulk/r509-ocsp-responder). This hash is optional and if not provided r509 will automatically use the ca\_cert as the OCSP certificate.
448
-
449
- * cert (cannot use with pkcs12)
450
- * key (optional, cannot use with pkcs12)
451
- * engine (optional, cannot be used with key or pkcs12. Must be a hash with SO_PATH and ID keys)
452
- * key\_name (required when using engine)
453
- * pkcs12 (optional, cannot be used with key or cert)
454
- * password (optional, used for pkcs12 or passworded private key)
455
-
456
- ###cdp\_location
457
- An array of CRL distribution points for certificates issued from this CA.
458
-
459
- ```yaml
460
- ['http://crl.r509.org/myca.crl']
461
- ```
462
-
463
- ###crl\_list
464
- The path on the filesystem of the list of revoked certificates for this CA.
465
-
466
- Example: '/path/to/my\_ca\_crl\_list.txt'
467
-
468
- ###crl\_number
469
- The path on the filesystem of the current CRL number for this CA.
470
-
471
- Example: '/path/to/my\_ca\_crl\_number.txt'
472
-
473
- ###crl\_validity\_hours
474
- Integer hours for CRL validity.
475
-
476
- ###ocsp\_location
477
- An array of URIs for client OCSP checks. These strings will be scanned and automatically processed to determine their proper type in the certificate.
478
-
479
- ```yaml
480
- ['http://ocsp.r509.org']
481
- ```
482
-
483
- ###ca\_issuers\_location
484
- An array of ca issuer locations. These strings will be scanned and automatically processed to determine their proper type in the certificate.
485
-
486
- ```yaml
487
- ['http://www.r509.org/some_roots.html']
488
- ```
489
-
490
- ###ocsp\_chain
491
- An optional path to a concatenated text file of PEMs that should be attached to OCSP responses
492
-
493
- ###ocsp\_validity\_hours
494
- Integer hours for OCSP response validity.
495
-
496
- ###ocsp\_start\_skew\_seconds
497
- Integer seconds to skew back the "thisUpdate" field. This prevents issues where the OCSP responder signs a response and the client rejects it because the response is "not yet valid" due to slight clock synchronization problems.
498
-
499
- ###message\_digest
500
- String value of the message digest to use for signing (both CRL and certificates). Allowed values are:
501
-
502
- * SHA1 (default)
503
- * SHA224
504
- * SHA256
505
- * SHA384
506
- * SHA512
507
- * MD5 (Don't use this unless you have a really, really good reason. Even then, you shouldn't)
508
-
509
- ###profiles
510
- Each CA can have an arbitrary number of issuance profiles (with arbitrary names). For example, a CA named __test\_ca__ might have 3 issuance profiles: server, email, clientserver. Each of these profiles then has a set of options that define the encoded data in the certificate for that profile. If no profiles are defined the root cannot issue certs, but can still issue CRLs.
511
-
512
- ####basic\_constraints
513
- All basic constraints are encoded with the critical bit set to true. The basic constraints config expects a hash with between one and two keys.
514
-
515
- #####ca
516
- The ca key is required and must be set to true (for an issuing CA) or false (everything else).
517
-
518
- #####path\_length
519
- This option is only allowed if ca is set to TRUE. path_length allows you to define the maximum number of non-self-issued intermediate certificates that may follow this certificate in a valid certification path. For example, if you set this value to 0 then the certificate issued can only issue end entity certificates, not additional subroots. This must be a non-negative integer (>=0).
520
-
521
- ```yaml
522
- {ca : true}
523
- {ca : false}
524
- {ca : true, path_length: 3}
525
- ```
526
-
527
- ####key\_usage
528
- An array of strings that conform to the OpenSSL naming scheme for available key usage OIDs.
529
-
530
- * digitalSignature
531
- * nonRepudiation
532
- * keyEncipherment
533
- * dataEncipherment
534
- * keyAgreement
535
- * keyCertSign
536
- * cRLSign
537
- * encipherOnly
538
- * decipherOnly
539
-
540
- ####extended\_key\_usage
541
- An array of strings that conform to the OpenSSL naming scheme for available EKU OIDs. The following list of allowed shortnames is taken from the OpenSSL docs. Depending on your OpenSSL version there may be more than this list.
542
-
543
- * serverAuth
544
- * clientAuth
545
- * codeSigning
546
- * emailProtection
547
- * OCSPSigning
548
- * timeStamping
549
- * msCodeInd (not part of RFC 5280)
550
- * msCodeCom (not part of RFC 5280)
551
- * msCTLSign (not part of RFC 5280)
552
- * msSGC (not part of RFC 5280)
553
- * msEFS (not part of RFC 5280)
554
- * nsSGC (not part of RFC 5280)
555
-
556
- ####certificate\_policies
557
- An array of hashes containing policy identifiers, CPS URI(s), and user notice(s)
558
-
559
- ```yaml
560
- [
561
- { policy_identifier: "2.16.840.1.99999.21.234",
562
- cps_uris: ["http://example.com/cps"]
563
- }
564
- ]
565
- ```
566
-
567
- or
568
-
569
- ```yaml
570
- [
571
- { policy_identifier: "2.16.840.1.99999.21.234",
572
- cps_uris: ["http://example.com/cps","http://haha.com"],
573
- user_notices: [ { explicit_text: "this is a great thing", organization: "my org", notice_numbers: "1,2,3" } ]
574
- },
575
- { policy_identifier: "2.16.840.1.99999.21.235",
576
- cps_uris: ["http://example.com/cps2"],
577
- user_notices: [ { explicit_text: "this is a bad thing", organization: "another org", notice_numbers: "3,2,1" },{ explicit_text: "another user notice"} ]
578
- }
579
- ]
580
- ```
581
-
582
- ####ocsp\_no\_check
583
- This is a boolean option that determines whether the OCSPNoCheck extension should be encoded in certificates issued by the profile. This flag is _only_ meaningful on certificates that contain the OCSPSigning EKU.
584
-
585
- ####inhibit\_any\_policy
586
- A non-negative integer value. From RFC 5280: "The inhibit anyPolicy extension can be used in certificates issued to CAs. The inhibit anyPolicy extension indicates that the special anyPolicy OID, with the value { 2 5 29 32 0 }, is not considered an explicit match for other certificate policies except when it appears in an intermediate self-issued CA certificate."
587
-
588
- ####policy\_constraints
589
- A hash with two optional keys (one or both may be present). From RFC 5280: "The policy constraints extension can be used in certificates issued to CAs. The policy constraints extension constrains path validation in two ways. It can be used to prohibit policy mapping or require that each certificate in a path contain an acceptable policy identifier"
590
-
591
- ```yaml
592
- { require_explicit_policy: 0, inhibit_policy_mapping: 0 }
593
- ```
594
-
595
- or if you only need one of the keys
596
-
597
- ```yaml
598
- { inhibit_policy_mapping: 0 }
599
- ```
600
-
601
- ###name\_constraints
602
- From RFC 5280: "The name constraints extension, which MUST be used only in a CA certificate, indicates a name space within which all subject names in subsequent certificates in a certification path MUST be located. Restrictions apply to the subject distinguished name and apply to subject alternative names. Restrictions apply only when the specified name form is present. If no name of the type is in the certificate, the certificate is acceptable.".
603
-
604
- This section is made up of a hash that contains permitted and excluded keys. Each (optional) key in turn has an array of hashes that declare a type and value. Types allowed are defined by R509::ASN1::GeneralName.map_type_to_tag. (examples: DNS, URI, IP, email, dirName)
605
-
606
- Notes:
607
- * When supplying IP you _must_ supply a full netmask in addition to an IP.
608
- * When supplying dirName the value is an array of arrays structured the same way as input to :subject in R509::CSR.new
609
-
610
- ```yaml
611
- {
612
- permitted: [
613
- {type: "IP", value: "192.168.0.0/255.255.0.0"},
614
- {type: "dirName", value: [['CN','myCN'],['O','Org']]}
615
- ],
616
- excluded: [
617
- {type: "email", value: "domain.com"},
618
- {type: "URI", value: ".net"},
619
- {type: "DNS", value: "test.us"}
620
- ]
621
- }
622
- ```
623
-
624
- ####subject\_item\_policy
625
- Hash of required/optional subject items. These must be in OpenSSL shortname format. If subject\_item\_policy is excluded from the profile then all subject items will be used. If it is included, __only items listed in the policy will be copied to the certificate__.
626
- Example:
627
-
628
- ```yaml
629
- CN : "required",
630
- O: "required",
631
- OU: "optional",
632
- ST: "required",
633
- C: "required",
634
- L: "required",
635
- emailAddress: "optional"
636
- ```
637
-
638
- If you use the R509::OIDMapper you can create new shortnames that are allowed within this directive.