r509 0.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (162) hide show
  1. data/README.md +447 -0
  2. data/Rakefile +38 -0
  3. data/bin/r509 +96 -0
  4. data/bin/r509-parse +35 -0
  5. data/doc/R509.html +154 -0
  6. data/doc/R509/Cert.html +3954 -0
  7. data/doc/R509/Cert/Extensions.html +360 -0
  8. data/doc/R509/Cert/Extensions/AuthorityInfoAccess.html +391 -0
  9. data/doc/R509/Cert/Extensions/AuthorityKeyIdentifier.html +148 -0
  10. data/doc/R509/Cert/Extensions/BasicConstraints.html +482 -0
  11. data/doc/R509/Cert/Extensions/CrlDistributionPoints.html +316 -0
  12. data/doc/R509/Cert/Extensions/ExtendedKeyUsage.html +780 -0
  13. data/doc/R509/Cert/Extensions/KeyUsage.html +1230 -0
  14. data/doc/R509/Cert/Extensions/SubjectAlternativeName.html +467 -0
  15. data/doc/R509/Cert/Extensions/SubjectKeyIdentifier.html +216 -0
  16. data/doc/R509/CertificateAuthority.html +126 -0
  17. data/doc/R509/CertificateAuthority/Signer.html +855 -0
  18. data/doc/R509/Config.html +127 -0
  19. data/doc/R509/Config/CaConfig.html +2144 -0
  20. data/doc/R509/Config/CaConfigPool.html +599 -0
  21. data/doc/R509/Config/CaProfile.html +656 -0
  22. data/doc/R509/Config/SubjectItemPolicy.html +578 -0
  23. data/doc/R509/Crl.html +126 -0
  24. data/doc/R509/Crl/Administrator.html +2077 -0
  25. data/doc/R509/Crl/Parser.html +1224 -0
  26. data/doc/R509/Csr.html +2248 -0
  27. data/doc/R509/IOHelpers.html +564 -0
  28. data/doc/R509/MessageDigest.html +396 -0
  29. data/doc/R509/NameSanitizer.html +319 -0
  30. data/doc/R509/Ocsp.html +128 -0
  31. data/doc/R509/Ocsp/Request.html +126 -0
  32. data/doc/R509/Ocsp/Request/Nonce.html +160 -0
  33. data/doc/R509/Ocsp/Response.html +837 -0
  34. data/doc/R509/OidMapper.html +393 -0
  35. data/doc/R509/PrivateKey.html +1647 -0
  36. data/doc/R509/R509Error.html +134 -0
  37. data/doc/R509/Spki.html +1424 -0
  38. data/doc/R509/Subject.html +836 -0
  39. data/doc/R509/Validity.html +160 -0
  40. data/doc/R509/Validity/Checker.html +320 -0
  41. data/doc/R509/Validity/DefaultChecker.html +283 -0
  42. data/doc/R509/Validity/DefaultWriter.html +330 -0
  43. data/doc/R509/Validity/Status.html +561 -0
  44. data/doc/R509/Validity/Writer.html +394 -0
  45. data/doc/_index.html +501 -0
  46. data/doc/class_list.html +53 -0
  47. data/doc/css/common.css +1 -0
  48. data/doc/css/full_list.css +57 -0
  49. data/doc/css/style.css +328 -0
  50. data/doc/file.README.html +534 -0
  51. data/doc/file.r509.html +149 -0
  52. data/doc/file_list.html +58 -0
  53. data/doc/frames.html +28 -0
  54. data/doc/index.html +534 -0
  55. data/doc/js/app.js +208 -0
  56. data/doc/js/full_list.js +173 -0
  57. data/doc/js/jquery.js +4 -0
  58. data/doc/methods_list.html +1932 -0
  59. data/doc/top-level-namespace.html +112 -0
  60. data/lib/r509.rb +22 -0
  61. data/lib/r509/cert.rb +414 -0
  62. data/lib/r509/cert/extensions.rb +309 -0
  63. data/lib/r509/certificateauthority.rb +290 -0
  64. data/lib/r509/config.rb +407 -0
  65. data/lib/r509/crl.rb +379 -0
  66. data/lib/r509/csr.rb +324 -0
  67. data/lib/r509/exceptions.rb +5 -0
  68. data/lib/r509/io_helpers.rb +52 -0
  69. data/lib/r509/messagedigest.rb +49 -0
  70. data/lib/r509/ocsp.rb +85 -0
  71. data/lib/r509/oidmapper.rb +32 -0
  72. data/lib/r509/privatekey.rb +185 -0
  73. data/lib/r509/spki.rb +112 -0
  74. data/lib/r509/subject.rb +133 -0
  75. data/lib/r509/validity.rb +92 -0
  76. data/lib/r509/version.rb +4 -0
  77. data/r509.yaml +73 -0
  78. data/spec/cert/extensions_spec.rb +632 -0
  79. data/spec/cert_spec.rb +321 -0
  80. data/spec/certificate_authority_spec.rb +260 -0
  81. data/spec/config_spec.rb +349 -0
  82. data/spec/crl_spec.rb +215 -0
  83. data/spec/csr_spec.rb +302 -0
  84. data/spec/fixtures.rb +233 -0
  85. data/spec/fixtures/cert1.der +0 -0
  86. data/spec/fixtures/cert1.pem +24 -0
  87. data/spec/fixtures/cert1_public_key_modulus.txt +1 -0
  88. data/spec/fixtures/cert3.p12 +0 -0
  89. data/spec/fixtures/cert3.pem +28 -0
  90. data/spec/fixtures/cert3_key.pem +27 -0
  91. data/spec/fixtures/cert3_key_des3.pem +30 -0
  92. data/spec/fixtures/cert4.pem +14 -0
  93. data/spec/fixtures/cert5.pem +30 -0
  94. data/spec/fixtures/cert6.pem +26 -0
  95. data/spec/fixtures/cert_expired.pem +26 -0
  96. data/spec/fixtures/cert_not_yet_valid.pem +26 -0
  97. data/spec/fixtures/cert_san.pem +27 -0
  98. data/spec/fixtures/cert_san2.pem +22 -0
  99. data/spec/fixtures/config_pool_test_minimal.yaml +15 -0
  100. data/spec/fixtures/config_test.yaml +41 -0
  101. data/spec/fixtures/config_test_engine_key.yaml +7 -0
  102. data/spec/fixtures/config_test_engine_no_key_name.yaml +6 -0
  103. data/spec/fixtures/config_test_minimal.yaml +7 -0
  104. data/spec/fixtures/config_test_password.yaml +7 -0
  105. data/spec/fixtures/config_test_various.yaml +100 -0
  106. data/spec/fixtures/crl_list_file.txt +1 -0
  107. data/spec/fixtures/crl_with_reason.pem +17 -0
  108. data/spec/fixtures/csr1.der +0 -0
  109. data/spec/fixtures/csr1.pem +17 -0
  110. data/spec/fixtures/csr1_key.der +0 -0
  111. data/spec/fixtures/csr1_key.pem +27 -0
  112. data/spec/fixtures/csr1_key_encrypted_des3.pem +30 -0
  113. data/spec/fixtures/csr1_newlines.pem +32 -0
  114. data/spec/fixtures/csr1_no_begin_end.pem +15 -0
  115. data/spec/fixtures/csr1_public_key_modulus.txt +1 -0
  116. data/spec/fixtures/csr2.pem +15 -0
  117. data/spec/fixtures/csr2_key.pem +27 -0
  118. data/spec/fixtures/csr3.pem +16 -0
  119. data/spec/fixtures/csr4.pem +25 -0
  120. data/spec/fixtures/csr_dsa.pem +15 -0
  121. data/spec/fixtures/csr_invalid_signature.pem +13 -0
  122. data/spec/fixtures/dsa_key.pem +20 -0
  123. data/spec/fixtures/key4.pem +27 -0
  124. data/spec/fixtures/key4_encrypted_des3.pem +30 -0
  125. data/spec/fixtures/missing_key_identifier_ca.cer +21 -0
  126. data/spec/fixtures/missing_key_identifier_ca.key +27 -0
  127. data/spec/fixtures/ocsptest.r509.local.pem +27 -0
  128. data/spec/fixtures/ocsptest.r509.local_ocsp_request.der +0 -0
  129. data/spec/fixtures/ocsptest2.r509.local.pem +27 -0
  130. data/spec/fixtures/second_ca.cer +26 -0
  131. data/spec/fixtures/second_ca.key +27 -0
  132. data/spec/fixtures/spkac.der +0 -0
  133. data/spec/fixtures/spkac.txt +1 -0
  134. data/spec/fixtures/spkac_dsa.txt +1 -0
  135. data/spec/fixtures/stca.pem +22 -0
  136. data/spec/fixtures/stca_ocsp_request.der +0 -0
  137. data/spec/fixtures/stca_ocsp_response.der +0 -0
  138. data/spec/fixtures/test1.csr +17 -0
  139. data/spec/fixtures/test_ca.cer +22 -0
  140. data/spec/fixtures/test_ca.key +28 -0
  141. data/spec/fixtures/test_ca.p12 +0 -0
  142. data/spec/fixtures/test_ca_des3.key +30 -0
  143. data/spec/fixtures/test_ca_ocsp.cer +26 -0
  144. data/spec/fixtures/test_ca_ocsp.key +27 -0
  145. data/spec/fixtures/test_ca_ocsp.p12 +0 -0
  146. data/spec/fixtures/test_ca_ocsp_chain.txt +48 -0
  147. data/spec/fixtures/test_ca_ocsp_response.der +0 -0
  148. data/spec/fixtures/test_ca_subroot.cer +26 -0
  149. data/spec/fixtures/test_ca_subroot.key +27 -0
  150. data/spec/fixtures/test_ca_subroot_ocsp.cer +25 -0
  151. data/spec/fixtures/test_ca_subroot_ocsp.key +27 -0
  152. data/spec/fixtures/test_ca_subroot_ocsp_response.der +0 -0
  153. data/spec/fixtures/unknown_oid.csr +17 -0
  154. data/spec/message_digest_spec.rb +89 -0
  155. data/spec/ocsp_spec.rb +111 -0
  156. data/spec/oid_mapper_spec.rb +31 -0
  157. data/spec/privatekey_spec.rb +198 -0
  158. data/spec/spec_helper.rb +14 -0
  159. data/spec/spki_spec.rb +157 -0
  160. data/spec/subject_spec.rb +203 -0
  161. data/spec/validity_spec.rb +98 -0
  162. metadata +257 -0
@@ -0,0 +1,393 @@
1
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
2
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
4
+ <head>
5
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
6
+ <title>
7
+ Class: R509::OidMapper
8
+
9
+ &mdash; Documentation by YARD 0.8.0
10
+
11
+ </title>
12
+
13
+ <link rel="stylesheet" href="../css/style.css" type="text/css" media="screen" charset="utf-8" />
14
+
15
+ <link rel="stylesheet" href="../css/common.css" type="text/css" media="screen" charset="utf-8" />
16
+
17
+ <script type="text/javascript" charset="utf-8">
18
+ hasFrames = window.top.frames.main ? true : false;
19
+ relpath = '../';
20
+ framesUrl = "../frames.html#!" + escape(window.location.href);
21
+ </script>
22
+
23
+
24
+ <script type="text/javascript" charset="utf-8" src="../js/jquery.js"></script>
25
+
26
+ <script type="text/javascript" charset="utf-8" src="../js/app.js"></script>
27
+
28
+
29
+ </head>
30
+ <body>
31
+ <div id="header">
32
+ <div id="menu">
33
+
34
+ <a href="../_index.html">Index (O)</a> &raquo;
35
+ <span class='title'><span class='object_link'><a href="../R509.html" title="R509 (module)">R509</a></span></span>
36
+ &raquo;
37
+ <span class="title">OidMapper</span>
38
+
39
+
40
+ <div class="noframes"><span class="title">(</span><a href="." target="_top">no frames</a><span class="title">)</span></div>
41
+ </div>
42
+
43
+ <div id="search">
44
+
45
+ <a class="full_list_link" id="class_list_link"
46
+ href="../class_list.html">
47
+ Class List
48
+ </a>
49
+
50
+ <a class="full_list_link" id="method_list_link"
51
+ href="../method_list.html">
52
+ Method List
53
+ </a>
54
+
55
+ <a class="full_list_link" id="file_list_link"
56
+ href="../file_list.html">
57
+ File List
58
+ </a>
59
+
60
+ </div>
61
+ <div class="clear"></div>
62
+ </div>
63
+
64
+ <iframe id="search_frame"></iframe>
65
+
66
+ <div id="content"><h1>Class: R509::OidMapper
67
+
68
+
69
+
70
+ </h1>
71
+
72
+ <dl class="box">
73
+
74
+ <dt class="r1">Inherits:</dt>
75
+ <dd class="r1">
76
+ <span class="inheritName">Object</span>
77
+
78
+ <ul class="fullTree">
79
+ <li>Object</li>
80
+
81
+ <li class="next">R509::OidMapper</li>
82
+
83
+ </ul>
84
+ <a href="#" class="inheritanceTree">show all</a>
85
+
86
+ </dd>
87
+
88
+
89
+
90
+
91
+
92
+
93
+
94
+
95
+
96
+ <dt class="r2 last">Defined in:</dt>
97
+ <dd class="r2 last">lib/r509/oidmapper.rb</dd>
98
+
99
+ </dl>
100
+ <div class="clear"></div>
101
+
102
+ <h2>Overview</h2><div class="docstring">
103
+ <div class="discussion">
104
+
105
+ <p>Helps map raw OIDs to friendlier short names</p>
106
+
107
+
108
+ </div>
109
+ </div>
110
+ <div class="tags">
111
+
112
+
113
+ </div>
114
+
115
+
116
+
117
+
118
+
119
+
120
+
121
+ <h2>
122
+ Class Method Summary
123
+ <small>(<a href="#" class="summary_toggle">collapse</a>)</small>
124
+ </h2>
125
+
126
+ <ul class="summary">
127
+
128
+ <li class="public ">
129
+ <span class="summary_signature">
130
+
131
+ <a href="#batch_register-class_method" title="batch_register (class method)">+ (Object) <strong>batch_register</strong>(oids) </a>
132
+
133
+
134
+
135
+ </span>
136
+
137
+
138
+
139
+
140
+
141
+
142
+
143
+
144
+
145
+ <span class="summary_desc"><div class='inline'>
146
+ <p>Register a batch of OIDs so we have friendly short names.</p>
147
+ </div></span>
148
+
149
+ </li>
150
+
151
+
152
+ <li class="public ">
153
+ <span class="summary_signature">
154
+
155
+ <a href="#register-class_method" title="register (class method)">+ (Boolean) <strong>register</strong>(oid, short_name, long_name = nil) </a>
156
+
157
+
158
+
159
+ </span>
160
+
161
+
162
+
163
+
164
+
165
+
166
+
167
+
168
+
169
+ <span class="summary_desc"><div class='inline'>
170
+ <p>Register an OID so we have a friendly short name.</p>
171
+ </div></span>
172
+
173
+ </li>
174
+
175
+
176
+ </ul>
177
+
178
+
179
+
180
+
181
+ <div id="class_method_details" class="method_details_list">
182
+ <h2>Class Method Details</h2>
183
+
184
+
185
+ <div class="method_details first">
186
+ <h3 class="signature first" id="batch_register-class_method">
187
+
188
+ + (<tt>Object</tt>) <strong>batch_register</strong>(oids)
189
+
190
+
191
+
192
+
193
+
194
+ </h3><div class="docstring">
195
+ <div class="discussion">
196
+
197
+ <p>Register a batch of OIDs so we have friendly short names</p>
198
+
199
+
200
+ </div>
201
+ </div>
202
+ <div class="tags">
203
+
204
+ <div class="examples">
205
+ <p class="tag_title">Examples:</p>
206
+
207
+
208
+ <pre class="example code">R509::OidMapper.batch_register([
209
+ {:oid =&gt; &quot;1.2.3.4.5&quot;, :short_name =&gt; &quot;sName&quot;, :long_name =&gt; &quot;lName&quot;},
210
+ {:oid =&gt; &quot;1.2.3.4.6&quot;, :short_name =&gt; &quot;oName&quot;}
211
+ ]</pre>
212
+
213
+ </div>
214
+ <p class="tag_title">Parameters:</p>
215
+ <ul class="param">
216
+
217
+ <li>
218
+
219
+ <span class='name'>oids</span>
220
+
221
+
222
+ <span class='type'>(<tt>Array</tt>)</span>
223
+
224
+
225
+
226
+ &mdash;
227
+ <div class='inline'>
228
+ <p>An array of hashes</p>
229
+ </div>
230
+
231
+ </li>
232
+
233
+ </ul>
234
+
235
+
236
+ </div><table class="source_code">
237
+ <tr>
238
+ <td>
239
+ <pre class="lines">
240
+
241
+
242
+ 25
243
+ 26
244
+ 27
245
+ 28
246
+ 29
247
+ 30</pre>
248
+ </td>
249
+ <td>
250
+ <pre class="code"><span class="info file"># File 'lib/r509/oidmapper.rb', line 25</span>
251
+
252
+ <span class='kw'>def</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_batch_register'>batch_register</span><span class='lparen'>(</span><span class='id identifier rubyid_oids'>oids</span><span class='rparen'>)</span>
253
+ <span class='id identifier rubyid_oids'>oids</span><span class='period'>.</span><span class='id identifier rubyid_each'>each</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_oid_hash'>oid_hash</span><span class='op'>|</span>
254
+ <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_register'>register</span><span class='lparen'>(</span><span class='id identifier rubyid_oid_hash'>oid_hash</span><span class='lbracket'>[</span><span class='symbol'>:oid</span><span class='rbracket'>]</span><span class='comma'>,</span><span class='id identifier rubyid_oid_hash'>oid_hash</span><span class='lbracket'>[</span><span class='symbol'>:short_name</span><span class='rbracket'>]</span><span class='comma'>,</span><span class='id identifier rubyid_oid_hash'>oid_hash</span><span class='lbracket'>[</span><span class='symbol'>:long_name</span><span class='rbracket'>]</span><span class='rparen'>)</span>
255
+ <span class='kw'>end</span>
256
+ <span class='kw'>nil</span>
257
+ <span class='kw'>end</span></pre>
258
+ </td>
259
+ </tr>
260
+ </table>
261
+ </div>
262
+
263
+ <div class="method_details ">
264
+ <h3 class="signature " id="register-class_method">
265
+
266
+ + (<tt>Boolean</tt>) <strong>register</strong>(oid, short_name, long_name = nil)
267
+
268
+
269
+
270
+
271
+
272
+ </h3><div class="docstring">
273
+ <div class="discussion">
274
+
275
+ <p>Register an OID so we have a friendly short name</p>
276
+
277
+
278
+ </div>
279
+ </div>
280
+ <div class="tags">
281
+ <p class="tag_title">Parameters:</p>
282
+ <ul class="param">
283
+
284
+ <li>
285
+
286
+ <span class='name'>oid</span>
287
+
288
+
289
+ <span class='type'>(<tt>String</tt>)</span>
290
+
291
+
292
+
293
+ &mdash;
294
+ <div class='inline'>
295
+ <p>A string representation of the OID you want to map (e.g. "1.6.2.3.55")</p>
296
+ </div>
297
+
298
+ </li>
299
+
300
+ <li>
301
+
302
+ <span class='name'>short_name</span>
303
+
304
+
305
+ <span class='type'>(<tt>String</tt>)</span>
306
+
307
+
308
+
309
+ &mdash;
310
+ <div class='inline'>
311
+ <p>The short name (e.g. CN, O, OU, emailAddress)</p>
312
+ </div>
313
+
314
+ </li>
315
+
316
+ <li>
317
+
318
+ <span class='name'>long_name</span>
319
+
320
+
321
+ <span class='type'>(<tt>String</tt>)</span>
322
+
323
+
324
+ <em class="default">(defaults to: <tt>nil</tt>)</em>
325
+
326
+
327
+ &mdash;
328
+ <div class='inline'>
329
+ <p>Optional long name. Defaults to the same as short_name</p>
330
+ </div>
331
+
332
+ </li>
333
+
334
+ </ul>
335
+
336
+ <p class="tag_title">Returns:</p>
337
+ <ul class="return">
338
+
339
+ <li>
340
+
341
+
342
+ <span class='type'>(<tt>Boolean</tt>)</span>
343
+
344
+
345
+
346
+ &mdash;
347
+ <div class='inline'>
348
+ <p>success/failure</p>
349
+ </div>
350
+
351
+ </li>
352
+
353
+ </ul>
354
+
355
+ </div><table class="source_code">
356
+ <tr>
357
+ <td>
358
+ <pre class="lines">
359
+
360
+
361
+ 11
362
+ 12
363
+ 13
364
+ 14
365
+ 15
366
+ 16</pre>
367
+ </td>
368
+ <td>
369
+ <pre class="code"><span class="info file"># File 'lib/r509/oidmapper.rb', line 11</span>
370
+
371
+ <span class='kw'>def</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_register'>register</span><span class='lparen'>(</span><span class='id identifier rubyid_oid'>oid</span><span class='comma'>,</span><span class='id identifier rubyid_short_name'>short_name</span><span class='comma'>,</span><span class='id identifier rubyid_long_name'>long_name</span><span class='op'>=</span><span class='kw'>nil</span><span class='rparen'>)</span>
372
+ <span class='kw'>if</span> <span class='id identifier rubyid_long_name'>long_name</span><span class='period'>.</span><span class='id identifier rubyid_nil?'>nil?</span>
373
+ <span class='id identifier rubyid_long_name'>long_name</span> <span class='op'>=</span> <span class='id identifier rubyid_short_name'>short_name</span>
374
+ <span class='kw'>end</span>
375
+ <span class='const'>OpenSSL</span><span class='op'>::</span><span class='const'>ASN1</span><span class='op'>::</span><span class='const'>ObjectId</span><span class='period'>.</span><span class='id identifier rubyid_register'>register</span><span class='lparen'>(</span><span class='id identifier rubyid_oid'>oid</span><span class='comma'>,</span> <span class='id identifier rubyid_short_name'>short_name</span><span class='comma'>,</span> <span class='id identifier rubyid_long_name'>long_name</span><span class='rparen'>)</span>
376
+ <span class='kw'>end</span></pre>
377
+ </td>
378
+ </tr>
379
+ </table>
380
+ </div>
381
+
382
+ </div>
383
+
384
+ </div>
385
+
386
+ <div id="footer">
387
+ Generated on Tue Oct 23 22:48:02 2012 by
388
+ <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
389
+ 0.8.0 (ruby-1.9.3).
390
+ </div>
391
+
392
+ </body>
393
+ </html>
@@ -0,0 +1,1647 @@
1
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
2
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
4
+ <head>
5
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
6
+ <title>
7
+ Class: R509::PrivateKey
8
+
9
+ &mdash; Documentation by YARD 0.8.0
10
+
11
+ </title>
12
+
13
+ <link rel="stylesheet" href="../css/style.css" type="text/css" media="screen" charset="utf-8" />
14
+
15
+ <link rel="stylesheet" href="../css/common.css" type="text/css" media="screen" charset="utf-8" />
16
+
17
+ <script type="text/javascript" charset="utf-8">
18
+ hasFrames = window.top.frames.main ? true : false;
19
+ relpath = '../';
20
+ framesUrl = "../frames.html#!" + escape(window.location.href);
21
+ </script>
22
+
23
+
24
+ <script type="text/javascript" charset="utf-8" src="../js/jquery.js"></script>
25
+
26
+ <script type="text/javascript" charset="utf-8" src="../js/app.js"></script>
27
+
28
+
29
+ </head>
30
+ <body>
31
+ <div id="header">
32
+ <div id="menu">
33
+
34
+ <a href="../_index.html">Index (P)</a> &raquo;
35
+ <span class='title'><span class='object_link'><a href="../R509.html" title="R509 (module)">R509</a></span></span>
36
+ &raquo;
37
+ <span class="title">PrivateKey</span>
38
+
39
+
40
+ <div class="noframes"><span class="title">(</span><a href="." target="_top">no frames</a><span class="title">)</span></div>
41
+ </div>
42
+
43
+ <div id="search">
44
+
45
+ <a class="full_list_link" id="class_list_link"
46
+ href="../class_list.html">
47
+ Class List
48
+ </a>
49
+
50
+ <a class="full_list_link" id="method_list_link"
51
+ href="../method_list.html">
52
+ Method List
53
+ </a>
54
+
55
+ <a class="full_list_link" id="file_list_link"
56
+ href="../file_list.html">
57
+ File List
58
+ </a>
59
+
60
+ </div>
61
+ <div class="clear"></div>
62
+ </div>
63
+
64
+ <iframe id="search_frame"></iframe>
65
+
66
+ <div id="content"><h1>Class: R509::PrivateKey
67
+
68
+
69
+
70
+ </h1>
71
+
72
+ <dl class="box">
73
+
74
+ <dt class="r1">Inherits:</dt>
75
+ <dd class="r1">
76
+ <span class="inheritName">Object</span>
77
+
78
+ <ul class="fullTree">
79
+ <li>Object</li>
80
+
81
+ <li class="next">R509::PrivateKey</li>
82
+
83
+ </ul>
84
+ <a href="#" class="inheritanceTree">show all</a>
85
+
86
+ </dd>
87
+
88
+
89
+
90
+
91
+
92
+
93
+ <dt class="r2">Includes:</dt>
94
+ <dd class="r2"><span class='object_link'><a href="IOHelpers.html" title="R509::IOHelpers (module)">IOHelpers</a></span></dd>
95
+
96
+
97
+
98
+
99
+
100
+ <dt class="r1 last">Defined in:</dt>
101
+ <dd class="r1 last">lib/r509/privatekey.rb</dd>
102
+
103
+ </dl>
104
+ <div class="clear"></div>
105
+
106
+ <h2>Overview</h2><div class="docstring">
107
+ <div class="discussion">
108
+
109
+ <p>private key management</p>
110
+
111
+
112
+ </div>
113
+ </div>
114
+ <div class="tags">
115
+
116
+
117
+ </div>
118
+
119
+
120
+
121
+
122
+
123
+
124
+
125
+ <h2>
126
+ Class Method Summary
127
+ <small>(<a href="#" class="summary_toggle">collapse</a>)</small>
128
+ </h2>
129
+
130
+ <ul class="summary">
131
+
132
+ <li class="public ">
133
+ <span class="summary_signature">
134
+
135
+ <a href="#load_from_file-class_method" title="load_from_file (class method)">+ (R509::PrivateKey) <strong>load_from_file</strong>(filename, password = nil) </a>
136
+
137
+
138
+
139
+ </span>
140
+
141
+
142
+
143
+
144
+
145
+
146
+
147
+
148
+
149
+ <span class="summary_desc"><div class='inline'>
150
+ <p>Helper method to quickly load a private key from the filesystem.</p>
151
+ </div></span>
152
+
153
+ </li>
154
+
155
+
156
+ </ul>
157
+
158
+ <h2>
159
+ Instance Method Summary
160
+ <small>(<a href="#" class="summary_toggle">collapse</a>)</small>
161
+ </h2>
162
+
163
+ <ul class="summary">
164
+
165
+ <li class="public ">
166
+ <span class="summary_signature">
167
+
168
+ <a href="#bit_strength-instance_method" title="#bit_strength (instance method)">- (Integer) <strong>bit_strength</strong> </a>
169
+
170
+
171
+
172
+ </span>
173
+
174
+
175
+
176
+
177
+
178
+
179
+
180
+
181
+
182
+ <span class="summary_desc"><div class='inline'></div></span>
183
+
184
+ </li>
185
+
186
+
187
+ <li class="public ">
188
+ <span class="summary_signature">
189
+
190
+ <a href="#dsa%3F-instance_method" title="#dsa? (instance method)">- (Boolean) <strong>dsa?</strong> </a>
191
+
192
+
193
+
194
+ </span>
195
+
196
+
197
+
198
+
199
+
200
+
201
+
202
+
203
+
204
+ <span class="summary_desc"><div class='inline'>
205
+ <p>Returns whether the public key is DSA.</p>
206
+ </div></span>
207
+
208
+ </li>
209
+
210
+
211
+ <li class="public ">
212
+ <span class="summary_signature">
213
+
214
+ <a href="#in_hardware%3F-instance_method" title="#in_hardware? (instance method)">- (Boolean) <strong>in_hardware?</strong> </a>
215
+
216
+
217
+
218
+ </span>
219
+
220
+
221
+
222
+
223
+
224
+
225
+
226
+
227
+
228
+ <span class="summary_desc"><div class='inline'>
229
+ <p>Whether the key is resident in hardware or not.</p>
230
+ </div></span>
231
+
232
+ </li>
233
+
234
+
235
+ <li class="public ">
236
+ <span class="summary_signature">
237
+
238
+ <a href="#initialize-instance_method" title="#initialize (instance method)">- (PrivateKey) <strong>initialize</strong>(opts) </a>
239
+
240
+
241
+
242
+ </span>
243
+
244
+
245
+ <span class="note title constructor">constructor</span>
246
+
247
+
248
+
249
+
250
+
251
+
252
+
253
+
254
+ <span class="summary_desc"><div class='inline'>
255
+ <p>A new instance of PrivateKey.</p>
256
+ </div></span>
257
+
258
+ </li>
259
+
260
+
261
+ <li class="public ">
262
+ <span class="summary_signature">
263
+
264
+ <a href="#key-instance_method" title="#key (instance method)">- (OpenSSL::PKey::RSA, ...) <strong>key</strong> </a>
265
+
266
+
267
+
268
+ </span>
269
+
270
+
271
+
272
+
273
+
274
+
275
+
276
+
277
+
278
+ <span class="summary_desc"><div class='inline'>
279
+ <p>This method may return the PKey object itself or a handle to the private
280
+ key in the HSM (which will not show the private key, just public).</p>
281
+ </div></span>
282
+
283
+ </li>
284
+
285
+
286
+ <li class="public ">
287
+ <span class="summary_signature">
288
+
289
+ <a href="#public_key-instance_method" title="#public_key (instance method)">- (OpenSSL::PKey::RSA, OpenSSL::PKey::DSA) <strong>public_key</strong> </a>
290
+
291
+
292
+
293
+ (also: #to_s)
294
+
295
+ </span>
296
+
297
+
298
+
299
+
300
+
301
+
302
+
303
+
304
+
305
+ <span class="summary_desc"><div class='inline'>
306
+ <p>Public key.</p>
307
+ </div></span>
308
+
309
+ </li>
310
+
311
+
312
+ <li class="public ">
313
+ <span class="summary_signature">
314
+
315
+ <a href="#rsa%3F-instance_method" title="#rsa? (instance method)">- (Boolean) <strong>rsa?</strong> </a>
316
+
317
+
318
+
319
+ </span>
320
+
321
+
322
+
323
+
324
+
325
+
326
+
327
+
328
+
329
+ <span class="summary_desc"><div class='inline'>
330
+ <p>Returns whether the public key is RSA.</p>
331
+ </div></span>
332
+
333
+ </li>
334
+
335
+
336
+ <li class="public ">
337
+ <span class="summary_signature">
338
+
339
+ <a href="#to_der-instance_method" title="#to_der (instance method)">- (String) <strong>to_der</strong> </a>
340
+
341
+
342
+
343
+ </span>
344
+
345
+
346
+
347
+
348
+
349
+
350
+
351
+
352
+
353
+ <span class="summary_desc"><div class='inline'>
354
+ <p>Converts the key into the DER format.</p>
355
+ </div></span>
356
+
357
+ </li>
358
+
359
+
360
+ <li class="public ">
361
+ <span class="summary_signature">
362
+
363
+ <a href="#to_encrypted_pem-instance_method" title="#to_encrypted_pem (instance method)">- (String) <strong>to_encrypted_pem</strong>(cipher, password) </a>
364
+
365
+
366
+
367
+ </span>
368
+
369
+
370
+
371
+
372
+
373
+
374
+
375
+
376
+
377
+ <span class="summary_desc"><div class='inline'>
378
+ <p>Converts the key into encrypted PEM format.</p>
379
+ </div></span>
380
+
381
+ </li>
382
+
383
+
384
+ <li class="public ">
385
+ <span class="summary_signature">
386
+
387
+ <a href="#to_pem-instance_method" title="#to_pem (instance method)">- (String) <strong>to_pem</strong> </a>
388
+
389
+
390
+
391
+ </span>
392
+
393
+
394
+
395
+
396
+
397
+
398
+
399
+
400
+
401
+ <span class="summary_desc"><div class='inline'>
402
+ <p>Converts the key into the PEM format.</p>
403
+ </div></span>
404
+
405
+ </li>
406
+
407
+
408
+ <li class="public ">
409
+ <span class="summary_signature">
410
+
411
+ <a href="#write_der-instance_method" title="#write_der (instance method)">- (Object) <strong>write_der</strong>(filename_or_io) </a>
412
+
413
+
414
+
415
+ </span>
416
+
417
+
418
+
419
+
420
+
421
+
422
+
423
+
424
+
425
+ <span class="summary_desc"><div class='inline'>
426
+ <p>Writes the key into the DER format.</p>
427
+ </div></span>
428
+
429
+ </li>
430
+
431
+
432
+ <li class="public ">
433
+ <span class="summary_signature">
434
+
435
+ <a href="#write_encrypted_pem-instance_method" title="#write_encrypted_pem (instance method)">- (Object) <strong>write_encrypted_pem</strong>(filename_or_io, cipher, password) </a>
436
+
437
+
438
+
439
+ </span>
440
+
441
+
442
+
443
+
444
+
445
+
446
+
447
+
448
+
449
+ <span class="summary_desc"><div class='inline'>
450
+ <p>Writes the key into encrypted PEM format with specified cipher.</p>
451
+ </div></span>
452
+
453
+ </li>
454
+
455
+
456
+ <li class="public ">
457
+ <span class="summary_signature">
458
+
459
+ <a href="#write_pem-instance_method" title="#write_pem (instance method)">- (Object) <strong>write_pem</strong>(filename_or_io) </a>
460
+
461
+
462
+
463
+ </span>
464
+
465
+
466
+
467
+
468
+
469
+
470
+
471
+
472
+
473
+ <span class="summary_desc"><div class='inline'>
474
+ <p>Writes the key into the PEM format.</p>
475
+ </div></span>
476
+
477
+ </li>
478
+
479
+
480
+ </ul>
481
+
482
+
483
+
484
+
485
+
486
+
487
+
488
+
489
+
490
+
491
+
492
+ <h3 class="inherited">Methods included from <span class='object_link'><a href="IOHelpers.html" title="R509::IOHelpers (module)">IOHelpers</a></span></h3>
493
+ <p class="inherited"><span class='object_link'><a href="IOHelpers.html#read_data-instance_method" title="R509::IOHelpers#read_data (method)">#read_data</a></span>, <span class='object_link'><a href="IOHelpers.html#read_data-class_method" title="R509::IOHelpers.read_data (method)">read_data</a></span>, <span class='object_link'><a href="IOHelpers.html#write_data-instance_method" title="R509::IOHelpers#write_data (method)">#write_data</a></span>, <span class='object_link'><a href="IOHelpers.html#write_data-class_method" title="R509::IOHelpers.write_data (method)">write_data</a></span></p>
494
+ <div id="constructor_details" class="method_details_list">
495
+ <h2>Constructor Details</h2>
496
+
497
+ <div class="method_details first">
498
+ <h3 class="signature first" id="initialize-instance_method">
499
+
500
+ - (<tt><span class='object_link'><a href="" title="R509::PrivateKey (class)">PrivateKey</a></span></tt>) <strong>initialize</strong>(opts)
501
+
502
+
503
+
504
+
505
+
506
+ </h3><div class="docstring">
507
+ <div class="discussion">
508
+
509
+ <p>A new instance of PrivateKey</p>
510
+
511
+
512
+ </div>
513
+ </div>
514
+ <div class="tags">
515
+ <p class="tag_title">Parameters:</p>
516
+ <ul class="param">
517
+
518
+ <li>
519
+
520
+ <span class='name'>opts</span>
521
+
522
+
523
+ <span class='type'>(<tt>Hash</tt>)</span>
524
+
525
+
526
+
527
+ &mdash;
528
+ <div class='inline'>
529
+ <p>a customizable set of options</p>
530
+ </div>
531
+
532
+ </li>
533
+
534
+ </ul>
535
+
536
+
537
+
538
+
539
+ <p class="tag_title">Options Hash (<tt>opts</tt>):</p>
540
+ <ul class="option">
541
+
542
+ <li>
543
+ <span class="name">:type</span>
544
+ <span class="type">(<tt>Symbol</tt>)</span>
545
+ <span class="default">
546
+
547
+ </span>
548
+ &mdash; <div class='inline'>
549
+ <p>:rsa/:dsa</p>
550
+ </div>
551
+ </li>
552
+
553
+ <li>
554
+ <span class="name">:bit_strength</span>
555
+ <span class="type">(<tt>Integer</tt>)</span>
556
+ <span class="default">
557
+
558
+ </span>
559
+
560
+ </li>
561
+
562
+ <li>
563
+ <span class="name">:password</span>
564
+ <span class="type">(<tt>String</tt>)</span>
565
+ <span class="default">
566
+
567
+ </span>
568
+
569
+ </li>
570
+
571
+ <li>
572
+ <span class="name">:key</span>
573
+ <span class="type">(<tt>String</tt>, <tt>OpenSSL::PKey::RSA</tt>, <tt>OpenSSL::PKey::DSA</tt>)</span>
574
+ <span class="default">
575
+
576
+ </span>
577
+
578
+ </li>
579
+
580
+ <li>
581
+ <span class="name">:engine</span>
582
+ <span class="type">(<tt>OpenSSL::Engine</tt>)</span>
583
+ <span class="default">
584
+
585
+ </span>
586
+
587
+ </li>
588
+
589
+ <li>
590
+ <span class="name">:key_name</span>
591
+ <span class="type">(<tt>string</tt>)</span>
592
+ <span class="default">
593
+
594
+ &mdash; default:
595
+ <tt>used with engine</tt>
596
+
597
+ </span>
598
+ &mdash; <div class='inline'></div>
599
+ </li>
600
+
601
+ </ul>
602
+
603
+
604
+
605
+ </div><table class="source_code">
606
+ <tr>
607
+ <td>
608
+ <pre class="lines">
609
+
610
+
611
+ 16
612
+ 17
613
+ 18
614
+ 19
615
+ 20
616
+ 21
617
+ 22
618
+ 23
619
+ 24
620
+ 25
621
+ 26
622
+ 27
623
+ 28
624
+ 29
625
+ 30
626
+ 31
627
+ 32
628
+ 33
629
+ 34
630
+ 35
631
+ 36
632
+ 37
633
+ 38
634
+ 39
635
+ 40
636
+ 41
637
+ 42
638
+ 43
639
+ 44
640
+ 45
641
+ 46
642
+ 47
643
+ 48
644
+ 49
645
+ 50
646
+ 51
647
+ 52
648
+ 53
649
+ 54
650
+ 55
651
+ 56
652
+ 57
653
+ 58
654
+ 59
655
+ 60</pre>
656
+ </td>
657
+ <td>
658
+ <pre class="code"><span class="info file"># File 'lib/r509/privatekey.rb', line 16</span>
659
+
660
+ <span class='kw'>def</span> <span class='id identifier rubyid_initialize'>initialize</span><span class='lparen'>(</span><span class='id identifier rubyid_opts'>opts</span><span class='rparen'>)</span>
661
+ <span class='kw'>if</span> <span class='kw'>not</span> <span class='id identifier rubyid_opts'>opts</span><span class='period'>.</span><span class='id identifier rubyid_kind_of?'>kind_of?</span><span class='lparen'>(</span><span class='const'>Hash</span><span class='rparen'>)</span>
662
+ <span class='id identifier rubyid_raise'>raise</span> <span class='const'>ArgumentError</span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>Must provide a hash of options</span><span class='tstring_end'>'</span></span>
663
+ <span class='kw'>end</span>
664
+
665
+ <span class='kw'>if</span> <span class='id identifier rubyid_opts'>opts</span><span class='period'>.</span><span class='id identifier rubyid_has_key?'>has_key?</span><span class='lparen'>(</span><span class='symbol'>:engine</span><span class='rparen'>)</span> <span class='kw'>and</span> <span class='id identifier rubyid_opts'>opts</span><span class='period'>.</span><span class='id identifier rubyid_has_key?'>has_key?</span><span class='lparen'>(</span><span class='symbol'>:key</span><span class='rparen'>)</span>
666
+ <span class='id identifier rubyid_raise'>raise</span> <span class='const'>ArgumentError</span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>You can\'t pass both :key and :engine</span><span class='tstring_end'>'</span></span>
667
+ <span class='kw'>elsif</span> <span class='id identifier rubyid_opts'>opts</span><span class='period'>.</span><span class='id identifier rubyid_has_key?'>has_key?</span><span class='lparen'>(</span><span class='symbol'>:key_name</span><span class='rparen'>)</span> <span class='kw'>and</span> <span class='kw'>not</span> <span class='id identifier rubyid_opts'>opts</span><span class='period'>.</span><span class='id identifier rubyid_has_key?'>has_key?</span><span class='lparen'>(</span><span class='symbol'>:engine</span><span class='rparen'>)</span>
668
+ <span class='id identifier rubyid_raise'>raise</span> <span class='const'>ArgumentError</span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>When providing a :key_name you MUST provide an :engine</span><span class='tstring_end'>'</span></span>
669
+ <span class='kw'>elsif</span> <span class='id identifier rubyid_opts'>opts</span><span class='period'>.</span><span class='id identifier rubyid_has_key?'>has_key?</span><span class='lparen'>(</span><span class='symbol'>:engine</span><span class='rparen'>)</span> <span class='kw'>and</span> <span class='kw'>not</span> <span class='id identifier rubyid_opts'>opts</span><span class='period'>.</span><span class='id identifier rubyid_has_key?'>has_key?</span><span class='lparen'>(</span><span class='symbol'>:key_name</span><span class='rparen'>)</span>
670
+ <span class='id identifier rubyid_raise'>raise</span> <span class='const'>ArgumentError</span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>When providing an :engine you MUST provide a :key_name</span><span class='tstring_end'>'</span></span>
671
+ <span class='kw'>elsif</span> <span class='id identifier rubyid_opts'>opts</span><span class='period'>.</span><span class='id identifier rubyid_has_key?'>has_key?</span><span class='lparen'>(</span><span class='symbol'>:engine</span><span class='rparen'>)</span> <span class='kw'>and</span> <span class='id identifier rubyid_opts'>opts</span><span class='period'>.</span><span class='id identifier rubyid_has_key?'>has_key?</span><span class='lparen'>(</span><span class='symbol'>:key_name</span><span class='rparen'>)</span>
672
+ <span class='kw'>if</span> <span class='kw'>not</span> <span class='id identifier rubyid_opts'>opts</span><span class='lbracket'>[</span><span class='symbol'>:engine</span><span class='rbracket'>]</span><span class='period'>.</span><span class='id identifier rubyid_kind_of?'>kind_of?</span><span class='lparen'>(</span><span class='const'>OpenSSL</span><span class='op'>::</span><span class='const'>Engine</span><span class='rparen'>)</span>
673
+ <span class='id identifier rubyid_raise'>raise</span> <span class='const'>ArgumentError</span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>When providing an engine, it must be of type OpenSSL::Engine</span><span class='tstring_end'>'</span></span>
674
+ <span class='kw'>end</span>
675
+ <span class='ivar'>@engine</span> <span class='op'>=</span> <span class='id identifier rubyid_opts'>opts</span><span class='lbracket'>[</span><span class='symbol'>:engine</span><span class='rbracket'>]</span>
676
+ <span class='ivar'>@key_name</span> <span class='op'>=</span> <span class='id identifier rubyid_opts'>opts</span><span class='lbracket'>[</span><span class='symbol'>:key_name</span><span class='rbracket'>]</span>
677
+ <span class='kw'>end</span>
678
+
679
+ <span class='kw'>if</span> <span class='id identifier rubyid_opts'>opts</span><span class='period'>.</span><span class='id identifier rubyid_has_key?'>has_key?</span><span class='lparen'>(</span><span class='symbol'>:key</span><span class='rparen'>)</span>
680
+ <span class='id identifier rubyid_password'>password</span> <span class='op'>=</span> <span class='id identifier rubyid_opts'>opts</span><span class='lbracket'>[</span><span class='symbol'>:password</span><span class='rbracket'>]</span> <span class='op'>||</span> <span class='kw'>nil</span>
681
+ <span class='comment'>#OpenSSL::PKey.read solves this begin/rescue garbage but is only
682
+ </span> <span class='comment'>#available to Ruby 1.9.3+
683
+ </span> <span class='kw'>begin</span>
684
+ <span class='ivar'>@key</span> <span class='op'>=</span> <span class='const'>OpenSSL</span><span class='op'>::</span><span class='const'>PKey</span><span class='op'>::</span><span class='const'>RSA</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='id identifier rubyid_opts'>opts</span><span class='lbracket'>[</span><span class='symbol'>:key</span><span class='rbracket'>]</span><span class='comma'>,</span><span class='id identifier rubyid_password'>password</span><span class='rparen'>)</span>
685
+ <span class='kw'>rescue</span> <span class='const'>OpenSSL</span><span class='op'>::</span><span class='const'>PKey</span><span class='op'>::</span><span class='const'>RSAError</span>
686
+ <span class='kw'>begin</span>
687
+ <span class='ivar'>@key</span> <span class='op'>=</span> <span class='const'>OpenSSL</span><span class='op'>::</span><span class='const'>PKey</span><span class='op'>::</span><span class='const'>DSA</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='id identifier rubyid_opts'>opts</span><span class='lbracket'>[</span><span class='symbol'>:key</span><span class='rbracket'>]</span><span class='comma'>,</span><span class='id identifier rubyid_password'>password</span><span class='rparen'>)</span>
688
+ <span class='kw'>rescue</span>
689
+ <span class='id identifier rubyid_raise'>raise</span> <span class='const'>R509</span><span class='op'>::</span><span class='const'>R509Error</span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>Failed to load private key. Invalid key or incorrect password.</span><span class='tstring_end'>&quot;</span></span>
690
+ <span class='kw'>end</span>
691
+ <span class='kw'>end</span>
692
+ <span class='kw'>else</span>
693
+ <span class='id identifier rubyid_bit_strength'>bit_strength</span> <span class='op'>=</span> <span class='id identifier rubyid_opts'>opts</span><span class='lbracket'>[</span><span class='symbol'>:bit_strength</span><span class='rbracket'>]</span> <span class='op'>||</span> <span class='int'>2048</span>
694
+ <span class='id identifier rubyid_type'>type</span> <span class='op'>=</span> <span class='id identifier rubyid_opts'>opts</span><span class='lbracket'>[</span><span class='symbol'>:type</span><span class='rbracket'>]</span> <span class='op'>||</span> <span class='symbol'>:rsa</span>
695
+ <span class='kw'>case</span> <span class='id identifier rubyid_type'>type</span>
696
+ <span class='kw'>when</span> <span class='symbol'>:rsa</span>
697
+ <span class='ivar'>@key</span> <span class='op'>=</span> <span class='const'>OpenSSL</span><span class='op'>::</span><span class='const'>PKey</span><span class='op'>::</span><span class='const'>RSA</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='id identifier rubyid_bit_strength'>bit_strength</span><span class='rparen'>)</span>
698
+ <span class='kw'>when</span> <span class='symbol'>:dsa</span>
699
+ <span class='ivar'>@key</span> <span class='op'>=</span> <span class='const'>OpenSSL</span><span class='op'>::</span><span class='const'>PKey</span><span class='op'>::</span><span class='const'>DSA</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='id identifier rubyid_bit_strength'>bit_strength</span><span class='rparen'>)</span>
700
+ <span class='kw'>else</span>
701
+ <span class='id identifier rubyid_raise'>raise</span> <span class='const'>ArgumentError</span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>Must provide :rsa or :dsa as type when key or engine is nil</span><span class='tstring_end'>'</span></span>
702
+ <span class='kw'>end</span>
703
+ <span class='kw'>end</span>
704
+ <span class='kw'>end</span></pre>
705
+ </td>
706
+ </tr>
707
+ </table>
708
+ </div>
709
+
710
+ </div>
711
+
712
+
713
+ <div id="class_method_details" class="method_details_list">
714
+ <h2>Class Method Details</h2>
715
+
716
+
717
+ <div class="method_details first">
718
+ <h3 class="signature first" id="load_from_file-class_method">
719
+
720
+ + (<tt><span class='object_link'><a href="" title="R509::PrivateKey (class)">R509::PrivateKey</a></span></tt>) <strong>load_from_file</strong>(filename, password = nil)
721
+
722
+
723
+
724
+
725
+
726
+ </h3><div class="docstring">
727
+ <div class="discussion">
728
+
729
+ <p>Helper method to quickly load a private key from the filesystem</p>
730
+
731
+
732
+ </div>
733
+ </div>
734
+ <div class="tags">
735
+ <p class="tag_title">Parameters:</p>
736
+ <ul class="param">
737
+
738
+ <li>
739
+
740
+ <span class='name'>filename</span>
741
+
742
+
743
+ <span class='type'>(<tt>String</tt>)</span>
744
+
745
+
746
+
747
+ &mdash;
748
+ <div class='inline'>
749
+ <p>Path to file you want to load</p>
750
+ </div>
751
+
752
+ </li>
753
+
754
+ </ul>
755
+
756
+ <p class="tag_title">Returns:</p>
757
+ <ul class="return">
758
+
759
+ <li>
760
+
761
+
762
+ <span class='type'>(<tt><span class='object_link'><a href="" title="R509::PrivateKey (class)">R509::PrivateKey</a></span></tt>)</span>
763
+
764
+
765
+
766
+ &mdash;
767
+ <div class='inline'>
768
+ <p>PrivateKey object</p>
769
+ </div>
770
+
771
+ </li>
772
+
773
+ </ul>
774
+
775
+ </div><table class="source_code">
776
+ <tr>
777
+ <td>
778
+ <pre class="lines">
779
+
780
+
781
+ 66
782
+ 67
783
+ 68</pre>
784
+ </td>
785
+ <td>
786
+ <pre class="code"><span class="info file"># File 'lib/r509/privatekey.rb', line 66</span>
787
+
788
+ <span class='kw'>def</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_load_from_file'>load_from_file</span><span class='lparen'>(</span> <span class='id identifier rubyid_filename'>filename</span><span class='comma'>,</span> <span class='id identifier rubyid_password'>password</span> <span class='op'>=</span> <span class='kw'>nil</span> <span class='rparen'>)</span>
789
+ <span class='kw'>return</span> <span class='const'>R509</span><span class='op'>::</span><span class='const'>PrivateKey</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='symbol'>:key</span> <span class='op'>=&gt;</span> <span class='const'>IOHelpers</span><span class='period'>.</span><span class='id identifier rubyid_read_data'>read_data</span><span class='lparen'>(</span><span class='id identifier rubyid_filename'>filename</span><span class='rparen'>)</span><span class='comma'>,</span> <span class='symbol'>:password</span> <span class='op'>=&gt;</span> <span class='id identifier rubyid_password'>password</span> <span class='rparen'>)</span>
790
+ <span class='kw'>end</span></pre>
791
+ </td>
792
+ </tr>
793
+ </table>
794
+ </div>
795
+
796
+ </div>
797
+
798
+ <div id="instance_method_details" class="method_details_list">
799
+ <h2>Instance Method Details</h2>
800
+
801
+
802
+ <div class="method_details first">
803
+ <h3 class="signature first" id="bit_strength-instance_method">
804
+
805
+ - (<tt>Integer</tt>) <strong>bit_strength</strong>
806
+
807
+
808
+
809
+
810
+
811
+ </h3><div class="docstring">
812
+ <div class="discussion">
813
+
814
+
815
+ </div>
816
+ </div>
817
+ <div class="tags">
818
+
819
+ <p class="tag_title">Returns:</p>
820
+ <ul class="return">
821
+
822
+ <li>
823
+
824
+
825
+ <span class='type'>(<tt>Integer</tt>)</span>
826
+
827
+
828
+
829
+ </li>
830
+
831
+ </ul>
832
+
833
+ </div><table class="source_code">
834
+ <tr>
835
+ <td>
836
+ <pre class="lines">
837
+
838
+
839
+ 72
840
+ 73
841
+ 74
842
+ 75
843
+ 76
844
+ 77
845
+ 78</pre>
846
+ </td>
847
+ <td>
848
+ <pre class="code"><span class="info file"># File 'lib/r509/privatekey.rb', line 72</span>
849
+
850
+ <span class='kw'>def</span> <span class='id identifier rubyid_bit_strength'>bit_strength</span>
851
+ <span class='kw'>if</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_rsa?'>rsa?</span>
852
+ <span class='kw'>return</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_public_key'>public_key</span><span class='period'>.</span><span class='id identifier rubyid_n'>n</span><span class='period'>.</span><span class='id identifier rubyid_num_bits'>num_bits</span>
853
+ <span class='kw'>elsif</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_dsa?'>dsa?</span>
854
+ <span class='kw'>return</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_public_key'>public_key</span><span class='period'>.</span><span class='id identifier rubyid_p'>p</span><span class='period'>.</span><span class='id identifier rubyid_num_bits'>num_bits</span>
855
+ <span class='kw'>end</span>
856
+ <span class='kw'>end</span></pre>
857
+ </td>
858
+ </tr>
859
+ </table>
860
+ </div>
861
+
862
+ <div class="method_details ">
863
+ <h3 class="signature " id="dsa?-instance_method">
864
+
865
+ - (<tt>Boolean</tt>) <strong>dsa?</strong>
866
+
867
+
868
+
869
+
870
+
871
+ </h3><div class="docstring">
872
+ <div class="discussion">
873
+
874
+ <p>Returns whether the public key is DSA</p>
875
+
876
+
877
+ </div>
878
+ </div>
879
+ <div class="tags">
880
+
881
+ <p class="tag_title">Returns:</p>
882
+ <ul class="return">
883
+
884
+ <li>
885
+
886
+
887
+ <span class='type'>(<tt>Boolean</tt>)</span>
888
+
889
+
890
+
891
+ &mdash;
892
+ <div class='inline'>
893
+ <p>true if the public key is DSA, false otherwise</p>
894
+ </div>
895
+
896
+ </li>
897
+
898
+ </ul>
899
+
900
+ </div><table class="source_code">
901
+ <tr>
902
+ <td>
903
+ <pre class="lines">
904
+
905
+
906
+ 181
907
+ 182
908
+ 183</pre>
909
+ </td>
910
+ <td>
911
+ <pre class="code"><span class="info file"># File 'lib/r509/privatekey.rb', line 181</span>
912
+
913
+ <span class='kw'>def</span> <span class='id identifier rubyid_dsa?'>dsa?</span>
914
+ <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_key'>key</span><span class='period'>.</span><span class='id identifier rubyid_kind_of?'>kind_of?</span><span class='lparen'>(</span><span class='const'>OpenSSL</span><span class='op'>::</span><span class='const'>PKey</span><span class='op'>::</span><span class='const'>DSA</span><span class='rparen'>)</span>
915
+ <span class='kw'>end</span></pre>
916
+ </td>
917
+ </tr>
918
+ </table>
919
+ </div>
920
+
921
+ <div class="method_details ">
922
+ <h3 class="signature " id="in_hardware?-instance_method">
923
+
924
+ - (<tt>Boolean</tt>) <strong>in_hardware?</strong>
925
+
926
+
927
+
928
+
929
+
930
+ </h3><div class="docstring">
931
+ <div class="discussion">
932
+
933
+ <p>Whether the key is resident in hardware or not</p>
934
+
935
+
936
+ </div>
937
+ </div>
938
+ <div class="tags">
939
+
940
+ <p class="tag_title">Returns:</p>
941
+ <ul class="return">
942
+
943
+ <li>
944
+
945
+
946
+ <span class='type'>(<tt>Boolean</tt>)</span>
947
+
948
+
949
+
950
+ &mdash;
951
+ <div class='inline'>
952
+ <p>whether the key is resident in hardware or not</p>
953
+ </div>
954
+
955
+ </li>
956
+
957
+ </ul>
958
+
959
+ </div><table class="source_code">
960
+ <tr>
961
+ <td>
962
+ <pre class="lines">
963
+
964
+
965
+ 90
966
+ 91
967
+ 92
968
+ 93
969
+ 94
970
+ 95
971
+ 96</pre>
972
+ </td>
973
+ <td>
974
+ <pre class="code"><span class="info file"># File 'lib/r509/privatekey.rb', line 90</span>
975
+
976
+ <span class='kw'>def</span> <span class='id identifier rubyid_in_hardware?'>in_hardware?</span>
977
+ <span class='kw'>if</span> <span class='kw'>not</span> <span class='ivar'>@engine</span><span class='period'>.</span><span class='id identifier rubyid_nil?'>nil?</span>
978
+ <span class='kw'>true</span>
979
+ <span class='kw'>else</span>
980
+ <span class='kw'>false</span>
981
+ <span class='kw'>end</span>
982
+ <span class='kw'>end</span></pre>
983
+ </td>
984
+ </tr>
985
+ </table>
986
+ </div>
987
+
988
+ <div class="method_details ">
989
+ <h3 class="signature " id="key-instance_method">
990
+
991
+ - (<tt>OpenSSL::PKey::RSA</tt>, ...) <strong>key</strong>
992
+
993
+
994
+
995
+
996
+
997
+ </h3><div class="docstring">
998
+ <div class="discussion">
999
+
1000
+ <p>This method may return the PKey object itself or a handle to the private
1001
+ key in the HSM (which will not show the private key, just public)</p>
1002
+
1003
+
1004
+ </div>
1005
+ </div>
1006
+ <div class="tags">
1007
+
1008
+ <p class="tag_title">Returns:</p>
1009
+ <ul class="return">
1010
+
1011
+ <li>
1012
+
1013
+
1014
+ <span class='type'>(<tt>OpenSSL::PKey::RSA</tt>, <tt>OpenSSL::PKey::DSA</tt>, <tt>OpenSSL::Engine pkey</tt>)</span>
1015
+
1016
+
1017
+
1018
+ &mdash;
1019
+ <div class='inline'>
1020
+ <p>this method may return the PKey object itself or a handle to the private
1021
+ key in the HSM (which will not show the private key, just public)</p>
1022
+ </div>
1023
+
1024
+ </li>
1025
+
1026
+ </ul>
1027
+
1028
+ </div><table class="source_code">
1029
+ <tr>
1030
+ <td>
1031
+ <pre class="lines">
1032
+
1033
+
1034
+ 81
1035
+ 82
1036
+ 83
1037
+ 84
1038
+ 85
1039
+ 86
1040
+ 87</pre>
1041
+ </td>
1042
+ <td>
1043
+ <pre class="code"><span class="info file"># File 'lib/r509/privatekey.rb', line 81</span>
1044
+
1045
+ <span class='kw'>def</span> <span class='id identifier rubyid_key'>key</span>
1046
+ <span class='kw'>if</span> <span class='id identifier rubyid_in_hardware?'>in_hardware?</span>
1047
+ <span class='ivar'>@engine</span><span class='period'>.</span><span class='id identifier rubyid_load_private_key'>load_private_key</span><span class='lparen'>(</span><span class='ivar'>@key_name</span><span class='rparen'>)</span>
1048
+ <span class='kw'>else</span>
1049
+ <span class='ivar'>@key</span>
1050
+ <span class='kw'>end</span>
1051
+ <span class='kw'>end</span></pre>
1052
+ </td>
1053
+ </tr>
1054
+ </table>
1055
+ </div>
1056
+
1057
+ <div class="method_details ">
1058
+ <h3 class="signature " id="public_key-instance_method">
1059
+
1060
+ - (<tt>OpenSSL::PKey::RSA</tt>, <tt>OpenSSL::PKey::DSA</tt>) <strong>public_key</strong>
1061
+
1062
+
1063
+
1064
+ <span class="aliases">Also known as:
1065
+ <span class="names"><span id='to_s-instance_method'>to_s</span></span>
1066
+ </span>
1067
+
1068
+
1069
+
1070
+ </h3><div class="docstring">
1071
+ <div class="discussion">
1072
+
1073
+ <p>Public key</p>
1074
+
1075
+
1076
+ </div>
1077
+ </div>
1078
+ <div class="tags">
1079
+
1080
+ <p class="tag_title">Returns:</p>
1081
+ <ul class="return">
1082
+
1083
+ <li>
1084
+
1085
+
1086
+ <span class='type'>(<tt>OpenSSL::PKey::RSA</tt>, <tt>OpenSSL::PKey::DSA</tt>)</span>
1087
+
1088
+
1089
+
1090
+ &mdash;
1091
+ <div class='inline'>
1092
+ <p>public key</p>
1093
+ </div>
1094
+
1095
+ </li>
1096
+
1097
+ </ul>
1098
+
1099
+ </div><table class="source_code">
1100
+ <tr>
1101
+ <td>
1102
+ <pre class="lines">
1103
+
1104
+
1105
+ 99
1106
+ 100
1107
+ 101</pre>
1108
+ </td>
1109
+ <td>
1110
+ <pre class="code"><span class="info file"># File 'lib/r509/privatekey.rb', line 99</span>
1111
+
1112
+ <span class='kw'>def</span> <span class='id identifier rubyid_public_key'>public_key</span>
1113
+ <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_key'>key</span><span class='period'>.</span><span class='id identifier rubyid_public_key'>public_key</span>
1114
+ <span class='kw'>end</span></pre>
1115
+ </td>
1116
+ </tr>
1117
+ </table>
1118
+ </div>
1119
+
1120
+ <div class="method_details ">
1121
+ <h3 class="signature " id="rsa?-instance_method">
1122
+
1123
+ - (<tt>Boolean</tt>) <strong>rsa?</strong>
1124
+
1125
+
1126
+
1127
+
1128
+
1129
+ </h3><div class="docstring">
1130
+ <div class="discussion">
1131
+
1132
+ <p>Returns whether the public key is RSA</p>
1133
+
1134
+
1135
+ </div>
1136
+ </div>
1137
+ <div class="tags">
1138
+
1139
+ <p class="tag_title">Returns:</p>
1140
+ <ul class="return">
1141
+
1142
+ <li>
1143
+
1144
+
1145
+ <span class='type'>(<tt>Boolean</tt>)</span>
1146
+
1147
+
1148
+
1149
+ &mdash;
1150
+ <div class='inline'>
1151
+ <p>true if the public key is RSA, false otherwise</p>
1152
+ </div>
1153
+
1154
+ </li>
1155
+
1156
+ </ul>
1157
+
1158
+ </div><table class="source_code">
1159
+ <tr>
1160
+ <td>
1161
+ <pre class="lines">
1162
+
1163
+
1164
+ 174
1165
+ 175
1166
+ 176</pre>
1167
+ </td>
1168
+ <td>
1169
+ <pre class="code"><span class="info file"># File 'lib/r509/privatekey.rb', line 174</span>
1170
+
1171
+ <span class='kw'>def</span> <span class='id identifier rubyid_rsa?'>rsa?</span>
1172
+ <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_key'>key</span><span class='period'>.</span><span class='id identifier rubyid_kind_of?'>kind_of?</span><span class='lparen'>(</span><span class='const'>OpenSSL</span><span class='op'>::</span><span class='const'>PKey</span><span class='op'>::</span><span class='const'>RSA</span><span class='rparen'>)</span>
1173
+ <span class='kw'>end</span></pre>
1174
+ </td>
1175
+ </tr>
1176
+ </table>
1177
+ </div>
1178
+
1179
+ <div class="method_details ">
1180
+ <h3 class="signature " id="to_der-instance_method">
1181
+
1182
+ - (<tt>String</tt>) <strong>to_der</strong>
1183
+
1184
+
1185
+
1186
+
1187
+
1188
+ </h3><div class="docstring">
1189
+ <div class="discussion">
1190
+
1191
+ <p>Converts the key into the DER format</p>
1192
+
1193
+
1194
+ </div>
1195
+ </div>
1196
+ <div class="tags">
1197
+
1198
+ <p class="tag_title">Returns:</p>
1199
+ <ul class="return">
1200
+
1201
+ <li>
1202
+
1203
+
1204
+ <span class='type'>(<tt>String</tt>)</span>
1205
+
1206
+
1207
+
1208
+ &mdash;
1209
+ <div class='inline'>
1210
+ <p>the key converted into DER format.</p>
1211
+ </div>
1212
+
1213
+ </li>
1214
+
1215
+ </ul>
1216
+
1217
+ </div><table class="source_code">
1218
+ <tr>
1219
+ <td>
1220
+ <pre class="lines">
1221
+
1222
+
1223
+ 134
1224
+ 135
1225
+ 136
1226
+ 137
1227
+ 138
1228
+ 139</pre>
1229
+ </td>
1230
+ <td>
1231
+ <pre class="code"><span class="info file"># File 'lib/r509/privatekey.rb', line 134</span>
1232
+
1233
+ <span class='kw'>def</span> <span class='id identifier rubyid_to_der'>to_der</span>
1234
+ <span class='kw'>if</span> <span class='id identifier rubyid_in_hardware?'>in_hardware?</span>
1235
+ <span class='id identifier rubyid_raise'>raise</span> <span class='const'>R509</span><span class='op'>::</span><span class='const'>R509Error</span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>This method cannot be called when using keys in hardware</span><span class='tstring_end'>&quot;</span></span>
1236
+ <span class='kw'>end</span>
1237
+ <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_key'>key</span><span class='period'>.</span><span class='id identifier rubyid_to_der'>to_der</span>
1238
+ <span class='kw'>end</span></pre>
1239
+ </td>
1240
+ </tr>
1241
+ </table>
1242
+ </div>
1243
+
1244
+ <div class="method_details ">
1245
+ <h3 class="signature " id="to_encrypted_pem-instance_method">
1246
+
1247
+ - (<tt>String</tt>) <strong>to_encrypted_pem</strong>(cipher, password)
1248
+
1249
+
1250
+
1251
+
1252
+
1253
+ </h3><div class="docstring">
1254
+ <div class="discussion">
1255
+
1256
+ <p>Converts the key into encrypted PEM format</p>
1257
+
1258
+ <p>full list of available ciphers can be obtained with OpenSSL::Cipher.ciphers
1259
+ (common ones are des3, aes256, aes128)</p>
1260
+
1261
+
1262
+ </div>
1263
+ </div>
1264
+ <div class="tags">
1265
+ <p class="tag_title">Parameters:</p>
1266
+ <ul class="param">
1267
+
1268
+ <li>
1269
+
1270
+ <span class='name'>cipher</span>
1271
+
1272
+
1273
+ <span class='type'>(<tt>String</tt>, <tt>OpenSSL::Cipher</tt>)</span>
1274
+
1275
+
1276
+
1277
+ &mdash;
1278
+ <div class='inline'>
1279
+ <p>to use for encryption</p>
1280
+ </div>
1281
+
1282
+ </li>
1283
+
1284
+ <li>
1285
+
1286
+ <span class='name'>password</span>
1287
+
1288
+
1289
+ <span class='type'>(<tt>String</tt>)</span>
1290
+
1291
+
1292
+
1293
+ &mdash;
1294
+ <div class='inline'>
1295
+ <p>password</p>
1296
+ </div>
1297
+
1298
+ </li>
1299
+
1300
+ </ul>
1301
+
1302
+ <p class="tag_title">Returns:</p>
1303
+ <ul class="return">
1304
+
1305
+ <li>
1306
+
1307
+
1308
+ <span class='type'>(<tt>String</tt>)</span>
1309
+
1310
+
1311
+
1312
+ &mdash;
1313
+ <div class='inline'>
1314
+ <p>the key converted into encrypted PEM format.</p>
1315
+ </div>
1316
+
1317
+ </li>
1318
+
1319
+ </ul>
1320
+
1321
+ </div><table class="source_code">
1322
+ <tr>
1323
+ <td>
1324
+ <pre class="lines">
1325
+
1326
+
1327
+ 122
1328
+ 123
1329
+ 124
1330
+ 125
1331
+ 126
1332
+ 127
1333
+ 128</pre>
1334
+ </td>
1335
+ <td>
1336
+ <pre class="code"><span class="info file"># File 'lib/r509/privatekey.rb', line 122</span>
1337
+
1338
+ <span class='kw'>def</span> <span class='id identifier rubyid_to_encrypted_pem'>to_encrypted_pem</span><span class='lparen'>(</span><span class='id identifier rubyid_cipher'>cipher</span><span class='comma'>,</span><span class='id identifier rubyid_password'>password</span><span class='rparen'>)</span>
1339
+ <span class='kw'>if</span> <span class='id identifier rubyid_in_hardware?'>in_hardware?</span>
1340
+ <span class='id identifier rubyid_raise'>raise</span> <span class='const'>R509</span><span class='op'>::</span><span class='const'>R509Error</span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>This method cannot be called when using keys in hardware</span><span class='tstring_end'>&quot;</span></span>
1341
+ <span class='kw'>end</span>
1342
+ <span class='id identifier rubyid_cipher'>cipher</span> <span class='op'>=</span> <span class='const'>OpenSSL</span><span class='op'>::</span><span class='const'>Cipher</span><span class='op'>::</span><span class='const'>Cipher</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='id identifier rubyid_cipher'>cipher</span><span class='rparen'>)</span>
1343
+ <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_key'>key</span><span class='period'>.</span><span class='id identifier rubyid_to_pem'>to_pem</span><span class='lparen'>(</span><span class='id identifier rubyid_cipher'>cipher</span><span class='comma'>,</span><span class='id identifier rubyid_password'>password</span><span class='rparen'>)</span>
1344
+ <span class='kw'>end</span></pre>
1345
+ </td>
1346
+ </tr>
1347
+ </table>
1348
+ </div>
1349
+
1350
+ <div class="method_details ">
1351
+ <h3 class="signature " id="to_pem-instance_method">
1352
+
1353
+ - (<tt>String</tt>) <strong>to_pem</strong>
1354
+
1355
+
1356
+
1357
+
1358
+
1359
+ </h3><div class="docstring">
1360
+ <div class="discussion">
1361
+
1362
+ <p>Converts the key into the PEM format</p>
1363
+
1364
+
1365
+ </div>
1366
+ </div>
1367
+ <div class="tags">
1368
+
1369
+ <p class="tag_title">Returns:</p>
1370
+ <ul class="return">
1371
+
1372
+ <li>
1373
+
1374
+
1375
+ <span class='type'>(<tt>String</tt>)</span>
1376
+
1377
+
1378
+
1379
+ &mdash;
1380
+ <div class='inline'>
1381
+ <p>the key converted into PEM format.</p>
1382
+ </div>
1383
+
1384
+ </li>
1385
+
1386
+ </ul>
1387
+
1388
+ </div><table class="source_code">
1389
+ <tr>
1390
+ <td>
1391
+ <pre class="lines">
1392
+
1393
+
1394
+ 108
1395
+ 109
1396
+ 110
1397
+ 111
1398
+ 112
1399
+ 113</pre>
1400
+ </td>
1401
+ <td>
1402
+ <pre class="code"><span class="info file"># File 'lib/r509/privatekey.rb', line 108</span>
1403
+
1404
+ <span class='kw'>def</span> <span class='id identifier rubyid_to_pem'>to_pem</span>
1405
+ <span class='kw'>if</span> <span class='id identifier rubyid_in_hardware?'>in_hardware?</span>
1406
+ <span class='id identifier rubyid_raise'>raise</span> <span class='const'>R509</span><span class='op'>::</span><span class='const'>R509Error</span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>This method cannot be called when using keys in hardware</span><span class='tstring_end'>&quot;</span></span>
1407
+ <span class='kw'>end</span>
1408
+ <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_key'>key</span><span class='period'>.</span><span class='id identifier rubyid_to_pem'>to_pem</span>
1409
+ <span class='kw'>end</span></pre>
1410
+ </td>
1411
+ </tr>
1412
+ </table>
1413
+ </div>
1414
+
1415
+ <div class="method_details ">
1416
+ <h3 class="signature " id="write_der-instance_method">
1417
+
1418
+ - (<tt>Object</tt>) <strong>write_der</strong>(filename_or_io)
1419
+
1420
+
1421
+
1422
+
1423
+
1424
+ </h3><div class="docstring">
1425
+ <div class="discussion">
1426
+
1427
+ <p>Writes the key into the DER format</p>
1428
+
1429
+
1430
+ </div>
1431
+ </div>
1432
+ <div class="tags">
1433
+ <p class="tag_title">Parameters:</p>
1434
+ <ul class="param">
1435
+
1436
+ <li>
1437
+
1438
+ <span class='name'>filename_or_io</span>
1439
+
1440
+
1441
+ <span class='type'>(<tt>String</tt>, <tt>#write</tt>)</span>
1442
+
1443
+
1444
+
1445
+ &mdash;
1446
+ <div class='inline'>
1447
+ <p>Either a string of the path for the file that you'd like to write, or an
1448
+ IO-like object.</p>
1449
+ </div>
1450
+
1451
+ </li>
1452
+
1453
+ </ul>
1454
+
1455
+
1456
+ </div><table class="source_code">
1457
+ <tr>
1458
+ <td>
1459
+ <pre class="lines">
1460
+
1461
+
1462
+ 166
1463
+ 167
1464
+ 168</pre>
1465
+ </td>
1466
+ <td>
1467
+ <pre class="code"><span class="info file"># File 'lib/r509/privatekey.rb', line 166</span>
1468
+
1469
+ <span class='kw'>def</span> <span class='id identifier rubyid_write_der'>write_der</span><span class='lparen'>(</span><span class='id identifier rubyid_filename_or_io'>filename_or_io</span><span class='rparen'>)</span>
1470
+ <span class='id identifier rubyid_write_data'>write_data</span><span class='lparen'>(</span><span class='id identifier rubyid_filename_or_io'>filename_or_io</span><span class='comma'>,</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_to_der'>to_der</span><span class='rparen'>)</span>
1471
+ <span class='kw'>end</span></pre>
1472
+ </td>
1473
+ </tr>
1474
+ </table>
1475
+ </div>
1476
+
1477
+ <div class="method_details ">
1478
+ <h3 class="signature " id="write_encrypted_pem-instance_method">
1479
+
1480
+ - (<tt>Object</tt>) <strong>write_encrypted_pem</strong>(filename_or_io, cipher, password)
1481
+
1482
+
1483
+
1484
+
1485
+
1486
+ </h3><div class="docstring">
1487
+ <div class="discussion">
1488
+
1489
+ <p>Writes the key into encrypted PEM format with specified cipher</p>
1490
+
1491
+ <p>full list of available ciphers can be obtained with OpenSSL::Cipher.ciphers
1492
+ (common ones are des3, aes256, aes128)</p>
1493
+
1494
+
1495
+ </div>
1496
+ </div>
1497
+ <div class="tags">
1498
+ <p class="tag_title">Parameters:</p>
1499
+ <ul class="param">
1500
+
1501
+ <li>
1502
+
1503
+ <span class='name'>filename_or_io</span>
1504
+
1505
+
1506
+ <span class='type'>(<tt>String</tt>, <tt>#write</tt>)</span>
1507
+
1508
+
1509
+
1510
+ &mdash;
1511
+ <div class='inline'>
1512
+ <p>Either a string of the path for the file that you'd like to write, or an
1513
+ IO-like object.</p>
1514
+ </div>
1515
+
1516
+ </li>
1517
+
1518
+ <li>
1519
+
1520
+ <span class='name'>cipher</span>
1521
+
1522
+
1523
+ <span class='type'>(<tt>String</tt>, <tt>OpenSSL::Cipher</tt>)</span>
1524
+
1525
+
1526
+
1527
+ &mdash;
1528
+ <div class='inline'>
1529
+ <p>to use for encryption</p>
1530
+ </div>
1531
+
1532
+ </li>
1533
+
1534
+ <li>
1535
+
1536
+ <span class='name'>password</span>
1537
+
1538
+
1539
+ <span class='type'>(<tt>String</tt>)</span>
1540
+
1541
+
1542
+
1543
+ &mdash;
1544
+ <div class='inline'>
1545
+ <p>password</p>
1546
+ </div>
1547
+
1548
+ </li>
1549
+
1550
+ </ul>
1551
+
1552
+
1553
+ </div><table class="source_code">
1554
+ <tr>
1555
+ <td>
1556
+ <pre class="lines">
1557
+
1558
+
1559
+ 158
1560
+ 159
1561
+ 160</pre>
1562
+ </td>
1563
+ <td>
1564
+ <pre class="code"><span class="info file"># File 'lib/r509/privatekey.rb', line 158</span>
1565
+
1566
+ <span class='kw'>def</span> <span class='id identifier rubyid_write_encrypted_pem'>write_encrypted_pem</span><span class='lparen'>(</span><span class='id identifier rubyid_filename_or_io'>filename_or_io</span><span class='comma'>,</span><span class='id identifier rubyid_cipher'>cipher</span><span class='comma'>,</span><span class='id identifier rubyid_password'>password</span><span class='rparen'>)</span>
1567
+ <span class='id identifier rubyid_write_data'>write_data</span><span class='lparen'>(</span><span class='id identifier rubyid_filename_or_io'>filename_or_io</span><span class='comma'>,</span> <span class='id identifier rubyid_to_encrypted_pem'>to_encrypted_pem</span><span class='lparen'>(</span><span class='id identifier rubyid_cipher'>cipher</span><span class='comma'>,</span><span class='id identifier rubyid_password'>password</span><span class='rparen'>)</span><span class='rparen'>)</span>
1568
+ <span class='kw'>end</span></pre>
1569
+ </td>
1570
+ </tr>
1571
+ </table>
1572
+ </div>
1573
+
1574
+ <div class="method_details ">
1575
+ <h3 class="signature " id="write_pem-instance_method">
1576
+
1577
+ - (<tt>Object</tt>) <strong>write_pem</strong>(filename_or_io)
1578
+
1579
+
1580
+
1581
+
1582
+
1583
+ </h3><div class="docstring">
1584
+ <div class="discussion">
1585
+
1586
+ <p>Writes the key into the PEM format</p>
1587
+
1588
+
1589
+ </div>
1590
+ </div>
1591
+ <div class="tags">
1592
+ <p class="tag_title">Parameters:</p>
1593
+ <ul class="param">
1594
+
1595
+ <li>
1596
+
1597
+ <span class='name'>filename_or_io</span>
1598
+
1599
+
1600
+ <span class='type'>(<tt>String</tt>, <tt>#write</tt>)</span>
1601
+
1602
+
1603
+
1604
+ &mdash;
1605
+ <div class='inline'>
1606
+ <p>Either a string of the path for the file that you'd like to write, or an
1607
+ IO-like object.</p>
1608
+ </div>
1609
+
1610
+ </li>
1611
+
1612
+ </ul>
1613
+
1614
+
1615
+ </div><table class="source_code">
1616
+ <tr>
1617
+ <td>
1618
+ <pre class="lines">
1619
+
1620
+
1621
+ 145
1622
+ 146
1623
+ 147</pre>
1624
+ </td>
1625
+ <td>
1626
+ <pre class="code"><span class="info file"># File 'lib/r509/privatekey.rb', line 145</span>
1627
+
1628
+ <span class='kw'>def</span> <span class='id identifier rubyid_write_pem'>write_pem</span><span class='lparen'>(</span><span class='id identifier rubyid_filename_or_io'>filename_or_io</span><span class='rparen'>)</span>
1629
+ <span class='id identifier rubyid_write_data'>write_data</span><span class='lparen'>(</span><span class='id identifier rubyid_filename_or_io'>filename_or_io</span><span class='comma'>,</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_to_pem'>to_pem</span><span class='rparen'>)</span>
1630
+ <span class='kw'>end</span></pre>
1631
+ </td>
1632
+ </tr>
1633
+ </table>
1634
+ </div>
1635
+
1636
+ </div>
1637
+
1638
+ </div>
1639
+
1640
+ <div id="footer">
1641
+ Generated on Tue Oct 23 22:48:03 2012 by
1642
+ <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
1643
+ 0.8.0 (ruby-1.9.3).
1644
+ </div>
1645
+
1646
+ </body>
1647
+ </html>