From bf3b492f3eda79a5b492a87750b26d4228777601 Mon Sep 17 00:00:00 2001 From: eater Date: Sun, 13 Aug 2017 18:19:51 +0200 Subject: Add SSL support --- META6.json | 1 + lib/IRC/Client.pm6 | 17 +++++++++++++++-- lib/IRC/Client/Server.pm6 | 2 ++ 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/META6.json b/META6.json index 40f461e..4042d2f 100644 --- a/META6.json +++ b/META6.json @@ -6,6 +6,7 @@ "description" : "Extendable Internet Relay Chat client", "tags" : [ "Net", "IRC" ], "depends" : [ + "IO::Socket::Async::SSL" ], "test-depends" : [ "Test", diff --git a/lib/IRC/Client.pm6 b/lib/IRC/Client.pm6 index 400a326..db1b4d4 100644 --- a/lib/IRC/Client.pm6 +++ b/lib/IRC/Client.pm6 @@ -1,5 +1,7 @@ unit class IRC::Client; +use IO::Socket::Async::SSL; + use IRC::Client::Message; use IRC::Client::Grammar; use IRC::Client::Server; @@ -34,6 +36,8 @@ submethod BUILD ( Str:D :$host = 'localhost', :$nick = ['P6Bot'], :$alias = [], + Bool:D :$ssl = False, + Str :$ca-file, Str:D :$username = 'Perl6IRC', Str:D :$userhost = 'localhost', Str:D :$userreal = 'Perl6 IRC Client', @@ -56,7 +60,7 @@ submethod BUILD ( :nick[ |($conf // %all-conf) ], :alias[ |($conf // %all-conf) ], |%( - + .map: { $_ => $conf{$_} // %all-conf{$_} } ), ); @@ -168,7 +172,16 @@ method !change-nick ($server) { method !connect-socket ($server) { $!debug and debug-print 'Attempting to connect to server', :out, :$server; - IO::Socket::Async.connect($server.host, $server.port).then: sub ($prom) { + + my $socket; + + if ($server.ssl) { + $socket = IO::Socket::Async::SSL.connect($server.host, $server.port, ca-file => $server.ca-file); + } else { + $socket = IO::Socket::Async.connect($server.host, $server.port); + } + + $socket.then: sub ($prom) { if $prom.status ~~ Broken { $server.is-connected = False; $!debug and debug-print 'Could not connect', :out, :$server; diff --git a/lib/IRC/Client/Server.pm6 b/lib/IRC/Client/Server.pm6 index 2ed5d69..2952869 100644 --- a/lib/IRC/Client/Server.pm6 +++ b/lib/IRC/Client/Server.pm6 @@ -4,6 +4,8 @@ has @.channels where .all ~~ Str|Pair; has @.nick where .all ~~ Str; has @.alias where .all ~~ Str|Regex; has Int $.port where 0 <= $_ <= 65535; +has Bool $.ssl; +has Str $.ca-file; has Str $.label; has Str $.host; has Str $.password; -- cgit v1.1