mirror of
https://github.com/Snawoot/opera-proxy.git
synced 2025-09-04 11:41:14 +00:00
WIP
This commit is contained in:
parent
fabf1d9af1
commit
2b8ebb29ba
1 changed files with 44 additions and 5 deletions
|
@ -1,13 +1,23 @@
|
|||
package seclient
|
||||
|
||||
import (
|
||||
"encoding/hex"
|
||||
"io"
|
||||
"math/rand"
|
||||
"net/http"
|
||||
"net/http/cookiejar"
|
||||
"time"
|
||||
|
||||
dac "github.com/Snawoot/go-http-digest-auth-client"
|
||||
"golang.org/x/net/publicsuffix"
|
||||
)
|
||||
|
||||
const (
|
||||
ANON_EMAIL_LOCALPART_BYTES = 32
|
||||
ANON_PASSWORD_BYTES = 20
|
||||
DEVICE_ID_BYTES = 20
|
||||
)
|
||||
|
||||
type SEEndpoints struct {
|
||||
RegisterSubscriber string
|
||||
SubscriberLogin string
|
||||
|
@ -26,21 +36,32 @@ var DefaultSEEndpoints = SEEndpoints{
|
|||
|
||||
type SESettings struct {
|
||||
ClientVersion string
|
||||
ClientType string
|
||||
DeviceHash string
|
||||
DeviceName string
|
||||
OperatingSystem string
|
||||
APIUsername string
|
||||
APISecret string
|
||||
Endpoints SEEndpoints
|
||||
}
|
||||
|
||||
var DefaultSESettings = SESettings{
|
||||
ClientVersion: "Stable 74.0.3911.232",
|
||||
ClientType: "se0316",
|
||||
DeviceName: "Opera-Browser-Client",
|
||||
DeviceHash: "",
|
||||
OperatingSystem: "Windows",
|
||||
Endpoints: DefaultSEEndpoints,
|
||||
}
|
||||
|
||||
type SEClient struct {
|
||||
HttpClient *http.Client
|
||||
Settings SESettings
|
||||
HttpClient *http.Client
|
||||
Settings SESettings
|
||||
SubscriberEmail string
|
||||
SubscriberPassword string
|
||||
DeviceID string
|
||||
AssignedDeviceID string
|
||||
AssignedDevideIDHash string
|
||||
DevicePassword string
|
||||
rng *rand.Rand
|
||||
}
|
||||
|
||||
// Instantiates SurfEasy client with default settings and given API keys.
|
||||
|
@ -58,11 +79,29 @@ func NewSEClient(apiUsername, apiSecret string, transport http.RoundTripper) (*S
|
|||
return nil, err
|
||||
}
|
||||
|
||||
rng := rand.New(rand.NewSource(time.Now().UnixNano()))
|
||||
|
||||
device_id, err := randomCapitalHexString(rng, DEVICE_ID_BYTES)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &SEClient{
|
||||
HttpClient: &http.Client{
|
||||
Transport: dac.NewDigestTransport(apiUsername, apiSecret, transport),
|
||||
Jar: jar,
|
||||
Jar: jar,
|
||||
},
|
||||
Settings: DefaultSESettings,
|
||||
rng: rng,
|
||||
DeviceID: device_id,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func randomCapitalHexString(rng io.Reader, length int) (string, error) {
|
||||
b := make([]byte, length)
|
||||
_, err := rng.Read(b)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return hex.EncodeToString(b), nil
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue