Skip to content

Commit 89b77f7

Browse files
committed
fix: unable to connect on servers with self-signed certificates
1 parent 5c1ec53 commit 89b77f7

13 files changed

+146
-92
lines changed

CHANGELOG.md

+16-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,20 @@
11
# Changelog
2-
## [Unreleased](https://github.com/jipaix/xdccjs/tree/main)
3-
### Chore(dev-deps)
4-
* updating dev-dependencies to their latest version
2+
## [v4.5.0](https://github.com/jipaix/xdccjs/tree/v4.5.0)
3+
### Fix(lib+cli)
4+
* add option to allow/reject connection on TLS enabled server with self-signed certificates
5+
* CLI user can use the `--no-insecure` option to enable this feature.
6+
### BREAKING CHANGES (cli)
7+
* remove parameter `--no-secure` that allowed downloads if the bot's name did not match the requested
8+
* add parameter `--bot-name-match` to block downloads if bot's name does not match the requested
9+
### BREAKING CHANGES (lib)
10+
* renamed parameter `secure` to `botNameMatch` to avoid confusion with `tls`
11+
* optional parameter **`tls` is no longer a boolean**
12+
```js
13+
params.tls = {
14+
enable: false, // required
15+
rejectUnauthorized: false // optional - default false
16+
}
17+
```
518
---
619
## [v4.4.21](https://github.com/jipaix/xdccjs/tree/v4.4.21)
720
### Feat(lib)

README.md

+22-18
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,10 @@ Every parameter is optional, except for `host`.
7373
const opts = {
7474
host: 'irc.server.net', // IRC hostname - required
7575
port: 6660, // IRC port - default: 6667
76-
tls: false, // Enable SSL/TLS Support - default false
76+
tls: {
77+
enable: true, // Enable TLS Support - default: false
78+
rejectUnauthorized: true, // Reject self-signed certificates - default: false
79+
},
7780
nickname: 'ItsMeJiPaix', // Nickname - default: xdccJS + random
7881
chan: ['#candy', '#fruits'], // Array of channels - default : [ ]
7982
path: 'downloads', // Download path or 'false' - default: false (which enables piping)
@@ -82,7 +85,7 @@ const opts = {
8285
verbose: true, // Display download progress and jobs status - default: false
8386
randomizeNick: false, // Add random numbers at end of nickname - default: true
8487
passivePort: [5000, 5001, 5002], // Array of port(s) to use with Passive DCC - default: [5001]
85-
secure: false, // Allow/Deny files sent by bot with different name than the one requested - default: true
88+
botNameMatch: false, // Block downloads if the bot's name does not match the request - default: true
8689
}
8790
```
8891
### Download
@@ -290,26 +293,27 @@ npm install xdccjs -g
290293
## Options
291294
```
292295
Options:
293-
-V, --version output the version number
296+
-V, --version Output the version number
294297
-h, --host <server> IRC server hostname
295298
--port <number> IRC server port
296299
--tls Enable SSL/TLS Support
297-
-b, --bot <botname> xdcc bot nickname
298-
-d, --download <packs...> pack number(s) to download
299-
-p, --path <path> download path
300-
-n, --nickname <nickname> Your IRC nickname
301-
-c, --channel [chan...] channel(s) to join (without #)
302-
-r, --retry <number> number of attempts before skipping pack
303-
-q, --quiet disable console output
304-
--passive-port <number> port used for passive dccs
300+
--allow-insecure Allow self-signed certificate (tls needs to be enabled)
301+
-b, --bot <botname> XDCC bot nickname
302+
-d, --download <packs...> Pack number(s) to download
303+
-p, --path <path> Download path
304+
-n, --nickname <nickname> Your nickname
305+
-c, --channel [chan...] Channel(s) to join (without #)
306+
-r, --retry <number> Number of attempts before skipping pack
307+
-q, --quiet Disable console output
308+
--passive-port <number> Port used for passive dccs
305309
--no-randomize Disable nickname randomization
306-
-w, --wait [number] wait time (in seconds) in channel(s) before sending download request (default: 0)
307-
--no-secure Allow files sent by bot with different name than the one requested
308-
--save-profile [string] save current options as a profile
309-
--delete-profile [string] delete profile
310-
--set-profile [string] set profile as default
311-
--list-profile list all available profiles
312-
--help display help for command
310+
-w, --wait [number] Wait time (in seconds) in channel(s) before sending download request (default: 0)
311+
--botNameMatch Block downloads if the bot's name does not match the request
312+
--save-profile [string] Save current options as a profile
313+
--delete-profile [string] Delete profile
314+
--set-profile [string] Set profile as default
315+
--list-profile List all available profiles
316+
--help Display help for command
313317
```
314318
## Usage
315319
```bash

docs/assets/search.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/classes/Job.html

+3-3
Large diffs are not rendered by default.

docs/classes/default.html

+3-3
Large diffs are not rendered by default.

docs/index.html

+14-14
Large diffs are not rendered by default.

docs/interfaces/Candidate.html

+8-8
Large diffs are not rendered by default.

docs/interfaces/Params.html

+24-17
Large diffs are not rendered by default.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "xdccjs",
3-
"version": "4.4.21",
3+
"version": "4.5.0",
44
"description": "download files from XDCC bots on IRC, complete implementation of the XDCC protocol",
55
"engines": {
66
"node": ">=14.0.0"

src/bin/commander.ts

+10-5
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export interface InterfaceCLI extends commander.Command {
1414
host?: string
1515
port?: number
1616
tls?: boolean
17+
noInsecure?: boolean
1718
bot?: string
1819
download?: string[]
1920
path?: string
@@ -22,7 +23,7 @@ export interface InterfaceCLI extends commander.Command {
2223
retry?: number
2324
passivePort?: number
2425
randomize?: boolean
25-
secure?: boolean
26+
botNameMatch?: boolean
2627
wait?: number
2728
quiet?: boolean
2829
saveProfile?: string
@@ -45,8 +46,9 @@ export class BaseCommander {
4546
.name('xdccJS')
4647
.version(version)
4748
.option('-h, --host <server>', 'IRC server hostname')
48-
.option('--port <number>', 'IRC server port')
49+
.option('--port <number>', 'IRC server port', BaseCommander.parseIfNotInt)
4950
.option('--tls', 'enable SSL/TLS')
51+
.option('--no-insecure', 'Reject self-signed SSL/TLS certificates')
5052
.option('-b, --bot <botname>', 'xdcc bot nickname')
5153
.option('-d, --download <packs...>', 'pack number(s) to download')
5254
.option('-p, --path <path>', 'download path', path.normalize)
@@ -62,7 +64,7 @@ export class BaseCommander {
6264
BaseCommander.parseIfNotInt,
6365
0,
6466
)
65-
.option('--no-secure', 'Allow files sent by bot with different name than the one requested')
67+
.option('--bot-name-match', 'Block downloads if bot name does not match')
6668
.option('--save-profile <string>', 'save current options as a profile')
6769
.option('--delete-profile <string>', 'delete profile')
6870
.option('--set-profile <string>', 'set profile as default')
@@ -88,15 +90,18 @@ export class BaseCommander {
8890
return {
8991
host: this.program.host,
9092
port: this.program.port,
91-
tls: this.program.tls,
93+
tls: {
94+
enable: this.program.tls || false,
95+
rejectUnauthorized: this.program.noInsecure || false,
96+
},
9297
nickname: this.program.nickname,
9398
chan: this.program.channel,
9499
path: this.program.path,
95100
retry: this.program.retry,
96101
randomizeNick: this.program.randomize,
97102
passivePort: [this.program.passivePort || 5001],
98103
verbose: !this.program.quiet,
99-
secure: this.program.secure,
104+
botNameMatch: this.program.botNameMatch,
100105
};
101106
}
102107

src/bin/profiles.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,6 @@ export default class Profiles extends BaseCommander {
148148
if (this.program.bot) this.defaultProfile[1].bot = this.program.bot;
149149
this.defaultProfile[0].randomizeNick = this.program.randomize;
150150
this.defaultProfile[1].wait = this.program.wait;
151-
this.defaultProfile[0].secure = this.program.secure;
151+
this.defaultProfile[0].botNameMatch = this.program.botNameMatch;
152152
}
153153
}

src/connect.ts

+35-10
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* eslint-disable no-param-reassign */
12
/* eslint-disable @typescript-eslint/member-delimiter-style */
23
/* eslint-disable @typescript-eslint/no-this-alias */
34
/* eslint-disable @typescript-eslint/triple-slash-reference */
@@ -64,14 +65,28 @@ export type ParamsIRC = {
6465
*/
6566
verbose?: boolean
6667
/**
67-
* Enable TLS/SSL
68-
* @default `false`
69-
* @example
70-
* ```js
71-
* params.tls = true
72-
* ```
68+
* TLS/SSL
7369
*/
74-
tls?: boolean
70+
tls?: {
71+
/**
72+
* Enable TLS/SSL
73+
* @default `false`
74+
* @example
75+
* ```js
76+
* params.tls = { enable: true }
77+
* ```
78+
*/
79+
enable: boolean,
80+
/**
81+
* (optional) Reject self-signed certificates
82+
* @default `false`
83+
* @example
84+
* ```js
85+
* params.tls = { enable: true, rejectUnauthorized: true }
86+
* ```
87+
*/
88+
rejectUnauthorized?: boolean
89+
}
7590
}
7691

7792
export default class Connect extends Client {
@@ -87,7 +102,10 @@ export default class Connect extends Client {
87102

88103
protected connectionTimeout!:ReturnType<typeof setTimeout>;
89104

90-
protected tls: boolean;
105+
protected tls: {
106+
enable: boolean,
107+
rejectUnauthorized?: boolean
108+
};
91109

92110
constructor(params: ParamsIRC) {
93111
super();
@@ -99,7 +117,13 @@ export default class Connect extends Client {
99117
this.port = Connect.is('port', params.port, 'number', 6667);
100118
this.verbose = Connect.is('verbose', params.verbose, 'boolean', false);
101119
this.chan = Connect.chanCheck(params.chan);
102-
this.tls = Connect.is('tls', params.tls, 'boolean', false);
120+
if (params.tls) {
121+
params.tls.enable = Connect.is('tls.enable', params.tls.enable, 'boolean', false);
122+
params.tls.rejectUnauthorized = Connect.is('tls.rejectUnauthorized', params.tls.rejectUnauthorized, 'boolean', true);
123+
} else {
124+
params.tls = { enable: false, rejectUnauthorized: true };
125+
}
126+
this.tls = params.tls;
103127
this.onConnect();
104128
this.connect({
105129
host: this.host,
@@ -108,7 +132,8 @@ export default class Connect extends Client {
108132
username: params.nickname || 'xdccJS',
109133
auto_reconnect_max_wait: 0,
110134
auto_reconnect_max_retries: 0,
111-
ssl: this.tls,
135+
ssl: this.tls.enable,
136+
rejectUnauthorized: this.tls.rejectUnauthorized,
112137
debug: true,
113138
});
114139
this.on('debug', (msg) => {

src/ctcp_parser.ts

+8-8
Original file line numberDiff line numberDiff line change
@@ -35,27 +35,27 @@ export type ParamsCTCP = ParamsTimeout & {
3535
* */
3636
path?: string | false
3737
/**
38-
* Allow/Deny files sent by bot with different name than the one requested.
38+
* Block downloads if the bot's name does not match the request
3939
* @example
4040
* ```js
41-
* // with secure = true
42-
* xdccJS.download('XDCC|SECURE', 1)
43-
* //=> Only accept files comming from 'XDCC|SECURE'
41+
* // with botNameMatch = true
42+
* xdccJS.download('BOT-A', 1)
43+
* //=> Only accept files comming from 'BOT-A'
4444
* ```js
4545
*
4646
*/
47-
secure?: boolean
47+
botNameMatch?: boolean
4848
}
4949
export class CtcpParser extends AddJob {
5050
path: string | boolean;
5151

52-
secure: boolean;
52+
botNameMatch: boolean;
5353

5454
protected resumequeue: ResumeQueue[] = [];
5555

5656
constructor(params: ParamsCTCP) {
5757
super(params);
58-
this.secure = CtcpParser.is('secure', params.secure, 'boolean', true);
58+
this.botNameMatch = CtcpParser.is('botNameMatch', params.botNameMatch, 'boolean', true);
5959
this.path = CtcpParser.pathCheck(params.path);
6060
this.on('ctcp request', (resp: { [prop: string]: string }): void => {
6161
const isDownloadRequest = this.checkBeforeDL(resp, this.candidates[0]);
@@ -91,7 +91,7 @@ export class CtcpParser extends AddJob {
9191
nick = nick.toLowerCase();
9292
candidate.nick = candidate.nick.toLowerCase();
9393
candidate.cancelNick = nick;
94-
if (this.secure) {
94+
if (this.botNameMatch) {
9595
if (nick === candidate.nick) {
9696
return true;
9797
}

0 commit comments

Comments
 (0)