sergot / openssl

OpenSSL bindings for Perl 6
MIT License
14 stars 31 forks source link

Can not connect to a TLS only server #22

Closed kalkin closed 8 years ago

kalkin commented 8 years ago

When connecting to a server which only supports ≥ TLS1.0. I get the error: error:1408F10B:SSL routines:SSL3_GET_RECORD:wrong version number. It looks like it tries to use SSLv3, even if the new method is fixed via PR#21 and specific TLS version is given.

See also https://xmpp.net/result.php?domain=jabber.ccc.de&type=client

use OpenSSL;
use Test;

constant $host = <jabber.ccc.de>;
constant $port = 5222;

sub connect($version = -1) {
    my $socket = IO::Socket::INET.new(:$host, :$port);
    my $ssl = OpenSSL.new(:client, :$version);
    is $ssl.set-socket($socket), 0, 'set-socket success';
    $ssl.set-connect-state;
    my $result = $ssl.connect;
    if -1 == $result {
        my $e = OpenSSL::Err::ERR_get_error();
        repeat {
            diag "\n err code: $e";
            diag OpenSSL::Err::ERR_error_string($e, Str);
            $e = OpenSSL::Err::ERR_get_error();
        } while $e != 0 && $e != 4294967296;
    }
    $ssl.close;
    $socket.close;
    is $result, 1;
}

plan 8;
connect();
connect(1);
connect(1.1);
connect(1.2);
kalkin commented 8 years ago

Not a bug. I first need to negotiate the encryption via StartTLS. Connecting to the legacy ssl port 5223 works flawlessly.