Skip to content

Commit

Permalink
Merge pull request #177 from fisuda/hardening/insecure_skip_verify
Browse files Browse the repository at this point in the history
Add insecureSkipVerify option
  • Loading branch information
fisuda committed Jul 17, 2021
2 parents ccf3b64 + 63bd255 commit 8755158
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 33 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
## NGSI Go v0.8.4-next

- Hardening: Add insecureSkipVerify option (#177)
- Fix: Fix URL path join (#176)
- Fix: Fix EOF error when ngsi-go-config.json is empty (#175)
- Hardening: Add replace option in regproxy (#174)
Expand Down
15 changes: 8 additions & 7 deletions e2e/cases/1000_common/0001_ngsi.test
Original file line number Diff line number Diff line change
Expand Up @@ -92,13 +92,14 @@ COMMANDS:
hget get historical raw and aggregated time series context information

GLOBAL OPTIONS:
--syslog LEVEL specify logging LEVEL (off, err, info, debug)
--stderr LEVEL specify logging LEVEL (off, err, info, debug)
--config FILE specify configuration FILE
--cache FILE specify cache FILE
--batch, -B don't use previous args (batch) (default: false)
--help show help (default: false)
--version, -v print the version (default: false)
--syslog LEVEL specify logging LEVEL (off, err, info, debug)
--stderr LEVEL specify logging LEVEL (off, err, info, debug)
--config FILE specify configuration FILE
--cache FILE specify cache FILE
--batch, -B don't use previous args (batch) (default: false)
--insecureSkipVerify TLS/SSL skip certificate verification (default: false)
--help show help (default: false)
--version, -v print the version (default: false)

COPYRIGHT:
(c) 2020-2021 Kazuhito Suda
Expand Down
4 changes: 4 additions & 0 deletions internal/ngsicmd/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@ var (
Name: "cmdName",
Hidden: true,
}
insecureSkipVerifyFlag = &cli.BoolFlag{
Name: "insecureSkipVerify",
Usage: "TLS/SSL skip certificate verification",
}
)

// Common flags
Expand Down
2 changes: 2 additions & 0 deletions internal/ngsicmd/initcmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,8 @@ func initCmd(c *cli.Context, cmdName string, requiredHost bool) (*ngsilib.NGSI,
ngsi.Maxsize = maxsize
}

ngsi.InsecureSkipVerify = c.Bool("insecureSkipVerify")

c.App.Writer = ngsi.StdWriter
c.App.ErrWriter = ngsi.LogWriter

Expand Down
1 change: 1 addition & 0 deletions internal/ngsicmd/ngsi.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ func getNgsiApp() *cli.App {
timeOutFlag,
maxCountFlag,
batchFlag,
insecureSkipVerifyFlag,
cmdNameFlag,
},
Commands: []*cli.Command{
Expand Down
7 changes: 6 additions & 1 deletion internal/ngsilib/http_lib.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ package ngsilib

import (
"bytes"
"crypto/tls"
"io"
"io/ioutil"
"net/http"
Expand Down Expand Up @@ -78,7 +79,11 @@ func NewHTTPRequet() HTTPRequest {
func (r *httpRequest) Request(method string, url *url.URL, headers map[string]string, body interface{}) (res *http.Response, b []byte, err error) {
const funcName = "Request"

client := &http.Client{Timeout: time.Duration(60 * time.Second)}
tr := &http.Transport{
TLSClientConfig: &tls.Config{InsecureSkipVerify: gNGSI.InsecureSkipVerify},
}

client := &http.Client{Timeout: time.Duration(60 * time.Second), Transport: tr}

var reader io.Reader

Expand Down
52 changes: 27 additions & 25 deletions internal/ngsilib/ngsilib.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,31 +46,32 @@ type NGSI struct {
tokenList tokenInfoList
contextList ContextsInfo

LogLevel int
ConfigFile IoLib
CacheFile IoLib
StdReader io.Reader
StdWriter io.Writer
LogWriter io.Writer
FileReader FileLib
JSONConverter JSONLib
FilePath FilePathLib
Ioutil IoutilLib
ZipLib ZipLib
MultiPart MultiPart
Host string
Destination string
Margin int64
Maxsize int
Timeout time.Duration
PreviousArgs *Settings
Updated bool
HTTP HTTPRequest
Stderr io.Writer
OsType string
SyslogLib SyslogLib
TimeLib TimeLib
BatchFlag *bool
LogLevel int
ConfigFile IoLib
CacheFile IoLib
StdReader io.Reader
StdWriter io.Writer
LogWriter io.Writer
FileReader FileLib
JSONConverter JSONLib
FilePath FilePathLib
Ioutil IoutilLib
ZipLib ZipLib
MultiPart MultiPart
Host string
Destination string
Margin int64
Maxsize int
Timeout time.Duration
PreviousArgs *Settings
Updated bool
HTTP HTTPRequest
Stderr io.Writer
OsType string
SyslogLib SyslogLib
TimeLib TimeLib
BatchFlag *bool
InsecureSkipVerify bool
}

// CmdFlags is ...
Expand Down Expand Up @@ -108,6 +109,7 @@ func NewNGSI() *NGSI {
gNGSI.SyslogLib = &syslogLib{}
gNGSI.PreviousArgs = &Settings{UsePreviousArgs: true}
gNGSI.TimeLib = &timeLib{}
gNGSI.InsecureSkipVerify = false
gNGSI.serverList = make(ServerList)
gNGSI.contextList = make(ContextsInfo)
gNGSI.contextList["etsi1.0"] = "https://uri.etsi.org/ngsi-ld/v1/ngsi-ld-core-context.jsonld"
Expand Down

0 comments on commit 8755158

Please sign in to comment.