Skip to content

Commit dc5e76d

Browse files
committed
Adds flag to skip certificate validation
1 parent 7760081 commit dc5e76d

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

cmd/jsluice/main.go

+10-2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ package main
44

55
import (
66
"bufio"
7+
"crypto/tls"
78
"fmt"
89
"io"
910
"io/ioutil"
@@ -28,6 +29,7 @@ type options struct {
2829
help bool
2930
warc bool
3031
rawInput bool
32+
certCheck bool
3133

3234
// urls
3335
includeSource bool
@@ -92,6 +94,7 @@ func init() {
9294
" -P, --placeholder string Set the expression placeholder to a custom string (default 'EXPR')",
9395
" -j, --raw-input Read raw JavaScript source from stdin",
9496
" -w, --warc Treat the input files as WARC (Web ARChive) files",
97+
" -i, --no-check-certificate Ignore validation of server certificates",
9598
"",
9699
"URLs mode:",
97100
" -I, --ignore-strings Ignore matches from string literals",
@@ -130,6 +133,7 @@ func main() {
130133
flag.StringVarP(&opts.placeholder, "placeholder", "P", "EXPR", "Set the expression placeholder to a custom string")
131134
flag.BoolVarP(&opts.help, "help", "h", false, "")
132135
flag.BoolVarP(&opts.warc, "warc", "w", false, "")
136+
flag.BoolVarP(&opts.certCheck, "no-check-certificate", "i", false, "Ignore validation of server certificates")
133137

134138
// url options
135139
flag.BoolVarP(&opts.includeSource, "include-source", "S", false, "Include the source code where the URL was found")
@@ -230,7 +234,7 @@ func main() {
230234
continue
231235
}
232236

233-
source, err := readFromFileOrURL(filename, opts.cookie, opts.headers)
237+
source, err := readFromFileOrURL(filename, opts.cookie, opts.headers, opts.certCheck)
234238
if err != nil {
235239
errs <- err
236240
continue
@@ -288,10 +292,14 @@ func main() {
288292

289293
}
290294

291-
func readFromFileOrURL(path string, cookie string, headers []string) ([]byte, error) {
295+
func readFromFileOrURL(path string, cookie string, headers []string, ignoreCert bool) ([]byte, error) {
292296
if strings.HasPrefix(path, "http://") || strings.HasPrefix(path, "https://") {
293297
client := &http.Client{}
294298

299+
if ignoreCert {
300+
client.Transport = &http.Transport{TLSClientConfig: &tls.Config{InsecureSkipVerify: true}}
301+
}
302+
295303
req, err := http.NewRequest("GET", path, nil)
296304
if err != nil {
297305
return nil, err

0 commit comments

Comments
 (0)