Skip to content

Commit

Permalink
[CLI] Support proto=http (#649)
Browse files Browse the repository at this point in the history
* tdexconnect support proto=http

* cover case no_tls=false & cert_path empty

* addition tdexconnect validation checks, cli tls config

* avoid sec linter in cli for testing purpose

* avoid sec linter in cli for testing purpose

* avoid sec linter in cli for testing purpose

* removed https/no_tls combo check

* //nogosec

* //nogosec

* cli tls cred opts update
  • Loading branch information
sekulicd authored Oct 20, 2022
1 parent 8f15fe9 commit 2f0bc47
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
1 change: 1 addition & 0 deletions cmd/tdex/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ func configConnectAction(c *cli.Context) (err error) {

if err = setState(map[string]string{
"proto": proto,
"no_tls": strconv.FormatBool(proto == "http"),
"rpcserver": rpcServerAddr,
"no_macaroons": noMacaroons,
"tls_cert_path": tlsCertPath,
Expand Down
21 changes: 10 additions & 11 deletions cmd/tdex/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -281,19 +281,18 @@ func getClientConn(skipMacaroon bool) (*grpc.ClientConn, error) {
if noTls {
opts = append(opts, grpc.WithTransportCredentials(insecure.NewCredentials()))
} else {
certPath, ok := state["tls_cert_path"]
if !ok {
return nil, fmt.Errorf(
"TLS certificate filepath is missing. Try " +
"'tdex config set tls_cert_path path/to/tls/certificate'",
)
}
certPath := state["tls_cert_path"]
dialOpt := grpc.WithTransportCredentials(credentials.NewTLS(nil))
if certPath != "" {
tlsCreds, err := credentials.NewClientTLSFromFile(certPath, "")
if err != nil {
return nil, fmt.Errorf("could not read TLS certificate: %s", err)
}

tlsCreds, err := credentials.NewClientTLSFromFile(certPath, "")
if err != nil {
return nil, fmt.Errorf("could not read TLS certificate: %s", err)
dialOpt = grpc.WithTransportCredentials(tlsCreds)
}
opts = append(opts, grpc.WithTransportCredentials(tlsCreds))

opts = append(opts, dialOpt)
}

noMacaroons, _ := strconv.ParseBool(state["no_macaroons"])
Expand Down
2 changes: 1 addition & 1 deletion internal/interfaces/http/tdex_connect_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func NewTdexConnectService(

p := protocol
if len(certBytes) > 0 {
if protocol == "" || protocol == httpsProtocol {
if protocol == httpsProtocol {
p = httpsProtocol
} else {
return nil, fmt.Errorf(
Expand Down

0 comments on commit 2f0bc47

Please sign in to comment.