Last active
August 29, 2015 14:05
-
-
Save peschwa/c60c1c06a96781418d27 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ perl6 -Ilib -I../openssl/lib/ github.pl6 | |
err code: 4631097625 | |
error:1408F119:SSL routines:SSL3_GET_RECORD:decryption failed or bad record mac | |
$ cat github.pl6 | |
use IO::Socket::SSL; | |
my $ssl = IO::Socket::SSL.new(:host<github.com>, :port(443)); | |
my $content = Buf.new; | |
$ssl.send("GET /\r\n\r\n"); | |
while my $read = $ssl.recv(1024) { | |
$content ~= $read; | |
} | |
$ perl6 --version | |
This is perl6 version 2014.07-153-g0c42c11 built on MoarVM version 2014.07-365-g29d2e7b |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ perl6 | |
> use IO::Socket::SSL | |
> my $sock = IO::Socket::SSL.new(:host<google.com>, :port(443)) | |
IO::Socket::SSL.new(encoding => "utf8", host => "google.com", port => 443, localhost => Str, localport => Int, certfile => Str, listen => Bool, input-line-separator => "\n", ins => 0, fd => 10, ssl => OpenSSL.new(ctx => SSL_CTX.new(method => SSL_METHOD.new(version => 769)), ssl => SSL.new(version => 769, type => 4096, method => SSL_METHOD.new(version => 769), rbio => BIO.new(method => BIO_METHOD.new(type => 1285, name => "socket"), cb_arg => Str, init => 0, shutdown => 1, flags => 0, retry_reason => 0, num => 0, ptr => OpaquePointer.new(10), next_bio => BIO, prev_bio => BIO, references => 0, num_read => 19181323943937, num_write => 353), wbio => BIO.new(method => BIO_METHOD.new(type => 1285, name => "socket"), cb_arg => Str, init => 0, shutdown => 1, flags => 0, retry_reason => 0, num => 0, ptr => OpaquePointer.new(10), next_bio => BIO, prev_bio => BIO, references => 0, num_read => 19181323943937, num_write => 353), bbio => BIO, rwstate => 1, in_handshake => 0, handshake_func => OpaquePointer.new(-1279529744), server => 0, new_session => 0, quiet_shutdown => 0, shutdown => 0, state => 3, rstate => 240), client => Bool::True)) | |
> my $othersock = IO::Socket::SSL.new(:host<github.com>, :port(443)) | |
Segmentation fault | |
$ perl6 --version | |
This is perl6 version 2014.07-157-g42dfe38 built on MoarVM version 2014.07-365-g29d2e7b | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ cat github.pl6 | |
use v6; | |
use IO::Socket::SSL; | |
my $ssl = IO::Socket::SSL.new(:host<github.com>, :port(443)); | |
my $content = Buf.new; | |
$ssl.send("GET /\r\n\r\n"); | |
while my $read = $ssl.recv { | |
$content ~= $read; | |
} | |
say $content; | |
psch@debvm:~/rakudo$ perl6 github.pl6 | |
Buf:0x<> | |
psch@debvm:~/rakudo$ perl6 --version | |
This is perl6 version 2014.07-157-g42dfe38 built on MoarVM version 2014.07-365-g29d2e7b |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/lib/IO/Socket/SSL.pm6 b/lib/IO/Socket/SSL.pm6 | |
index 29c9088..b995382 100644 | |
--- a/lib/IO/Socket/SSL.pm6 | |
+++ b/lib/IO/Socket/SSL.pm6 | |
@@ -2,6 +2,8 @@ class IO::Socket::SSL; | |
use NativeCall; | |
use OpenSSL; | |
+use OpenSSL::SSL; | |
+use OpenSSL::Err; | |
use libclient; | |
@@ -74,7 +76,15 @@ method !initialize { | |
$!ssl = OpenSSL.new(:client); | |
$!ssl.set-fd($!fd); | |
$!ssl.set-connect-state; | |
- $!ssl.connect; | |
+ my $ret = $!ssl.connect; | |
+ if $ret < 0 { | |
+ my $e = OpenSSL::Err::ERR_get_error(); | |
+ repeat { | |
+ say "err code: $e"; | |
+ say OpenSSL::Err::ERR_error_string($e); | |
+ $e = OpenSSL::Err::ERR_get_error(); | |
+ } while $e != 0 && $e != 4294967296; | |
+ } | |
} | |
else { | |
die "Failed to connect"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ git diff origin/HEAD | |
diff --git a/lib/OpenSSL/Err.pm6 b/lib/OpenSSL/Err.pm6 | |
new file mode 100644 | |
index 0000000..712a54e | |
--- /dev/null | |
+++ b/lib/OpenSSL/Err.pm6 | |
@@ -0,0 +1,8 @@ | |
+module OpenSSL::Err; | |
+ | |
+use NativeCall; | |
+ | |
+our sub ERR_error_string(Int $e) returns Str is native('libssl') {*}; | |
+ | |
+our sub ERR_get_error() returns Int is native('libssl') {*}; | |
+ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment