-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
162 lines (137 loc) · 3.83 KB
/
main.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
package main
import (
"bytes"
"crypto/sha256"
"encoding/hex"
"encoding/json"
"errors"
"flag"
"fmt"
"log"
"net/http"
"github.com/cossacklabs/themis/gothemis/cell"
)
func main() {
var (
email string
password string
)
flag.StringVar(&email, "email", "", "your email")
flag.StringVar(&password, "pass", "", "your password")
flag.Parse()
hasher := sha256.New()
hasher.Write([]byte(password))
passwordHash := hex.EncodeToString(hasher.Sum(nil))
// Get access token by signing in!
accessToken, err := signIn(email, passwordHash)
if err != nil {
log.Fatalln("Probably wrong email or password!", err)
}
// Get encrypted app key with access token!
encryptedAppKey, err := getAppKey(accessToken)
if err != nil {
log.Fatalln("Error while trying to get encrypted app key!", err)
}
// Get encrypted mnemonic with access token!
encryptedMnemonic, err := getMnemonics(accessToken)
if err != nil {
log.Fatalln("Error while trying to get encrypted mnemonic key!", err)
}
// Decrypt app key!
seal1, err := cell.SealWithPassphrase(password)
if err != nil {
log.Fatalln("Empty password!")
}
rawAppKey, err := seal1.Decrypt(encryptedAppKey, nil)
if err != nil {
log.Fatalln("Error while trying to decrypt encrypted app key!", err)
}
// Decrypt mnemonic!
seal2, err := cell.SealWithPassphrase(string(rawAppKey))
if err != nil {
log.Fatalln("Empty app key!")
}
data, err := seal2.Decrypt(encryptedMnemonic, nil)
if err != nil {
log.Fatalln("Error while trying to decrypt encrypted mnemonic!")
}
// Print it!
fmt.Println("Your mnemonic: " + string(data))
}
func signIn(email, passwordHash string) (string, error) {
type SignInRequest struct {
Email string `json:"email"`
Password string `json:"password"`
}
type SignInResponse struct {
UserID int `json:"user_id"`
AccessToken string `json:"access_token"`
}
signinReq := &SignInRequest{
Email: email,
Password: passwordHash,
}
buf := bytes.NewBuffer(nil)
if err := json.NewEncoder(buf).Encode(signinReq); err != nil {
return "", err
}
req, err := http.NewRequest(http.MethodPost, "https://account-api-chad.solarlabs.ee/auth/signIn", buf)
if err != nil {
return "", err
}
req.Header.Set("Content-Type", "application/json")
resp, err := http.DefaultClient.Do(req)
if err != nil {
return "", err
}
defer resp.Body.Close()
var signInResp *SignInResponse
if err := json.NewDecoder(resp.Body).Decode(&signInResp); err != nil {
return "", err
}
return signInResp.AccessToken, nil
}
func getAppKey(accessToken string) ([]byte, error) {
type GetAppKeyResponse struct {
EncryptedAppKey []byte `json:"encrypted_app_key"`
}
req, err := http.NewRequest(http.MethodGet, "https://account-api-chad.solarlabs.ee/profile/getAppKey", nil)
if err != nil {
return nil, err
}
req.Header.Set("X-Authorization", accessToken)
resp, err := http.DefaultClient.Do(req)
if err != nil {
return nil, err
}
defer resp.Body.Close()
var getAppKeyResp *GetAppKeyResponse
if err := json.NewDecoder(resp.Body).Decode(&getAppKeyResp); err != nil {
return nil, err
}
return getAppKeyResp.EncryptedAppKey, nil
}
func getMnemonics(accessToken string) ([]byte, error) {
type GetMnemonicsResponse struct {
EncryptedMnemonic []byte `json:"encrypted_mnemonic"`
}
req, err := http.NewRequest(http.MethodGet, "https://account-api-chad.solarlabs.ee/blockchain/getMnemonics?network=DVPN", nil)
if err != nil {
return nil, err
}
req.Header.Set("X-Authorization", accessToken)
resp, err := http.DefaultClient.Do(req)
if err != nil {
return nil, err
}
defer resp.Body.Close()
var getMnemonicsResp []*GetMnemonicsResponse
if err := json.NewDecoder(resp.Body).Decode(&getMnemonicsResp); err != nil {
return nil, err
}
if len(getMnemonicsResp) > 0 {
return getMnemonicsResp[0].EncryptedMnemonic, nil
} else {
return nil, errors.New("wrong length")
}
}