# Net::SSLeay
๐ฆ max
Net::SSLeay - ืืจืืืืช Perl ืึพlibssl ืืึพlibcrypto ืฉื OpenSSL.
ืืืืืจื TLS, ืชืขืืืืช, ืืคืชืืืช, digests ืืฉืืจ OpenSSL, ืคืื ืงืฆืืืช Perl ืืืช ืืื ืคืื ืงืฆืืืช C: `Net::SSLeay::CTX_new` ืืื `SSL_CTX_new`, ืึพ`Net::SSLeay::X509_get_subject_name` ืืื `X509_get_subject_name`, ืขื ืืืชื ืืจืืืื ืืื, ืขืจืื ืืืืจื ืืงืืืขืื. ืขืฆืืื ืืืขืืจืื ืืืกืคืจืื ืฉืืืื ืคืฉืืืื (ืืฆืืืขื ืึพC) ืืืฉืืืจืจืื ืืืคืืจืฉ, ืืื ืึพC. ืจืื ืืชืืื ืืืช ืืฉืชืืฉืืช ืื ืืจื IO::Socket::SSL ืื AnyEvent::TLS, ืืื ืืืื ืขืืื; ืืฉืชืืฉืื ืื ืืฉืืจืืช ืขืืืจ ืื ืฉืื ืืื ื ืืืฉืคืื.
ืืื Net::SSLeay 1.96: ืื 709 ืืคืื ืงืฆืืืช ืึพ769 ืืงืืืขืื ืฉื ืืืคืฆื ืึพCPAN, ืืืฆื ืึพPerl ืฉืื (`Net/SSLeay.pm`, `Net/SSLeay/Handle.pm`) ืืื ืฉืื ืื. ืืฉืื ืฉืื ืคืื ืงืฆืื ืืื ืืชึพืืฉื ืฉืื ืึพC, ืืคื ืืืืจืื ืฉื OpenSSL (`man SSL_CTX_new`) ืืชืืจืื ืื ืืื ืขืืฉื; ืืกืงืืจื ืฉืืืื ืืืืจืช ืืืื ืืืคืฉ.
## ืืจืืฉืืช
OpenSSL 3.0 ืืืขืื, ืืชืืจ `libssl.so.3` ืึพ`libcrypto.so.3`, ืื ืืขื ืืช ืืืฉืจ ืืืืืื ื ืืขื: ืืืจ ืืื ื ืืงืืฉืจ ืืชืื pperl. ืืืขืืืื `use Net::SSLeay` ืขืืฉื die ืื ืืงื ืืฉื ืืืืืื ืฉืืฉ ืืืชืงืื. ืืืืืื ืืื ืืืง ืืืื ืืื `native-max`.
## ืชืงืฆืืจ
ืื ืืฉื, ืืืขื ืืชืคืืื ืืืืืขืช ืืืฆืืข ืฉื ืชืขืืื - ืืื ืฆืืจื ืืจืฉืช:
```perl
use Net::SSLeay;
my $bio = Net::SSLeay::BIO_new_file('cert.pem', 'r') or die "cert.pem: $!";
my $x509 = Net::SSLeay::PEM_read_bio_X509($bio);
Net::SSLeay::BIO_free($bio);
print Net::SSLeay::X509_NAME_oneline(Net::SSLeay::X509_get_subject_name($x509)), "\n";
print Net::SSLeay::P_ASN1_TIME_get_isotime(Net::SSLeay::X509_get_notAfter($x509)), "\n";
print unpack('H*', Net::SSLeay::X509_digest($x509,
Net::SSLeay::EVP_get_digestbyname('sha256'))), "\n";
Net::SSLeay::X509_free($x509);
```
ืืงืื TLS ืืขื ืกืืงื ืืฉืืื:
```perl
use Socket;
use Net::SSLeay qw(die_now die_if_ssl_error);
my ($host, $port) = ('example.com', 443);
Net::SSLeay::initialize();
socket(my $sock, PF_INET, SOCK_STREAM, getprotobyname('tcp')) or die "socket: $!";
connect($sock, sockaddr_in($port, inet_aton($host))) or die "connect: $!";
my $ctx = Net::SSLeay::CTX_new() or die_now("CTX_new: $!");
Net::SSLeay::CTX_set_options($ctx, Net::SSLeay::OP_ALL());
my $ssl = Net::SSLeay::new($ctx) or die_now("new: $!");
Net::SSLeay::set_tlsext_host_name($ssl, $host); # SNI
Net::SSLeay::set_fd($ssl, fileno $sock);
Net::SSLeay::connect($ssl) == 1 or die_if_ssl_error('connect');
print 'cipher: ', Net::SSLeay::get_cipher($ssl), "\n";
Net::SSLeay::write($ssl, "GET / HTTP/1.0\r\nHost: $host\r\n\r\n");
my $reply = '';
while (defined(my $chunk = Net::SSLeay::read($ssl))) {
last unless length $chunk;
$reply .= $chunk;
}
Net::SSLeay::free($ssl);
Net::SSLeay::CTX_free($ctx);
```
ืืงืื ืื ืืื ื ืืืืช ืืช ืชืขืืืช ืืฉืจืช. ืืื ืืขืฉืืช ืืืช, ืืคื ื `connect`:
```perl
Net::SSLeay::CTX_set_default_verify_paths($ctx); # the system's CAs
Net::SSLeay::set_verify($ssl, Net::SSLeay::VERIFY_PEER(), undef);
Net::SSLeay::X509_VERIFY_PARAM_set1_host(Net::SSLeay::get0_param($ssl), $host);
```
`connect` ื ืืฉืืช ืื ืขืืืจ ืชืขืืื ืฉืืื ื ืืฉืชืจืฉืจืช ืึพCA ืืืืื ืื ืฉืืื ื ื ืืงืืช ืืฉื `$host`. IO::Socket::SSL ืขืืฉื ืืช ืื ืื ืืืจืืจืช ืืืื.
## ืืคืื ืงืฆืืืช, ืืคื ืืฉืคืื
ืืฉื ืืืืจ ืขื ืืืื ืขืฆื C ืืคืื ืงืฆืื ืคืืขืืช; ืืื ืฉื ืคืื ืงืฆืืืช ืึพC ืืื ืืงืืืืืช ืฉืืืืชื ืื (`SSL_`, ืืืคืขืืื `SSL_CTX_` ืืืคื ืึพ`CTX_`), ืืืช ืคืื ืงืฆืืืช ืึพC ืืื ืืฉ ืืืคืฉ ืืืืจืื ืฉื OpenSSL.
- **ืืงืฉืจืื** - `CTX_*` (112): `CTX_new`, ืืจืกืืืช ืืคืจืืืืงืื, ืืฆืคื ืื, ืืชืขืืืืช ืืืืคืชืืืช ืฉืืงืฉืจ ืืฆืืข, ืืืืืช, ืกืฉื ืื, ืืื callback (`CTX_set_verify`, `CTX_set_alpn_select_cb`, `CTX_set_tlsext_servername_callback`).
- **ืืืืืจืื** - ืคืื ืงืฆืืืช ืืื ืงืืืืืช: `new`, `set_fd`, `connect`, `accept`, `read`, `write`, `shutdown`, `free`, ืืืชืืืืช ืืืืฉื `get_*`/`set_*` ืฉื ืืืืืจ (`get_peer_certificate`, `get_cipher`, `set_tlsext_host_name`).
- **ืกืฉื ืื** - `SESSION_*`, `get_session`, `set_session`.
- **ืชืขืืืืช** - `X509_*` (162): ืฉืืืช, ืืจืืืืช, ืืืืจืื ืืืืืืช, ืจืฉืืืืช CRL, ืืงืฉืืช; `P_X509_*` ืื ืคืื ืงืฆืืืช ืขืืจ ืฉื Net::SSLeay ืขืฆืื ืฉืืืืืจืืช ืจืฉืืืืช Perl (`P_X509_get_crl_distribution_points`, `P_X509_get_ext_key_usage`).
- **ืืคืชืืืช ืึพdigests** - `EVP_*`, `RSA_*`, `EC_*`, `BN_*`; ืึพ`RAND_*` ืืืชืื ืืงืจืืืื.
- **ืงืืฆืื ืืงืืืืืื** - `PEM_*`, ืืคืื ืงืฆืืืช `d2i_*`/`i2d_*` ืฉื DER, ืืคืื ืงืฆืืืช `BIO_*` ืืืืฆืฆื ืืืืจืื ืืงืืฆืื, ืืืคืื ืงืฆืืืช `ASN1_*` ืึพ`P_ASN1_*` ืืืื ืื ืืืืกืคืจืื ืฉืืืื.
- **ืฉืืืืืช** - `ERR_get_error`, `ERR_error_string`, ืึพ`die_now`, `die_if_ssl_error` ืึพ`print_errs` ืฉื ืืืืืื.
- **ืืฉืืจ** - `OCSP_*`, `OBJ_*`, `OSSL_PROVIDER_*`, ืึพ`OPENSSL_*` ืืืจืกื ืืืืชืืื.
ืื ืืงืืืขืื ืื ืคืื ืงืฆืืืช, ืื ืงืจืืืช ืืื ืงืืืืืช ืึพC ืฉืืื: `Net::SSLeay::VERIFY_PEER()`, `Net::SSLeay::OP_ALL()`, `Net::SSLeay::ERROR_WANT_READ()`.
## ืืชืื ืึพPerl
`Net/SSLeay.pm` ืืืกืืฃ ืคืื ืงืฆืืืช ืขืืจ ืืืงืฉื ืฉืืื: `get_https`, `post_https`, `sslcat`, `make_headers`, `make_form`, ืืืช `Net::SSLeay::Handle`, ืืืคื ืงืืืฅ ืงืฉืืจ ืืขื ืืืืืจ.
```perl
my ($page, $response, %headers) = Net::SSLeay::get_https('example.com', 443, '/');
```
## ืืืืืื ืึพupstream
- ืืืื ืคืื ืงืฆืืืช ืงืืืืืช ื ืงืืข ืืคื ืึพOpenSSL ืืืขืื, ืื ืืคื ืื ืฉืืืืืื ืืืืจ ืืืื. ืึพupstream ืืืืจ ืคืื ืงืฆืื ืจืง ืขืืืจ OpenSSL ืฉืืฉ ืื ืืช ืืชืืื ื ืฉืื; ืืื ืคืื ืงืฆืื ืืืืืจืช ืจืง ืืืฉืจ ืืกืคืจืืื ืืืขืื ื ืืฉ ืื ืคืื ืงืฆืืืช C ืฉืืื ืฆืจืืื - ืืืื `defined &Net::SSLeay::client_hello_get_extension_order` ืืื ืฉืงืจ ืชืืช OpenSSL 3.0 ืึพ3.1, ืืคื ืฉืืื ืขืืืจ Net::SSLeay ืฉื ืื ื ืฉื (t/81-xs-native/Net-SSLeay/660-xsub-set-follows-openssl.t). ืขื ืึพOpenSSL ืฉื ืืืืื ื ืืื ืืืื ืงืืืฆืช 709 ืืคืื ืงืฆืืืช ืฉื ืึพupstream (600-xsub-set.t).
- ืืคืื ืงืฆืืืช ืฉึพOpenSSL ืืืื ืืกืคืง ืจืง ืืืฉืจ ืืื ื ืื ื ืขื ืืคืฉืจืืืืช ืืืืืืืช ืืืจืืจืช ืืืื (MD2, ืืชืืืืช SSLv3) ืืื ื ืืกืืคืงืืช, ืืืื ืึพOpenSSL ืืืขืื ืืฉืจ ืืืื.
- OpenSSL ืฉืงืืื ืึพ3.0 ืึพLibreSSL ืืื ื ื ืชืืืื; ืึพupstream ื ืื ื ืื ืืืื.
- `RAND_bytes`, `RAND_priv_bytes` and `RAND_pseudo_bytes` with a
negative count return 0 and leave the buffer empty, where perl exits
โOut of memoryโ (670-or-better.t).
## ืืืืืืื
- [`Net::SSLeay::Handle`](SSLeay/Handle.md) - ืืืืื Perl ืฉืืืคืฉืจ ืืืคื ืืกืืงืืื ืฉื SSL (ืืืืืจ HTTPS) ืืื ืืืืคืื ืงืืฆืื ืจืืืืื.