しゃある通信

#08-01 [perl,hack]Net::SSL::ExpireDate にタイムアウトできるオプションを追加

Net::SSL::ExpireDate 1.00 - (ひ)メモ
とまあ、便利なモジュールがあるもので、ありがたく利用させていただこうかと。

で、このモジュールを使ったスクリプトをふにふにと書いてみたら、あらまあ、タイムアウトができないわ。ってことで ad hoc patch 作成。

--- Net-SSL-ExpireDate-1.08/lib/Net/SSL/ExpireDate.pm.orig      2010-11-08 18:19:23.000000000 +0900
+++ Net-SSL-ExpireDate-1.08/lib/Net/SSL/ExpireDate.pm   2010-11-08 18:20:17.000000000 +0900
@@ -61,6 +61,7 @@
         type        => undef,
         target      => undef,
         expire_date => undef,
+        timeout     => undef,
        }, $class;

     if ( $opt{https} or $opt{ssl} ) {
@@ -75,6 +76,9 @@
     } else {
         croak "missing option: neither ssl nor file";
     }
+    if ($opt{timeout}) {
+        $self->{timeout} = $opt{timeout};
+    }

     return $self;
 }
@@ -88,7 +92,7 @@
             $port ||= 443;
             ### $host
             ### $port
-            my $cert = _peer_certificate($host, $port);
+            my $cert = _peer_certificate($host, $port, $self->{timeout});
             my $x509 = Crypt::OpenSSL::X509->new_from_string($cert, FORMAT_ASN1);
             my $begin_date_str  = $x509->notBefore;
             my $expire_date_str = $x509->notAfter;
@@ -140,7 +144,7 @@
 }

 sub _peer_certificate {
-    my($host, $port) = @_;
+    my($host, $port, $timeout) = @_;

     my $cert;

@@ -167,6 +171,7 @@
         PeerAddr => $host,
         PeerPort => $port,
         Proto    => 'tcp',
+        Timeout  => $timeout,
     };

     $sock = $Socket->new( %$sock ) or croak "cannot create socket: $!";
見ればわかるように無理やりですねこのパッチ(苦笑)

これでめでたくタイムアウトするようになった。

追記:

というやりとりが。速攻取り込まれました(笑) http://search.cpan.org/dist/Net-SSL-ExpireDate/



マクロミルへ登録

© 2010 Kazuya 'Sharl' Masuda
(C)Willoo Entertainment Inc. (C)Konami Digital Entertainment 株式会社ウィローエンターテイメント及び株式会社コナミデジタルエンタテインメントの著作権を侵害する行為は禁止されています。 0.004769 cached