1 # NOTE: Derived from blib/lib/Net/SSLeay.pm.
2 # Changes made here will be lost when autosplit is run again.
6 #line 2167 "blib/lib/Net/SSLeay.pm (autosplit into blib/lib/auto/Net/SSLeay/sslcat.al)"
8 ### Basic request - response primitive (don't use for https)
11 sub sslcat { # address, port, message, $crt, $key --> reply / (reply,errs,cert)
12 my ($dest_serv, $port, $out_message, $crt_path, $key_path) = @_;
13 my ($ctx, $ssl, $got, $errs, $written);
15 ($got, $errs) = open_proxy_tcp_connection($dest_serv, $port);
16 return (wantarray ? (undef, $errs) : undef) unless $got;
18 ### Do SSL negotiation stuff
20 warn "Creating SSL $ssl_version context...\n" if $trace>2;
21 load_error_strings(); # Some bloat, but I'm after ease of use
22 SSLeay_add_ssl_algorithms(); # and debuggability.
26 goto cleanup2 if $errs = print_errs('CTX_new') or !$ctx;
28 CTX_set_options($ctx, &OP_ALL);
29 goto cleanup2 if $errs = print_errs('CTX_set_options');
31 warn "Cert `$crt_path' given without key" if $crt_path && !$key_path;
32 set_cert_and_key($ctx, $crt_path, $key_path) if $crt_path;
34 warn "Creating SSL connection (context was '$ctx')...\n" if $trace>2;
36 goto cleanup if $errs = print_errs('SSL_new') or !$ssl;
38 warn "Setting fd (ctx $ctx, con $ssl)...\n" if $trace>2;
39 set_fd($ssl, fileno(SSLCAT_S));
40 goto cleanup if $errs = print_errs('set_fd');
42 warn "Entering SSL negotiation phase...\n" if $trace>2;
47 my $cipher_list = 'Cipher list: ';
48 $p=Net::SSLeay::get_cipher_list($ssl,$i);
49 $cipher_list .= $p if $p;
52 $cipher_list .= ', ' . $p if $p;
53 $p=Net::SSLeay::get_cipher_list($ssl,$i);
59 $got = Net::SSLeay::connect($ssl);
60 warn "SSLeay connect returned $got\n" if $trace>2;
61 goto cleanup if $errs = print_errs('SSL_connect');
63 my $server_cert = get_peer_certificate($ssl);
64 print_errs('get_peer_certificate');
66 warn "Cipher `" . get_cipher($ssl) . "'\n";
67 print_errs('get_ciper');
68 warn dump_peer_certificate($ssl);
71 ### Connected. Exchange some data (doing repeated tries if necessary).
73 warn "sslcat $$: sending " . blength($out_message) . " bytes...\n"
75 warn "sslcat $$: sending `$out_message' (" . blength($out_message)
76 . " bytes)...\n" if $trace>3;
77 ($written, $errs) = ssl_write_all($ssl, $out_message);
78 goto cleanup unless $written;
80 sleep $slowly if $slowly; # Closing too soon can abort broken servers
81 CORE::shutdown SSLCAT_S, 1; # Half close --> No more output, send EOF to server
83 warn "waiting for reply...\n" if $trace>2;
84 ($got, $errs) = ssl_read_all($ssl);
85 warn "Got " . blength($got) . " bytes.\n" if $trace==3;
86 warn "Got `$got' (" . blength($got) . " bytes)\n" if $trace>3;
90 $errs .= print_errs('SSL_free');
93 $errs .= print_errs('CTX_free');
95 return wantarray ? ($got, $errs, $server_cert) : $got;
98 # end of Net::SSLeay::sslcat