mirror of
https://github.com/Snawoot/opera-proxy.git
synced 2025-09-07 13:10:32 +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
|
package seclient
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/hex"
|
||||||
|
"io"
|
||||||
|
"math/rand"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/http/cookiejar"
|
"net/http/cookiejar"
|
||||||
|
"time"
|
||||||
|
|
||||||
dac "github.com/Snawoot/go-http-digest-auth-client"
|
dac "github.com/Snawoot/go-http-digest-auth-client"
|
||||||
"golang.org/x/net/publicsuffix"
|
"golang.org/x/net/publicsuffix"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
ANON_EMAIL_LOCALPART_BYTES = 32
|
||||||
|
ANON_PASSWORD_BYTES = 20
|
||||||
|
DEVICE_ID_BYTES = 20
|
||||||
|
)
|
||||||
|
|
||||||
type SEEndpoints struct {
|
type SEEndpoints struct {
|
||||||
RegisterSubscriber string
|
RegisterSubscriber string
|
||||||
SubscriberLogin string
|
SubscriberLogin string
|
||||||
|
@ -26,21 +36,32 @@ var DefaultSEEndpoints = SEEndpoints{
|
||||||
|
|
||||||
type SESettings struct {
|
type SESettings struct {
|
||||||
ClientVersion string
|
ClientVersion string
|
||||||
|
ClientType string
|
||||||
|
DeviceHash string
|
||||||
|
DeviceName string
|
||||||
OperatingSystem string
|
OperatingSystem string
|
||||||
APIUsername string
|
|
||||||
APISecret string
|
|
||||||
Endpoints SEEndpoints
|
Endpoints SEEndpoints
|
||||||
}
|
}
|
||||||
|
|
||||||
var DefaultSESettings = SESettings{
|
var DefaultSESettings = SESettings{
|
||||||
ClientVersion: "Stable 74.0.3911.232",
|
ClientVersion: "Stable 74.0.3911.232",
|
||||||
|
ClientType: "se0316",
|
||||||
|
DeviceName: "Opera-Browser-Client",
|
||||||
|
DeviceHash: "",
|
||||||
OperatingSystem: "Windows",
|
OperatingSystem: "Windows",
|
||||||
Endpoints: DefaultSEEndpoints,
|
Endpoints: DefaultSEEndpoints,
|
||||||
}
|
}
|
||||||
|
|
||||||
type SEClient struct {
|
type SEClient struct {
|
||||||
HttpClient *http.Client
|
HttpClient *http.Client
|
||||||
Settings SESettings
|
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.
|
// 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
|
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{
|
return &SEClient{
|
||||||
HttpClient: &http.Client{
|
HttpClient: &http.Client{
|
||||||
Transport: dac.NewDigestTransport(apiUsername, apiSecret, transport),
|
Transport: dac.NewDigestTransport(apiUsername, apiSecret, transport),
|
||||||
Jar: jar,
|
Jar: jar,
|
||||||
},
|
},
|
||||||
Settings: DefaultSESettings,
|
Settings: DefaultSESettings,
|
||||||
|
rng: rng,
|
||||||
|
DeviceID: device_id,
|
||||||
}, nil
|
}, 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