Skip to content

Commit

Permalink
Merge pull request #2010 from jairajmahadev/Adding-insecure-option-to…
Browse files Browse the repository at this point in the history
…-disable-client-certificate-verification

Adding insecure option to disable client certificate verification
  • Loading branch information
kelson42 committed Apr 8, 2024
2 parents b44e49a + 3a18048 commit 55b9134
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/Downloader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ interface DownloaderOpts {
webp: boolean
backoffOptions?: BackoffOptions
mwWikiPath?: string
insecure?: boolean
}

interface BackoffOptions {
Expand Down Expand Up @@ -105,8 +106,9 @@ class Downloader {

private articleUrlDirector: URLDirector
private mainPageUrlDirector: URLDirector
private readonly insecure: boolean = false

constructor({ uaString, speed, reqTimeout, optimisationCacheUrl, s3, webp, backoffOptions }: DownloaderOpts) {
constructor({ uaString, speed, reqTimeout, optimisationCacheUrl, s3, webp, backoffOptions, insecure }: DownloaderOpts) {
this.uaString = uaString
this.speed = speed
this.maxActiveRequests = speed * 10
Expand All @@ -116,6 +118,7 @@ class Downloader {
this.webp = webp
this.s3 = s3
this.apiUrlDirector = new ApiURLDirector(MediaWiki.actionApiUrl.href)
this.insecure = insecure

this.backoffOptions = {
strategy: new backoff.ExponentialStrategy(),
Expand All @@ -130,7 +133,7 @@ class Downloader {
this.arrayBufferRequestOptions = {
// HTTP agent pools with 'keepAlive' to reuse TCP connections, so it's faster
httpAgent: new http.Agent({ keepAlive: true }),
httpsAgent: new https.Agent({ keepAlive: true }),
httpsAgent: new https.Agent({ keepAlive: true, rejectUnauthorized: !this.insecure }), // rejectUnauthorized: false disables TLS

headers: {
'cache-control': 'public, max-stale=86400',
Expand All @@ -148,7 +151,7 @@ class Downloader {
this.jsonRequestOptions = {
// HTTP agent pools with 'keepAlive' to reuse TCP connections, so it's faster
httpAgent: new http.Agent({ keepAlive: true }),
httpsAgent: new https.Agent({ keepAlive: true }),
httpsAgent: new https.Agent({ keepAlive: true, rejectUnauthorized: !this.insecure }),

headers: {
accept: 'application/json',
Expand All @@ -166,7 +169,7 @@ class Downloader {
// HTTP agent pools with 'keepAlive' to reuse TCP connections, so it's faster
...defaultStreamRequestOptions,
httpAgent: new http.Agent({ keepAlive: true }),
httpsAgent: new https.Agent({ keepAlive: true }),
httpsAgent: new https.Agent({ keepAlive: true, rejectUnauthorized: !this.insecure }),

headers: {
...defaultStreamRequestOptions.headers,
Expand Down
1 change: 1 addition & 0 deletions src/mwoffliner.lib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ async function execute(argv: any) {
optimisationCacheUrl,
s3,
webp,
insecure: argv.insecure,
})

/* perform login */
Expand Down
1 change: 1 addition & 0 deletions src/parameterList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export const parameterDescriptions = {
optimisationCacheUrl: 'Object Storage URL (including credentials and bucket name) to cache optimised media files',
forceRender:
'Force the usage of a specific API end-point/render, automatically chosen otherwise. Accepted values: [ VisualEditor, WikimediaDesktop. WikimediaMobile ]. More details at https://github.com/openzim/mwoffliner/wiki/API-end-points',
insecure: 'Skip HTTPS server authenticity verification step',
}

// TODO: Add an interface based on the object above

0 comments on commit 55b9134

Please sign in to comment.