-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathroute.go
40 lines (31 loc) · 896 Bytes
/
route.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
package socketify
import (
"crypto/rsa"
"encoding/base64"
"fmt"
"github.com/aliforever/encryptionbox"
"net/http"
)
func (s *Server) parseRsaPublicKey(r *http.Request) (*rsa.PublicKey, error) {
publicKeyPem := r.Header.Get("rsa_public_key_pem_b64")
if publicKeyPem == "" {
publicKeyPem = r.URL.Query().Get("rsa_public_key_pem_b64")
}
if publicKeyPem == "" {
return nil, fmt.Errorf("rsa_public_key_pem_base64_not_provided")
}
b64, err := base64.StdEncoding.DecodeString(publicKeyPem)
if err != nil {
return nil, fmt.Errorf("cant_decode_rsa_public_key_pem_base64_%s", err)
}
publicKey, err := encryptionbox.EncryptionBox{}.RSA.PublicKeyFromPKCS1PEMBytes(b64)
if err != nil {
return nil, err
}
return publicKey, nil
}
func (s *Server) websocketUpgrade(w http.ResponseWriter, r *http.Request) {
ur := newUpgradeRequest(s, w, r)
s.upgradeRequests <- ur
<-ur.done
}