Net-SSLeay-1.20 >
1.36
との差分
Net::SSLeay 1.36 と 1.20 の差分
1 | 1 | |
2 | 2 | =encoding euc-jp |
3 | 3 | |
4 | 4 | =head1 NAME |
5 | 5 | |
6 | 6 | =begin original |
7 | 7 | |
8 | Net::SSLeay - Perl extension for using OpenSSL | |
8 | Net::SSLeay - Perl extension for using OpenSSL or SSLeay | |
9 | 9 | |
10 | 10 | =end original |
11 | 11 | |
12 | Net::SSLeay - OpenSSL | |
12 | Net::SSLeay - OpenSSLやSSLeayを使うためのPerl拡張 | |
13 | 13 | |
14 | 14 | =head1 SYNOPSIS |
15 | 15 | |
16 | use Net::SSLeay qw(get_https post_https sslcat make_headers make_form); | |
16 | use Net::SSLeay, qw(get_https post_https sslcat make_headers make_form); | |
17 | 17 | |
18 | 18 | ($page) = get_https('www.bacus.pt', 443, '/'); # 1 |
19 | 19 | |
20 | 20 | ($page, $response, %reply_headers) |
21 | 21 | = get_https('www.bacus.pt', 443, '/', # 2 |
22 | 22 | make_headers(User-Agent => 'Cryptozilla/5.0b1', |
23 | 23 | Referer => 'https://www.bacus.pt' |
24 | 24 | )); |
25 | 25 | |
26 | 26 | ($page, $result, %headers) = # 2b |
27 | 27 | = get_https('www.bacus.pt', 443, '/protected.html', |
28 | 28 | make_headers(Authorization => |
29 | 29 | 'Basic ' . MIME::Base64::encode("$user:$pass",'')) |
30 | 30 | ); |
31 | 31 | |
32 | 32 | ($page, $response, %reply_headers) |
33 | 33 | = post_https('www.bacus.pt', 443, '/foo.cgi', '', # 3 |
34 | 34 | make_form(OK => '1', |
35 | 35 | name => 'Sampo' |
36 | 36 | )); |
37 | 37 | |
38 | 38 | $reply = sslcat($host, $port, $request); # 4 |
39 | 39 | |
40 | 40 | ($reply, $err, $server_cert) = sslcat($host, $port, $request); # 5 |
41 | 41 | |
42 | 42 | $Net::SSLeay::trace = 2; # 0=no debugging, 1=ciphers, 2=trace, 3=dump data |
43 | 43 | |
44 | 44 | =head1 DESCRIPTION |
45 | 45 | |
46 | 46 | =begin original |
47 | 47 | |
48 | There is a related module called | |
48 | There is a related module called Net::SSLeay::Handle included in this | |
49 | 49 | distribution that you might want to use instead. It has its own pod |
50 | 50 | documentation. |
51 | 51 | |
52 | 52 | =end original |
53 | 53 | |
54 | あなたが代わりに使いたいかもしれない、この | |
54 | あなたが代わりに使いたいかもしれない、このディストリビューションに | |
55 | 含まれている | |
55 | 含まれているNet::SSLeay::Handleという関連するモジュールがあります。 | |
56 | それは、それ独自の | |
56 | それは、それ独自のPODドキュメントを持っています。 | |
57 | 57 | |
58 | 58 | =begin original |
59 | 59 | |
60 | This module offers some high level conv | |
60 | This module offers some high level convinience functions for accessing | |
61 | web pages on SSL servers | |
61 | web pages on SSL servers, a sslcat() function for writing your own | |
62 | ||
62 | clients, and finally access to the SSL api of SSLeay/OpenSSL package so you | |
63 | c | |
63 | can write servers or clients for more complicated applications. | |
64 | so you can write servers or clients for more complicated applications. | |
65 | 64 | |
66 | 65 | =end original |
67 | 66 | |
68 | このモジュールは、SSL | |
67 | このモジュールは、SSLサーバー上のWebページにアクセスするためのいくつかの | |
69 | 高レベルで便利な関数 | |
68 | 高レベルで便利な関数、独自のクライアントを書くためのsslcat() | |
70 | ||
69 | 関数、そして最終的にはより複雑なアプリケーションのためにサーバーや | |
71 | ||
70 | クライアントを書くことができるようなSSLeay/OpenSSLパッケージのSSL apiへの | |
72 | より複雑なアプリケーションのためにサーバやクライアントを書くことが | |
73 | できるような SSLeay/OpenSSL パッケージの SSL api への | |
74 | 71 | アクセスを提供します。 |
75 | 72 | |
76 | 73 | =begin original |
77 | 74 | |
78 | For high level functions it is most conv | |
75 | For high level functions it is most convinient to import them to your | |
79 | 76 | main namespace as indicated in the synopsis. |
80 | 77 | |
81 | 78 | =end original |
82 | 79 | |
83 | 高レベルの関数については、概要で示したように、あなたの | |
80 | 高レベルの関数については、概要で示したように、あなたのmain名前空間に | |
84 | 81 | インポートすることが、とても便利でしょう。 |
85 | 82 | |
86 | 83 | =begin original |
87 | 84 | |
88 | Case 1 demonstrates t | |
85 | Case 1 demonstrates typical invocation of get_https() to fetch an HTML | |
89 | page from secure server. The first argument provides | |
86 | page from secure server. The first argument provides host name or ip | |
90 | in dotted decimal notation of the remote server to contact. | |
87 | in dotted decimal notation of the remote server to contact. Second | |
91 | 88 | argument is the TCP port at the remote end (your own port is picked |
92 | 89 | arbitrarily from high numbered ports as usual for TCP). The third |
93 | 90 | argument is the URL of the page without the host name part. If in |
94 | doubt consult | |
91 | doubt consult HTTP specifications at <http://www.w3c.org> | |
95 | 92 | |
96 | 93 | =end original |
97 | 94 | |
98 | ケース 1 | |
95 | ケース 1はセキュアなサーバからHTMLページを取り出すためのget_https()の | |
99 | 典型的な呼び出しを示しています。 | |
96 | 典型的な呼び出しを示しています。最初の引数は接続するリモートのサーバーの | |
100 | ||
97 | ホスト名あるいはIPをドット区切られた数字による書き方によって与えます。 | |
101 | ||
98 | 2番目の引数はリモート側のTCPポートです(あなた自身のポートは通常のTCPのための | |
102 | ||
99 | 高く番号が振られたものから勝手に選択されます)。3番目の引数はホスト名の | |
103 | ||
100 | 部分を抜いたページのURLです。もし疑問があれば、<http://www.w3c.org>にある | |
104 | ||
101 | HTTPの仕様をあたってみてください。 | |
105 | もし疑問があれば、L<http://www.w3c.org> にある HTTP の仕様を | |
106 | あたってみてください。 | |
107 | 102 | |
108 | 103 | =begin original |
109 | 104 | |
110 | Case 2 demonstrates full fledged use of | |
105 | Case 2 demonstrates full fledged use of get_https(). As can be seen, | |
111 | ||
106 | get_https() parses the response and response headers and returns them as | |
112 | 107 | a list, which can be captured in a hash for later reference. Also a |
113 | fourth argument to | |
108 | fourth argument to get_https() is used to insert some additional headers | |
114 | in the request. | |
109 | in the request. make_headers() is a function that will convert a list or | |
115 | hash to such headers. By default | |
110 | hash to such headers. By default get_https() supplies Host (make virtual | |
116 | ||
111 | hosting easy) and Accept (reportedly needed by IIS) headers. | |
117 | 112 | |
118 | 113 | =end original |
119 | 114 | |
120 | ケース 2 | |
115 | ケース 2は、完全に一人前のget_https()の使い方を示しています。ご覧になった通り、 | |
121 | ||
116 | get_https()は応答と応答のヘッダを解析し、それをリストで返しています。 | |
122 | ||
117 | それらはハッシュや後者のリファレンスで捉えることができます。またget_https()の | |
123 | ||
118 | 4番目の引数は、応答での追加のヘッダを挿入するために使われます。 | |
124 | ||
119 | make_headers()はリストやハッシュを、そのようなヘッダに変換する関数です。 | |
125 | ||
120 | デフォルトではget_https()はHost(バーチャル・ホストを簡単に行えるように)と | |
126 | ||
121 | Accept(IISが必要としているとのこと)ヘッダを提供します。 | |
127 | デフォルトでは C<get_https()> は C<Host>(バーチャルホストを簡単に | |
128 | 行えるように)と C<Accept> (IIS が必要としているとのこと)ヘッダを提供します。 | |
129 | 122 | |
130 | 123 | =begin original |
131 | 124 | |
132 | Case 2b demonstrates how to get | |
125 | Case 2b demonstrates how to get password protected page. Refer to | |
133 | ||
126 | HTTP protocol specifications for further details (e.g. RFC2617). | |
134 | 127 | |
135 | 128 | =end original |
136 | 129 | |
137 | ケース 2b | |
130 | ケース 2bはパスワードで保護されているページを取得する方法を示しています。 | |
138 | 更なる詳細に関しては、HTTP | |
131 | 更なる詳細に関しては、HTTPプロトコルの仕様を参照してください。(例えばRFC2617)。 | |
139 | (例えば RFC-2617)。 | |
140 | 132 | |
141 | 133 | =begin original |
142 | 134 | |
143 | Case 3 invokes | |
135 | Case 3 invokes post_https() to submit a HTML/CGI form to secure | |
144 | server. | |
136 | server. First four arguments are equal to get_https() (note that empty | |
145 | ||
137 | string ('') is passed as header argument). The fifth argument is the | |
146 | The fifth argument is the | |
147 | 138 | contents of the form formatted according to CGI specification. In this |
148 | case the helper function | |
139 | case the helper function make_https() is used to do the formatting, | |
149 | but you could pass any string. | |
140 | but you could pass any string. The post_https() automatically adds | |
150 | C | |
141 | Content-Type and Content-Length headers to the request. | |
151 | 142 | |
152 | 143 | =end original |
153 | 144 | |
154 | ケース 3 | |
145 | ケース 3はHTML/CGIフォームをセキュアなサーバーで実行するためにpost_https()を | |
155 | ||
146 | 呼び出します。最初の4つの引数はget_https()と同じです(空文字列('')が | |
156 | ||
147 | ヘッダの引数として渡されていることに注意してください)。5番目の引数は | |
157 | ||
148 | CGIの仕様に従って形式が整えられたフォームの内容です。この場合、 | |
158 | ||
149 | そのように形式を整えるためにヘルパー関数make_https()が使われますが、 | |
159 | ||
150 | どのような文字列でも渡すことができます。post_https()は自動的にリクエストに | |
160 | ||
151 | Content-Type と Content-Length ヘッダを付与します。 | |
161 | C<post_https()> は自動的にリクエストに C<Content-Type> と C<Content-Length> | |
162 | ヘッダを付与します。 | |
163 | 152 | |
164 | 153 | =begin original |
165 | 154 | |
166 | Case 4 shows the fundamental | |
155 | Case 4 shows the fundamental sslcat() function (inspired in spirit by | |
167 | ||
156 | netcat utility :-). Its your swiss army knife that allows you to | |
168 | 157 | easily contact servers, send some data, and then get the response. You |
169 | 158 | are responsible for formatting the data and parsing the response - |
170 | ||
159 | sslcat() is just a transport. | |
171 | 160 | |
172 | 161 | =end original |
173 | 162 | |
174 | ケース 4 | |
163 | ケース 4は、基本的なsslcat()関数を示しています(netcatユーティリティに | |
175 | ||
164 | 心を動かされました :-)。これは単純にサーバーに接続し、データを送信し、 | |
176 | ||
165 | それから応答を取得することを簡単にするスイス・アーミーナイフのような | |
177 | ||
166 | ものです。データの整形と応答の解析についてはあなたの責任です - sslcat()は | |
178 | データの整形と応答の解析についてはあなたの責任です - C<sslcat()> は | |
179 | 167 | 単に転送するだけのものです。 |
180 | 168 | |
181 | 169 | =begin original |
182 | 170 | |
183 | Case 5 is a full invocation of | |
171 | Case 5 is a full invocation of sslcat() which allows return of errors | |
184 | 172 | as well as the server (peer) certificate. |
185 | 173 | |
186 | 174 | =end original |
187 | 175 | |
188 | ケース 5 | |
176 | ケース 5は、エラーだけでなくサーバー(相手側)証明書と同様も返すことを | |
189 | 可能にする、 | |
177 | 可能にする、sslcat()の完全な呼び出しです。 | |
190 | 178 | |
191 | 179 | =begin original |
192 | 180 | |
193 | The | |
181 | The $trace global variable can be used to control the verbosity of high | |
194 | ||
182 | level functions. Level 0 guarantees silence, level 1 (the default) | |
195 | 183 | only emits error messages. |
196 | 184 | |
197 | 185 | =end original |
198 | 186 | |
199 | ||
187 | $traceグローバル変数は高レベル関数の冗長さを制御するために使うことが | |
200 | 出来ます。 | |
188 | 出来ます。レベル0は何もいわないことを保障します。レベル1(デフォルト)は | |
201 | ||
189 | エラーメッセージだけを吐き出します。 | |
202 | レベル 1 (デフォルト) はエラーメッセージだけを吐き出します。 | |
203 | 190 | |
204 | 191 | =head2 Alternate versions of the API |
205 | 192 | |
206 | (API | |
193 | (APIの代替バージョン) | |
207 | 194 | |
208 | 195 | =begin original |
209 | 196 | |
210 | 197 | The above mentioned functions actually return the response headers as |
211 | 198 | a list, which only gets converted to hash upon assignment (this |
212 | 199 | assignment looses information if the same header occurs twice, as may |
213 | 200 | be the case with cookies). There are also other variants of the |
214 | 201 | functions that return unprocessed headers and that return a reference |
215 | 202 | to a hash. |
216 | 203 | |
217 | 204 | =end original |
218 | 205 | |
219 | 上記の関数は実際には応答ヘッダをリストで返します。 | |
206 | 上記の関数は実際には応答ヘッダをリストで返します。それは代入されたハッシュに | |
220 | ||
207 | 変換されます(もしクッキーの場合がそうであるかもしれないように同じヘッダが | |
221 | ||
208 | 2回発生すると、この代入によって情報が失われるかもしれません)。処理されて | |
222 | ||
209 | いないヘッダとハッシュへのリファレンスを返す関数の別の形もあります。 | |
223 | 処理されていないヘッダとハッシュへのリファレンスを返す別の形の関数もあります。 | |
224 | 210 | |
225 | 211 | ($page, $response, @headers) = get_https('www.bacus.pt', 443, '/'); |
226 | 212 | for ($i = 0; $i < $#headers; $i+=2) { |
227 | 213 | print "$headers[$i] = " . $headers[$i+1] . "\n"; |
228 | 214 | } |
215 | ||
230 | 216 | ($page, $response, $headers, $server_cert) |
231 | 217 | = get_https3('www.bacus.pt', 443, '/'); |
232 | 218 | print "$headers\n"; |
233 | 219 | |
234 | 220 | ($page, $response, %headers_ref, $server_cert) |
235 | 221 | = get_https4('www.bacus.pt', 443, '/'); |
236 | 222 | for $k (sort keys %{headers_ref}) { |
237 | 223 | for $v (@{$headers_ref{$k}}) { |
238 | 224 | print "$k = $v\n"; |
239 | 225 | } |
240 | 226 | } |
241 | 227 | |
242 | 228 | =begin original |
243 | 229 | |
244 | 230 | All of the above code fragments accomplish the same thing: display all |
245 | 231 | values of all headers. The API functions ending in "3" return the |
246 | 232 | headers simply as a scalar string and it is up to the application to |
247 | 233 | split them up. The functions ending in "4" return a reference to |
248 | ||
234 | hash of arrays (see perlref and perllol manual pages if you are | |
249 | not familiar with complex perl data structures). To access | |
235 | not familiar with complex perl data structures). To access single value | |
250 | of such | |
236 | of such header hash you would do something like | |
251 | 237 | |
252 | 238 | =end original |
253 | 239 | |
254 | 上記の全てのちょっとしたコードは、同じ事を実現します: | |
240 | 上記の全てのちょっとしたコードは、同じ事を実現します:ヘッダの全ての値を | |
255 | 表示します。 | |
241 | 表示します。"3"で終わるAPI関数はヘッダを単なるスカラーの文字列で返します。 | |
256 | " | |
242 | アプリケーションがそれを分割することになります。"4"で終わる関数は | |
257 | ||
243 | 配列のハッシュへのリファレンスを返します(複雑なperlデータ構造体に精通して | |
258 | ||
244 | いなければperlrefとperllolマニュアル・ページをご覧ください)。そのような | |
259 | ||
245 | ヘッダ・ハッシュの1つの値にアクセスするためには、以下のようにしてください | |
260 | マニュアルページをご覧ください)。 | |
261 | そのようなヘッダハッシュの1つの値にアクセスするためには、 | |
262 | 以下のようにしてください: | |
263 | 246 | |
264 | 247 | print $headers_ref{COOKIE}[0]; |
265 | 248 | |
266 | 249 | =begin original |
267 | 250 | |
268 | ||
251 | The variants 3 and 4 also allow you to discover the server certificate | |
269 | 252 | in case you would like to store or display it, e.g. |
270 | 253 | |
271 | 254 | =end original |
272 | 255 | |
273 | 3 | |
256 | 3と4の形は、それを格納したり表示したいときサーバー証明書を見つけることも | |
274 | 可能にします。 | |
257 | 可能にします。例えば | |
275 | 例えば: | |
276 | 258 | |
277 | 259 | ($p, $resp, $hdrs, $server_cert) = get_https3('www.bacus.pt', 443, '/'); |
278 | 260 | if (!defined($server_cert) || ($server_cert == 0)) { |
279 | 261 | warn "Subject Name: undefined, Issuer Name: undefined"; |
280 | 262 | } else { |
281 | 263 | warn 'Subject Name: ' |
282 | 264 | . Net::SSLeay::X509_NAME_oneline( |
283 | 265 | Net::SSLeay::X509_get_subject_name($server_cert)) |
284 | 266 | . 'Issuer Name: ' |
285 | 267 | . Net::SSLeay::X509_NAME_oneline( |
286 | 268 | Net::SSLeay::X509_get_issuer_name($server_cert)); |
287 | 269 | } |
288 | 270 | |
289 | 271 | =begin original |
290 | 272 | |
291 | 273 | Beware that this method only allows after the fact verification of |
292 | the certificate: by the time | |
274 | the certificate: by the time get_https3() has returned the https | |
293 | 275 | request has already been sent to the server, whether you decide to |
294 | tr | |
276 | tryst it or not. To do the verification correctly you must either | |
295 | 277 | employ the OpenSSL certificate verification framework or use |
296 | 278 | the lower level API to first connect and verify the certificate |
297 | and only then send the http data. See | |
279 | and only then send the http data. See implementation of ds_https3() | |
298 | 280 | for guidance on how to do this. |
299 | 281 | |
300 | 282 | =end original |
301 | 283 | |
302 | 284 | この方法は証明書の確認の後にだけ可能になるということに注意してください: |
303 | そのときには、あなたが信用するかどうかに関わらず、 | |
285 | そのときには、あなたが信用するかどうかに関わらず、get_https3()は | |
304 | サーバに送信された | |
286 | サーバーに送信されたhttpsリクエストを返してしまっています。 | |
305 | 正しく確認するためには、OpenSSL | |
287 | 正しく確認するためには、OpenSSL証明書確認フレームワークを採用するか、 | |
306 | 最初に接続し、証明書を確認し、そのときにだけ | |
288 | 最初に接続し、証明書を確認し、そのときにだけhttpデータを送信するため | |
307 | 低レベル | |
289 | 低レベルAPIを利用するかのどちらかをする必要があります。この | |
308 | ||
290 | やり方についてのガイダンスはds_https3()の実装をご覧ください。 | |
309 | 291 | |
310 | 292 | =head2 Using client certificates |
311 | 293 | |
312 | (クライアント証明書 | |
294 | (クライアント証明書の使い方) | |
313 | 295 | |
314 | 296 | =begin original |
315 | 297 | |
316 | 298 | Secure web communications are encrypted using symmetric crypto keys |
317 | 299 | exchanged using encryption based on the certificate of the |
318 | 300 | server. Therefore in all SSL connections the server must have a |
319 | 301 | certificate. This serves both to authenticate the server to the |
320 | 302 | clients and to perform the key exchange. |
321 | 303 | |
322 | 304 | =end original |
323 | 305 | |
324 | セキュアな | |
306 | セキュアなWeb通信はサーバーの証明書をベースにした暗号を使って | |
325 | 交換された対称になった暗号鍵を使って暗号化されます。 | |
307 | 交換された対称になった暗号鍵を使って暗号化されます。このため | |
326 | ||
308 | 全てのSSLの通信では、サーバーは証明書を持っていなければなりません。 | |
327 | これはクライアントへのサーバの認証と鍵の交換の両方を提供します。 | |
309 | これはクライアントへのサーバーの認証と鍵の交換の両方を提供します。 | |
328 | 310 | |
329 | 311 | =begin original |
330 | 312 | |
331 | 313 | Sometimes it is necessary to authenticate the client as well. Two |
332 | options are available: | |
314 | options are available: http basic authentication and client side | |
333 | certificate. The basic authentication over | |
315 | certificate. The basic authentication over https is actually quite | |
334 | safe because | |
316 | safe because https guarantees that the password will not travel in | |
335 | ||
317 | clear. Never-the-less, problems like easily guessable passwords | |
336 | 318 | remain. The client certificate method involves authentication of the |
337 | client at | |
319 | client at SSL level using a certificate. For this to work, both the | |
338 | client and the server have certificates (which typically are | |
320 | client and the server will have certificates (which typically are | |
339 | 321 | different) and private keys. |
340 | 322 | |
341 | 323 | =end original |
342 | 324 | |
343 | 場合によってはクライアントも認証する必要があります。 | |
325 | 場合によってはクライアントも認証する必要があります。2つの選択を | |
344 | ||
326 | 利用することができます: http基本認証とクライアント側の証明書です。 | |
345 | ||
327 | httpsがパスワードが平文で流れないことを保障するので、https越しの | |
346 | 基本認証は実際には非常に安全です。 | |
328 | 基本認証は実際には非常に安全です。しかし、そうであったとしても | |
347 | ||
329 | 簡単にわかるようなパスワードのような問題は残ります。クライアント | |
348 | ||
330 | 証明書の方法には証明書を使ったSSLレベルでのクライアントの認証を | |
349 | ||
331 | 意味します。これが機能するためにはクライアントとサーバーの両方が | |
350 | 認証を意味します。 | |
351 | これが機能するためにはクライアントとサーバの両方が | |
352 | 332 | (典型的には異なる)証明書と秘密鍵を持つ必要があります。 |
353 | 333 | |
354 | 334 | =begin original |
355 | 335 | |
356 | 336 | The API functions outlined above accept additional arguments that |
357 | 337 | allow one to supply the client side certificate and key files. The |
358 | 338 | format of these files is the same as used for server certificates and |
359 | the caveat about encrypting private key | |
339 | the caveat about encrypting private key applies. | |
360 | 340 | |
361 | 341 | =end original |
362 | 342 | |
363 | 上記で概説された | |
343 | 上記で概説されたAPI関数は、クライアント側の証明書と鍵ファイルを | |
364 | 提供することができる追加の引数を受け取ります。 | |
344 | 提供することができる追加の引数を受け取ります。これらのファイルの | |
365 | ||
345 | 形式はサーバー証明書で使われているものと同じです。そして秘密鍵の | |
366 | ||
346 | 暗号化に関する注意も当てはまります。 | |
367 | 347 | |
368 | 348 | ($page, $result, %headers) = # 2c |
369 | 349 | = get_https('www.bacus.pt', 443, '/protected.html', |
370 | 350 | make_headers(Authorization => |
371 | 351 | 'Basic ' . MIME::Base64::encode("$user:$pass",'')), |
372 | 352 | '', $mime_type6, $path_to_crt7, $path_to_key8); |
373 | 353 | |
374 | 354 | ($page, $response, %reply_headers) |
375 | 355 | = post_https('www.bacus.pt', 443, '/foo.cgi', # 3b |
376 | 356 | make_headers('Authorization' => |
377 | 357 | 'Basic ' . MIME::Base64::encode("$user:$pass",'')), |
378 | 358 | make_form(OK => '1', name => 'Sampo'), |
379 | 359 | $mime_type6, $path_to_crt7, $path_to_key8); |
380 | 360 | |
381 | 361 | =begin original |
382 | 362 | |
383 | Case 2c demonstrates getting | |
363 | Case 2c demonstrates getting password protected page that also requires | |
384 | ||
364 | client certificate, i.e. it is possible to use both authentication | |
385 | 365 | methods simultaneously. |
386 | 366 | |
387 | 367 | =end original |
388 | 368 | |
389 | ケース 2c | |
369 | ケース 2cはクライアント証明書も必要とする、パスワードで保護された | |
390 | ページを取得することを示しています。 | |
370 | ページを取得することを示しています。つまり両方の認証方法を同時に | |
391 | ||
371 | 使うことも可能です。 | |
392 | 372 | |
393 | 373 | =begin original |
394 | 374 | |
395 | Case 3b is | |
375 | Case 3b is full blown post to secure server that requires both password | |
396 | authentication and | |
376 | authentication and client certificate, just like in case 2c. | |
397 | 377 | |
398 | 378 | =end original |
399 | 379 | |
400 | ケース 3b | |
380 | ケース 3bは、ケース2cとちょうど同じようにパスワード認証とクライアント | |
401 | 証明書の両方を必要とするセキュアなサーバへの完全に展開された | |
381 | 証明書の両方を必要とするセキュアなサーバーへの完全に展開された | |
382 | postです。 | |
402 | 383 | |
403 | 384 | =begin original |
404 | 385 | |
405 | Note: | |
386 | Note: Client will not send a certificate unless the server requests one. | |
406 | This is typically achieved by setting | |
387 | This is typically achieved by setting verify mode to VERIFY_PEER on the | |
407 | 388 | server: |
408 | 389 | |
409 | 390 | =end original |
410 | 391 | |
411 | 注意: | |
392 | 注意: サーバーが要求しなければ、クライアントは証明書を送信しません。 | |
412 | これは典型的にはサーバで確認モードを | |
393 | これは典型的にはサーバーで確認モードをVERIFY_PEERに設定することにより | |
413 | 394 | 実現されます: |
414 | 395 | |
415 | 396 | Net::SSLeay::set_verify(ssl, Net::SSLeay::VERIFY_PEER, 0); |
416 | 397 | |
417 | 398 | =begin original |
418 | 399 | |
419 | See | |
400 | See perldoc ~openssl/doc/ssl/SSL_CTX_set_verify.pod for full description. | |
420 | 401 | |
421 | 402 | =end original |
422 | 403 | |
423 | 完全な説明については、 | |
404 | 完全な説明については、perldoc ~openssl/doc/ssl/SSL_CTX_set_verify.pod をご覧ください。 | |
424 | ご覧ください。 | |
425 | 405 | |
426 | =head2 Working through | |
406 | =head2 Working through Web proxy | |
427 | 407 | |
428 | (Web | |
408 | (Webプロキシーを通して動かす) | |
429 | 409 | |
430 | 410 | =begin original |
431 | 411 | |
432 | ||
412 | Net::SSLeay can use a web proxy to make its connections. You need to | |
433 | first set the proxy host and port using | |
413 | first set the proxy host and port using set_proxy() and then just | |
434 | 414 | use the normal API functions, e.g: |
435 | 415 | |
436 | 416 | =end original |
437 | 417 | |
438 | ||
418 | Net::SSLeayは接続を行うためにWebプロキシーを利用することができます。 | |
439 | 最初に | |
419 | 最初にset_proxy()を使ってプロキシーホストとポートを設定したら、 | |
440 | 後は通常のAPI関数を使うだけです。 | |
420 | 後は通常のAPI関数を使うだけです。例えば: | |
441 | 例えば: | |
442 | 421 | |
443 | 422 | Net::SSLeay::set_proxy('gateway.myorg.com', 8080); |
444 | 423 | ($page) = get_https('www.bacus.pt', 443, '/'); |
445 | 424 | |
446 | 425 | =begin original |
447 | 426 | |
448 | If your proxy requires authentication, you can supply | |
427 | If your proxy requires authentication, you can supply username and | |
449 | 428 | password as well |
450 | 429 | |
451 | 430 | =end original |
452 | 431 | |
453 | あなたのプロキシが認証を必要とするのであれば、ユーザ名とパスワードも | |
432 | あなたのプロキシーが認証を必要とするのであれば、ユーザ名とパスワードも | |
454 | 433 | 与えることができます |
455 | 434 | |
456 | 435 | Net::SSLeay::set_proxy('gateway.myorg.com', 8080, 'joe', 'salainen'); |
457 | 436 | ($page, $result, %headers) = |
458 | 437 | = get_https('www.bacus.pt', 443, '/protected.html', |
459 | 438 | make_headers(Authorization => |
460 | 439 | 'Basic ' . MIME::Base64::encode("susie:pass",'')) |
461 | 440 | ); |
462 | 441 | |
463 | 442 | =begin original |
464 | 443 | |
465 | This example demonstrates | |
444 | This example demonstrates case where we authenticate to the proxy as | |
466 | ||
445 | "joe" and to the final web server as "susie". Proxy authentication | |
467 | requires | |
446 | requires MIME::Base64 module to work. | |
468 | 447 | |
469 | 448 | =end original |
470 | 449 | |
471 | この例は | |
450 | この例は"joe"でプロキシーに、最終的なWebサーバーには"susie"で認証を | |
472 | 行うケースを示しています。 | |
451 | 行うケースを示しています。プロキシーの認証はMIME::Base64が機能することを | |
473 | ||
452 | 必要とします。 | |
474 | 453 | |
475 | =head2 Certificate verification and Certificate Revoocation Lists (CRLs) | |
476 | ||
477 | (証明書の検証と証明書失効リスト(CRL)) | |
478 | ||
479 | =begin original | |
480 | ||
481 | OpenSSL supports the ability to verify peer certificates. It can also | |
482 | optionally check the peer certificate against a Certificate Revocation | |
483 | List (CRL) from the certificates issuer. A CRL is a file, created by | |
484 | the certificate issuer that lists all the certificates that it | |
485 | previously signed, but which it now revokes. CRLs are in PEM format. | |
486 | ||
487 | =end original | |
488 | ||
489 | OpenSSL はピア証明書の検証に対応しています。 | |
490 | オプションで、証明書発行者からの 証明書失効リスト (CRL) に対する | |
491 | ピア証明書のチェックもできます。 | |
492 | CRL は、証明者の発行者によって作られた、以前に署名したけれども、 | |
493 | 今は廃止されている全ての証明書の一覧のファイルです。 | |
494 | CRL は PEM 形式です。 | |
495 | ||
496 | =begin original | |
497 | ||
498 | You can enable C<Net::SSLeay CRL> checking like this: | |
499 | ||
500 | =end original | |
501 | ||
502 | 次のようにして C<Net::SSLeay CRL> チェックを有効にします: | |
503 | ||
504 | &Net::SSLeay::X509_STORE_CTX_set_flags | |
505 | (&Net::SSLeay::CTX_get_cert_store($ssl), | |
506 | &Net::SSLeay::X509_V_FLAG_CRL_CHECK); | |
507 | ||
508 | =begin original | |
509 | ||
510 | After setting this flag, if OpenSSL checks a peer's certificate, then | |
511 | it will attempt to find a CRL for the issuer. It does this by looking | |
512 | for a specially named file in the search directory specified by | |
513 | CTX_load_verify_locations. CRL files are named with the hash of the | |
514 | issuer's subject name, followed by C<.r0>, C<.r1> etc. For example | |
515 | C<ab1331b2.r0>, C<ab1331b2.r1>. It will read all the .r files for the | |
516 | issuer, and then check for a revocation of the peer cerificate in all | |
517 | of them. (You can also force it to look in a specific named CRL | |
518 | file., see below). You can find out the hash of the issuer subject | |
519 | name in a CRL with | |
520 | ||
521 | =end original | |
522 | ||
523 | After setting this flag, if OpenSSL checks a peer's certificate, then | |
524 | it will attempt to find a CRL for the issuer. It does this by looking | |
525 | for a specially named file in the search directory specified by | |
526 | CTX_load_verify_locations. CRL files are named with the hash of the | |
527 | issuer's subject name, followed by C<.r0>, C<.r1> etc. For example | |
528 | C<ab1331b2.r0>, C<ab1331b2.r1>. It will read all the .r files for the | |
529 | issuer, and then check for a revocation of the peer cerificate in all | |
530 | of them. (You can also force it to look in a specific named CRL | |
531 | file., see below). You can find out the hash of the issuer subject | |
532 | name in a CRL with | |
533 | (TBT) | |
534 | ||
535 | openssl crl -in crl.pem -hash -noout | |
536 | ||
537 | =begin original | |
538 | ||
539 | If the peer certificate does not pass the revocation list, or if no | |
540 | CRL is found, then the handshaking fails with an error. | |
541 | ||
542 | =end original | |
543 | ||
544 | ピア証明書が証明書失効リストを通過しなかった場合、 | |
545 | あるいは CRL が見つからなかった場合、 | |
546 | ハンドシェイクはエラー終了します。 | |
547 | ||
548 | =begin original | |
549 | ||
550 | You can also force OpenSSL to look for CRLs in one or more arbitrarily | |
551 | named files. | |
552 | ||
553 | =end original | |
554 | ||
555 | また、任意の名前の一つまたは複数のファイルにある CRL を探させるように | |
556 | OpenSSL を強制できます。 | |
557 | ||
558 | my $bio = Net::SSLeay::BIO_new_file($crlfilename, 'r'); | |
559 | my $crl = Net::SSLeay::PEM_read_bio_X509_CRL($bio); | |
560 | if ($crl) { | |
561 | Net::SSLeay::X509_STORE_add_crl(Net::SSLeay::CTX_get_cert_store($ssl, $crl); | |
562 | } else { | |
563 | error reading CRL.... | |
564 | } | |
565 | ||
566 | 454 | =head2 Convenience routines |
567 | 455 | |
568 | 456 | (便利なルーチン) |
569 | 457 | |
570 | 458 | =begin original |
571 | 459 | |
572 | 460 | To be used with Low level API |
573 | 461 | |
574 | 462 | =end original |
575 | 463 | |
576 | 低レベルで使うために | |
464 | 低レベルで使うために | |
577 | 465 | |
578 | 466 | Net::SSLeay::randomize($rn_seed_file,$additional_seed); |
579 | 467 | Net::SSLeay::set_cert_and_key($ctx, $cert_path, $key_path); |
580 | 468 | $cert = Net::SSLeay::dump_peer_certificate($ssl); |
581 | 469 | Net::SSLeay::ssl_write_all($ssl, $message) or die "ssl write failure"; |
582 | 470 | $got = Net::SSLeay::ssl_read_all($ssl) or die "ssl read failure"; |
583 | 471 | |
584 | 472 | $got = Net::SSLeay::ssl_read_CRLF($ssl [, $max_length]); |
585 | 473 | $got = Net::SSLeay::ssl_read_until($ssl [, $delimit [, $max_length]]); |
586 | 474 | Net::SSLeay::ssl_write_CRLF($ssl, $message); |
587 | 475 | |
588 | 476 | =begin original |
589 | 477 | |
590 | ||
478 | randomize() seeds the eay PRNG with /dev/urandom (see top of SSLeay.pm | |
591 | 479 | for how to change or configure this) and optionally with user provided |
592 | 480 | data. It is very important to properly seed your random numbers, so |
593 | 481 | do not forget to call this. The high level API functions automatically |
594 | call | |
482 | call randomize() so it is not needed with them. See also caveats. | |
595 | 483 | |
596 | 484 | =end original |
597 | 485 | |
598 | ||
486 | randomize()は/dev/urandomとオプションでユーザに与えられたデータで | |
599 | ||
487 | eay PRNGを種付けし(これの変更あるいは設定のやり方については、 | |
600 | ||
488 | SSLeay.pmの先頭をご覧ください)。適切に乱数の種付けをすることは非常に | |
601 | ||
489 | 重要です。ですから、これを呼び出すことを忘れないでください。高レベルの | |
602 | ||
490 | API関数は自動的にrandomize()を呼び出します。そのためそれらでは | |
603 | ||
491 | 必要ありません。注意もご覧ください。 | |
604 | そのためそれらでは必要ありません。 | |
605 | 注意もご覧ください。 | |
606 | 492 | |
607 | 493 | =begin original |
608 | 494 | |
609 | ||
495 | set_cert_and_key() takes two file names as arguments and sets | |
610 | 496 | the certificate and private key to those. This can be used to |
611 | 497 | set either cerver certificates or client certificates. |
612 | 498 | |
613 | 499 | =end original |
614 | 500 | |
615 | ||
501 | set_cert_and_key()は引数として2つのファイル名を取り、 | |
616 | それらを証明書と秘密鍵に設定します。 | |
502 | それらを証明書と秘密鍵に設定します。これはサーバー証明書と | |
617 | ||
503 | クライアント証明書の両方に使うことが出来ます。 | |
618 | 504 | |
619 | 505 | =begin original |
620 | 506 | |
621 | ||
507 | dump_peer_certificate() allows you to get plaintext description of the | |
622 | certificate the peer (usually | |
508 | certificate the peer (usually server) presented to us. | |
623 | 509 | |
624 | 510 | =end original |
625 | 511 | |
626 | ||
512 | dump_peer_certificate()は相手側(通常はサーバー)が提出した | |
627 | 513 | 証明書の平文の説明を取得することを可能にします。 |
628 | 514 | |
629 | 515 | =begin original |
630 | 516 | |
631 | ||
517 | ssl_read_all() and ssl_write_all() provide true blocking semantics for | |
632 | 518 | these operations (see limitation, below, for explanation). These are |
633 | 519 | much preferred to the low level API equivalents (which implement BSD |
634 | blocking semantics). The message argument to | |
520 | blocking semantics). The message argument to ssl_write_all() can be | |
635 | ||
521 | reference. This is helpful to avoid unnecessary copy when writing | |
636 | 522 | something big, e.g: |
637 | 523 | |
638 | 524 | =end original |
639 | 525 | |
640 | ||
526 | ssl_read_all()とssl_write_all()は、これらの処理のための | |
641 | 527 | 本当のブロック化の意味論で提供します(説明については下記の制限を |
642 | ご覧ください)。 | |
528 | ご覧ください)。これらは低レベルAPIと同じものとして非常に好まれます | |
643 | これ | |
529 | (これはBSDブロック化セマンティクを実装しています)。ssl_write_all() | |
644 | ||
530 | へのmessage引数はリファレンスにすることができます。これは | |
645 | ||
531 | 何か大きなものを出力するとき、不必要なコピーを避けるために便利です。 | |
646 | これは何か大きなものを出力するとき、不必要なコピーを避けるために便利です。 | |
647 | 532 | 例えば: |
648 | 533 | |
649 | 534 | $data = 'A' x 1000000000; |
650 | 535 | Net::SSLeay::ssl_write_all($ssl, \$data) or die "ssl write failed"; |
651 | 536 | |
652 | 537 | =begin original |
653 | 538 | |
654 | ||
539 | ssl_read_CRLF() uses ssl_read_all() to read in a line terminated with a | |
655 | 540 | carriage return followed by a linefeed (CRLF). The CRLF is included in |
656 | 541 | the returned scalar. |
657 | 542 | |
658 | 543 | =end original |
659 | 544 | |
660 | ||
545 | ssl_read_CRLF() はssl_read_all()を使ってラインフィードが後ろについた | |
661 | ||
546 | キャリッジ・リターン(CRLF)で終わる行を読み込みます。CRLFは返される | |
662 | ||
547 | スカラーに含まれます。 | |
663 | 548 | |
664 | 549 | =begin original |
665 | 550 | |
666 | ||
551 | ssl_read_until() uses ssl_read_all() to read from the SSL input | |
667 | 552 | stream until it encounters a programmer specified delimiter. |
668 | If the delimiter is undefined, | |
553 | If the delimiter is undefined, $/ is used. If $/ is undefined, | |
669 | ||
554 | \n is used. One can optionally set a maximum length of bytes to read | |
670 | 555 | from the SSL input stream. |
671 | 556 | |
672 | 557 | =end original |
673 | 558 | |
674 | ||
559 | ssl_read_until() ssl_read_all()を使ってSSL入力インプットからプログラマに | |
675 | ||
560 | よって指定された区切り文字まで読み込みます。区切り文字が未定義であれば | |
676 | ||
561 | $/が使われます。$/が未定義であれば、\nが使われます。SSL入力ストリームからの | |
677 | ||
562 | 読み込む最大バイト長をオプションで設定することができます。 | |
678 | SSL入力ストリームからの読み込む最大バイト長をオプションで | |
679 | 設定することができます。 | |
680 | 563 | |
681 | 564 | =begin original |
682 | 565 | |
683 | ||
566 | ssl_write_CRLF() writes $message and appends CRLF to the SSL output stream. | |
684 | 567 | |
685 | 568 | =end original |
686 | 569 | |
687 | ||
570 | ssl_write_CRLF()はSSL出力ストリームに$messageを出力し、CRLFを追加します。 | |
688 | 追加します。 | |
689 | 571 | |
690 | 572 | =head2 Low level API |
691 | 573 | |
692 | (低レベル | |
574 | (低レベルAPI) | |
693 | 575 | |
694 | 576 | =begin original |
695 | 577 | |
696 | 578 | In addition to the high level functions outlined above, this module |
697 | contains straight | |
579 | contains straight forward access to SSL part of OpenSSL C api. Only the SSL | |
698 | 580 | subpart of OpenSSL is implemented (if anyone wants to implement other |
699 | 581 | parts, feel free to submit patches). |
700 | 582 | |
701 | 583 | =end original |
702 | 584 | |
703 | 上記で説明した高レベル関数に加えて、このモジュールには | |
585 | 上記で説明した高レベル関数に加えて、このモジュールにはOpenSSL C apiの | |
704 | SSL | |
586 | SSL部分にそのままアクセスすることもできます。OpenSSLのSSLサブパートだけが | |
705 | ||
587 | 実装されています(他の部分も実装したければ、パッチを提供することをためらわない | |
706 | ||
588 | でください)。 | |
707 | 589 | |
708 | 590 | =begin original |
709 | 591 | |
710 | See | |
592 | See ssl.h header from OpenSSL C distribution for list of low lever | |
711 | SSLeay functions to call (check | |
593 | SSLeay functions to call (to check if some function has been | |
712 | implemented | |
594 | implemented see directly in SSLeay.xs). The module strips SSLeay names | |
595 | of the initial "SSL_", generally you should use Net::SSLeay:: in | |
713 | 596 | place. For example: |
714 | 597 | |
715 | 598 | =end original |
716 | 599 | |
717 | 低レベル | |
600 | 低レベルSSLeay関数の呼び出し方の一覧については、OpenSSL Cディストリビューション | |
718 | ||
601 | のssl.hヘッダをご覧ください(関数が実装されているかをチェックするためには、直接 | |
719 | ||
602 | SSLeay.xlをご覧ください)。このモジュールではSSLeayの名前から先頭の"SSL_"を | |
720 | ||
603 | はずしています。一般的にはその場所にNet::SSLeayを使わなければなりません。 | |
721 | 一般的にはその場所に C<Net::SSLeay::> を使わなければなりません。 | |
722 | 604 | 例えば: |
723 | 605 | |
724 | 606 | =begin original |
725 | 607 | |
726 | 608 | In C: |
727 | 609 | |
728 | 610 | =end original |
729 | 611 | |
730 | C | |
612 | Cでは: | |
731 | 613 | |
732 | ||
614 | =begin original | |
733 | 615 | |
616 | #include <ssl.h> | |
617 | ||
734 | 618 | err = SSL_set_verify (ssl, SSL_VERIFY_CLIENT_ONCE, |
735 | 619 | &your_call_back_here); |
620 | ||
621 | In perl: | |
736 | 622 | |
737 | =begin original | |
738 | ||
739 | In Perl: | |
740 | ||
741 | 623 | =end original |
742 | 624 | |
743 | ||
625 | #include <ssl.h> | |
626 | ||
627 | err = SSL_set_verify (ssl, SSL_VERIFY_CLIENT_ONCE, | |
628 | &your_call_back_here); | |
629 | ||
630 | perlでは: | |
744 | 631 | |
745 | 632 | use Net::SSLeay; |
746 | 633 | |
747 | 634 | $err = Net::SSLeay::set_verify ($ssl, |
748 | Net::SSLeay::VERIFY_CLIENT_ONCE, | |
635 | &Net::SSLeay::VERIFY_CLIENT_ONCE, | |
749 | 636 | \&your_call_back_here); |
750 | 637 | |
751 | 638 | =begin original |
752 | 639 | |
753 | If the function does not start | |
640 | If the function does not start by SSL_ you should use the full | |
754 | 641 | function name, e.g.: |
755 | 642 | |
756 | 643 | =end original |
757 | 644 | |
758 | ||
645 | SSL_で始まらない関数では、関数名全体を使わなければなりません。例えば: | |
759 | 例えば: | |
760 | 646 | |
761 | $err = Net::SSLeay::ERR_get_error; | |
647 | $err = &Net::SSLeay::ERR_get_error; | |
762 | 648 | |
763 | 649 | =begin original |
764 | 650 | |
765 | ||
651 | Following new functions behave in perlish way: | |
766 | 652 | |
767 | 653 | =end original |
768 | 654 | |
769 | 以下の新しい関数は | |
655 | 以下の新しい関数はperl的に振舞います: | |
770 | 656 | |
771 | 657 | =begin original |
772 | 658 | |
773 | 659 | $got = Net::SSLeay::read($ssl); |
774 | 660 | # Performs SSL_read, but returns $got |
775 | 661 | # resized according to data received. |
776 | 662 | # Returns undef on failure. |
777 | 663 | |
778 | 664 | =end original |
779 | 665 | |
780 | 666 | $got = Net::SSLeay::read($ssl); |
781 | # SSL_read | |
667 | # SSL_readを行いますが、受け取られたデータに | |
782 | # 従って大きさが変更された | |
668 | # 従って大きさが変更された$gotを返します | |
783 | # 失敗したときには | |
669 | # 失敗したときにはundefを返します。 | |
784 | 670 | |
785 | 671 | =begin original |
786 | 672 | |
787 | 673 | Net::SSLeay::write($ssl, $foo) || die; |
788 | 674 | # Performs SSL_write, but automatically |
789 | 675 | # figures out the size of $foo |
790 | 676 | |
791 | 677 | =end original |
792 | 678 | |
793 | 679 | Net::SSLeay::write($ssl, $foo) || die; |
794 | # SSL_write | |
680 | # SSL_writeを実行します。しかし自動的に | |
795 | # $foo | |
681 | # $fooの大きさを計算します。 | |
796 | 682 | |
797 | 683 | =begin original |
798 | 684 | |
799 | 685 | In order to use the low level API you should start your programs with |
800 | the following | |
686 | the following encantation: | |
801 | 687 | |
802 | 688 | =end original |
803 | 689 | |
804 | 低レベル | |
690 | 低レベルAPIを使うためには、あなたのプログラムは以下のように始まらなければ | |
805 | 691 | なりません: |
806 | 692 | |
807 | 693 | =begin original |
808 | 694 | |
809 | 695 | use Net::SSLeay qw(die_now die_if_ssl_error); |
810 | 696 | Net::SSLeay::load_error_strings(); |
811 | Net::SSLeay::SSLeay_add_ssl_algorithms(); | |
697 | Net::SSLeay::SSLeay_add_ssl_algorithms(); # Important! | |
812 | Net::SSLeay::ENGINE_load_builtin_engines(); # If you want built-in engines | |
813 | Net::SSLeay::ENGINE_register_all_complete(); # If you want built-in engines | |
814 | 698 | Net::SSLeay::randomize(); |
815 | 699 | |
816 | 700 | =end original |
817 | 701 | |
818 | 702 | use Net::SSLeay qw(die_now die_if_ssl_error); |
819 | 703 | Net::SSLeay::load_error_strings(); |
820 | Net::SSLeay::SSLeay_add_ssl_algorithms(); | |
704 | Net::SSLeay::SSLeay_add_ssl_algorithms(); # 重要! | |
821 | Net::SSLeay::ENGINE_load_builtin_engines(); # 組み込みエンジンが必要なら | |
822 | Net::SSLeay::ENGINE_register_all_complete(); # 組み込みエンジンが必要なら | |
823 | 705 | Net::SSLeay::randomize(); |
824 | 706 | |
825 | 707 | =begin original |
826 | 708 | |
827 | ||
709 | die_now() and die_if_ssl_error() are used to conveniently print SSLeay error | |
710 | stack when something goes wrong, thusly: | |
828 | 711 | |
829 | 712 | =end original |
830 | 713 | |
831 | ||
714 | die_now()とdie_if_ssl_error()は、以下のように何かがおかしくなったとき | |
832 | 簡単に | |
715 | 簡単にSSLeayエラー・スタックを出力するために使用されます: | |
833 | 716 | |
834 | Net::SSLeay: | |
717 | Net::SSLeay:connect($ssl) or die_now("Failed SSL connect ($!)"); | |
835 | 718 | Net::SSLeay::write($ssl, "foo") or die_if_ssl_error("SSL write ($!)"); |
836 | 719 | |
837 | 720 | =begin original |
838 | 721 | |
839 | You can also use | |
722 | You can also use Net::SSLeay::print_errs() to dump the error stack without | |
840 | 723 | exiting the program. As can be seen, your code becomes much more readable |
841 | if you import the error reporting functions | |
724 | if you import the error reporting functions to your main name space. | |
842 | 725 | |
843 | 726 | =end original |
844 | 727 | |
845 | 728 | プログラムを終了させることなくエラースタックをダンプさせるために |
846 | ||
729 | Net::SSLeay::print_errs()を使うことも出来ます。今見たように、main名前空間に | |
847 | ||
730 | エラー報告関数をインポートすれば、あなたのコードは、さらにとても読みやすく | |
848 | ||
731 | なります。 | |
849 | 732 | |
850 | 733 | =begin original |
851 | 734 | |
852 | I can not emphasize the need to check | |
735 | I can not emphasize enough the need to check error returns. Use these | |
853 | functions even in | |
736 | functions even in most simple programs, they will reduce debugging | |
854 | time greatly. Do not ask questions | |
737 | time greatly. Do not ask questions in mailing list without having | |
855 | 738 | first sprinkled these in your code. |
856 | 739 | |
857 | 740 | =end original |
858 | 741 | |
859 | 742 | エラーの戻り値をチェックする必要性はいくら強調しても足りません。 |
860 | 743 | 非常に単純なプログラムであっても、これらの関数を使ってください。 |
861 | これらはデバッグにかかる時間を大幅に削減します。 | |
744 | これらはデバッグにかかる時間を大幅に削減します。先にこれらのものを | |
862 | ||
745 | あなたコードのあちこちに入れることなく、メーリングリストに質問しないで | |
863 | ||
746 | ください。 | |
864 | 747 | |
865 | 748 | =head2 Sockets |
866 | 749 | |
867 | 750 | (ソケット) |
868 | 751 | |
869 | 752 | =begin original |
870 | 753 | |
871 | Perl uses file handles for all I/O. While SSLeay has | |
754 | Perl uses file handles for all I/O. While SSLeay has quite flexible BIO | |
872 | mechanism and perl has | |
755 | mechanism and perl has evolved PerlIO mechanism, this module still | |
873 | sticks to using file descriptors. Thus to attach SSLeay to | |
756 | sticks to using file descriptors. Thus to attach SSLeay to socket you | |
874 | should use | |
757 | should use fileno() to extract the underlying file descriptor: | |
875 | 758 | |
876 | 759 | =end original |
877 | 760 | |
878 | Perl | |
761 | Perlは全てのI/Oにファイルハンドルを使います。SSLeayは非常に柔軟性のある | |
879 | ||
762 | BIO機構を持っていますし、perlはPerlIO機構を進化させていますが、 | |
880 | 進化させていますが、 | |
881 | 763 | このモジュールはファイル記述子を使うことにこだわっています。 |
882 | このため | |
764 | このためSSLeayをソケットにつけるためには、元になっているファイル記述子を | |
883 | 取り出すために | |
765 | 取り出すためにfineno()を使わなければなりません: | |
884 | 766 | |
885 | 767 | =begin original |
886 | 768 | |
887 | 769 | Net::SSLeay::set_fd($ssl, fileno(S)); # Must use fileno |
888 | 770 | |
889 | 771 | =end original |
890 | 772 | |
891 | Net::SSLeay::set_fd($ssl, fileno(S)); # fineno | |
773 | Net::SSLeay::set_fd($ssl, fileno(S)); # finenoを使わなければなりません | |
892 | 774 | |
893 | 775 | =begin original |
894 | 776 | |
895 | You should also se | |
777 | You should also use "$|=1;" to eliminate STDIO buffering so you do not | |
896 | 778 | get confused if you use perl I/O functions to manipulate your socket |
897 | 779 | handle. |
898 | 780 | |
899 | 781 | =end original |
900 | 782 | |
901 | あなたのソケットハンドルを操作するために | |
783 | あなたのソケットハンドルを操作するためにperlのI/O関数を使のであれば、 | |
902 | 混乱しないよう、STDIO | |
784 | 混乱しないよう、STDIOのバッファリングを止めさせるためには、"$|=1;"を | |
903 | ||
785 | 使わなければなりません。 | |
904 | 786 | |
905 | 787 | =begin original |
906 | 788 | |
907 | If you need to | |
789 | If you need to select(2) on the socket, go right ahead, but be warned | |
908 | 790 | that OpenSSL does some internal buffering so SSL_read does not always |
909 | return data even if | |
791 | return data even if socket selected for reading (just keep on | |
910 | selecting and trying to read). | |
792 | selecting and trying to read). Net::SSLeay.pm is no different from the | |
911 | 793 | C language OpenSSL in this respect. |
912 | 794 | |
913 | 795 | =end original |
914 | 796 | |
915 | ソケットに | |
797 | ソケットにselect(2)する必要があれば、すぐに行ってください。ただし | |
916 | ||
798 | OpenSSLは内部バッファリングを行っていて、そのためソケットが読み込みの | |
917 | 799 | ために選択されているときでも(単に選択し、読み込もうとし続けるだけ)、 |
918 | 常にデータを返すわけではないことに注意してください。 | |
800 | 常にデータを返すわけではないことに注意してください。この点で | |
919 | ||
801 | Net::SSLeay.pmはC言語OpenSSLとは違います。 | |
920 | 802 | |
921 | 803 | =head2 Callbacks |
922 | 804 | |
923 | 805 | (コールバック) |
924 | 806 | |
925 | 807 | =begin original |
926 | 808 | |
927 | ||
809 | WARNING: as of 1.04 the callbacks have changed and have not been tested. | |
928 | 810 | |
929 | 811 | =end original |
930 | 812 | |
931 | ||
813 | 警告: 1.04で、コールバックは変更され、テストされていません。 | |
932 | 814 | |
933 | sub verify { | |
934 | my ($ok, $x509_store_ctx) = @_; | |
935 | print "Verifying certificate...\n"; | |
936 | ... | |
937 | return $ok; | |
938 | } | |
939 | ||
940 | 815 | =begin original |
941 | 816 | |
942 | ||
817 | At this moment the implementation of verify_callback is crippeled in | |
818 | the sense that at any given time there can be only one call back which | |
819 | is shared by all SSL contexts, sessions and connections. This is | |
820 | due to having to keep the reference to the perl call back in a | |
821 | static variable so that the callback C glue can find it. To remove | |
822 | this restriction would require either a more complex data structure | |
823 | (like a hash?) in XSUB to map the call backs to their owners or, | |
824 | cleaner, adding a context pointer in the SSL structure. This context would | |
825 | then be passed to the C callback, which in our case would be the glue | |
826 | to look up the proper Perl function from the context and call it. | |
943 | 827 | |
944 | 828 | =end original |
945 | 829 | |
946 | ||
830 | 今の時点では、全てのコンテキスト、セッション、接続によって | |
831 | 共有されている1つのコールバックしかないときにはいつでも、 | |
832 | verify_callbackの実装は台無しになってしまいます。これは | |
833 | コールバックのCのグルーがそれを見つけられるように、スタティックな | |
834 | 変数にperlコールバックへのリファレンスを入れておくためです。 | |
835 | この制限を取り除くためには、SSL構造体でのコンテキスト・ポインタに加えて、 | |
836 | その所有者とコールバックを対応付けるためにXSUBの中での、 | |
837 | さらに複雑なデータ構造体(ハッシュのような?)を持つか、後始末をするものが必要です。 | |
838 | そのときには、このコンテキストはコ−ルバックに渡されます。それは私たちのケースでは | |
839 | コンテキストから適切なPerl関数を探し出す、呼び出すための仲介役となります。 | |
947 | 840 | |
948 | Net::SSLeay::set_verify ($ssl, Net::SSLeay::VERIFY_PEER, \&verify); | |
949 | ||
950 | 841 | =begin original |
951 | 842 | |
952 | ||
843 | ---- inaccurate ---- | |
844 | The verify call back looks like this in C: | |
953 | 845 | |
954 | 846 | =end original |
955 | 847 | |
956 | ||
848 | ---- 不正確 ---- | |
957 | ||
849 | verifyコールバックはCでは以下のようになります: | |
958 | 850 | |
959 | ||
851 | int (*callback)(int ok,X509 *subj_cert,X509 *issuer_cert, | |
960 | | |
852 | int depth,int errorcode,char *arg,STACK *cert_chain) | |
961 | Net::SSLeay::FILETYPE_PEM) | |
962 | or die "Error reading private key"; | |
963 | Net::SSLeay::CTX_set_default_passwd_cb($ctx, undef); | |
964 | 853 | |
965 | 854 | =begin original |
966 | 855 | |
967 | ||
856 | The corresponding Perl function should be something like this: | |
968 | a session secret callback can be set up to be called when a session secret is set | |
969 | by openssl. | |
970 | 857 | |
971 | 858 | =end original |
972 | 859 | |
973 | ||
860 | 対応するPerl関数は以下のようにものになります: | |
974 | セッションシークレットコールバックは、 | |
975 | セッションシークレットが openssl によって設定されたときに | |
976 | 呼び出されるように設定できます。 | |
977 | 861 | |
862 | sub verify { | |
863 | my ($ok, $subj_cert, $issuer_cert, $depth, $errorcode, | |
864 | $arg, $chain) = @_; | |
865 | print "Verifying certificate...\n"; | |
866 | ... | |
867 | return $ok; | |
868 | } | |
869 | ||
978 | 870 | =begin original |
979 | 871 | |
980 | ||
872 | It is used like this: | |
981 | Net::SSLeay::set_session_secret_cb($ssl, \&session_secret_cb, $somedata); | |
982 | 873 | |
983 | 874 | =end original |
984 | 875 | |
985 | ||
876 | こrは以下のように使われます: | |
986 | Net::SSLeay::set_session_secret_cb($ssl, \&session_secret_cb, $somedata); | |
987 | 877 | |
878 | Net::SSLeay::set_verify ($ssl, Net::SSLeay::VERIFY_PEER, \&verify); | |
879 | ||
988 | 880 | =begin original |
989 | 881 | |
990 | ||
882 | Callbacks for decrypting private keys are implemented, but have the | |
883 | same limitation as the verify_callback implementation (one password | |
884 | callback shared between all contexts.) You might use it something | |
885 | like this: | |
991 | 886 | |
992 | 887 | =end original |
993 | 888 | |
994 | ||
889 | 復号化するための秘密鍵のためのコールバックは実装されています。しかし | |
890 | verify_callbackの実装と同じ制限を持ちます(全てのコンテキストで | |
891 | 共有されている1つのパスワード・コールバック)。以下のように使うことが | |
892 | できるでしょう: | |
995 | 893 | |
996 | | |
894 | Net::SSLeay::CTX_set_default_passwd_cb($ctx, sub { "top-secret" }); | |
997 | | |
895 | Net::SSLeay::CTX_use_PrivateKey_file($ctx, "key.pem", | |
998 | | |
896 | Net::SSLeay::FILETYPE_PEM) | |
999 | | |
897 | or die "Error reading private key"; | |
1000 | 898 | |
1001 | 899 | =begin original |
1002 | 900 | |
1003 | 901 | No other callbacks are implemented. You do not need to use any |
1004 | 902 | callback for simple (i.e. normal) cases where the SSLeay built-in |
1005 | 903 | verify mechanism satisfies your needs. |
904 | ---- end inaccurate ---- | |
1006 | 905 | |
1007 | 906 | =end original |
1008 | 907 | |
1009 | その他のコールバックは実装されていません。 | |
908 | その他のコールバックは実装されていません。SSLeay組込の確認機構があなたの | |
1010 | ||
909 | ニーズを満足させているところでは、単純な(つまり通常の)ケースでは | |
1011 | ||
910 | 何もコールバックを使う必要はありません。 | |
911 | ---- 不正確 ここまで ---- | |
1012 | 912 | |
1013 | 913 | =begin original |
1014 | 914 | |
1015 | It is required to reset these callbacks to undef immediately after use to prevent | |
1016 | memory leaks, thread safety problems and crashes on exit that | |
1017 | can occur if different threads set different callbacks. | |
1018 | ||
1019 | =end original | |
1020 | ||
1021 | 異なるスレッドが異なるコールバックを持つ場合に起きるかもしれない | |
1022 | メモリリーク、スレッドセーフ性問題、終了時のクラッシュを防ぐために、 | |
1023 | これらのコールバックは使用後直ちに未定義にリセットする必要があります。 | |
1024 | ||
1025 | =begin original | |
1026 | ||
1027 | 915 | If you want to use callback stuff, see examples/callback.pl! Its the |
1028 | 916 | only one I am able to make work reliably. |
1029 | 917 | |
1030 | 918 | =end original |
1031 | 919 | |
1032 | コールバックを使いたければ、examples/callback.pl | |
920 | コールバックを使いたければ、examples/callback.plをご覧ください!それは | |
1033 | ||
921 | 私が信頼して動かすことができる唯一のものです。 | |
1034 | 922 | |
1035 | 923 | =head2 X509 and RAND stuff |
1036 | 924 | |
1037 | 925 | (X509 と RAND について) |
1038 | 926 | |
1039 | 927 | =begin original |
1040 | 928 | |
1041 | 929 | This module largely lacks interface to the X509 and RAND routines, but |
1042 | 930 | as I was lazy and needed them, the following kludges are implemented: |
1043 | 931 | |
1044 | 932 | =end original |
1045 | 933 | |
1046 | このモジュールでは | |
934 | このモジュールではX509とRANDルーチンへのインターフェースが大きく欠けて | |
1047 | ||
935 | いますが、私は怠け者で、それらを必要としていました。以下のものが実装 | |
1048 | ||
936 | されています: | |
1049 | 937 | |
938 | =begin original | |
939 | ||
1050 | 940 | $x509_name = Net::SSLeay::X509_get_subject_name($x509_cert); |
1051 | 941 | $x509_name = Net::SSLeay::X509_get_issuer_name($x509_cert); |
1052 | 942 | print Net::SSLeay::X509_NAME_oneline($x509_name); |
1053 | $text = Net::SSLeay::X509_NAME_get_text_by_NID($name, $nid); | |
1054 | ||
1055 | ($type1, $subject1, $type2, $subject2, ...) = | |
1056 | Net::SSLeay::X509_get_subjectAltNames($x509_cert) | |
1057 | ||
1058 | subjectAltName types as per x509v3.h GEN_*, for example | |
1059 | GEN_DNS or GEN_IPADD which can be imported. | |
1060 | ||
1061 | =begin original | |
1062 | ||
1063 | 943 | Net::SSLeay::RAND_seed($buf); # Perlishly figures out buf size |
1064 | Net::SSLeay::RAND_bytes($buf, $num); | |
1065 | Net::SSLeay::RAND_pseudo_bytes($buf, $num); | |
1066 | Net::SSLeay::RAND_add($buf, $num, $entropy); | |
1067 | Net::SSLeay::RAND_poll(); | |
1068 | Net::SSLeay::RAND_status(); | |
1069 | 944 | Net::SSLeay::RAND_cleanup(); |
1070 | Net::SSLeay::RAND_file_name($num); | |
1071 | 945 | Net::SSLeay::RAND_load_file($file_name, $how_many_bytes); |
1072 | 946 | Net::SSLeay::RAND_write_file($file_name); |
1073 | 947 | Net::SSLeay::RAND_egd($path); |
1074 | Net::SSLeay:: | |
948 | $text = Net::SSLeay::X509_NAME_get_text_by_NID($name, $nid); | |
1075 | 949 | |
1076 | 950 | =end original |
1077 | 951 | |
1078 | Net::SSLeay:: | |
952 | $x509_name = Net::SSLeay::X509_get_subject_name($x509_cert); | |
1079 | Net::SSLeay:: | |
953 | $x509_name = Net::SSLeay::X509_get_issuer_name($x509_cert); | |
1080 | Net::SSLeay:: | |
954 | print Net::SSLeay::X509_NAME_oneline($x509_name); | |
1081 | Net::SSLeay::RAND_ | |
955 | Net::SSLeay::RAND_seed($buf); # Perl的に大きさを計算します | |
1082 | Net::SSLeay::RAND_poll(); | |
1083 | Net::SSLeay::RAND_status(); | |
1084 | 956 | Net::SSLeay::RAND_cleanup(); |
1085 | Net::SSLeay::RAND_file_name($num); | |
1086 | 957 | Net::SSLeay::RAND_load_file($file_name, $how_many_bytes); |
1087 | 958 | Net::SSLeay::RAND_write_file($file_name); |
1088 | 959 | Net::SSLeay::RAND_egd($path); |
1089 | Net::SSLeay:: | |
960 | $text = Net::SSLeay::X509_NAME_get_text_by_NID($name, $nid); | |
1090 | 961 | |
1091 | 962 | =begin original |
1092 | 963 | |
1093 | 964 | Actually you should consider using the following helper functions: |
1094 | 965 | |
1095 | 966 | =end original |
1096 | 967 | |
1097 | 968 | 実際には、以下のヘルパー関数を使うことを考えるべきです: |
1098 | 969 | |
1099 | 970 | print Net::SSLeay::dump_peer_certificate($ssl); |
1100 | 971 | Net::SSLeay::randomize(); |
1101 | 972 | |
1102 | 973 | =head2 RSA interface |
1103 | 974 | |
1104 | 975 | (RSA インターフェース) |
1105 | 976 | |
1106 | 977 | =begin original |
1107 | 978 | |
1108 | 979 | Some RSA functions are available: |
1109 | 980 | |
1110 | 981 | =end original |
1111 | 982 | |
1112 | いくつかの | |
983 | いくつかのRSA関数を利用することができます: | |
1113 | 984 | |
1114 | ||
985 | $rsakey = Net::SSLeay::RSA_generate_key(); | |
1115 | ||
986 | Net::SSLeay::CTX_set_tmp_rsa($ctx, $rsakey); | |
1116 | ||
987 | Net::SSLeay::RSA_free($rsakey); | |
1117 | 988 | |
1118 | =head2 Digests | |
1119 | ||
1120 | (ダイジェスト) | |
1121 | ||
1122 | =begin original | |
1123 | ||
1124 | Some Digest functions are available if supported by the underlying | |
1125 | library. These may include MD2, MD4, MD5, and RIPEMD160: | |
1126 | ||
1127 | =end original | |
1128 | ||
1129 | 基となるライブラリが対応していれば、いくつかのダイジェスト関数が | |
1130 | 利用できます。 | |
1131 | MD2, MD4, MD5, RIPEMD160 があります: | |
1132 | ||
1133 | $hash = Net::SSLeay::MD5($foo); | |
1134 | print unpack('H*', $hash); | |
1135 | ||
1136 | 989 | =head2 BIO interface |
1137 | 990 | |
1138 | 991 | (BIO インターフェース) |
1139 | 992 | |
1140 | 993 | =begin original |
1141 | 994 | |
1142 | 995 | Some BIO functions are available: |
1143 | 996 | |
1144 | 997 | =end original |
1145 | 998 | |
1146 | いくつかの | |
999 | いくつかのBIO関数を利用することができます: | |
1147 | 1000 | |
1148 | | |
1001 | Net::SSLeay::BIO_s_mem(); | |
1149 | | |
1002 | $bio = Net::SSLeay::BIO_new(BIO_s_mem()) | |
1150 | | |
1003 | $bio = Net::SSLeay::BIO_new_file($filename, $mode); | |
1151 | | |
1004 | Net::SSLeay::BIO_free($bio) | |
1152 | | |
1005 | $count = Net::SSLeay::BIO_write($data); | |
1153 | | |
1006 | $data = Net::SSLeay::BIO_read($bio); | |
1154 | | |
1007 | $data = Net::SSLeay::BIO_read($bio, $maxbytes); | |
1155 | | |
1008 | $is_eof = Net::SSLeay::BIO_eof($bio); | |
1156 | | |
1009 | $count = Net::SSLeay::BIO_pending($bio); | |
1157 | | |
1010 | $count = Net::SSLeay::BIO_wpending ($bio); | |
1158 | 1011 | |
1159 | 1012 | =head2 Low level API |
1160 | 1013 | |
1161 | 1014 | (低レベル API) |
1162 | 1015 | |
1163 | 1016 | =begin original |
1164 | 1017 | |
1165 | 1018 | Some very low level API functions are available: |
1166 | 1019 | |
1167 | 1020 | =end original |
1168 | 1021 | |
1169 | いくつかの非常に低レベルの | |
1022 | いくつかの非常に低レベルのAPI関数を使うことが出来ます: | |
1170 | 1023 | |
1171 | $client_random = Net::SSLeay::get_client_random($ssl); | |
1024 | $client_random = &Net::SSLeay::get_client_random($ssl); | |
1172 | $server_random = Net::SSLeay::get_server_random($ssl); | |
1025 | $server_random = &Net::SSLeay::get_server_random($ssl); | |
1173 | $session = Net::SSLeay::get_session($ssl); | |
1026 | $session = &Net::SSLeay::get_session($ssl); | |
1174 | $master_key = Net::SSLeay::SESSION_get_master_key($session); | |
1027 | $master_key = &Net::SSLeay::SESSION_get_master_key($session); | |
1175 | Net::SSLeay::SESSION_set_master_key($session, $master_secret); | |
1176 | $keyblocksize = Net::SSLeay::get_keyblock_size($session); | |
1177 | 1028 | |
1178 | =head2 HTTP (without S) API | |
1179 | ||
1180 | (HTTP (S なし) API) | |
1181 | ||
1182 | =begin original | |
1183 | ||
1184 | Over the years it has become clear that it would be convenient to use | |
1185 | the light-weight flavour API of C<Net::SSLeay> for normal HTTP as well (see | |
1186 | C<LWP> for the heavy-weight object-oriented approach). In fact it would be | |
1187 | nice to be able to flip https on and off on the fly. Thus regular HTTP | |
1188 | support was evolved. | |
1189 | ||
1190 | =end original | |
1191 | ||
1192 | Over the years it has become clear that it would be convenient to use | |
1193 | the light-weight flavour API of C<Net::SSLeay> for normal HTTP as well (see | |
1194 | C<LWP> for the heavy-weight object-oriented approach). | |
1195 | In fact it would be nice to be able to flip https on and off on the fly. | |
1196 | Thus regular HTTP support was evolved. | |
1197 | (TBT) | |
1198 | ||
1199 | use Net::SSLeay qw(get_http post_http tcpcat | |
1200 | get_httpx post_httpx tcpxcat | |
1201 | make_headers make_form); | |
1202 | ||
1203 | ($page, $result, %headers) = | |
1204 | = get_http('www.bacus.pt', 443, '/protected.html', | |
1205 | make_headers(Authorization => | |
1206 | 'Basic ' . MIME::Base64::encode("$user:$pass",'')) | |
1207 | ); | |
1208 | ||
1209 | ($page, $response, %reply_headers) | |
1210 | = post_http('www.bacus.pt', 443, '/foo.cgi', '', | |
1211 | make_form(OK => '1', | |
1212 | name => 'Sampo' | |
1213 | )); | |
1214 | ||
1215 | ($reply, $err) = tcpcat($host, $port, $request); | |
1216 | ||
1217 | ($page, $result, %headers) = | |
1218 | = get_httpx($usessl, 'www.bacus.pt', 443, '/protected.html', | |
1219 | make_headers(Authorization => | |
1220 | 'Basic ' . MIME::Base64::encode("$user:$pass",'')) | |
1221 | ); | |
1222 | ||
1223 | ($page, $response, %reply_headers) | |
1224 | = post_httpx($usessl, 'www.bacus.pt', 443, '/foo.cgi', '', | |
1225 | make_form(OK => '1', name => 'Sampo' )); | |
1226 | ||
1227 | ($reply, $err, $server_cert) = tcpxcat($usessl, $host, $port, $request); | |
1228 | ||
1229 | =begin original | |
1230 | ||
1231 | As can be seen, the C<"x"> family of APIs takes as the first argument a flag | |
1232 | which indicates whether SSL is used or not. | |
1233 | ||
1234 | =end original | |
1235 | ||
1236 | ここで見られるように、API の C<"x"> ファミリーは、最初の引数として、 | |
1237 | SSL が使われているかどうかを示すフラグを取ります。 | |
1238 | ||
1239 | 1029 | =head1 EXAMPLES |
1240 | 1030 | |
1241 | 1031 | =begin original |
1242 | 1032 | |
1243 | One very good example to look at | |
1033 | One very good example is to look at the implementation of sslcat() in the | |
1244 | ||
1034 | SSLeay.pm file. | |
1245 | 1035 | |
1246 | 1036 | =end original |
1247 | 1037 | |
1248 | ||
1038 | 1つの非常に素晴らしい例は、SSLeay.pmファイルにあるsslcat()の実装を | |
1249 | 1039 | 見ることです。 |
1250 | 1040 | |
1251 | 1041 | =begin original |
1252 | 1042 | |
1253 | ||
1043 | Following is a simple SSLeay client (with too little error checking :-( | |
1254 | 1044 | |
1255 | 1045 | =end original |
1256 | 1046 | |
1257 | (あまりにもエラーチェックが少ない :-( | |
1047 | (あまりにもエラー・チェックが少ない :-()簡単なSSLeayクライアントを以下に | |
1258 | 1048 | 示します: |
1259 | 1049 | |
1260 | 1050 | #!/usr/local/bin/perl |
1261 | 1051 | use Socket; |
1262 | 1052 | use Net::SSLeay qw(die_now die_if_ssl_error) ; |
1263 | 1053 | Net::SSLeay::load_error_strings(); |
1264 | 1054 | Net::SSLeay::SSLeay_add_ssl_algorithms(); |
1265 | 1055 | Net::SSLeay::randomize(); |
1266 | 1056 | |
1267 | 1057 | =begin original |
1268 | 1058 | |
1269 | 1059 | ($dest_serv, $port, $msg) = @ARGV; # Read command line |
1270 | 1060 | $port = getservbyname ($port, 'tcp') unless $port =~ /^\d+$/; |
1271 | 1061 | $dest_ip = gethostbyname ($dest_serv); |
1272 | 1062 | $dest_serv_params = sockaddr_in($port, $dest_ip); |
1063 | ||
1064 | socket (S, &AF_INET, &SOCK_STREAM, 0) or die "socket: $!"; | |
1065 | connect (S, $dest_serv_params) or die "connect: $!"; | |
1066 | select (S); $| = 1; select (STDOUT); # Eliminate STDIO buffering | |
1067 | ||
1068 | # The network connection is now open, lets fire up SSL | |
1273 | 1069 | |
1274 | 1070 | =end original |
1275 | 1071 | |
1276 | 1072 | ($dest_serv, $port, $msg) = @ARGV; # コマンドラインを読み込みます |
1277 | 1073 | $port = getservbyname ($port, 'tcp') unless $port =~ /^\d+$/; |
1278 | 1074 | $dest_ip = gethostbyname ($dest_serv); |
1279 | 1075 | $dest_serv_params = sockaddr_in($port, $dest_ip); |
1076 | ||
1281 | =begin original | |
1282 | ||
1283 | 1077 | socket (S, &AF_INET, &SOCK_STREAM, 0) or die "socket: $!"; |
1284 | 1078 | connect (S, $dest_serv_params) or die "connect: $!"; |
1285 | select (S); $| = 1; select (STDOUT); # | |
1079 | select (S); $| = 1; select (STDOUT); # STDIOへのバッファリングの抑止 | |
1080 | ||
1081 | # ネットワークへの接続が今、開きました。SSLeayに火をつけましょう... | |
1286 | 1082 | |
1287 | =end original | |
1288 | ||
1289 | socket (S, &AF_INET, &SOCK_STREAM, 0) or die "socket: $!"; | |
1290 | connect (S, $dest_serv_params) or die "connect: $!"; | |
1291 | select (S); $| = 1; select (STDOUT); # STDIO へのバッファリングの抑止 | |
1292 | ||
1293 | 1083 | =begin original |
1294 | 1084 | |
1295 | # The network connection is now open, lets fire up SSL | |
1296 | ||
1297 | =end original | |
1298 | ||
1299 | # ネットワークへの接続が今、開きました。SSLeayを起動しましょう | |
1300 | ||
1301 | =begin original | |
1302 | ||
1303 | 1085 | $ctx = Net::SSLeay::CTX_new() or die_now("Failed to create SSL_CTX $!"); |
1304 | 1086 | Net::SSLeay::CTX_set_options($ctx, &Net::SSLeay::OP_ALL) |
1305 | 1087 | and die_if_ssl_error("ssl ctx set options"); |
1306 | 1088 | $ssl = Net::SSLeay::new($ctx) or die_now("Failed to create SSL $!"); |
1307 | 1089 | Net::SSLeay::set_fd($ssl, fileno(S)); # Must use fileno |
1308 | 1090 | $res = Net::SSLeay::connect($ssl) and die_if_ssl_error("ssl connect"); |
1309 | 1091 | print "Cipher `" . Net::SSLeay::get_cipher($ssl) . "'\n"; |
1092 | ||
1311 | =end original | |
1312 | ||
1313 | $ctx = Net::SSLeay::CTX_new() or die_now("Failed to create SSL_CTX $!"); | |
1314 | Net::SSLeay::CTX_set_options($ctx, &Net::SSLeay::OP_ALL) | |
1315 | and die_if_ssl_error("ssl ctx set options"); | |
1316 | $ssl = Net::SSLeay::new($ctx) or die_now("Failed to create SSL $!"); | |
1317 | Net::SSLeay::set_fd($ssl, fileno(S)); # fileno を使わなければなりません | |
1318 | $res = Net::SSLeay::connect($ssl) and die_if_ssl_error("ssl connect"); | |
1319 | print "Cipher `" . Net::SSLeay::get_cipher($ssl) . "'\n"; | |
1320 | ||
1321 | =begin original | |
1322 | ||
1323 | 1093 | # Exchange data |
1094 | ||
1325 | =end original | |
1326 | ||
1327 | # データの交換 | |
1328 | ||
1329 | =begin original | |
1330 | ||
1331 | 1095 | $res = Net::SSLeay::write($ssl, $msg); # Perl knows how long $msg is |
1332 | 1096 | die_if_ssl_error("ssl write"); |
1333 | 1097 | CORE::shutdown S, 1; # Half close --> No more output, sends EOF to server |
1334 | 1098 | $got = Net::SSLeay::read($ssl); # Perl returns undef on failure |
1335 | 1099 | die_if_ssl_error("ssl read"); |
1336 | 1100 | print $got; |
1101 | ||
1338 | =end original | |
1339 | ||
1340 | $res = Net::SSLeay::write($ssl, $msg); # Perl は $msgの 長さがわかります | |
1341 | die_if_ssl_error("ssl write"); | |
1342 | CORE::shutdown S, 1; # 半分クローズ --> 出力終わり、サーバに EOF を送信 | |
1343 | $got = Net::SSLeay::read($ssl); # Perl は失敗時 undef を返します | |
1344 | die_if_ssl_error("ssl read"); | |
1345 | print $got; | |
1346 | ||
1347 | =begin original | |
1348 | ||
1349 | 1102 | Net::SSLeay::free ($ssl); # Tear down connection |
1350 | 1103 | Net::SSLeay::CTX_free ($ctx); |
1351 | 1104 | close S; |
1352 | 1105 | |
1353 | 1106 | =end original |
1354 | 1107 | |
1108 | $ctx = Net::SSLeay::CTX_new() or die_now("Failed to create SSL_CTX $!"); | |
1109 | Net::SSLeay::CTX_set_options($ctx, &Net::SSLeay::OP_ALL) | |
1110 | and die_if_ssl_error("ssl ctx set options"); | |
1111 | $ssl = Net::SSLeay::new($ctx) or die_now("Failed to create SSL $!"); | |
1112 | Net::SSLeay::set_fd($ssl, fileno(S)); # filenoを使わなければなりません | |
1113 | $res = Net::SSLeay::connect($ssl) and die_if_ssl_error("ssl connect"); | |
1114 | print "Cipher `" . Net::SSLeay::get_cipher($ssl) . "'\n"; | |
1115 | ||
1116 | # データの交換 | |
1117 | ||
1118 | $res = Net::SSLeay::write($ssl, $msg); # Perlは$msgの長さがわかります | |
1119 | die_if_ssl_error("ssl write"); | |
1120 | CORE::shutdown S, 1; # 半分クローズ --> 出力はありません、サーバーにEOFを送信します | |
1121 | $got = Net::SSLeay::read($ssl); # Perlは失敗するとundefを返します | |
1122 | die_if_ssl_error("ssl read"); | |
1123 | print $got; | |
1124 | ||
1355 | 1125 | Net::SSLeay::free ($ssl); # 接続を終了させます |
1356 | 1126 | Net::SSLeay::CTX_free ($ctx); |
1357 | 1127 | close S; |
1358 | 1128 | |
1359 | 1129 | =begin original |
1360 | 1130 | |
1361 | ||
1131 | Following is a simple SSLeay echo server (non forking): | |
1362 | 1132 | |
1363 | 1133 | =end original |
1364 | 1134 | |
1365 | 簡単な | |
1135 | 簡単なSSLeay echoサーバー(forkなし)を以下に示します: | |
1366 | 1136 | |
1137 | =begin original | |
1138 | ||
1367 | 1139 | #!/usr/local/bin/perl -w |
1368 | 1140 | use Socket; |
1369 | 1141 | use Net::SSLeay qw(die_now die_if_ssl_error); |
1370 | 1142 | Net::SSLeay::load_error_strings(); |
1371 | 1143 | Net::SSLeay::SSLeay_add_ssl_algorithms(); |
1372 | 1144 | Net::SSLeay::randomize(); |
1145 | ||
1374 | =begin original | |
1375 | ||
1376 | 1146 | $our_ip = "\0\0\0\0"; # Bind to all interfaces |
1377 | 1147 | $port = 1235; |
1378 | 1148 | $sockaddr_template = 'S n a4 x8'; |
1379 | 1149 | $our_serv_params = pack ($sockaddr_template, &AF_INET, $port, $our_ip); |
1380 | 1150 | |
1381 | 1151 | =end original |
1382 | 1152 | |
1153 | #!/usr/local/bin/perl -w | |
1154 | use Socket; | |
1155 | use Net::SSLeay qw(die_now die_if_ssl_error); | |
1156 | Net::SSLeay::load_error_strings(); | |
1157 | Net::SSLeay::SSLeay_add_ssl_algorithms(); | |
1158 | Net::SSLeay::randomize(); | |
1159 | ||
1383 | 1160 | $our_ip = "\0\0\0\0"; # 全てのインターフェースにバインド |
1384 | 1161 | $port = 1235; |
1385 | 1162 | $sockaddr_template = 'S n a4 x8'; |
1386 | 1163 | $our_serv_params = pack ($sockaddr_template, &AF_INET, $port, $our_ip); |
1387 | 1164 | |
1388 | 1165 | socket (S, &AF_INET, &SOCK_STREAM, 0) or die "socket: $!"; |
1389 | 1166 | bind (S, $our_serv_params) or die "bind: $!"; |
1390 | 1167 | listen (S, 5) or die "listen: $!"; |
1391 | 1168 | $ctx = Net::SSLeay::CTX_new () or die_now("CTX_new ($ctx): $!"); |
1392 | 1169 | Net::SSLeay::CTX_set_options($ctx, &Net::SSLeay::OP_ALL) |
1393 | 1170 | and die_if_ssl_error("ssl ctx set options"); |
1394 | 1171 | |
1395 | =begin original | |
1396 | ||
1397 | 1172 | # Following will ask password unless private key is not encrypted |
1398 | 1173 | Net::SSLeay::CTX_use_RSAPrivateKey_file ($ctx, 'plain-rsa.pem', |
1399 | 1174 | &Net::SSLeay::FILETYPE_PEM); |
1400 | 1175 | die_if_ssl_error("private key"); |
1401 | 1176 | Net::SSLeay::CTX_use_certificate_file ($ctx, 'plain-cert.pem', |
1402 | 1177 | &Net::SSLeay::FILETYPE_PEM); |
1403 | 1178 | die_if_ssl_error("certificate"); |
1179 | ||
1180 | while (1) { | |
1181 | print "Accepting connections...\n"; | |
1182 | ($addr = accept (NS, S)) or die "accept: $!"; | |
1183 | select (NS); $| = 1; select (STDOUT); # Piping hot! | |
1184 | ||
1185 | ($af,$client_port,$client_ip) = unpack($sockaddr_template,$addr); | |
1186 | @inetaddr = unpack('C4',$client_ip); | |
1187 | print "$af connection from " . | |
1188 | join ('.', @inetaddr) . ":$client_port\n"; | |
1189 | ||
1190 | # We now have a network connection, lets fire up SSLeay... | |
1404 | 1191 | |
1192 | =begin original | |
1193 | ||
1194 | $ssl = Net::SSLeay::new($ctx) or die_now("SSL_new ($ssl): $!"); | |
1195 | Net::SSLeay::set_fd($ssl, fileno(NS)); | |
1196 | ||
1197 | $err = Net::SSLeay::accept($ssl) and die_if_ssl_error('ssl accept'); | |
1198 | print "Cipher `" . Net::SSLeay::get_cipher($ssl) . "'\n"; | |
1199 | ||
1200 | # Connected. Exchange some data. | |
1201 | ||
1202 | $got = Net::SSLeay::read($ssl); # Returns undef on fail | |
1203 | die_if_ssl_error("ssl read"); | |
1204 | print "Got `$got' (" . length ($got) . " chars)\n"; | |
1205 | ||
1206 | Net::SSLeay::write ($ssl, uc ($got)) or die "write: $!"; | |
1207 | die_if_ssl_error("ssl write"); | |
1208 | ||
1209 | Net::SSLeay::free ($ssl); # Tear down connection | |
1210 | close NS; | |
1211 | } | |
1212 | ||
1405 | 1213 | =end original |
1406 | 1214 | |
1407 | # 以下の行は秘密鍵が | |
1215 | # 以下の行は秘密鍵が暗号化されてないということがなければ、パスワードを尋ねます | |
1408 | 1216 | Net::SSLeay::CTX_use_RSAPrivateKey_file ($ctx, 'plain-rsa.pem', |
1409 | 1217 | &Net::SSLeay::FILETYPE_PEM); |
1410 | 1218 | die_if_ssl_error("private key"); |
1411 | 1219 | Net::SSLeay::CTX_use_certificate_file ($ctx, 'plain-cert.pem', |
1412 | 1220 | &Net::SSLeay::FILETYPE_PEM); |
1413 | 1221 | die_if_ssl_error("certificate"); |
1222 | ||
1415 | =begin original | |
1416 | ||
1417 | 1223 | while (1) { |
1418 | 1224 | print "Accepting connections...\n"; |
1419 | 1225 | ($addr = accept (NS, S)) or die "accept: $!"; |
1420 | select (NS); $| = 1; select (STDOUT); # Piping hot! | |
1421 | ||
1422 | =end original | |
1423 | ||
1424 | while (1) { | |
1425 | print "Accepting connections...\n"; | |
1426 | ($addr = accept (NS, S)) or die "accept: $!"; | |
1427 | 1226 | select (NS); $| = 1; select (STDOUT); # パイプがホット! |
1227 | ||
1429 | 1228 | ($af,$client_port,$client_ip) = unpack($sockaddr_template,$addr); |
1430 | 1229 | @inetaddr = unpack('C4',$client_ip); |
1431 | 1230 | print "$af connection from " . |
1432 | 1231 | join ('.', @inetaddr) . ":$client_port\n"; |
1232 | ||
1233 | # これでネットワーク接続を持っています、SSLeayに火をつけましょう... | |
1433 | 1234 | |
1434 | =begin original | |
1435 | ||
1436 | # We now have a network connection, lets fire up SSLeay... | |
1437 | ||
1438 | =end original | |
1439 | ||
1440 | # これでネットワーク接続を持っています、SSLeay を起動しましょう... | |
1441 | ||
1442 | 1235 | $ssl = Net::SSLeay::new($ctx) or die_now("SSL_new ($ssl): $!"); |
1443 | 1236 | Net::SSLeay::set_fd($ssl, fileno(NS)); |
1237 | ||
1445 | 1238 | $err = Net::SSLeay::accept($ssl) and die_if_ssl_error('ssl accept'); |
1446 | 1239 | print "Cipher `" . Net::SSLeay::get_cipher($ssl) . "'\n"; |
1240 | ||
1448 | =begin original | |
1449 | ||
1450 | # Connected. Exchange some data. | |
1451 | ||
1452 | =end original | |
1453 | ||
1454 | 1241 | # 接続しました。データを交換しましょう。 |
1242 | ||
1456 | ||
1243 | $got = Net::SSLeay::read($ssl); # 失敗したときにはundefを返します | |
1457 | ||
1458 | $got = Net::SSLeay::read($ssl); # Returns undef on fail | |
1459 | 1244 | die_if_ssl_error("ssl read"); |
1460 | 1245 | print "Got `$got' (" . length ($got) . " chars)\n"; |
1246 | ||
1462 | =end original | |
1463 | ||
1464 | $got = Net::SSLeay::read($ssl); # 失敗時は undef を返します | |
1465 | die_if_ssl_error("ssl read"); | |
1466 | print "Got `$got' (" . length ($got) . " chars)\n"; | |
1467 | ||
1468 | 1247 | Net::SSLeay::write ($ssl, uc ($got)) or die "write: $!"; |
1469 | 1248 | die_if_ssl_error("ssl write"); |
1249 | ||
1471 | =begin original | |
1472 | ||
1473 | Net::SSLeay::free ($ssl); # Tear down connection | |
1474 | close NS; | |
1475 | } | |
1476 | ||
1477 | =end original | |
1478 | ||
1479 | 1250 | Net::SSLeay::free ($ssl); # 接続を終了させます |
1480 | 1251 | close NS; |
1481 | 1252 | } |
1482 | 1253 | |
1483 | 1254 | =begin original |
1484 | 1255 | |
1485 | Yet another echo server. This one runs from | |
1256 | Yet another echo server. This one runs from /etc/inetd.conf so it avoids | |
1486 | all the socket code overhead. Only caveat is opening | |
1257 | all the socket code overhead. Only caveat is opening rsa key file - | |
1487 | 1258 | it had better be without any encryption or else it will not know where |
1488 | to ask for the password. Note how | |
1259 | to ask for the password. Note how STDIN and STDOUT are wired to SSL. | |
1489 | 1260 | |
1490 | 1261 | =end original |
1491 | 1262 | |
1492 | echo | |
1263 | echoサーバをもう1つ。今度のものは/etc/inetd.confから走ります。 | |
1493 | ||
1264 | そのためソケット・コードのオーバーヘッドを全て回避します。唯一の注意は、 | |
1494 | ||
1265 | rsa鍵ファイルを開くことです - 暗号化をしないほうがよりうまくいきます。 | |
1495 | ||
1266 | そうでなければパスワードをどこで聞けばいいのかわかりません。どのように | |
1496 | ||
1267 | STDINとSTDOUTがSSLにつながれるかに注意してください。 | |
1497 | そうでなければパスワードをどこで聞けばいいのかわかりません。 | |
1498 | どのように C<STDIN> と C<STDOUT> が SSL につながれるかに注意してください。 | |
1499 | 1268 | |
1500 | 1269 | #!/usr/local/bin/perl |
1501 | 1270 | # /etc/inetd.conf |
1502 | 1271 | # ssltst stream tcp nowait root /path/to/server.pl server.pl |
1503 | 1272 | # /etc/services |
1504 | 1273 | # ssltst 1234/tcp |
1505 | 1274 | |
1506 | 1275 | use Net::SSLeay qw(die_now die_if_ssl_error); |
1507 | 1276 | Net::SSLeay::load_error_strings(); |
1508 | 1277 | Net::SSLeay::SSLeay_add_ssl_algorithms(); |
1509 | 1278 | Net::SSLeay::randomize(); |
1510 | 1279 | |
1511 | 1280 | =begin original |
1512 | 1281 | |
1513 | 1282 | chdir '/key/dir' or die "chdir: $!"; |
1514 | 1283 | $| = 1; # Piping hot! |
1515 | 1284 | open LOG, ">>/dev/console" or die "Can't open log file $!"; |
1516 | 1285 | select LOG; print "server.pl started\n"; |
1286 | ||
1287 | $ctx = Net::SSLeay::CTX_new() or die_now "CTX_new ($ctx) ($!)"; | |
1288 | $ssl = Net::SSLeay::new($ctx) or die_now "new ($ssl) ($!)"; | |
1289 | Net::SSLeay::set_options($ssl, &Net::SSLeay::OP_ALL) | |
1290 | and die_if_ssl_error("ssl set options"); | |
1517 | 1291 | |
1518 | 1292 | =end original |
1519 | 1293 | |
1520 | 1294 | chdir '/key/dir' or die "chdir: $!"; |
1521 | 1295 | $| = 1; # パイプがホット! |
1522 | 1296 | open LOG, ">>/dev/console" or die "Can't open log file $!"; |
1523 | 1297 | select LOG; print "server.pl started\n"; |
1524 | 1298 | |
1525 | 1299 | $ctx = Net::SSLeay::CTX_new() or die_now "CTX_new ($ctx) ($!)"; |
1526 | 1300 | $ssl = Net::SSLeay::new($ctx) or die_now "new ($ssl) ($!)"; |
1527 | 1301 | Net::SSLeay::set_options($ssl, &Net::SSLeay::OP_ALL) |
1528 | 1302 | and die_if_ssl_error("ssl set options"); |
1529 | 1303 | |
1530 | $ctx = Net::SSLeay::CTX_new() or die_now "CTX_new ($ctx) ($!)"; | |
1531 | $ssl = Net::SSLeay::new($ctx) or die_now "new ($ssl) ($!)"; | |
1532 | Net::SSLeay::set_options($ssl, &Net::SSLeay::OP_ALL) | |
1533 | and die_if_ssl_error("ssl set options"); | |
1534 | ||
1535 | 1304 | =begin original |
1536 | 1305 | |
1537 | 1306 | # We get already open network connection from inetd, now we just |
1538 | 1307 | # need to attach SSLeay to STDIN and STDOUT |
1539 | 1308 | Net::SSLeay::set_rfd($ssl, fileno(STDIN)); |
1540 | 1309 | Net::SSLeay::set_wfd($ssl, fileno(STDOUT)); |
1541 | 1310 | |
1542 | 1311 | =end original |
1543 | 1312 | |
1544 | # inetd | |
1313 | # inetdからネットワーク接続は既にオープンしてあるので、 | |
1545 | # STDIN | |
1314 | # STDINとSTDOUTにSSLeayをつける必要があるだけです | |
1546 | 1315 | Net::SSLeay::set_rfd($ssl, fileno(STDIN)); |
1547 | 1316 | Net::SSLeay::set_wfd($ssl, fileno(STDOUT)); |
1548 | 1317 | |
1549 | 1318 | Net::SSLeay::use_RSAPrivateKey_file ($ssl, 'plain-rsa.pem', |
1550 | Net::SSLeay::FILETYPE_PEM); | |
1319 | &Net::SSLeay::FILETYPE_PEM); | |
1551 | 1320 | die_if_ssl_error("private key"); |
1552 | 1321 | Net::SSLeay::use_certificate_file ($ssl, 'plain-cert.pem', |
1553 | | |
1322 | &Net::SSLeay::FILETYPE_PEM); | |
1554 | 1323 | die_if_ssl_error("certificate"); |
1555 | 1324 | |
1556 | 1325 | Net::SSLeay::accept($ssl) and die_if_ssl_err("ssl accept: $!"); |
1557 | 1326 | print "Cipher `" . Net::SSLeay::get_cipher($ssl) . "'\n"; |
1327 | ||
1559 | 1328 | $got = Net::SSLeay::read($ssl); |
1560 | 1329 | die_if_ssl_error("ssl read"); |
1561 | 1330 | print "Got `$got' (" . length ($got) . " chars)\n"; |
1562 | 1331 | |
1563 | 1332 | Net::SSLeay::write ($ssl, uc($got)) or die "write: $!"; |
1564 | 1333 | die_if_ssl_error("ssl write"); |
1565 | 1334 | |
1566 | 1335 | =begin original |
1567 | 1336 | |
1568 | 1337 | Net::SSLeay::free ($ssl); # Tear down the connection |
1569 | 1338 | Net::SSLeay::CTX_free ($ctx); |
1570 | 1339 | close LOG; |
1571 | 1340 | |
1572 | 1341 | =end original |
1573 | 1342 | |
1574 | 1343 | Net::SSLeay::free ($ssl); # 接続を終わらせます |
1575 | 1344 | Net::SSLeay::CTX_free ($ctx); |
1576 | 1345 | close LOG; |
1577 | 1346 | |
1578 | 1347 | =begin original |
1579 | 1348 | |
1580 | 1349 | There are also a number of example/test programs in the examples directory: |
1581 | 1350 | |
1582 | 1351 | =end original |
1583 | 1352 | |
1584 | examples | |
1353 | examplesディレクトリにも例/テストプログラムがたくさん入っています: | |
1585 | 1354 | |
1586 | 1355 | =begin original |
1587 | 1356 | |
1588 | 1357 | sslecho.pl - A simple server, not unlike the one above |
1589 | 1358 | minicli.pl - Implements a client using low level SSLeay routines |
1590 | 1359 | sslcat.pl - Demonstrates using high level sslcat utility function |
1591 | 1360 | get_page.pl - Is a utility for getting html pages from secure servers |
1592 | 1361 | callback.pl - Demonstrates certificate verification and callback usage |
1593 | 1362 | stdio_bulk.pl - Does SSL over Unix pipes |
1594 | 1363 | ssl-inetd-serv.pl - SSL server that can be invoked from inetd.conf |
1595 | 1364 | httpd-proxy-snif.pl - Utility that allows you to see how a browser |
1596 | 1365 | sends https request to given server and what reply |
1597 | 1366 | it gets back (very educative :-) |
1598 | 1367 | makecert.pl - Creates a self signed cert (does not use this module) |
1599 | 1368 | |
1600 | 1369 | =end original |
1601 | 1370 | |
1602 | sslecho.pl - 上記のものと違わない簡単なサーバ | |
1371 | sslecho.pl - 上記のものと違わない簡単なサーバー | |
1603 | minicli.pl - 低レベル | |
1372 | minicli.pl - 低レベルSSLeayルーチンを使ったクライアントを実装しています | |
1604 | sslcat.pl - 高レベル | |
1373 | sslcat.pl - 高レベルsslcatユーティリティ関数の使い方を示しています | |
1605 | get_page.pl - セキュアなサーバから | |
1374 | get_page.pl - セキュアなサーバーからHTMLページを取り出すためのユーティリティ | |
1606 | callback.pl - 証明書の確認とコールバックの使い方 | |
1375 | callback.pl - 証明書の確認とコールバックの使い方を示しています | |
1607 | stdio_bulk.pl - Unix | |
1376 | stdio_bulk.pl - Unixパイプ越しにSSLを行います | |
1608 | ssl-inetd-serv.pl - inetd.conf | |
1377 | ssl-inetd-serv.pl - inetd.confから呼び出すことができるSSLサーバー | |
1609 | httpd-proxy-snif.pl - ブラウザが | |
1378 | httpd-proxy-snif.pl - ブラウザが与えられたどのようにhttpsリクエストを送信するのか、 | |
1610 | | |
1379 | そして応答として何を受け取ったのかを見えるようにするユーティリティ | |
1611 | | |
1380 | (とっても教育的 :-) | |
1612 | ||
1381 | makecert.pl - 自分で署名した証明書を作成します(このモジュールを使いません) | |
1613 | 1382 | |
1614 | 1383 | =head1 LIMITATIONS |
1615 | 1384 | |
1616 | 1385 | (制約) |
1617 | 1386 | |
1618 | 1387 | =begin original |
1619 | 1388 | |
1620 | ||
1389 | Net::SSLeay::read uses internal buffer of 32KB, thus no single read | |
1621 | 1390 | will return more. In practice one read returns much less, usually |
1622 | 1391 | as much as fits in one network packet. To work around this, |
1623 | 1392 | you should use a loop like this: |
1624 | 1393 | |
1625 | 1394 | =end original |
1626 | 1395 | |
1627 | ||
1396 | Net::SSLeay::readは32KBの内部バッファを利用しています。そのため1回の読み込みは、それ以上、 | |
1628 | ||
1397 | 多く返すことはありません。実際、通常通り1つのネットワーク・パケットに収まっているかぎり、 | |
1629 | ||
1398 | 1回の読み込みは、これよりもかなり少なく返します。これを回避するためには以下のように | |
1630 | 1 回の読み込みは、これよりもかなり少なく返します。 | |
1631 | これを回避するためには以下のように | |
1632 | 1399 | ループを使わなければなりません: |
1633 | 1400 | |
1634 | 1401 | $reply = ''; |
1635 | 1402 | while ($got = Net::SSLeay::read($ssl)) { |
1636 | ||
1403 | last if print_errs('SSL_read'); | |
1637 | ||
1404 | $reply .= $got; | |
1638 | 1405 | } |
1639 | 1406 | |
1640 | 1407 | =begin original |
1641 | 1408 | |
1642 | Although there is no built-in limit in | |
1409 | Although there is no built-in limit in Net::SSLeay::write, the network | |
1643 | 1410 | packet size limitation applies here as well, thus use: |
1644 | 1411 | |
1645 | 1412 | =end original |
1646 | 1413 | |
1647 | ||
1414 | Net::SSLeay::writeには組み込まれた制約はありませんが、ネットワーク・パケット | |
1648 | ||
1415 | サイズの制限は、ここでも当てはまります。そこで以下のようにしてください: | |
1649 | そこで以下のようにしてください: | |
1650 | 1416 | |
1651 | 1417 | $written = 0; |
1652 | 1418 | |
1653 | 1419 | while ($written < length($message)) { |
1654 | ||
1420 | $written += Net::SSLeay::write($ssl, substr($message, $written)); | |
1655 | ||
1421 | last if print_errs('SSL_write'); | |
1656 | 1422 | } |
1657 | 1423 | |
1658 | 1424 | =begin original |
1659 | 1425 | |
1660 | Or alternatively you can just use the following conv | |
1426 | Or alternatively you can just use the following convinence functions: | |
1661 | 1427 | |
1662 | 1428 | =end original |
1663 | 1429 | |
1664 | 1430 | あるいは、代わりに単に以下の便利な関数を使うことも出来ます: |
1665 | 1431 | |
1666 | 1432 | Net::SSLeay::ssl_write_all($ssl, $message) or die "ssl write failure"; |
1667 | 1433 | $got = Net::SSLeay::ssl_read_all($ssl) or die "ssl read failure"; |
1668 | 1434 | |
1669 | 1435 | =head1 KNOWN BUGS AND CAVEATS |
1670 | 1436 | |
1671 | 1437 | (既知のバグと注意) |
1672 | 1438 | |
1673 | 1439 | =begin original |
1674 | 1440 | |
1675 | Autoloader emits | |
1441 | Autoloader emits | |
1676 | 1442 | |
1677 | 1443 | =end original |
1678 | 1444 | |
1679 | Autoloader | |
1445 | die_if_ssl_errorがautoload可能であると、Autoloader 以下の警告を吐き出します | |
1680 | 1446 | |
1681 | 1447 | Argument "xxx" isn't numeric in entersub at blib/lib/Net/SSLeay.pm' |
1682 | 1448 | |
1683 | 1449 | =begin original |
1684 | 1450 | |
1685 | 1451 | warning if die_if_ssl_error is made autoloadable. If you figure out why, |
1686 | 1452 | drop me a line. |
1687 | 1453 | |
1688 | 1454 | =end original |
1689 | 1455 | |
1690 | die_if_ssl_error が autoload 可能であると、このの警告を吐き出します。 | |
1691 | 1456 | なぜだかわかったら、私に連絡してください。 |
1692 | 1457 | |
1693 | 1458 | =begin original |
1694 | 1459 | |
1695 | Callback set using | |
1460 | Callback set using SSL_set_verify() does not appear to work. This may | |
1696 | well be a | |
1461 | well be eay problem (e.g. see ssl/ssl_lib.c line 1029). Try using | |
1697 | ||
1462 | SSL_CTX_set_verify() instead and do not be surprised if even this stops | |
1698 | 1463 | working in future versions. |
1699 | 1464 | |
1700 | 1465 | =end original |
1701 | 1466 | |
1702 | ||
1467 | SSL_set_verify()を使って設定されたコールバックが動かないようです。 | |
1703 | これは | |
1468 | これはeayの問題かもしれません(例えばssl/ssl_lib.cの1029行をご覧ください)。 | |
1704 | ||
1469 | 代わりにSSL_CTX_set_verify()を使ってみてください。そして将来のバージョンで | |
1705 | ||
1470 | これが動かないようになっても驚かないでください。 | |
1706 | そして将来のバージョンでこれが動かないようになっても驚かないでください。 | |
1707 | 1471 | |
1708 | 1472 | =begin original |
1709 | 1473 | |
1710 | 1474 | Callback and certificate verification stuff is generally too little tested. |
1711 | 1475 | |
1712 | 1476 | =end original |
1713 | 1477 | |
1714 | コールバックと証明書の確認に関しては、一般的に余りにも | |
1478 | コールバックと証明書の確認に関しては、一般的に余りにも少ししかテストされて | |
1715 | 1479 | いません。 |
1716 | 1480 | |
1717 | 1481 | =begin original |
1718 | 1482 | |
1719 | 1483 | Random numbers are not initialized randomly enough, especially if you |
1720 | do not have | |
1484 | do not have /dev/random and/or /dev/urandom (such as in Solaris | |
1721 | platforms - but I've been suggested that cryptorand daemon from | |
1485 | platforms - but I've been suggested that cryptorand daemon from SUNski | |
1722 | 1486 | package solves this). In this case you should investigate third party |
1723 | 1487 | software that can emulate these devices, e.g. by way of a named pipe |
1724 | 1488 | to some program. |
1725 | 1489 | |
1726 | 1490 | =end original |
1727 | 1491 | |
1728 | ||
1492 | 特に/dev/random そして/あるいは /dev/urandom を持っていなければ、 | |
1729 | ||
1493 | (Solarisプラットホームのように - しかし私はSUNskiパッケージからの | |
1730 | ||
1494 | cryptorandデーモンが、これを解決するという提案を受けたことがあります) | |
1731 | 乱数は十分にランダムに初期化されません。 | |
1495 | 乱数は十分にランダムに初期化されません。この場合、これらのデバイスを | |
1732 | ||
1496 | エミュレートすることができるサード・パーティのソフトウェア、例えば | |
1733 | ||
1497 | あるプログラムへの名前付きパイプによる方法などを調査する必要があります。 | |
1734 | 名前付きパイプによる方法などを調査する必要があります。 | |
1735 | 1498 | |
1736 | 1499 | =begin original |
1737 | 1500 | |
1738 | 1501 | Another gotcha with random number initialization is randomness |
1739 | 1502 | depletion. This phenomenon, which has been extensively discussed in |
1740 | 1503 | OpenSSL, Apache-SSL, and Apache-mod_ssl forums, can cause your |
1741 | script to block if you use | |
1504 | script to block if you use /dev/random or to operate insecurely | |
1742 | if you use | |
1505 | if you use /dev/urandom. What happens is that when too much | |
1743 | 1506 | randomness is drawn from the operating system's randomness pool |
1744 | then randomness can temporarily be unavailable. | |
1507 | then randomness can temporarily be unavailable. /dev/random solves | |
1745 | 1508 | this problem by waiting until enough randomness can be gathered - and |
1746 | 1509 | this can take a long time since blocking reduces activity in the |
1747 | 1510 | machine and less activity provides less random events: a vicious circle. |
1748 | ||
1511 | /dev/urandom solves this dilemma more pragmatically by simply returning | |
1749 | predictable "random" numbers. Some | |
1512 | predictable "random" numbers. Some /dev/urandom emulation software | |
1750 | however actually seems to implement | |
1513 | however actually seems to implement /dev/random semantics. Caveat emptor. | |
1751 | 1514 | |
1752 | 1515 | =end original |
1753 | 1516 | |
1754 | 乱数の初期化に関して、もう | |
1517 | 乱数の初期化に関して、もう1つわかっていることは乱数が枯渇することです。 | |
1755 | OpenSSL、Apache-SSL、そして | |
1518 | OpenSSL、Apache-SSL、そしてApache-mod_sslフォーラムで | |
1756 | 広く議論されていますが、この現象は、 | |
1519 | 広く議論されていますが、この現象は、/dev/randomを使うならば、あなたの | |
1757 | スクリプトをブロックすることを、あるいは | |
1520 | スクリプトをブロックすることを、あるいは/dev/urandomを使うならば、 | |
1758 | 1521 | セキュアでなく操作することを引き起こすかもしれません。 |
1759 | 1522 | 発生していることは、あまりにも多くの乱数がシステムの乱数プールから |
1760 | 1523 | 引っ張られたとき、乱数が一時的に利用不能になることがあります。 |
1761 | ||
1524 | /dev/randomはこの問題は、十分な乱数が集められるまで待つことにより解決 | |
1762 | ||
1525 | します - そしてこれには長い時間がかかることがあります。ブロックすること | |
1763 | ||
1526 | がマシンでの活動を減らしてしまい、活動が少なくなると乱数イベントも | |
1764 | ||
1527 | 少なくなるためです:悪循環です。/dev/urandomは、このジレンマをより | |
1765 | ||
1528 | 実用的に簡単に予測できる"ランダムな"数を返すことにより解決します。 | |
1766 | ||
1529 | しかしながら、いくつかの/dev/urandomエミュレーション・ソフトウェアは | |
1767 | ||
1530 | 実際には/dev/randomのセマンティクを実装しているようです。 | |
1768 | 実際には C</dev/random> の意味論を実装しているようです。 | |
1769 | 1531 | 利用者はご注意を(Caveat emptor)。 |
1770 | 1532 | |
1771 | 1533 | =begin original |
1772 | 1534 | |
1773 | 1535 | I've been pointed to two such daemons by Mik Firestone <mik@@speed.stdio._com> |
1774 | who has used them on Solaris 8 | |
1536 | who has used them on Solaris 8 | |
1775 | 1537 | |
1776 | 1538 | =end original |
1777 | 1539 | |
1778 | 私は | |
1540 | 私はSolaris 8でそれらを使っているMik Firestone <mik@@speed.stdio._com>から、 | |
1779 | ||
1541 | そのような2つのデーモンを指摘されました。 | |
1780 | そのような二つのデーモンを指摘されました: | |
1781 | 1542 | |
1782 | ||
1543 | 1. Entropy Gathering Daemon (EGD) at http://www.lothar.com/tech/crypto/ | |
1544 | 2. Pseudo-random number generating daemon (PRNGD) at | |
1545 | http://www.aet.tu-cottbus.de/personen/jaenicke/postfix_tls/prngd.html | |
1783 | 1546 | |
1784 | =item 1 | |
1785 | ||
1786 | L<http://www.lothar.com/tech/crypto/> の | |
1787 | Entropy Gathering Daemon (EGD) | |
1788 | ||
1789 | =item 2 | |
1790 | ||
1791 | L<http://www.aet.tu-cottbus.de/personen/jaenicke/postfix_tls/prngd.html> の | |
1792 | Pseudo-random number generating daemon (PRNGD) | |
1793 | ||
1794 | =back | |
1795 | ||
1796 | 1547 | =begin original |
1797 | 1548 | |
1798 | 1549 | If you are using the low level API functions to communicate with other |
1799 | 1550 | SSL implementations, you would do well to call |
1800 | 1551 | |
1801 | 1552 | =end original |
1802 | 1553 | |
1803 | 他の | |
1554 | 他のSSL実装と通信するために低レベルAPI関数を使っているのであれば、 | |
1804 | 以下のようにして、他のいくるかの | |
1555 | 以下のようにして、他のいくるかのSSL実装での、よく知られているバグをうまく | |
1805 | 処理するよう、以下のように呼び出すとうまくいきます | |
1556 | 処理するよう、以下のように呼び出すとうまくいきます | |
1806 | 1557 | |
1807 | 1558 | Net::SSLeay::CTX_set_options($ctx, &Net::SSLeay::OP_ALL) |
1808 | 1559 | and die_if_ssl_error("ssl ctx set options"); |
1809 | 1560 | |
1810 | 1561 | =begin original |
1811 | 1562 | |
1812 | 1563 | to cope with some well know bugs in some other SSL |
1813 | 1564 | implementations. The high level API functions always set all known |
1814 | 1565 | compatibility options. |
1815 | 1566 | |
1816 | 1567 | =end original |
1817 | 1568 | |
1818 | 高レベル | |
1569 | 高レベルAPI関数は常に全てのわかっている互換性オプションを設定します。 | |
1819 | 1570 | |
1820 | 1571 | =begin original |
1821 | 1572 | |
1822 | Sometimes | |
1573 | Sometimes sslcat (and the high level https functions that build on it) | |
1823 | is too fast in signaling the EOF to legacy | |
1574 | is too fast in signaling the EOF to legacy https servers. This causes | |
1824 | 1575 | the server to return empty page. To work around this problem you can |
1825 | set | |
1576 | set global variable | |
1826 | 1577 | |
1827 | 1578 | =end original |
1828 | 1579 | |
1829 | 時折、 | |
1580 | 時折、sslcat(そしてそれを基に構築された高レベルhttps関数)が、 | |
1830 | レガシーな | |
1581 | レガシーなhttpsサーバーにEOFの合図を出すのが速すぎることがあります。 | |
1831 | これによりサーバが空のページを返してしまいます。 | |
1582 | これによりサーバーが空のページを返してしまいます。この問題を回避する | |
1832 | ||
1583 | ためには、グローバル変数を設定することができます | |
1833 | 1584 | |
1834 | 1585 | =begin original |
1835 | 1586 | |
1836 | 1587 | $Net::SSLeay::slowly = 1; # Add sleep so broken servers can keep up |
1837 | 1588 | |
1838 | 1589 | =end original |
1839 | 1590 | |
1840 | $Net::SSLeay::slowly = 1; # 壊れたサーバでも保持できるよう | |
1591 | $Net::SSLeay::slowly = 1; # 壊れたサーバーでも保持できるようsleepを追加します | |
1841 | 1592 | |
1842 | 1593 | =begin original |
1843 | 1594 | |
1844 | ||
1595 | http/1.1 is not supported. Specifically this module does not know to | |
1845 | 1596 | issue or serve multiple http requests per connection. This is a serious |
1846 | shortcoming, but using | |
1597 | short coming, but using SSL session cache on your server helps to | |
1847 | 1598 | alleviate the CPU load somewhat. |
1848 | 1599 | |
1849 | 1600 | =end original |
1850 | 1601 | |
1851 | ||
1602 | http/1.1はサポートされていません。明確に、このモジュールは | |
1852 | ||
1603 | 接続ごとに複数のhttpリクエストを発行したり、それをサービスすることを | |
1853 | ||
1604 | 知りません。これは重大な短所です。しかしサーバーでSSLセッション・キャッシュを | |
1854 | これ | |
1605 | 使うことがCPUの負荷をいくぶん軽くすることを助けてくれます。 | |
1855 | しかしサーバで SSL セッションキャッシュを使うことが CPU の負荷を | |
1856 | いくぶん軽くすることを助けてくれます。 | |
1857 | 1606 | |
1858 | 1607 | =begin original |
1859 | 1608 | |
1860 | 1609 | As of version 1.09 many newer OpenSSL auxiliary functions were |
1861 | added (from | |
1610 | added (from REM_AUTOMATICALLY_GENERATED_1_09 onwards in SSLeay.xs). | |
1862 | 1611 | Unfortunately I have not had any opportunity to test these. Some of |
1863 | 1612 | them are trivial enough that I believe they "just work", but others |
1864 | 1613 | have rather complex interfaces with function pointers and all. In these |
1865 | 1614 | cases you should proceed wit great caution. |
1866 | 1615 | |
1867 | 1616 | =end original |
1868 | 1617 | |
1869 | バージョン | |
1618 | バージョン1.09では多くの新しいOpenSSL補助関数が追加されました( | |
1870 | ||
1619 | SSLeayxsではREM_AUTOMATICALLY_GENERATED_1_09が前に付いています)。 | |
1871 | 1620 | 残念ながらこれらをテストする機会を持つことができていません。 |
1872 | 1621 | それらのいくつかは私が"動くだけ"だと思うに十分なほどささいなものです。 |
1873 | 1622 | しかし他のものは機能ポインタや全てで、どちらかといえば複雑な |
1874 | インターフェースを持っています。 | |
1623 | インターフェースを持っています。これらの場合には、大いに注意する | |
1875 | ||
1624 | 必要があります。 | |
1876 | 1625 | |
1877 | 1626 | =begin original |
1878 | 1627 | |
1879 | 1628 | This module defaults to using OpenSSL automatic protocol negotiation |
1880 | 1629 | code for automatically detecting the version of the SSL protocol |
1881 | 1630 | that the other end talks. With most web servers this works just |
1882 | 1631 | fine, but once in a while I get complaints from people that the module |
1883 | 1632 | does not work with some web servers. Usually this can be solved |
1884 | 1633 | by explicitly setting the protocol version, e.g. |
1885 | 1634 | |
1886 | 1635 | =end original |
1887 | 1636 | |
1888 | このモジュールはデフォルトで、自動的にもう一方が話す | |
1637 | このモジュールはデフォルトで、自動的にもう一方が話すSSLプロトコル・コードの | |
1889 | バージョンを検出するための | |
1638 | バージョンを検出するためのOpenSSL自動プロトコル・ネゴシエイションの | |
1890 | コードを使います。 | |
1639 | コードを使います。ほとんどのWebサーバーでは、これはうまく機能します。 | |
1891 | ||
1640 | しかし私は時折、モジュールがある種のWebサーバーでは動かないという | |
1892 | ||
1641 | 苦情を受けます。通常これは、明示的にプロトコル・バージョンを | |
1893 | ||
1642 | 設定することにより解決することができます。例えば | |
1894 | 通常これは、明示的にプロトコルバージョンを | |
1895 | 設定することにより解決することができます。 | |
1896 | 例えば: | |
1897 | 1643 | |
1898 | 1644 | =begin original |
1899 | 1645 | |
1900 | 1646 | $Net::SSLeay::ssl_version = 2; # Insist on SSLv2 |
1901 | 1647 | $Net::SSLeay::ssl_version = 3; # Insist on SSLv3 |
1902 | 1648 | $Net::SSLeay::ssl_version = 10; # Insist on TLSv1 |
1903 | 1649 | |
1904 | 1650 | =end original |
1905 | 1651 | |
1906 | $Net::SSLeay::ssl_version = 2; # SSLv2 | |
1652 | $Net::SSLeay::ssl_version = 2; # SSLv2を要求します | |
1907 | $Net::SSLeay::ssl_version = 3; # SSLv3 | |
1653 | $Net::SSLeay::ssl_version = 3; # SSLv3を要求します | |
1908 | $Net::SSLeay::ssl_version = 10; # TLSv1 | |
1654 | $Net::SSLeay::ssl_version = 10; # TLSv1を要求します | |
1909 | 1655 | |
1910 | 1656 | =begin original |
1911 | 1657 | |
1912 | 1658 | Although the autonegotiation is nice to have, the SSL standards |
1913 | 1659 | do not formally specify any such mechanism. Most of the world has |
1914 | 1660 | accepted the SSLeay/OpenSSL way of doing it as the de facto standard. But |
1915 | 1661 | for the few that think differently, you have to explicitly speak |
1916 | 1662 | the correct version. This is not really a bug, but rather a deficiency |
1917 | 1663 | in the standards. If a site refuses to respond or sends back some |
1918 | nonsensical error codes (at | |
1664 | nonsensical error codes (at SSL handshake level), try this option | |
1919 | 1665 | before mailing me. |
1920 | 1666 | |
1921 | 1667 | =end original |
1922 | 1668 | |
1923 | 自動ネゴシエ | |
1669 | 自動ネゴシエイションは素晴らしいのですが、SSL標準では公式には | |
1924 | そのような機能を規定していません。 | |
1670 | そのような機能を規定していません。世界中のほとんどがSSLeay/OpenSSLの | |
1925 | ||
1671 | やり方をデファクト・スダンダードとして受け入れています。しかし | |
1926 | ||
1672 | 中には違う考えを持つ人には、明示的に正しいバージョンを話さなければ | |
1927 | ||
1673 | なりません。これは本当はバグではありません。むしろ標準での欠落です。 | |
1928 | 話さなければなりません。 | |
1929 | これは本当はバグではありません。 | |
1930 | むしろ標準での欠落です。 | |
1931 | 1674 | もしサイトが応答を拒絶したり、無意味なエラーコードを送り返してきたら、 |
1932 | 1675 | 私にメールする前に、このオプションを試してみてください。 |
1933 | 1676 | |
1934 | 1677 | =begin original |
1935 | 1678 | |
1936 | 1679 | The high level API returns the certificate of the peer, thus allowing |
1937 | 1680 | one to check what certificate was supplied. However, you will only be |
1938 | 1681 | able to check the certificate after the fact, i.e. you already sent |
1939 | 1682 | your form data by the time you find out that you did not trust them, |
1940 | 1683 | oops. |
1941 | 1684 | |
1942 | 1685 | =end original |
1943 | 1686 | |
1944 | 高レベル | |
1687 | 高レベルAPIは相手側の証明書を返します。これにより、どんな証明書が | |
1945 | ||
1688 | 提供されたかをチェックすることができます。しかしその事の後にだけ、 | |
1946 | ||
1689 | 証明書をチェックすることができます。つまり | |
1947 | ||
1690 | 彼らを信頼しないことがわかったときには、あなたは既にあなたの | |
1948 | フォームデータを送信しているのです | |
1691 | フォームデータを送信しているのです。アリャマ。 | |
1949 | アリャマ。 | |
1950 | 1692 | |
1951 | 1693 | =begin original |
1952 | 1694 | |
1953 | 1695 | So, while being able to know the certificate after the fact is surely |
1954 | 1696 | useful, the security minded would still choose to do the connection |
1955 | and certificate verification first and only t | |
1697 | and certificate verification first and only after that exchange data | |
1956 | 1698 | with the site. Currently none of the high level API functions do |
1957 | 1699 | this, thus you would have to program it using the low level API. A |
1958 | good place to start is to see how | |
1700 | good place to start is to see how Net::SSLeay::http_cat() function | |
1959 | 1701 | is implemented. |
1960 | 1702 | |
1961 | 1703 | =end original |
1962 | 1704 | |
1963 | 1705 | そこで、その事が後に証明書を知ることができることが便利だとしても、 |
1964 | 1706 | セキュリティを気にする人たちは、先に接続し証明書の確認を行い、 |
1965 | 1707 | その後にだけそのサイトとデータを交換することを選択するでしょう。 |
1966 | 現在、これを行う高レベルの | |
1708 | 現在、これを行う高レベルのAPI関数はありません。このため低レベルの | |
1967 | ||
1709 | APIを使ってプログラムしなければなりません。 | |
1968 | ||
1710 | Net::SSLeay::http_cat()関数がどのように実装されているかを見ることから | |
1969 | 1711 | はじめるといいでしょう。 |
1970 | 1712 | |
1971 | =begin original | |
1972 | ||
1973 | The high level API functions use a global file handle C<SSLCAT_S> | |
1974 | internally. This really should not be a problem because there is no | |
1975 | way to interleave the high level API functions, unless you use threads | |
1976 | (but threads are not very well supported in perl anyway (as of version | |
1977 | 5.6.1). However, you may run into problems if you call undocumented | |
1978 | internal functions in an interleaved fashion. | |
1979 | ||
1980 | =end original | |
1981 | ||
1982 | 高レベル API 関数は内部でグローバルファイルハンドル C<SSLCAT_S> を使います。 | |
1983 | 高レベル API 関数をインターリーブする方法はないので、 | |
1984 | スレッドを使わない限り、実際に問題になることはないはずです | |
1985 | (しかし (バージョン 5.6.1 から) どちらにしても perl はスレッドに | |
1986 | うまく対応していません))。 | |
1987 | しかし、インターリーブされた方法で文書化されていない内部関数を呼び出すと、 | |
1988 | 問題に突き当たるかもしれません。 | |
1989 | ||
1990 | 1713 | =head1 DIAGNOSTICS |
1991 | 1714 | |
1992 | 1715 | (診断情報) |
1993 | 1716 | |
1994 | =over | |
1995 | ||
1996 | =item Random number generator not seeded!!! | |
1997 | ||
1998 | 1717 | =begin original |
1999 | 1718 | |
2000 | ||
1719 | "Random number generator not seeded!!!" | |
2001 | ||
1720 | This warning indicates that randomize() was not able to read | |
2002 | ||
1721 | /dev/random or /dev/urandom, possibly because your system does not | |
2003 | ||
1722 | have them or they are differently named. You can still use SSL, but | |
1723 | the encryption will not be as strong. | |
2004 | 1724 | |
2005 | 1725 | =end original |
2006 | 1726 | |
2007 | ||
1727 | "Random number generator not seeded!!!" | |
2008 | ||
1728 | (日本語訳:"乱数発生装置が種付けされていません!!!") | |
2009 | ||
1729 | この警告はrandomize()が/dev/random あるいは /dev/urandomを | |
2010 | ||
1730 | 読むことができなかったことをしめします。おそらくあなたのシステムが | |
2011 | これでも | |
1731 | それらを持っていないか、別の名前になっているからでしょう。これでもSSLを | |
2012 | しかし暗号化はあまり強力ではありません。 | |
1732 | 使うことは出来ます。しかし暗号化はあまり強力ではありません。 | |
2013 | 1733 | |
2014 | =item open_tcp_connection: destination host not found:`server' (port 123) ($!) | |
2015 | ||
2016 | 1734 | =begin original |
2017 | 1735 | |
2018 | ||
1736 | "open_tcp_connection: destination host not found:`server' (port 123) ($!)" | |
1737 | Name lookup for host named `server' failed. | |
2019 | 1738 | |
2020 | 1739 | =end original |
2021 | 1740 | |
2022 | ||
1741 | "open_tcp_connection: destination host not found:`server' (port 123) ($!)" | |
1742 | (日本語訳:"open_tcp_connection: 出力先ホストが見つかりませんでした:`server' (ポート 123) ($!)" | |
1743 | `server'名前のホストの名前検索が失敗しました。 | |
2023 | 1744 | |
2024 | =item open_tcp_connection: failed `server', 123 ($!) | |
2025 | ||
2026 | 1745 | =begin original |
2027 | 1746 | |
2028 | ||
1747 | "open_tcp_connection: failed `server', 123 ($!)" | |
1748 | The name was resolved, but establising the TCP connection failed. | |
2029 | 1749 | |
2030 | 1750 | =end original |
2031 | 1751 | |
2032 | ||
1752 | "open_tcp_connection: failed `server', 123 ($!)" | |
1753 | (日本語訳:"open_tcp_connection: 失敗:`server' (ポート 123) ($!)" | |
1754 | 名前は解決されましたが、TCP接続の確立が失敗しました。 | |
2033 | 1755 | |
2034 | =item msg 123: 1 - error:140770F8:SSL routines:SSL23_GET_SERVER_HELLO:unknown proto | |
2035 | ||
2036 | 1756 | =begin original |
2037 | 1757 | |
2038 | ||
1758 | "msg 123: 1 - error:140770F8:SSL routines:SSL23_GET_SERVER_HELLO:unknown proto" | |
2039 | ||
1759 | SSLeay error string. First (123) number is PID, second number (1) indicates | |
2040 | ||
1760 | the position of the error message in SSLeay error stack. You often see | |
1761 | a pile of these messages as errors cascade. | |
2041 | 1762 | |
2042 | 1763 | =end original |
2043 | 1764 | |
2044 | SSLe | |
1765 | "msg 123: 1 - error:140770F8:SSL routines:SSL23_GET_SERVER_HELLO:unknown proto" | |
2045 | ||
1766 | (日本語訳:"msg 123: 1 - error:140770F8:SSLルーチン:SSL23_GET_SERVER_HELLO:proto不明") | |
2046 | エラー | |
1767 | SSLeayエラー文字列。最初の(123)番号はPID、2番目の数字(1)はSSLeayエラー | |
2047 | 階段状になったエラーで、これらの | |
1768 | スタックでのエラーメッセージの位置を示します。階段状になったエラーで、これらの | |
2048 | 目にするでしょう。 | |
1769 | メッセージが重なったものを、しばしば目にするでしょう。 | |
2049 | 1770 | |
2050 | =item msg 123: 1 - error:02001002::lib(2) :func(1) :reason(2) | |
2051 | ||
2052 | 1771 | =begin original |
2053 | 1772 | |
2054 | ||
1773 | "msg 123: 1 - error:02001002::lib(2) :func(1) :reason(2)" | |
2055 | ||
1774 | The same as above, but you didn't call load_error_strings() so SSLeay | |
2056 | ||
1775 | couldn't verbosely explain the error. You can still find out what it | |
1776 | means with this command: | |
2057 | 1777 | |
2058 | 1778 | =end original |
2059 | 1779 | |
2060 | ||
1780 | "msg 123: 1 - error:02001002::lib(2) :func(1) :reason(2)" | |
2061 | ||
1781 | (日本語訳:"msg 123: 1 - error:02001002::lib(2) :関数(1) :理由(2)") | |
2062 | ||
1782 | 上記と同じ。しかしload_error_strings()を呼ばなかったので、SSLeayは | |
2063 | ||
1783 | 多くの言葉でエラーを説明することができませんでした。それでも、 | |
1784 | それがどんな意味かは以下のコマンドにより知ることができます: | |
2064 | 1785 | |
2065 | /usr/local/ssl/bin/ssleay errstr 02001002 | |
1786 | /usr/local/ssl/bin/ssleay errstr 02001002 | |
2066 | 1787 | |
2067 | =item Password is being asked for private key | |
2068 | ||
2069 | (秘密鍵のためのパスワードを聞かれる) | |
2070 | ||
2071 | 1788 | =begin original |
2072 | 1789 | |
2073 | ||
1790 | Password is being asked for private key | |
2074 | ||
1791 | This is normal behaviour if your private key is encrypted. Either | |
2075 | ||
1792 | you have to supply the password or you have to use unencrypted | |
2076 | ||
1793 | private key. Scan OpenSSL.org for the FAQ that explains how to | |
2077 | ||
1794 | do this (or just study examples/makecert.pl which is used | |
1795 | during `make test' to do just that). | |
2078 | 1796 | |
2079 | 1797 | =end original |
2080 | 1798 | |
2081 | ||
1799 | 秘密鍵のためのパスワードを聞かれる | |
2082 | ||
1800 | あなたの秘密鍵が暗号化されていれば、これは通常の動きです。パスワードを | |
2083 | どちらかをする必要があります。 | |
1801 | 与えるか、暗号化されていない秘密鍵を使うかのどちらかをする必要があります。 | |
2084 | これをどのように行うかの | |
1802 | これをどのように行うかのFAQについてはOpenSSL.orgをよく見てください。 | |
2085 | (あるいは単純に、 | |
1803 | (あるいは単純に、`make test'の時、それを行うためだけに使われる | |
2086 | examples/makecert.pl | |
1804 | examples/makecert.plを勉強してください) | |
2087 | 1805 | |
2088 | = | |
1806 | =head1 REPORTING BUGS AND SUPPORT | |
2089 | 1807 | |
2090 | ||
1808 | (バグの報告とサポート) | |
2091 | 1809 | |
2092 | (バグ報告とサポート) | |
2093 | ||
2094 | 1810 | =begin original |
2095 | 1811 | |
2096 | Please | |
1812 | Please see README for full bug reporting instructions. In general I do | |
2097 | ||
1813 | not answer for free stupid questions or questions where you did not | |
2098 | ||
1814 | do your home work. | |
2099 | I will be notified, and then you'll automatically be notified of progress on | |
2100 | your bug as I make changes. | |
2101 | 1815 | |
2102 | 1816 | =end original |
2103 | 1817 | |
2104 | バグ | |
1818 | 完全なバグ報告の手順はREADMEをご覧ください。一般的に、私は只では、 | |
2105 | ||
1819 | 馬鹿げた質問やあなたが宿題をやっていない質問について回答しません。 | |
2106 | L<http://rt.cpan.org/Public/Dist/Display.html?Name=Net-SSLeay> | |
2107 | の web インターフェースで報告してください。 | |
2108 | 私には通知が届き、私が変更するとバグに関する進展について | |
2109 | 自動的にあなたに通知されます。 | |
2110 | 1820 | |
2111 | 1821 | =begin original |
2112 | 1822 | |
2113 | ||
1823 | Commercial support for Net::SSLeay may be obtained from | |
2114 | L<http://alioth.debian.org/projects/net-ssleay> | |
2115 | 1824 | |
2116 | 1825 | =end original |
2117 | 1826 | |
2118 | ||
1827 | Net::SSLeayの商用サポートは、以下のところで得られるでしょう | |
2119 | L<http://alioth.debian.org/projects/net-ssleay> で得られます。 | |
2120 | 1828 | |
2121 | ||
1829 | Symlabs (netssleay@symlabs.com) | |
1830 | Tel: +351-214.222.630 | |
1831 | Fax: +351-214.222.637 | |
2122 | 1832 | |
2123 | ||
1833 | =head1 VERSION | |
2124 | to the source code) can be found at | |
2125 | L<http://lists.alioth.debian.org/mailman/listinfo/net-ssleay-devel> | |
2126 | 1834 | |
2127 | ||
1835 | (バージョン) | |
2128 | 1836 | |
2129 | (ソースコードに貢献することに興味のある人々のための) | |
2130 | 開発者メーリングリストは | |
2131 | L<http://lists.alioth.debian.org/mailman/listinfo/net-ssleay-devel> に | |
2132 | あります。 | |
2133 | ||
2134 | 1837 | =begin original |
2135 | 1838 | |
2136 | ||
1839 | This man page documents version 1.14, released on 25.3.2002. | |
2137 | 1840 | |
2138 | 1841 | =end original |
2139 | 1842 | |
2140 | この | |
1843 | このmanページ・ドキュメントは バージョン1.14、2002.3.25にリリースされました。 | |
2141 | 1844 | |
2142 | perldoc Net::SSLeay | |
2143 | ||
2144 | 1845 | =begin original |
2145 | 1846 | |
2146 | ||
1847 | There are currently two perl modules for using OpenSSL C | |
1848 | library: Net::SSLeay (maintaned by me) and SSLeay (maintained by OpenSSL | |
1849 | team). This module is the Net::SSLeay variant. | |
2147 | 1850 | |
2148 | 1851 | =end original |
2149 | 1852 | |
2150 | ||
1853 | 現在2つのperlモジュールがOpenSSL Cライブラリを使っています: | |
1854 | Net::SSLeay (私によってメンテされています)とSSLeay(OpenSSLチームにより | |
1855 | メンテされています)。このモジュールはNet::SSLeayの一種です。 | |
2151 | 1856 | |
2152 | = | |
1857 | =begin original | |
2153 | 1858 | |
2154 | ||
1859 | At the time of making this release, Eric's module was still quite | |
1860 | sketchy and could not be used for real work, thus I felt motivated to | |
1861 | make this maintenance release. This module is not planned to evolve to | |
1862 | contain any further functionality, i.e. I will concentrate on just | |
1863 | making a simple SSL connection over TCP socket. Presumably Eric's own | |
1864 | module will offer full SSLeay API one day. | |
2155 | 1865 | |
2156 | ||
1866 | =end original | |
2157 | 1867 | |
2158 | ||
1868 | このリリースを作成している辞典では、Ericのモジュールはまだ非常に不完全で、 | |
1869 | 実務に使うことは出来ませんでした。そのためこのメンテナンス・リリースを作る | |
1870 | 気になりました。このモジュールはさらなる機能を入れるように進化する計画は | |
1871 | ありません。つまり私はTCPソケット越しの単純なSSL接続を作ることだけに | |
1872 | 集中するつもりです。いつか、Eric自身のモジュールがSSLeay APIの全てを提供 | |
1873 | するでしょう。 | |
2159 | 1874 | |
2160 | L<http://cpanratings.perl.org/d/Net-SSLeay> | |
2161 | ||
2162 | =item * Search CPAN | |
2163 | ||
2164 | L<http://search.cpan.org/dist/Net-SSLeay> | |
2165 | ||
2166 | =back | |
2167 | ||
2168 | 1875 | =begin original |
2169 | 1876 | |
2170 | ||
1877 | This module uses OpenSSL-0.9.6c. It does not work with any earlier | |
1878 | version and there is no guarantee that it will work with later | |
1879 | versions either, though as long as C API does not change, it | |
1880 | should. This module requires perl5.005, or 5.6.0 (or better?) though I | |
1881 | believe it would build with any perl5.002 or newer. | |
2171 | 1882 | |
2172 | 1883 | =end original |
2173 | 1884 | |
2174 | ||
1885 | このモジュールはOpenSSL-0.9.6cを使っています。これは前のバージョンでは | |
1886 | 動きません。そしてこの後のバージョンでも動くという保障はありません。 | |
1887 | しかしC APIが変更されない限り、動くはずです。このモジュールはperl5.005 | |
1888 | あるいは5.6.0(それ以上?)を必要とします。しかし私はperl5.002以降でビルド | |
1889 | できると思っています。 | |
2175 | 1890 | |
2176 | Symlabs (netssleay@symlabs.com) | |
2177 | Tel: +351-214.222.630 | |
2178 | Fax: +351-214.222.637 | |
2179 | ||
2180 | 1891 | =head1 AUTHOR |
2181 | 1892 | |
2182 | 1893 | (作者) |
2183 | 1894 | |
2184 | ||
1895 | Sampo Kellomaki <sampo@symlabs.com> | |
2185 | 1896 | |
2186 | ||
1897 | =begin original | |
2187 | 1898 | |
2188 | ||
1899 | Please send bug reports to the above address. General questions should be | |
1900 | sent either to me or to the mailing list (subscribe by sending mail | |
1901 | to openssl-users-request@openssl.org or using web interface at | |
1902 | http://www.openssl.org/support/). | |
2189 | 1903 | |
2190 | ||
1904 | =end original | |
2191 | 1905 | |
2192 | ||
1906 | バグレポートは上記のアドレスの送ってください。一般的な質問は私あるいは | |
1907 | メーリングリスト(openssl-users-request@openssl.org にメールを送るか | |
1908 | http://www.openssl.org/support/ にあるWebインターフェースによって | |
1909 | 参加してください) | |
2193 | 1910 | |
2194 | ||
1911 | =head1 COPYRIGHT | |
2195 | 1912 | |
1913 | Copyright (c) 1996-2002 Sampo Kellomaki <sampo@symlabs.com> | |
2196 | 1914 | All Rights Reserved. |
2197 | 1915 | |
2198 | 1916 | Distribution and use of this module is under the same terms as the |
2199 | 1917 | OpenSSL package itself (i.e. free, but mandatory attribution; NO |
2200 | 1918 | WARRANTY). Please consult LICENSE file in the root of the OpenSSL |
2201 | 1919 | distribution. |
2202 | 1920 | |
2203 | 1921 | While the source distribution of this perl module does not contain |
2204 | 1922 | Eric's or OpenSSL's code, if you use this module you will use OpenSSL |
2205 | 1923 | library. Please give Eric and OpenSSL team credit (as required by |
2206 | 1924 | their licenses). |
2207 | 1925 | |
2208 | 1926 | And remember, you, and nobody else but you, are responsible for |
2209 | 1927 | auditing this module and OpenSSL library for security problems, |
2210 | 1928 | backdoors, and general suitability for your application. |
2211 | 1929 | |
2212 | 1930 | =head1 SEE ALSO |
2213 | 1931 | |
2214 | 1932 | =begin original |
2215 | 1933 | |
2216 | 1934 | Net::SSLeay::Handle - File handle interface |
2217 | ./examples | |
1935 | ./Net_SSLeay/examples - Example servers and a clients | |
1936 | <http://symlabs.com/Net_SSLeay/index.html> - Net::SSLeay.pm home | |
1937 | <http://symlabs.com/Net_SSLeay/smime.html> - Another module using OpenSSL | |
2218 | 1938 | <http://www.openssl.org/> - OpenSSL source, documentation, etc |
2219 | 1939 | openssl-users-request@openssl.org - General OpenSSL mailing list |
2220 | <http:// | |
1940 | <http://home.netscape.com/newsref/std/SSL.html> - SSL Draft specification | |
2221 | 1941 | <http://www.w3c.org> - HTTP specifications |
2222 | 1942 | <http://www.ietf.org/rfc/rfc2617.txt> - How to send password |
2223 | 1943 | <http://www.lothar.com/tech/crypto/> - Entropy Gathering Daemon (EGD) |
2224 | 1944 | <http://www.aet.tu-cottbus.de/personen/jaenicke/postfix_tls/prngd.html> |
2225 | 1945 | - pseudo-random number generating daemon (PRNGD) |
2226 | 1946 | perl(1) |
2227 | 1947 | perlref(1) |
2228 | 1948 | perllol(1) |
2229 | 1949 | perldoc ~openssl/doc/ssl/SSL_CTX_set_verify.pod |
2230 | 1950 | |
2231 | 1951 | =end original |
2232 | 1952 | |
2233 | Net::SSLeay::Handle - ファイルハンドルのインターフェース | |
1953 | Net::SSLeay::Handle - ファイル・ハンドルのインターフェース | |
2234 | ./examples | |
1954 | ./Net_SSLeay/examples - サーバーとクライアントの例 | |
1955 | <http://symlabs.com/Net_SSLeay/index.html> - Net::SSLeay.pm ホーム | |
1956 | <http://symlabs.com/Net_SSLeay/smime.html> - OpenSSLを使っている別のモジュール | |
2235 | 1957 | <http://www.openssl.org/> - OpenSSL ソース、ドキュメントなど |
2236 | openssl-users-request@openssl.org - 一般的な | |
1958 | openssl-users-request@openssl.org - 一般的なOpenSSLメーリングリスト | |
2237 | <http:// | |
1959 | <http://home.netscape.com/newsref/std/SSL.html> - SSL ドラフトの仕様 | |
2238 | <http://www.w3c.org> - HTTP | |
1960 | <http://www.w3c.org> - HTTPの仕様 | |
2239 | 1961 | <http://www.ietf.org/rfc/rfc2617.txt> - パスワードの送信方法 |
2240 | 1962 | <http://www.lothar.com/tech/crypto/> - Entropy Gathering Daemon (EGD) |
2241 | 1963 | <http://www.aet.tu-cottbus.de/personen/jaenicke/postfix_tls/prngd.html> |
2242 | - | |
1964 | - pseudo-random number generating daemon (PRNGD) | |
2243 | 1965 | perl(1) |
2244 | 1966 | perlref(1) |
2245 | 1967 | perllol(1) |
2246 | 1968 | perldoc ~openssl/doc/ssl/SSL_CTX_set_verify.pod |
2247 | ||
2248 | =begin meta | |
2249 | ||
2250 | Translate: hippo2000 | |
2251 | Update: SHIRAKATA Kentaro <argrath@ub32.org> (1.36-) | |
2252 | Status: in progress | |
2253 | ||
2254 | =end meta | |
2255 | 1969 | |
2256 | 1970 | =cut |