-
-
Notifications
You must be signed in to change notification settings - Fork 372
/
Copy pathutils.go
49 lines (41 loc) · 1023 Bytes
/
utils.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package launcher
import (
"crypto"
"crypto/sha256"
"crypto/x509"
"encoding/base64"
"fmt"
"net/url"
"github.com/go-rod/rod/lib/utils"
)
var inContainer = utils.InContainer
func toHTTP(u url.URL) *url.URL {
newURL := u
if newURL.Scheme == "ws" {
newURL.Scheme = "http"
} else if newURL.Scheme == "wss" {
newURL.Scheme = "https"
}
return &newURL
}
func toWS(u url.URL) *url.URL {
newURL := u
if newURL.Scheme == "http" {
newURL.Scheme = "ws"
} else if newURL.Scheme == "https" {
newURL.Scheme = "wss"
}
return &newURL
}
// certSPKI generates the SPKI of a certificate public key
// https://blog.afoolishmanifesto.com/posts/golang-self-signed-and-pinned-certs/
func certSPKI(pk crypto.PublicKey) ([]byte, error) {
pubDER, err := x509.MarshalPKIXPublicKey(pk)
if err != nil {
return nil, fmt.Errorf("x509.MarshalPKIXPublicKey: %w", err)
}
sum := sha256.Sum256(pubDER)
pin := make([]byte, base64.StdEncoding.EncodedLen(len(sum)))
base64.StdEncoding.Encode(pin, sum[:])
return pin, nil
}