aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authoreater <hello@eaterofco.de>2017-08-13 18:19:51 +0200
committereater <hello@eaterofco.de>2017-08-13 18:19:51 +0200
commitbf3b492f3eda79a5b492a87750b26d4228777601 (patch)
treeb433e6d31341be5066603c44901cc5a56b3d50a9 /lib
parentae1a1b9df8a4a5aa2ac24797cb2795bae811ac56 (diff)
Add SSL support
Diffstat (limited to 'lib')
-rw-r--r--lib/IRC/Client.pm617
-rw-r--r--lib/IRC/Client/Server.pm62
2 files changed, 17 insertions, 2 deletions
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<nick> // %all-conf<nick>) ],
:alias[ |($conf<alias> // %all-conf<alias>) ],
|%(
- <host password port username userhost userreal>
+ <host password port username userhost userreal ssl ca-file>
.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;