bridge-ruby 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (67) hide show
  1. data/LICENSE +19 -0
  2. data/README.md +31 -0
  3. data/Rakefile +24 -0
  4. data/bridge-ruby.gemspec +24 -0
  5. data/doc/Bridge.html +276 -0
  6. data/doc/Bridge/Bridge.html +1874 -0
  7. data/doc/Bridge/Bridge/SystemService.html +396 -0
  8. data/doc/Bridge/Client.html +271 -0
  9. data/doc/Bridge/Connection.html +1180 -0
  10. data/doc/Bridge/Connection/SockBuffer.html +322 -0
  11. data/doc/Bridge/Reference.html +605 -0
  12. data/doc/Bridge/Serializer.html +405 -0
  13. data/doc/Bridge/Serializer/Callback.html +498 -0
  14. data/doc/Bridge/Tcp.html +657 -0
  15. data/doc/Bridge/Util.html +643 -0
  16. data/doc/Bridge/Util/CallbackReference.html +557 -0
  17. data/doc/OpenSSL/X509/Certificate.html +275 -0
  18. data/doc/SSLCertificateVerification.html +446 -0
  19. data/doc/_index.html +239 -0
  20. data/doc/class_list.html +53 -0
  21. data/doc/css/common.css +1 -0
  22. data/doc/css/full_list.css +57 -0
  23. data/doc/css/style.css +328 -0
  24. data/doc/file.README.html +106 -0
  25. data/doc/file_list.html +55 -0
  26. data/doc/frames.html +28 -0
  27. data/doc/index.html +106 -0
  28. data/doc/js/app.js +214 -0
  29. data/doc/js/full_list.js +173 -0
  30. data/doc/js/jquery.js +4 -0
  31. data/doc/method_list.html +772 -0
  32. data/doc/top-level-namespace.html +112 -0
  33. data/examples/channels/client-writeable.rb +24 -0
  34. data/examples/channels/client.rb +23 -0
  35. data/examples/channels/server.rb +24 -0
  36. data/examples/chat/chatclient.rb +21 -0
  37. data/examples/chat/chatserver.rb +24 -0
  38. data/examples/client-context/client.rb +21 -0
  39. data/examples/client-context/server.rb +25 -0
  40. data/examples/secure/example.rb +8 -0
  41. data/examples/simple/channels.rb +47 -0
  42. data/examples/simple/services.rb +41 -0
  43. data/include/ssl/cacert.pem +3331 -0
  44. data/lib/bridge-ruby.rb +441 -0
  45. data/lib/client.rb +14 -0
  46. data/lib/connection.rb +162 -0
  47. data/lib/reference.rb +49 -0
  48. data/lib/serializer.rb +104 -0
  49. data/lib/ssl_utils.rb +68 -0
  50. data/lib/tcp.rb +73 -0
  51. data/lib/util.rb +101 -0
  52. data/lib/version.rb +3 -0
  53. data/rakelib/package.rake +4 -0
  54. data/rakelib/test.rake +8 -0
  55. data/test/regression/reconnect.rb +48 -0
  56. data/test/regression/rpc.rb +39 -0
  57. data/test/regression/test.rb +58 -0
  58. data/test/unit/bridge_dummy.rb +26 -0
  59. data/test/unit/connection_dummy.rb +21 -0
  60. data/test/unit/reference_dummy.rb +11 -0
  61. data/test/unit/tcp_dummy.rb +12 -0
  62. data/test/unit/test.rb +20 -0
  63. data/test/unit/test_reference.rb +30 -0
  64. data/test/unit/test_serializer.rb +109 -0
  65. data/test/unit/test_tcp.rb +51 -0
  66. data/test/unit/test_util.rb +59 -0
  67. metadata +162 -0
@@ -0,0 +1,275 @@
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: OpenSSL::X509::Certificate
8
+
9
+ &mdash; Documentation by YARD 0.8.2.1
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 (C)</a> &raquo;
35
+ <span class='title'>OpenSSL</span> &raquo; <span class='title'>X509</span>
36
+ &raquo;
37
+ <span class="title">Certificate</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: OpenSSL::X509::Certificate
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">OpenSSL::X509::Certificate</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/ssl_utils.rb</dd>
98
+
99
+ </dl>
100
+ <div class="clear"></div>
101
+
102
+
103
+
104
+
105
+
106
+
107
+
108
+
109
+
110
+ <h2>
111
+ Instance Method Summary
112
+ <small>(<a href="#" class="summary_toggle">collapse</a>)</small>
113
+ </h2>
114
+
115
+ <ul class="summary">
116
+
117
+ <li class="public ">
118
+ <span class="summary_signature">
119
+
120
+ <a href="#%3D%3D-instance_method" title="#== (instance method)">- (Object) <strong>==</strong>(other) </a>
121
+
122
+
123
+
124
+ </span>
125
+
126
+
127
+
128
+
129
+
130
+
131
+
132
+
133
+
134
+ <span class="summary_desc"><div class='inline'></div></span>
135
+
136
+ </li>
137
+
138
+
139
+ <li class="public ">
140
+ <span class="summary_signature">
141
+
142
+ <a href="#top_level%3F-instance_method" title="#top_level? (instance method)">- (Boolean) <strong>top_level?</strong> </a>
143
+
144
+
145
+
146
+ (also: #root?, #self_signed?)
147
+
148
+ </span>
149
+
150
+
151
+
152
+
153
+
154
+
155
+
156
+
157
+
158
+ <span class="summary_desc"><div class='inline'>
159
+ <p>A serial <strong>must</strong> be unique for each certificate.</p>
160
+ </div></span>
161
+
162
+ </li>
163
+
164
+
165
+ </ul>
166
+
167
+
168
+
169
+
170
+ <div id="instance_method_details" class="method_details_list">
171
+ <h2>Instance Method Details</h2>
172
+
173
+
174
+ <div class="method_details first">
175
+ <h3 class="signature first" id="==-instance_method">
176
+
177
+ - (<tt>Object</tt>) <strong>==</strong>(other)
178
+
179
+
180
+
181
+
182
+
183
+ </h3><table class="source_code">
184
+ <tr>
185
+ <td>
186
+ <pre class="lines">
187
+
188
+
189
+ 4
190
+ 5
191
+ 6</pre>
192
+ </td>
193
+ <td>
194
+ <pre class="code"><span class="info file"># File 'lib/ssl_utils.rb', line 4</span>
195
+
196
+ <span class='kw'>def</span> <span class='op'>==</span><span class='lparen'>(</span><span class='id identifier rubyid_other'>other</span><span class='rparen'>)</span>
197
+ <span class='id identifier rubyid_other'>other</span><span class='period'>.</span><span class='id identifier rubyid_respond_to?'>respond_to?</span><span class='lparen'>(</span><span class='symbol'>:to_pem</span><span class='rparen'>)</span> <span class='op'>&amp;&amp;</span> <span class='id identifier rubyid_to_pem'>to_pem</span> <span class='op'>==</span> <span class='id identifier rubyid_other'>other</span><span class='period'>.</span><span class='id identifier rubyid_to_pem'>to_pem</span>
198
+ <span class='kw'>end</span></pre>
199
+ </td>
200
+ </tr>
201
+ </table>
202
+ </div>
203
+
204
+ <div class="method_details ">
205
+ <h3 class="signature " id="top_level?-instance_method">
206
+
207
+ - (<tt>Boolean</tt>) <strong>top_level?</strong>
208
+
209
+
210
+
211
+ <span class="aliases">Also known as:
212
+ <span class="names"><span id='root?-instance_method'>root?</span>, <span id='self_signed?-instance_method'>self_signed?</span></span>
213
+ </span>
214
+
215
+
216
+
217
+ </h3><div class="docstring">
218
+ <div class="discussion">
219
+
220
+ <p>A serial <strong>must</strong> be unique for each certificate. Self-signed
221
+ certificates, and thus root CA certificates, have the same `issuer' as
222
+ `subject'.</p>
223
+
224
+
225
+ </div>
226
+ </div>
227
+ <div class="tags">
228
+
229
+ <p class="tag_title">Returns:</p>
230
+ <ul class="return">
231
+
232
+ <li>
233
+
234
+
235
+ <span class='type'>(<tt>Boolean</tt>)</span>
236
+
237
+
238
+
239
+ </li>
240
+
241
+ </ul>
242
+
243
+ </div><table class="source_code">
244
+ <tr>
245
+ <td>
246
+ <pre class="lines">
247
+
248
+
249
+ 10
250
+ 11
251
+ 12</pre>
252
+ </td>
253
+ <td>
254
+ <pre class="code"><span class="info file"># File 'lib/ssl_utils.rb', line 10</span>
255
+
256
+ <span class='kw'>def</span> <span class='id identifier rubyid_top_level?'>top_level?</span>
257
+ <span class='id identifier rubyid_serial'>serial</span> <span class='op'>==</span> <span class='id identifier rubyid_serial'>serial</span> <span class='op'>&amp;&amp;</span> <span class='id identifier rubyid_issuer'>issuer</span><span class='period'>.</span><span class='id identifier rubyid_to_s'>to_s</span> <span class='op'>==</span> <span class='id identifier rubyid_subject'>subject</span><span class='period'>.</span><span class='id identifier rubyid_to_s'>to_s</span>
258
+ <span class='kw'>end</span></pre>
259
+ </td>
260
+ </tr>
261
+ </table>
262
+ </div>
263
+
264
+ </div>
265
+
266
+ </div>
267
+
268
+ <div id="footer">
269
+ Generated on Wed Jun 20 11:00:11 2012 by
270
+ <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
271
+ 0.8.2.1 (ruby-1.9.3).
272
+ </div>
273
+
274
+ </body>
275
+ </html>
@@ -0,0 +1,446 @@
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
+ Module: SSLCertificateVerification
8
+
9
+ &mdash; Documentation by YARD 0.8.2.1
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 (S)</a> &raquo;
35
+
36
+
37
+ <span class="title">SSLCertificateVerification</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>Module: SSLCertificateVerification
67
+
68
+
69
+
70
+ </h1>
71
+
72
+ <dl class="box">
73
+
74
+
75
+
76
+
77
+
78
+
79
+
80
+ <dt class="r1">Included in:</dt>
81
+ <dd class="r1"><span class='object_link'><a href="Bridge/Tcp.html" title="Bridge::Tcp (class)">Bridge::Tcp</a></span></dd>
82
+
83
+
84
+
85
+ <dt class="r2 last">Defined in:</dt>
86
+ <dd class="r2 last">lib/ssl_utils.rb</dd>
87
+
88
+ </dl>
89
+ <div class="clear"></div>
90
+
91
+ <h2>Overview</h2><div class="docstring">
92
+ <div class="discussion">
93
+
94
+ <p>Verifies that the peer certificate is a valid chained certificate. That is,
95
+ it's signed by a root CA or a CA signed by a root CA.</p>
96
+
97
+ <p>This module will also perform hostname verification against the server???s
98
+ certificate, but <em>only</em> if an instance variable called <tt>@hostname</tt>
99
+ exists.</p>
100
+
101
+
102
+ </div>
103
+ </div>
104
+ <div class="tags">
105
+
106
+
107
+ </div>
108
+
109
+
110
+
111
+ <h2>Class Attribute Summary <small>(<a href="#" class="summary_toggle">collapse</a>)</small></h2>
112
+ <ul class="summary">
113
+
114
+ <li class="public ">
115
+ <span class="summary_signature">
116
+
117
+ <a href="#ca_cert_file-class_method" title="ca_cert_file (class method)">+ (Object) <strong>ca_cert_file</strong> </a>
118
+
119
+
120
+
121
+ </span>
122
+
123
+
124
+
125
+
126
+
127
+
128
+
129
+
130
+
131
+
132
+
133
+
134
+ <span class="summary_desc"><div class='inline'>
135
+ <p>In PEM format.</p>
136
+ </div></span>
137
+
138
+ </li>
139
+
140
+
141
+ </ul>
142
+
143
+
144
+
145
+
146
+
147
+ <h2>
148
+ Instance Method Summary
149
+ <small>(<a href="#" class="summary_toggle">collapse</a>)</small>
150
+ </h2>
151
+
152
+ <ul class="summary">
153
+
154
+ <li class="public ">
155
+ <span class="summary_signature">
156
+
157
+ <a href="#ca_store-instance_method" title="#ca_store (instance method)">- (Object) <strong>ca_store</strong> </a>
158
+
159
+
160
+
161
+ </span>
162
+
163
+
164
+
165
+
166
+
167
+
168
+
169
+
170
+
171
+ <span class="summary_desc"><div class='inline'></div></span>
172
+
173
+ </li>
174
+
175
+
176
+ <li class="public ">
177
+ <span class="summary_signature">
178
+
179
+ <a href="#ssl_handshake_completed-instance_method" title="#ssl_handshake_completed (instance method)">- (Object) <strong>ssl_handshake_completed</strong> </a>
180
+
181
+
182
+
183
+ </span>
184
+
185
+
186
+
187
+
188
+
189
+
190
+
191
+
192
+
193
+ <span class="summary_desc"><div class='inline'></div></span>
194
+
195
+ </li>
196
+
197
+
198
+ <li class="public ">
199
+ <span class="summary_signature">
200
+
201
+ <a href="#ssl_verify_peer-instance_method" title="#ssl_verify_peer (instance method)">- (Object) <strong>ssl_verify_peer</strong>(cert_string) </a>
202
+
203
+
204
+
205
+ </span>
206
+
207
+
208
+
209
+
210
+
211
+
212
+
213
+
214
+
215
+ <span class="summary_desc"><div class='inline'>
216
+ <p>It's important that we try to not add a certificate to the store that's
217
+ already in the store, because OpenSSL::X509::Store will raise an exception.</p>
218
+ </div></span>
219
+
220
+ </li>
221
+
222
+
223
+ </ul>
224
+
225
+
226
+
227
+ <div id="class_attr_details" class="attr_details">
228
+ <h2>Class Attribute Details</h2>
229
+
230
+
231
+ <span id="ca_cert_file=-class_method"></span>
232
+ <div class="method_details first">
233
+ <h3 class="signature first" id="ca_cert_file-class_method">
234
+
235
+ + (<tt>Object</tt>) <strong>ca_cert_file</strong>
236
+
237
+
238
+
239
+
240
+
241
+ </h3><div class="docstring">
242
+ <div class="discussion">
243
+
244
+ <p>In PEM format.</p>
245
+
246
+ <p>Eg: <a
247
+ href="http://curl.haxx.se/docs/caextract.html">curl.haxx.se/docs/caextract.html</a></p>
248
+
249
+
250
+ </div>
251
+ </div>
252
+ <div class="tags">
253
+
254
+
255
+ </div><table class="source_code">
256
+ <tr>
257
+ <td>
258
+ <pre class="lines">
259
+
260
+
261
+ 27
262
+ 28
263
+ 29</pre>
264
+ </td>
265
+ <td>
266
+ <pre class="code"><span class="info file"># File 'lib/ssl_utils.rb', line 27</span>
267
+
268
+ <span class='kw'>def</span> <span class='id identifier rubyid_ca_cert_file'>ca_cert_file</span>
269
+ <span class='ivar'>@ca_cert_file</span>
270
+ <span class='kw'>end</span></pre>
271
+ </td>
272
+ </tr>
273
+ </table>
274
+ </div>
275
+
276
+ </div>
277
+
278
+
279
+ <div id="instance_method_details" class="method_details_list">
280
+ <h2>Instance Method Details</h2>
281
+
282
+
283
+ <div class="method_details first">
284
+ <h3 class="signature first" id="ca_store-instance_method">
285
+
286
+ - (<tt>Object</tt>) <strong>ca_store</strong>
287
+
288
+
289
+
290
+
291
+
292
+ </h3><table class="source_code">
293
+ <tr>
294
+ <td>
295
+ <pre class="lines">
296
+
297
+
298
+ 30
299
+ 31
300
+ 32
301
+ 33
302
+ 34
303
+ 35
304
+ 36
305
+ 37
306
+ 38
307
+ 39
308
+ 40</pre>
309
+ </td>
310
+ <td>
311
+ <pre class="code"><span class="info file"># File 'lib/ssl_utils.rb', line 30</span>
312
+
313
+ <span class='kw'>def</span> <span class='id identifier rubyid_ca_store'>ca_store</span>
314
+ <span class='kw'>unless</span> <span class='ivar'>@ca_store</span>
315
+ <span class='kw'>if</span> <span class='id identifier rubyid_file'>file</span> <span class='op'>=</span> <span class='const'>SSLCertificateVerification</span><span class='period'>.</span><span class='id identifier rubyid_ca_cert_file'>ca_cert_file</span>
316
+ <span class='ivar'>@ca_store</span> <span class='op'>=</span> <span class='const'>OpenSSL</span><span class='op'>::</span><span class='const'>X509</span><span class='op'>::</span><span class='const'>Store</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span>
317
+ <span class='ivar'>@ca_store</span><span class='period'>.</span><span class='id identifier rubyid_add_file'>add_file</span><span class='lparen'>(</span><span class='id identifier rubyid_file'>file</span><span class='rparen'>)</span>
318
+ <span class='kw'>else</span>
319
+ <span class='id identifier rubyid_fail'>fail</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>you must specify a file with root CA certificates as `SSLCertificateVerification.ca_cert_file'</span><span class='tstring_end'>&quot;</span></span>
320
+ <span class='kw'>end</span>
321
+ <span class='kw'>end</span>
322
+ <span class='ivar'>@ca_store</span>
323
+ <span class='kw'>end</span></pre>
324
+ </td>
325
+ </tr>
326
+ </table>
327
+ </div>
328
+
329
+ <div class="method_details ">
330
+ <h3 class="signature " id="ssl_handshake_completed-instance_method">
331
+
332
+ - (<tt>Object</tt>) <strong>ssl_handshake_completed</strong>
333
+
334
+
335
+
336
+
337
+
338
+ </h3><table class="source_code">
339
+ <tr>
340
+ <td>
341
+ <pre class="lines">
342
+
343
+
344
+ 61
345
+ 62
346
+ 63
347
+ 64
348
+ 65
349
+ 66
350
+ 67</pre>
351
+ </td>
352
+ <td>
353
+ <pre class="code"><span class="info file"># File 'lib/ssl_utils.rb', line 61</span>
354
+
355
+ <span class='kw'>def</span> <span class='id identifier rubyid_ssl_handshake_completed'>ssl_handshake_completed</span>
356
+ <span class='kw'>if</span> <span class='ivar'>@hostname</span>
357
+ <span class='kw'>unless</span> <span class='const'>OpenSSL</span><span class='op'>::</span><span class='const'>SSL</span><span class='period'>.</span><span class='id identifier rubyid_verify_certificate_identity'>verify_certificate_identity</span><span class='lparen'>(</span><span class='ivar'>@last_seen_cert</span><span class='comma'>,</span> <span class='ivar'>@hostname</span><span class='rparen'>)</span>
358
+ <span class='id identifier rubyid_fail'>fail</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>the hostname `HOSTNAME' does not match the server certificate</span><span class='tstring_end'>&quot;</span></span>
359
+ <span class='kw'>end</span>
360
+ <span class='kw'>end</span>
361
+ <span class='kw'>end</span></pre>
362
+ </td>
363
+ </tr>
364
+ </table>
365
+ </div>
366
+
367
+ <div class="method_details ">
368
+ <h3 class="signature " id="ssl_verify_peer-instance_method">
369
+
370
+ - (<tt>Object</tt>) <strong>ssl_verify_peer</strong>(cert_string)
371
+
372
+
373
+
374
+
375
+
376
+ </h3><div class="docstring">
377
+ <div class="discussion">
378
+
379
+ <p>It's important that we try to not add a certificate to the store that's
380
+ already in the store, because OpenSSL::X509::Store will raise an exception.</p>
381
+
382
+
383
+ </div>
384
+ </div>
385
+ <div class="tags">
386
+
387
+
388
+ </div><table class="source_code">
389
+ <tr>
390
+ <td>
391
+ <pre class="lines">
392
+
393
+
394
+ 44
395
+ 45
396
+ 46
397
+ 47
398
+ 48
399
+ 49
400
+ 50
401
+ 51
402
+ 52
403
+ 53
404
+ 54
405
+ 55
406
+ 56
407
+ 57
408
+ 58
409
+ 59</pre>
410
+ </td>
411
+ <td>
412
+ <pre class="code"><span class="info file"># File 'lib/ssl_utils.rb', line 44</span>
413
+
414
+ <span class='kw'>def</span> <span class='id identifier rubyid_ssl_verify_peer'>ssl_verify_peer</span><span class='lparen'>(</span><span class='id identifier rubyid_cert_string'>cert_string</span><span class='rparen'>)</span>
415
+ <span class='id identifier rubyid_cert'>cert</span> <span class='op'>=</span> <span class='const'>OpenSSL</span><span class='op'>::</span><span class='const'>X509</span><span class='op'>::</span><span class='const'>Certificate</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='id identifier rubyid_cert_string'>cert_string</span><span class='rparen'>)</span>
416
+ <span class='comment'># Some servers send the same certificate multiple times. I'm not even joking... (gmail.com)
417
+ </span> <span class='kw'>return</span> <span class='kw'>true</span> <span class='kw'>if</span> <span class='id identifier rubyid_cert'>cert</span> <span class='op'>==</span> <span class='ivar'>@last_seen_cert</span>
418
+ <span class='ivar'>@last_seen_cert</span> <span class='op'>=</span> <span class='id identifier rubyid_cert'>cert</span>
419
+
420
+ <span class='kw'>if</span> <span class='id identifier rubyid_ca_store'>ca_store</span><span class='period'>.</span><span class='id identifier rubyid_verify'>verify</span><span class='lparen'>(</span><span class='ivar'>@last_seen_cert</span><span class='rparen'>)</span>
421
+ <span class='comment'># A server may send the root certifiacte, which we already have and thus
422
+ </span> <span class='comment'># should not be added to the store again.
423
+ </span> <span class='id identifier rubyid_ca_store'>ca_store</span><span class='period'>.</span><span class='id identifier rubyid_add_cert'>add_cert</span><span class='lparen'>(</span><span class='ivar'>@last_seen_cert</span><span class='rparen'>)</span> <span class='kw'>unless</span> <span class='ivar'>@last_seen_cert</span><span class='period'>.</span><span class='id identifier rubyid_root?'>root?</span>
424
+ <span class='kw'>true</span>
425
+ <span class='kw'>else</span>
426
+ <span class='id identifier rubyid_fail'>fail</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>unable to verify the server certificate of `</span><span class='embexpr_beg'>#{</span><span class='ivar'>@hostname</span><span class='rbrace'>}</span><span class='tstring_content'>'</span><span class='tstring_end'>&quot;</span></span>
427
+ <span class='kw'>false</span>
428
+ <span class='kw'>end</span>
429
+ <span class='kw'>end</span></pre>
430
+ </td>
431
+ </tr>
432
+ </table>
433
+ </div>
434
+
435
+ </div>
436
+
437
+ </div>
438
+
439
+ <div id="footer">
440
+ Generated on Wed Jun 20 11:00:11 2012 by
441
+ <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
442
+ 0.8.2.1 (ruby-1.9.3).
443
+ </div>
444
+
445
+ </body>
446
+ </html>