Skip to content

Commit 968d421

Browse files
committed
Add support for certfp in connection instance
1 parent c5cce73 commit 968d421

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

src/irc/ConnectionInstance.ts

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ function logError(err: Error) {
6161
export interface ConnectionOpts {
6262
localAddress?: string;
6363
password?: string;
64+
certificate?: { cert: string, key: string};
6465
realname: string;
6566
username?: string;
6667
nick: string;
@@ -404,6 +405,25 @@ export class ConnectionInstance {
404405
if (!opts.nick || !server) {
405406
throw new Error("Bad inputs. Nick: " + opts.nick);
406407
}
408+
409+
let saslType: undefined|"PLAIN"|"EXTERNAL";
410+
if (server.useSasl() && opts.password) {
411+
saslType = "PLAIN";
412+
}
413+
else if (server.useSasl() && opts.certificate) {
414+
saslType = "EXTERNAL";
415+
}
416+
417+
const secure = server.useSsl() ? server.getSecureOptions() : undefined;
418+
if (secure && opts.certificate) {
419+
secure.requestCert = true;
420+
secure.cert = opts.certificate.cert;
421+
secure.key = opts.certificate.key;
422+
saslType = "EXTERNAL";
423+
}
424+
425+
console.log("secure:", secure, saslType);
426+
407427
const connectionOpts: IrcClientOpts = {
408428
userName: opts.username,
409429
realName: opts.realname,
@@ -420,7 +440,8 @@ export class ConnectionInstance {
420440
family: (server.getIpv6Prefix() || server.getIpv6Only() ? 6 : null) as 6|null,
421441
bustRfc3484: true,
422442
sasl: opts.password ? server.useSasl() : false,
423-
secure: server.useSsl() ? server.getSecureOptions() : undefined,
443+
saslType: saslType,
444+
secure: secure,
424445
encodingFallback: opts.encodingFallback,
425446
};
426447

0 commit comments

Comments
 (0)