Skip to content
Snippets Groups Projects
Commit 46cd15e8 authored by pscalise2's avatar pscalise2
Browse files

added openssl ctx for api calls

parent 24d1974d
Branches
No related tags found
No related merge requests found
package WebUI
import (
"bytes"
"crypto/rand"
"crypto/tls"
"encoding/json"
"fmt"
"net"
"net/http"
"os"
"path/filepath"
"reflect"
"runtime/debug"
"strconv"
"strings"
"time"
"github.com/pexip/go-openssl"
"github.com/gin-gonic/gin"
"github.com/golang-jwt/jwt"
"github.com/google/uuid"
......@@ -45,13 +50,71 @@ const (
var jwtKey = "" // for generating JWT
var httpsClient *http.Client
var innerOpenSSLClientCtx *openssl.Ctx
func init() {
httpsClient = &http.Client{
Transport: &http.Transport{
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
//httpsClient = &http.Client{
// Transport: &http.Transport{
// TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
// },
//}
if CreateOpenSSLClientCtx("nrf") == nil {
logger.InitLog.Errorf("OpenSSL Context err: Issue creating Ctx in api_webgui.go")
}
if CreateOpenSSLInnerClientTransport() != nil {
logger.InitLog.Errorf("RestfulAPIDeleteOne err: Transport creation issue.")
}
var buf bytes.Buffer
buf.Write(debug.Stack())
// Capture the stack trace as a string
var trace = buf.String()
fmt.Println(trace)
}
func CreateOpenSSLInnerClientTransport() error {
// Custom dial function to use OpenSSL for TLS connections
dialTLS := func(network, addr string) (net.Conn, error) {
//cfg.tlsCtx.SetVerify(openssl.VerifyNone, nil)
conn, err := openssl.Dial(network, addr, innerOpenSSLClientCtx, openssl.InsecureSkipHostVerification)
if err != nil {
//fmt.Printf("Failed to establish TLS connection in CreateOpenSSLInnerClientTransport(): %v\n", err)
return nil, err
}
return conn, nil
}
// Create a custom transport using the custom dial function
tr := &http.Transport{
TLSClientConfig: &tls.Config{
InsecureSkipVerify: true, // Skip certificate verification,
},
TLSNextProto: make(map[string]func(authority string, c *tls.Conn) http.RoundTripper),
DialTLS: dialTLS,
}
httpsClient = &http.Client{Transport: tr}
return nil
}
func CreateOpenSSLClientCtx(nf string) *openssl.Ctx {
var err error
var opensslContext *openssl.Ctx
opensslContext, err = openssl.NewCtxFromFiles("cert/"+nf+".pem", "cert/"+nf+".key")
if err != nil {
return nil
}
opensslContext.SetVerify(openssl.VerifyNone, nil)
return opensslContext
//cfg.SetOpenSSLCtx(opensslContext)
//if err := opensslContext.SetNextProtos([]string{"h2"}); err != nil {
// fmt.Println("Failed to set Next Protos (ALPN)")
// return nil
//}
}
// Create Admin's Tenant & Account
......@@ -1394,7 +1457,9 @@ func sendRechargeNotification(ueId string, rg int32) {
}()
req.Header.Add("Content-Type", "application/json")
resp, err1 := http.DefaultClient.Do(req)
//resp, err1 := http.DefaultClient.Do(req)
resp, err1 := httpsClient.Do(req)
if err != nil {
logger.ProcLog.Errorf("Send Charging Notification err: %+v", err1)
}
......
......@@ -13,6 +13,7 @@ require (
github.com/golang-jwt/jwt v3.2.1+incompatible
github.com/google/uuid v1.3.0
github.com/jlaffaye/ftp v0.1.0
github.com/pexip/go-openssl v0.2.6
github.com/pkg/errors v0.9.1
github.com/sirupsen/logrus v1.9.0
github.com/urfave/cli v1.22.5
......@@ -56,6 +57,7 @@ require (
github.com/kr/fs v0.1.0 // indirect
github.com/leodido/go-urn v1.2.4 // indirect
github.com/mattn/go-isatty v0.0.19 // indirect
github.com/mattn/go-pointer v0.0.1 // indirect
github.com/mitchellh/mapstructure v1.4.2 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
......@@ -102,6 +104,6 @@ require (
github.com/go-logfmt/logfmt v0.6.0 // indirect
github.com/hashicorp/errwrap v1.1.0 // indirect
github.com/spf13/afero v1.9.5 // indirect
golang.org/x/oauth2 v0.8.0 // indirect
golang.org/x/oauth2 v0.8.0
google.golang.org/api v0.122.0 // indirect
)
......@@ -389,6 +389,8 @@ github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Ky
github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94=
github.com/mattn/go-isatty v0.0.19 h1:JITubQf0MOLdlGRuRq+jtsDlekdYPia9ZFsB8h/APPA=
github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/mattn/go-pointer v0.0.1 h1:n+XhsuGeVO6MEAp7xyEukFINEa+Quek5psIR/ylA6o0=
github.com/mattn/go-pointer v0.0.1/go.mod h1:2zXcozF6qYGgmsG+SeTZz3oAbFLdD3OWqnUbNvJZAlc=
github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0=
github.com/miekg/dns v1.0.14/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3Nrg=
github.com/miekg/dns v1.1.26/go.mod h1:bPDLeHnStXmXAq1m/Ch/hvfNHr14JKNPMBo3VZKjuso=
......@@ -431,6 +433,8 @@ github.com/pelletier/go-toml/v2 v2.0.1/go.mod h1:r9LEWfGN8R5k0VXJ+0BkIe7MYkRdwZO
github.com/pelletier/go-toml/v2 v2.0.8 h1:0ctb6s9mE31h0/lhu+J6OPmVeDxJn+kYnJc2jZR9tGQ=
github.com/pelletier/go-toml/v2 v2.0.8/go.mod h1:vuYfssBdrU2XDZ9bYydBu6t+6a6PYNcZljzZR9VXg+4=
github.com/performancecopilot/speed v3.0.0+incompatible/go.mod h1:/CLtqpZ5gBg1M9iaPbIdPPGyKcA8hKdoy6hAWba7Yac=
github.com/pexip/go-openssl v0.2.6 h1:6UXTphhY/gl9X46oU/NEvHxD2E1BvRpKIbqhKQSYUEI=
github.com/pexip/go-openssl v0.2.6/go.mod h1:xklrDkkB/fAl65ga/3V9x8DZEnR7tKijNS/DURrpB+A=
github.com/pierrec/lz4 v1.0.2-0.20190131084431-473cd7ce01a1/go.mod h1:3/3N9NVKO0jef7pBehbT1qWhCMrIgbYNnFAZCqQ5LRc=
github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA=
github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment