2014-01-23 27 views

回答

1

有參與TLS

  • 證書
  • 主要用於對稱加密的TLS連接

下面的代碼應該給你內外的公共密鑰幾個按鍵,用於對稱加密的公鑰和密碼的位。密碼是作爲所用算法的字符串給出的,有效密鑰長度取決於算法。使用公共密鑰它是相似的,例如只要使用相同的算法,您可以比較密鑰長度,但在比較RSA和橢圓曲線時,不能簡單比較密鑰長度。

use strict; 
use warnings; 
use IO::Socket::SSL; 

my $cl = IO::Socket::SSL->new('www.google.com:443') or die $!; 
my $cipher = $cl->get_cipher; 
my $issuer = $cl->peer_certificate('issuer'); 
my $pkey = Net::SSLeay::X509_get_pubkey($cl->peer_certificate); 
my $bits = Net::SSLeay::EVP_PKEY_bits($pkey); 
my $pkey_type = Net::SSLeay::OBJ_nid2sn(Net::SSLeay::EVP_PKEY_id($pkey)); 

print "cipher: $cipher\n"; 
print "cert: issuer=$issuer pkey=$pkey_type/$bits\n"; 

對於我這個代碼返回:

cipher: ECDHE-RSA-RC4-SHA 
cert: issuer=/C=US/O=Google Inc/CN=Google Internet Authority G2 pkey=rsaEncryption/2048 

如果您需要檢查很多的網站在很短的時間,你可以通過使用非阻塞的TCP加速代碼連接起來,後來不阻止SSL握手,從而並行處理多個目標。在這種情況下請參考IO :: Socket :: INET和IO :: Socket :: SSL的文檔。

0

你可以在Net::SSLeay使用VERIFY_PEER回調。

use Net::SSLeay; 
use Data::Dumper; 
use strict; 

# install the VERIFY callback 
Net::SSLeay::set_verify ($ssl, Net::SSLeay::VERIFY_PEER, sub { 
    # get out what you want here 
    # (this is just an example to allow you to see what's available) 
    print Dumper(\@_); 
}); 

# make an HTTPS request 
my ($page) = get_https('www.example.com', 443, '/'); 

看看你給了什麼。 Net :: SSLeay還從OpenSSL實現了一組類型特定的證書API,因此您可以查看很多內容。

Dumper行更改爲您想要拔出的任何內容。這樣做

my @domains; 
Net::SSLeay::set_verify ($ssl, Net::SSLeay::VERIFY_PEER, sub { 
    push @domains, { 
    somekey  => $_[0]->{somekey}, 
    someotherkey => $_[0]->{someotherkey} 
    } 
}); 

在任何情況下,只是把調用get_https在進入函數並調用它域的陣列中的每個元素進行檢查。

您可能希望使用Parallel::ForkManager來分離多個進程以同時驗證您的列表項。