mirror of
https://github.com/Snawoot/windscribe-proxy.git
synced 2026-04-05 02:28:20 +00:00
wndclient: register token WIP
This commit is contained in:
21
main.go
Normal file
21
main.go
Normal file
@@ -0,0 +1,21 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/Snawoot/windscribe-proxy/wndclient"
|
||||
)
|
||||
|
||||
func main() {
|
||||
wndc, err := wndclient.NewWndClient(nil)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
err = wndc.RegisterToken(context.TODO())
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
fmt.Printf("wndc=%#v\n", wndc)
|
||||
}
|
||||
15
wndclient/authhash.go
Normal file
15
wndclient/authhash.go
Normal file
@@ -0,0 +1,15 @@
|
||||
package wndclient
|
||||
|
||||
import (
|
||||
"crypto/md5"
|
||||
"encoding/hex"
|
||||
"strconv"
|
||||
"time"
|
||||
)
|
||||
|
||||
func MakeAuthHash(secret string) (string, int64) {
|
||||
iTime := time.Now().Unix()
|
||||
sTime := strconv.FormatInt(iTime, 10)
|
||||
h := md5.Sum([]byte(secret + sTime))
|
||||
return hex.EncodeToString(h[:]), iTime
|
||||
}
|
||||
@@ -1,11 +1,11 @@
|
||||
package wndclient
|
||||
|
||||
type WndRegisterTokenRequest struct {
|
||||
type RegisterTokenRequest struct {
|
||||
ClientAuthHash string `json:"client_auth_hash"`
|
||||
Time int64 `json:"time,string"`
|
||||
}
|
||||
|
||||
type WndRegisterTokenResponse struct {
|
||||
type RegisterTokenResponse struct {
|
||||
TokenID string `json:"id"`
|
||||
Token string `json:"token"`
|
||||
TokenSignature string `json:"signature"`
|
||||
|
||||
@@ -107,6 +107,24 @@ func (c *WndClient) resetCookies() error {
|
||||
func (c *WndClient) RegisterToken(ctx context.Context) error {
|
||||
c.Mux.Lock()
|
||||
defer c.Mux.Unlock()
|
||||
|
||||
clientAuthHash, authTime := MakeAuthHash(c.Settings.ClientAuthSecret)
|
||||
input := RegisterTokenRequest{
|
||||
ClientAuthHash: clientAuthHash,
|
||||
Time: authTime,
|
||||
}
|
||||
var output RegisterTokenResponse
|
||||
|
||||
err := c.postJSON(ctx, c.Settings.Endpoints.RegisterToken, input, &output)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
c.TokenID = output.TokenID
|
||||
c.Token = output.Token
|
||||
c.TokenSignature = output.TokenSignature
|
||||
c.TokenSignatureTime = output.TokenTime
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -127,6 +145,7 @@ func (c *WndClient) postJSON(ctx context.Context, endpoint string, input, output
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
c.populateRequest(req)
|
||||
req.Header.Set("Content-Type", "application/json")
|
||||
req.Header.Set("Accept", "application/json")
|
||||
|
||||
Reference in New Issue
Block a user