r509 0.8
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +447 -0
- data/Rakefile +38 -0
- data/bin/r509 +96 -0
- data/bin/r509-parse +35 -0
- data/doc/R509.html +154 -0
- data/doc/R509/Cert.html +3954 -0
- data/doc/R509/Cert/Extensions.html +360 -0
- data/doc/R509/Cert/Extensions/AuthorityInfoAccess.html +391 -0
- data/doc/R509/Cert/Extensions/AuthorityKeyIdentifier.html +148 -0
- data/doc/R509/Cert/Extensions/BasicConstraints.html +482 -0
- data/doc/R509/Cert/Extensions/CrlDistributionPoints.html +316 -0
- data/doc/R509/Cert/Extensions/ExtendedKeyUsage.html +780 -0
- data/doc/R509/Cert/Extensions/KeyUsage.html +1230 -0
- data/doc/R509/Cert/Extensions/SubjectAlternativeName.html +467 -0
- data/doc/R509/Cert/Extensions/SubjectKeyIdentifier.html +216 -0
- data/doc/R509/CertificateAuthority.html +126 -0
- data/doc/R509/CertificateAuthority/Signer.html +855 -0
- data/doc/R509/Config.html +127 -0
- data/doc/R509/Config/CaConfig.html +2144 -0
- data/doc/R509/Config/CaConfigPool.html +599 -0
- data/doc/R509/Config/CaProfile.html +656 -0
- data/doc/R509/Config/SubjectItemPolicy.html +578 -0
- data/doc/R509/Crl.html +126 -0
- data/doc/R509/Crl/Administrator.html +2077 -0
- data/doc/R509/Crl/Parser.html +1224 -0
- data/doc/R509/Csr.html +2248 -0
- data/doc/R509/IOHelpers.html +564 -0
- data/doc/R509/MessageDigest.html +396 -0
- data/doc/R509/NameSanitizer.html +319 -0
- data/doc/R509/Ocsp.html +128 -0
- data/doc/R509/Ocsp/Request.html +126 -0
- data/doc/R509/Ocsp/Request/Nonce.html +160 -0
- data/doc/R509/Ocsp/Response.html +837 -0
- data/doc/R509/OidMapper.html +393 -0
- data/doc/R509/PrivateKey.html +1647 -0
- data/doc/R509/R509Error.html +134 -0
- data/doc/R509/Spki.html +1424 -0
- data/doc/R509/Subject.html +836 -0
- data/doc/R509/Validity.html +160 -0
- data/doc/R509/Validity/Checker.html +320 -0
- data/doc/R509/Validity/DefaultChecker.html +283 -0
- data/doc/R509/Validity/DefaultWriter.html +330 -0
- data/doc/R509/Validity/Status.html +561 -0
- data/doc/R509/Validity/Writer.html +394 -0
- data/doc/_index.html +501 -0
- data/doc/class_list.html +53 -0
- data/doc/css/common.css +1 -0
- data/doc/css/full_list.css +57 -0
- data/doc/css/style.css +328 -0
- data/doc/file.README.html +534 -0
- data/doc/file.r509.html +149 -0
- data/doc/file_list.html +58 -0
- data/doc/frames.html +28 -0
- data/doc/index.html +534 -0
- data/doc/js/app.js +208 -0
- data/doc/js/full_list.js +173 -0
- data/doc/js/jquery.js +4 -0
- data/doc/methods_list.html +1932 -0
- data/doc/top-level-namespace.html +112 -0
- data/lib/r509.rb +22 -0
- data/lib/r509/cert.rb +414 -0
- data/lib/r509/cert/extensions.rb +309 -0
- data/lib/r509/certificateauthority.rb +290 -0
- data/lib/r509/config.rb +407 -0
- data/lib/r509/crl.rb +379 -0
- data/lib/r509/csr.rb +324 -0
- data/lib/r509/exceptions.rb +5 -0
- data/lib/r509/io_helpers.rb +52 -0
- data/lib/r509/messagedigest.rb +49 -0
- data/lib/r509/ocsp.rb +85 -0
- data/lib/r509/oidmapper.rb +32 -0
- data/lib/r509/privatekey.rb +185 -0
- data/lib/r509/spki.rb +112 -0
- data/lib/r509/subject.rb +133 -0
- data/lib/r509/validity.rb +92 -0
- data/lib/r509/version.rb +4 -0
- data/r509.yaml +73 -0
- data/spec/cert/extensions_spec.rb +632 -0
- data/spec/cert_spec.rb +321 -0
- data/spec/certificate_authority_spec.rb +260 -0
- data/spec/config_spec.rb +349 -0
- data/spec/crl_spec.rb +215 -0
- data/spec/csr_spec.rb +302 -0
- data/spec/fixtures.rb +233 -0
- data/spec/fixtures/cert1.der +0 -0
- data/spec/fixtures/cert1.pem +24 -0
- data/spec/fixtures/cert1_public_key_modulus.txt +1 -0
- data/spec/fixtures/cert3.p12 +0 -0
- data/spec/fixtures/cert3.pem +28 -0
- data/spec/fixtures/cert3_key.pem +27 -0
- data/spec/fixtures/cert3_key_des3.pem +30 -0
- data/spec/fixtures/cert4.pem +14 -0
- data/spec/fixtures/cert5.pem +30 -0
- data/spec/fixtures/cert6.pem +26 -0
- data/spec/fixtures/cert_expired.pem +26 -0
- data/spec/fixtures/cert_not_yet_valid.pem +26 -0
- data/spec/fixtures/cert_san.pem +27 -0
- data/spec/fixtures/cert_san2.pem +22 -0
- data/spec/fixtures/config_pool_test_minimal.yaml +15 -0
- data/spec/fixtures/config_test.yaml +41 -0
- data/spec/fixtures/config_test_engine_key.yaml +7 -0
- data/spec/fixtures/config_test_engine_no_key_name.yaml +6 -0
- data/spec/fixtures/config_test_minimal.yaml +7 -0
- data/spec/fixtures/config_test_password.yaml +7 -0
- data/spec/fixtures/config_test_various.yaml +100 -0
- data/spec/fixtures/crl_list_file.txt +1 -0
- data/spec/fixtures/crl_with_reason.pem +17 -0
- data/spec/fixtures/csr1.der +0 -0
- data/spec/fixtures/csr1.pem +17 -0
- data/spec/fixtures/csr1_key.der +0 -0
- data/spec/fixtures/csr1_key.pem +27 -0
- data/spec/fixtures/csr1_key_encrypted_des3.pem +30 -0
- data/spec/fixtures/csr1_newlines.pem +32 -0
- data/spec/fixtures/csr1_no_begin_end.pem +15 -0
- data/spec/fixtures/csr1_public_key_modulus.txt +1 -0
- data/spec/fixtures/csr2.pem +15 -0
- data/spec/fixtures/csr2_key.pem +27 -0
- data/spec/fixtures/csr3.pem +16 -0
- data/spec/fixtures/csr4.pem +25 -0
- data/spec/fixtures/csr_dsa.pem +15 -0
- data/spec/fixtures/csr_invalid_signature.pem +13 -0
- data/spec/fixtures/dsa_key.pem +20 -0
- data/spec/fixtures/key4.pem +27 -0
- data/spec/fixtures/key4_encrypted_des3.pem +30 -0
- data/spec/fixtures/missing_key_identifier_ca.cer +21 -0
- data/spec/fixtures/missing_key_identifier_ca.key +27 -0
- data/spec/fixtures/ocsptest.r509.local.pem +27 -0
- data/spec/fixtures/ocsptest.r509.local_ocsp_request.der +0 -0
- data/spec/fixtures/ocsptest2.r509.local.pem +27 -0
- data/spec/fixtures/second_ca.cer +26 -0
- data/spec/fixtures/second_ca.key +27 -0
- data/spec/fixtures/spkac.der +0 -0
- data/spec/fixtures/spkac.txt +1 -0
- data/spec/fixtures/spkac_dsa.txt +1 -0
- data/spec/fixtures/stca.pem +22 -0
- data/spec/fixtures/stca_ocsp_request.der +0 -0
- data/spec/fixtures/stca_ocsp_response.der +0 -0
- data/spec/fixtures/test1.csr +17 -0
- data/spec/fixtures/test_ca.cer +22 -0
- data/spec/fixtures/test_ca.key +28 -0
- data/spec/fixtures/test_ca.p12 +0 -0
- data/spec/fixtures/test_ca_des3.key +30 -0
- data/spec/fixtures/test_ca_ocsp.cer +26 -0
- data/spec/fixtures/test_ca_ocsp.key +27 -0
- data/spec/fixtures/test_ca_ocsp.p12 +0 -0
- data/spec/fixtures/test_ca_ocsp_chain.txt +48 -0
- data/spec/fixtures/test_ca_ocsp_response.der +0 -0
- data/spec/fixtures/test_ca_subroot.cer +26 -0
- data/spec/fixtures/test_ca_subroot.key +27 -0
- data/spec/fixtures/test_ca_subroot_ocsp.cer +25 -0
- data/spec/fixtures/test_ca_subroot_ocsp.key +27 -0
- data/spec/fixtures/test_ca_subroot_ocsp_response.der +0 -0
- data/spec/fixtures/unknown_oid.csr +17 -0
- data/spec/message_digest_spec.rb +89 -0
- data/spec/ocsp_spec.rb +111 -0
- data/spec/oid_mapper_spec.rb +31 -0
- data/spec/privatekey_spec.rb +198 -0
- data/spec/spec_helper.rb +14 -0
- data/spec/spki_spec.rb +157 -0
- data/spec/subject_spec.rb +203 -0
- data/spec/validity_spec.rb +98 -0
- metadata +257 -0
data/README.md
ADDED
@@ -0,0 +1,447 @@
|
|
1
|
+
#r509 [![Build Status](https://secure.travis-ci.org/reaperhulk/r509.png)](http://travis-ci.org/reaperhulk/r509)
|
2
|
+
r509 is a wrapper for various OpenSSL functions to allow easy creation of CSRs, signing of certificates, and revocation via CRL. 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 certificate authority for use in production environments.
|
3
|
+
|
4
|
+
##Requirements/Installation
|
5
|
+
|
6
|
+
r509 requires the Ruby OpenSSL bindings as well as yaml support (present by default in modern Ruby builds).
|
7
|
+
To install the gem: ```gem install r509-(version).gem```
|
8
|
+
|
9
|
+
##Running Tests/Building Gem
|
10
|
+
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.
|
11
|
+
|
12
|
+
##Continuous Integration
|
13
|
+
We run continuous integration tests (using Travis-CI) against 1.8.7, 1.9.2, 1.9.3, ree, ruby-head, and rubinius(rbx) 2.0 in 1.9 mode.
|
14
|
+
|
15
|
+
##Executable
|
16
|
+
|
17
|
+
Inside the gem there is a bin directory that contains ```r509```. You can use this in interactive mode to generate a CSR and (optionally) self-sign it.
|
18
|
+
|
19
|
+
##Usage
|
20
|
+
###CSR
|
21
|
+
To generate a 2048-bit RSA CSR
|
22
|
+
|
23
|
+
```ruby
|
24
|
+
csr = R509::Csr.new(
|
25
|
+
:subject => [
|
26
|
+
['CN','somedomain.com'],
|
27
|
+
['O','My Org'],
|
28
|
+
['L','City'],
|
29
|
+
['ST','State'],
|
30
|
+
['C','US']
|
31
|
+
]
|
32
|
+
)
|
33
|
+
```
|
34
|
+
|
35
|
+
To load an existing CSR (without private key)
|
36
|
+
|
37
|
+
```ruby
|
38
|
+
csr_pem = File.read("/path/to/csr")
|
39
|
+
csr = R509::Csr.new(:csr => csr_pem)
|
40
|
+
# or
|
41
|
+
csr = R509::Csr.load_from_file("/path/to/csr")
|
42
|
+
```
|
43
|
+
|
44
|
+
To create a new CSR from the subject of a certificate
|
45
|
+
|
46
|
+
```ruby
|
47
|
+
cert_pem = File.read("/path/to/cert")
|
48
|
+
csr = R509::Csr.new(:cert => cert_pem)
|
49
|
+
```
|
50
|
+
|
51
|
+
To create a CSR with SAN names
|
52
|
+
|
53
|
+
```ruby
|
54
|
+
csr = R509::Csr.new(
|
55
|
+
:subject => [['CN','something.com']],
|
56
|
+
:san_names => ["something2.com","something3.com"]
|
57
|
+
)
|
58
|
+
```
|
59
|
+
|
60
|
+
###Cert
|
61
|
+
To load an existing certificate
|
62
|
+
|
63
|
+
```ruby
|
64
|
+
cert_pem = File.read("/path/to/cert")
|
65
|
+
cert = R509::Cert.new(:cert => cert_pem)
|
66
|
+
# or
|
67
|
+
cert = R509::Cert.load_from_file("/path/to/cert")
|
68
|
+
```
|
69
|
+
|
70
|
+
Load a cert and key
|
71
|
+
|
72
|
+
```ruby
|
73
|
+
cert_pem = File.read("/path/to/cert")
|
74
|
+
key_pem = File.read("/path/to/key")
|
75
|
+
cert = R509::Cert.new(
|
76
|
+
:cert => cert_pem,
|
77
|
+
:key => key_pem
|
78
|
+
)
|
79
|
+
```
|
80
|
+
|
81
|
+
Load an encrypted private key
|
82
|
+
|
83
|
+
```ruby
|
84
|
+
cert_pem = File.read("/path/to/cert")
|
85
|
+
key_pem = File.read("/path/to/key")
|
86
|
+
cert = R509::Cert.new(
|
87
|
+
:cert => cert_pem,
|
88
|
+
:key => key_pem,
|
89
|
+
:password => "private_key_password"
|
90
|
+
)
|
91
|
+
```
|
92
|
+
|
93
|
+
Load a PKCS12 file
|
94
|
+
|
95
|
+
```ruby
|
96
|
+
pkcs12_der = File.read("/path/to/p12")
|
97
|
+
cert = R509::Cert.new(
|
98
|
+
:pkcs12 => pkcs12_der,
|
99
|
+
:password => "password"
|
100
|
+
)
|
101
|
+
```
|
102
|
+
|
103
|
+
###Self-Signed Certificate
|
104
|
+
To create a self-signed certificate
|
105
|
+
|
106
|
+
```ruby
|
107
|
+
not_before = Time.now.to_i
|
108
|
+
not_after = Time.now.to_i+3600*24*7300
|
109
|
+
csr = R509::Csr.new(
|
110
|
+
:subject => [['C','US'],['O','r509 LLC'],['CN','r509 Self-Signed CA Test']]
|
111
|
+
)
|
112
|
+
ca = R509::CertificateAuthority::Signer.new
|
113
|
+
cert = ca.selfsign(
|
114
|
+
:csr => csr,
|
115
|
+
:not_before => not_before,
|
116
|
+
:not_after => not_after
|
117
|
+
)
|
118
|
+
```
|
119
|
+
|
120
|
+
###Config
|
121
|
+
|
122
|
+
Create a basic CaConfig object
|
123
|
+
|
124
|
+
```ruby
|
125
|
+
cert_pem = File.read("/path/to/cert")
|
126
|
+
key_pem = File.read("/path/to/key")
|
127
|
+
cert = R509::Cert.new(
|
128
|
+
:cert => cert_pem,
|
129
|
+
:key => key_pem
|
130
|
+
)
|
131
|
+
config = R509::Config::CaConfig.new(
|
132
|
+
:ca_cert => cert
|
133
|
+
)
|
134
|
+
```
|
135
|
+
|
136
|
+
Add a signing profile named "server" (CaProfile) to a config object
|
137
|
+
|
138
|
+
```ruby
|
139
|
+
profile = R509::Config::CaProfile.new(
|
140
|
+
:basic_constraints => "CA:FALSE",
|
141
|
+
:key_usage => ["digitalSignature","keyEncipherment"],
|
142
|
+
:extended_key_usage => ["serverAuth"],
|
143
|
+
:certificate_policies => [ ["policyIdentifier=2.16.840.1.999999999.1.2.3.4.1", "CPS.1=http://example.com/cps"] ],
|
144
|
+
:subject_item_policy => nil
|
145
|
+
)
|
146
|
+
# config object from above assumed
|
147
|
+
config.set_profile("server",profile)
|
148
|
+
```
|
149
|
+
|
150
|
+
Set up a subject item policy (required/optional). The keys must match OpenSSL's shortnames!
|
151
|
+
|
152
|
+
```ruby
|
153
|
+
profile = R509::Config::CaProfile.new(
|
154
|
+
:basic_constraints => "CA:FALSE",
|
155
|
+
:key_usage => ["digitalSignature","keyEncipherment"],
|
156
|
+
:extended_key_usage => ["serverAuth"],
|
157
|
+
:certificate_policies => [ ["policyIdentifier=2.16.840.1.999999999.1.2.3.4.1", "CPS.1=http://example.com/cps"] ],
|
158
|
+
:subject_item_policy => {
|
159
|
+
"CN" => "required",
|
160
|
+
"O" => "optional"
|
161
|
+
}
|
162
|
+
)
|
163
|
+
# config object from above assumed
|
164
|
+
config.set_profile("server",profile)
|
165
|
+
```
|
166
|
+
|
167
|
+
Load CaConfig + Profile from YAML
|
168
|
+
|
169
|
+
```ruby
|
170
|
+
config = R509::Config::CaConfig.from_yaml("test_ca", "config_test.yaml")
|
171
|
+
```
|
172
|
+
|
173
|
+
Example YAML (more options are supported than this example)
|
174
|
+
|
175
|
+
```yaml
|
176
|
+
test_ca: {
|
177
|
+
ca_cert: {
|
178
|
+
cert: '/path/to/test_ca.cer',
|
179
|
+
key: '/path/to/test_ca.key'
|
180
|
+
},
|
181
|
+
crl_list: "crl_list_file.txt",
|
182
|
+
crl_number: "crl_number_file.txt",
|
183
|
+
cdp_location: 'URI:http://crl.domain.com/test_ca.crl',
|
184
|
+
crl_validity_hours: 168, #7 days
|
185
|
+
ocsp_location: 'URI:http://ocsp.domain.com',
|
186
|
+
message_digest: 'SHA1', #SHA1, SHA256, SHA512 supported. MD5 too, but you really shouldn't use that unless you have a good reason
|
187
|
+
profiles: {
|
188
|
+
server: {
|
189
|
+
basic_constraints: "CA:FALSE",
|
190
|
+
key_usage: [digitalSignature,keyEncipherment],
|
191
|
+
extended_key_usage: [serverAuth],
|
192
|
+
certificate_policies: [ [ "policyIdentifier=2.16.840.1.9999999999.1.2.3.4.1", "CPS.1=http://example.com/cps"] ],
|
193
|
+
subject_item_policy: {
|
194
|
+
"CN" : "required",
|
195
|
+
"O" : "optional",
|
196
|
+
"ST" : "required",
|
197
|
+
"C" : "required",
|
198
|
+
"OU" : "optional" }
|
199
|
+
}
|
200
|
+
}
|
201
|
+
}
|
202
|
+
```
|
203
|
+
|
204
|
+
Load multiple CaConfigs using a CaConfigPool
|
205
|
+
|
206
|
+
```ruby
|
207
|
+
pool = R509::Config::CaConfigPool.from_yaml("certificate_authorities", "config_pool.yaml")
|
208
|
+
```
|
209
|
+
|
210
|
+
Example (Minimal) Config Pool YAML
|
211
|
+
|
212
|
+
```yaml
|
213
|
+
certificate_authorities: {
|
214
|
+
test_ca: {
|
215
|
+
ca_cert: {
|
216
|
+
cert: 'test_ca.cer',
|
217
|
+
key: 'test_ca.key'
|
218
|
+
}
|
219
|
+
},
|
220
|
+
second_ca: {
|
221
|
+
ca_cert: {
|
222
|
+
cert: 'second_ca.cer',
|
223
|
+
key: 'second_ca.key'
|
224
|
+
}
|
225
|
+
}
|
226
|
+
}
|
227
|
+
```
|
228
|
+
|
229
|
+
###CertificateAuthority
|
230
|
+
|
231
|
+
Sign a CSR
|
232
|
+
|
233
|
+
```ruby
|
234
|
+
csr = R509::Csr.new(
|
235
|
+
:subject => [
|
236
|
+
['CN','somedomain.com'],
|
237
|
+
['O','My Org'],
|
238
|
+
['L','City'],
|
239
|
+
['ST','State'],
|
240
|
+
['C','US']
|
241
|
+
]
|
242
|
+
)
|
243
|
+
# assume config from yaml load above
|
244
|
+
ca = R509::CertificateAuthority::Signer.new(config)
|
245
|
+
cert = ca.sign(
|
246
|
+
:profile_name => "server",
|
247
|
+
:csr => csr
|
248
|
+
)
|
249
|
+
```
|
250
|
+
|
251
|
+
Override a CSR's subject or SAN names when signing
|
252
|
+
|
253
|
+
```ruby
|
254
|
+
csr = R509::Csr.new(
|
255
|
+
:subject => [
|
256
|
+
['CN','somedomain.com'],
|
257
|
+
['O','My Org'],
|
258
|
+
['L','City'],
|
259
|
+
['ST','State'],
|
260
|
+
['C','US']
|
261
|
+
]
|
262
|
+
)
|
263
|
+
data_hash = csr.to_hash
|
264
|
+
data_hash[:san_names] = ["sannames.com","domain2.com"]
|
265
|
+
data_hash[:subject]["CN"] = "newdomain.com"
|
266
|
+
data_hash[:subject]["O"] = "Org 2.0"
|
267
|
+
# assume config from yaml load above
|
268
|
+
ca = R509::CertificateAuthority::Signer.new(config)
|
269
|
+
cert = ca.sign(
|
270
|
+
:profile_name => "server",
|
271
|
+
:csr => csr,
|
272
|
+
:data_hash => data_hash
|
273
|
+
)
|
274
|
+
```
|
275
|
+
|
276
|
+
###Load Hardware Engines
|
277
|
+
|
278
|
+
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.
|
279
|
+
|
280
|
+
```ruby
|
281
|
+
OpenSSL::Engine.load("engine_name")
|
282
|
+
engine = OpenSSL::Engine.by_id("engine_name")
|
283
|
+
key = R509::PrivateKey(
|
284
|
+
:engine => engine,
|
285
|
+
:key_name => "my_key_name"
|
286
|
+
)
|
287
|
+
```
|
288
|
+
|
289
|
+
You can then use this key for signing.
|
290
|
+
|
291
|
+
|
292
|
+
###OID Mapping
|
293
|
+
|
294
|
+
Register one
|
295
|
+
|
296
|
+
```ruby
|
297
|
+
R509::OidMapper.register("1.3.5.6.7.8.3.23.3","short_name","optional_long_name")
|
298
|
+
```
|
299
|
+
|
300
|
+
Register in batch
|
301
|
+
|
302
|
+
```ruby
|
303
|
+
R509::OidMapper.batch_register([
|
304
|
+
{:oid => "1.3.5.6.7.8.3.23.3", :short_name => "short_name", :long_name => "optional_long_name"},
|
305
|
+
{:oid => "1.3.5.6.7.8.3.23.5", :short_name => "another_name"}
|
306
|
+
])
|
307
|
+
```
|
308
|
+
|
309
|
+
##Documentation
|
310
|
+
|
311
|
+
There is (relatively) complete 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.
|
312
|
+
|
313
|
+
|
314
|
+
##Thanks to...
|
315
|
+
* [Sean Schulte](https://github.com/sirsean)
|
316
|
+
* [Mike Ryan](https://github.com/justfalter)
|
317
|
+
|
318
|
+
##License
|
319
|
+
See the LICENSE file. Licensed under the Apache 2.0 License.
|
320
|
+
|
321
|
+
#YAML Config Options
|
322
|
+
r509 configs are nested hashes of key:values that define the behavior of each CA. See r509.yaml for a full example config.
|
323
|
+
|
324
|
+
##ca\_name
|
325
|
+
###ca\_cert
|
326
|
+
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)
|
327
|
+
|
328
|
+
* cert (cannot use with pkcs12)
|
329
|
+
* key (cannot use with key)
|
330
|
+
* engine (optional, cannot be used with key or pkcs12)
|
331
|
+
* key\_name (required when using engine)
|
332
|
+
* pkcs12 (optional, cannot be used with key or cert)
|
333
|
+
* password (optional, used for pkcs12 or passworded private key)
|
334
|
+
|
335
|
+
###ocsp\_cert
|
336
|
+
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.
|
337
|
+
|
338
|
+
* cert (cannot use with pkcs12)
|
339
|
+
* key (cannot use with key)
|
340
|
+
* engine (optional, cannot be used with key or pkcs12)
|
341
|
+
* key\_name (required when using engine)
|
342
|
+
* pkcs12 (optional, cannot be used with key or cert)
|
343
|
+
* password (optional, used for pkcs12 or passworded private key)
|
344
|
+
|
345
|
+
###cdp\_location
|
346
|
+
The CRL distribution point for certificates issued from this CA.
|
347
|
+
|
348
|
+
Example: 'URI:http://crl.r509.org/myca.crl'
|
349
|
+
|
350
|
+
###crl\_list
|
351
|
+
The path on the filesystem of the list of revoked certificates for this CA.
|
352
|
+
|
353
|
+
Example: '/path/to/my\_ca\_crl\_list.txt'
|
354
|
+
|
355
|
+
###crl\_number
|
356
|
+
The path on the filesystem of the current CRL number for this CA.
|
357
|
+
|
358
|
+
Example: '/path/to/my\_ca\_crl\_number.txt'
|
359
|
+
|
360
|
+
###crl\_validity\_hours
|
361
|
+
Integer hours for CRL validity.
|
362
|
+
|
363
|
+
###ocsp\_location
|
364
|
+
The OCSP AIA extension value for certificates issued from this CA.
|
365
|
+
|
366
|
+
Example: 'URI:http://ocsp.r509.org'
|
367
|
+
|
368
|
+
###ocsp\_chain
|
369
|
+
An optional path to a concatenated text file of PEMs that should be attached to OCSP responses
|
370
|
+
|
371
|
+
###ocsp\_validity\_hours
|
372
|
+
Integer hours for OCSP response validity.
|
373
|
+
|
374
|
+
###ocsp\_start\_skew\_seconds
|
375
|
+
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.
|
376
|
+
|
377
|
+
###message\_digest
|
378
|
+
String value of the message digest to use for signing (both CRL and certificates). Allowed values are:
|
379
|
+
|
380
|
+
* SHA1 (default)
|
381
|
+
* SHA256
|
382
|
+
* SHA512
|
383
|
+
* MD5 (Don't use this unless you have a really, really good reason. Even then, you shouldn't)
|
384
|
+
|
385
|
+
###profiles
|
386
|
+
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.
|
387
|
+
|
388
|
+
####basic\_constraints
|
389
|
+
All basic constraints are encoded with the critical bit set to true. In general you should only pass "CA:TRUE" (for an issuing CA) or "CA:FALSE" for everything else with this flag.
|
390
|
+
|
391
|
+
####key\_usage
|
392
|
+
An array of strings that conform to the OpenSSL naming scheme for available key usage OIDs. TODO: Document whether arbitrary OIDs can be passed here.
|
393
|
+
|
394
|
+
* digitalSignature
|
395
|
+
* nonRepudiation
|
396
|
+
* keyEncipherment
|
397
|
+
* dataEncipherment
|
398
|
+
* keyAgreement
|
399
|
+
* keyCertSign
|
400
|
+
* cRLSign
|
401
|
+
* encipherOnly
|
402
|
+
* decipherOnly
|
403
|
+
|
404
|
+
####extended\_key\_usage
|
405
|
+
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.
|
406
|
+
|
407
|
+
* serverAuth
|
408
|
+
* clientAuth
|
409
|
+
* codeSigning
|
410
|
+
* emailProtection
|
411
|
+
* OCSPSigning
|
412
|
+
* timeStamping
|
413
|
+
* msCodeInd
|
414
|
+
* msCodeCom
|
415
|
+
* msCTLSign
|
416
|
+
* msSGC
|
417
|
+
* msEFS
|
418
|
+
* nsSGC
|
419
|
+
|
420
|
+
####certificate\_policies
|
421
|
+
An array of arrays containing policy identifiers and CPS URIs. For example:
|
422
|
+
|
423
|
+
```yaml
|
424
|
+
[ [ "policyIdentifier=2.16.840.1.9999999.1.2.3.4.2","CPS.1=http://r509.org/cps" ] ]
|
425
|
+
```
|
426
|
+
|
427
|
+
or
|
428
|
+
|
429
|
+
```yaml
|
430
|
+
[ ["policyIdentifier=2.16.840.1.999999.0"], [ "policyIdentifier=2.16.840.1.9999999.1.2.3.4.2","CPS.1=http://r509.org/cps" ] ]
|
431
|
+
```
|
432
|
+
|
433
|
+
####subject\_item\_policy
|
434
|
+
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__.
|
435
|
+
Example:
|
436
|
+
|
437
|
+
```yaml
|
438
|
+
CN : "required",
|
439
|
+
O: "required",
|
440
|
+
OU: "optional",
|
441
|
+
ST: "required",
|
442
|
+
C: "required",
|
443
|
+
L: "required",
|
444
|
+
emailAddress: "optional"
|
445
|
+
```
|
446
|
+
|
447
|
+
If you use the R509::OidMapper you can create new shortnames that are allowed within this directive.
|
data/Rakefile
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rspec/core/rake_task'
|
3
|
+
require "#{File.dirname(__FILE__)}/lib/r509/version"
|
4
|
+
|
5
|
+
task :default => :spec
|
6
|
+
RSpec::Core::RakeTask.new(:spec)
|
7
|
+
|
8
|
+
desc 'Run all rspec tests with rcov (1.8 only)'
|
9
|
+
RSpec::Core::RakeTask.new(:rcov) do |t|
|
10
|
+
t.rcov_opts = %q[--exclude "spec,gems"]
|
11
|
+
t.rcov = true
|
12
|
+
end
|
13
|
+
|
14
|
+
|
15
|
+
namespace :gem do
|
16
|
+
desc 'Build the gem'
|
17
|
+
task :build do
|
18
|
+
puts `yard`
|
19
|
+
puts `gem build r509.gemspec`
|
20
|
+
end
|
21
|
+
|
22
|
+
desc 'Install gem'
|
23
|
+
task :install do
|
24
|
+
puts `gem install r509-#{R509::VERSION}.gem`
|
25
|
+
end
|
26
|
+
|
27
|
+
desc 'Uninstall gem'
|
28
|
+
task :uninstall do
|
29
|
+
puts `gem uninstall r509`
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
|
34
|
+
desc 'Build yard documentation'
|
35
|
+
task :yard do
|
36
|
+
puts `yard`
|
37
|
+
`open doc/index.html`
|
38
|
+
end
|