add insecure Tls param, skip wrong tls vms
This commit is contained in:
@@ -30,6 +30,7 @@ type MilestoneClient struct {
|
|||||||
ClientID string
|
ClientID string
|
||||||
Token string
|
Token string
|
||||||
GrantType string
|
GrantType string
|
||||||
|
InsecureTls bool
|
||||||
PeerConnection *pion.PeerConnection
|
PeerConnection *pion.PeerConnection
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -59,7 +60,7 @@ func setupMilestoneClient(rawURL string, query url.Values) *MilestoneClient {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func parseSessionDetails(query url.Values) WebRTCSessionDetails {
|
func parseSessionDetails(mc *MilestoneClient, query url.Values) WebRTCSessionDetails {
|
||||||
details := WebRTCSessionDetails{
|
details := WebRTCSessionDetails{
|
||||||
CameraId: query.Get("cameraId"),
|
CameraId: query.Get("cameraId"),
|
||||||
Resolution: "notInUse",
|
Resolution: "notInUse",
|
||||||
@@ -95,6 +96,13 @@ func parseSessionDetails(query url.Values) WebRTCSessionDetails {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if insecureTls := query.Get("insecureTls"); insecureTls != "" {
|
||||||
|
insecureTlsBool, err := strconv.ParseBool(insecureTls)
|
||||||
|
if err == nil {
|
||||||
|
mc.InsecureTls = insecureTlsBool
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if hasPlaybackDetails {
|
if hasPlaybackDetails {
|
||||||
details.PlaybackTimeNode = &playbackTimeNode
|
details.PlaybackTimeNode = &playbackTimeNode
|
||||||
}
|
}
|
||||||
@@ -102,6 +110,22 @@ func parseSessionDetails(query url.Values) WebRTCSessionDetails {
|
|||||||
return details
|
return details
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Helper function to create an HTTP client based on URL schema
|
||||||
|
func createHTTPClient(insecureTls bool) *http.Client {
|
||||||
|
tlsConfig := &tls.Config{}
|
||||||
|
|
||||||
|
// Set InsecureSkipVerify true only for "https" schema
|
||||||
|
if insecureTls {
|
||||||
|
tlsConfig.InsecureSkipVerify = true // FIXME, use httpx protocol
|
||||||
|
}
|
||||||
|
|
||||||
|
return &http.Client{
|
||||||
|
Transport: &http.Transport{
|
||||||
|
TLSClientConfig: tlsConfig,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func createWebRTCSession(mc *MilestoneClient, details WebRTCSessionDetails) (*http.Response, error) {
|
func createWebRTCSession(mc *MilestoneClient, details WebRTCSessionDetails) (*http.Response, error) {
|
||||||
body, err := json.Marshal(details)
|
body, err := json.Marshal(details)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -116,9 +140,7 @@ func createWebRTCSession(mc *MilestoneClient, details WebRTCSessionDetails) (*ht
|
|||||||
req.Header.Set("Authorization", "Bearer "+mc.Token)
|
req.Header.Set("Authorization", "Bearer "+mc.Token)
|
||||||
req.Header.Set("Content-Type", "application/json")
|
req.Header.Set("Content-Type", "application/json")
|
||||||
|
|
||||||
client := &http.Client{Transport: &http.Transport{
|
client := createHTTPClient(mc.InsecureTls)
|
||||||
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
|
|
||||||
}}
|
|
||||||
return client.Do(req)
|
return client.Do(req)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -137,9 +159,7 @@ func updateWebRTCSession(mc *MilestoneClient, sessionID string, answer pion.Sess
|
|||||||
req.Header.Set("Authorization", "Bearer "+mc.Token)
|
req.Header.Set("Authorization", "Bearer "+mc.Token)
|
||||||
req.Header.Set("Content-Type", "application/json")
|
req.Header.Set("Content-Type", "application/json")
|
||||||
|
|
||||||
client := &http.Client{Transport: &http.Transport{
|
client := createHTTPClient(mc.InsecureTls)
|
||||||
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
|
|
||||||
}}
|
|
||||||
return client.Do(req)
|
return client.Do(req)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -151,7 +171,8 @@ func (mc *MilestoneClient) Authenticate() error {
|
|||||||
"client_id": {mc.ClientID},
|
"client_id": {mc.ClientID},
|
||||||
}
|
}
|
||||||
|
|
||||||
resp, err := http.PostForm(mc.ApiGatewayUrl+"/IDP/connect/token", formData)
|
client := createHTTPClient(mc.InsecureTls)
|
||||||
|
resp, err := client.PostForm(mc.ApiGatewayUrl+"/IDP/connect/token", formData)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -178,12 +199,12 @@ func (mc *MilestoneClient) Authenticate() error {
|
|||||||
func milestoneClient(rawURL string, query url.Values, desc string) (core.Producer, error) {
|
func milestoneClient(rawURL string, query url.Values, desc string) (core.Producer, error) {
|
||||||
mc := setupMilestoneClient(rawURL, query)
|
mc := setupMilestoneClient(rawURL, query)
|
||||||
|
|
||||||
|
details := parseSessionDetails(mc, query)
|
||||||
|
|
||||||
if err := mc.Authenticate(); err != nil {
|
if err := mc.Authenticate(); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
details := parseSessionDetails(query)
|
|
||||||
|
|
||||||
config := pion.Configuration{
|
config := pion.Configuration{
|
||||||
ICEServers: []pion.ICEServer{
|
ICEServers: []pion.ICEServer{
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user