forked from TrueCloudLab/rclone
vendor: update all dependencies
This commit is contained in:
parent
3dcf1e61cf
commit
479c803fd9
446 changed files with 25054 additions and 8064 deletions
59
vendor/github.com/t3rm1n4l/go-mega/mega.go
generated
vendored
59
vendor/github.com/t3rm1n4l/go-mega/mega.go
generated
vendored
|
@ -105,7 +105,7 @@ type Mega struct {
|
|||
// Server state sn
|
||||
ssn string
|
||||
// Session ID
|
||||
sid []byte
|
||||
sid string
|
||||
// Master key
|
||||
k []byte
|
||||
// User handle
|
||||
|
@ -407,8 +407,8 @@ func (m *Mega) api_request(r []byte) (buf []byte, err error) {
|
|||
|
||||
url := fmt.Sprintf("%s/cs?id=%d", m.baseurl, m.sn)
|
||||
|
||||
if m.sid != nil {
|
||||
url = fmt.Sprintf("%s&sid=%s", url, string(m.sid))
|
||||
if m.sid != "" {
|
||||
url = fmt.Sprintf("%s&sid=%s", url, m.sid)
|
||||
}
|
||||
|
||||
sleepTime := minSleepTime // inital backoff time
|
||||
|
@ -499,7 +499,7 @@ func (m *Mega) prelogin(email string) error {
|
|||
if len(res[0].Salt) == 0 {
|
||||
return errors.New("prelogin: no salt returned")
|
||||
}
|
||||
m.accountSalt, err = base64urldecode([]byte(res[0].Salt))
|
||||
m.accountSalt, err = base64urldecode(res[0].Salt)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -532,7 +532,7 @@ func (m *Mega) login(email string, passwd string) error {
|
|||
msg[0].Cmd = "us"
|
||||
msg[0].User = email
|
||||
if m.accountVersion == 1 {
|
||||
msg[0].Handle = string(uhandle)
|
||||
msg[0].Handle = uhandle
|
||||
} else {
|
||||
const derivedKeyLength = 2 * aes.BlockSize
|
||||
derivedKey := pbkdf2.Key([]byte(passwd), m.accountSalt, 100000, derivedKeyLength, sha512.New)
|
||||
|
@ -544,8 +544,8 @@ func (m *Mega) login(email string, passwd string) error {
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
msg[0].Handle = string(base64urlencode(authKey))
|
||||
msg[0].SessionKey = string(base64urlencode(sessionKey))
|
||||
msg[0].Handle = base64urlencode(authKey)
|
||||
msg[0].SessionKey = base64urlencode(sessionKey)
|
||||
}
|
||||
|
||||
req, err := json.Marshal(msg)
|
||||
|
@ -562,7 +562,7 @@ func (m *Mega) login(email string, passwd string) error {
|
|||
return err
|
||||
}
|
||||
|
||||
m.k, err = base64urldecode([]byte(res[0].Key))
|
||||
m.k, err = base64urldecode(res[0].Key)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -571,7 +571,7 @@ func (m *Mega) login(email string, passwd string) error {
|
|||
return err
|
||||
}
|
||||
cipher.Decrypt(m.k, m.k)
|
||||
m.sid, err = decryptSessionId([]byte(res[0].Privk), []byte(res[0].Csid), m.k)
|
||||
m.sid, err = decryptSessionId(res[0].Privk, res[0].Csid, m.k)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -708,7 +708,7 @@ func (m *Mega) addFSNode(itm FSNode) (*Node, error) {
|
|||
switch {
|
||||
// File or folder owned by current user
|
||||
case args[0] == itm.User:
|
||||
buf, err := base64urldecode([]byte(args[1]))
|
||||
buf, err := base64urldecode(args[1])
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -722,7 +722,7 @@ func (m *Mega) addFSNode(itm FSNode) (*Node, error) {
|
|||
}
|
||||
// Shared folder
|
||||
case itm.SUser != "" && itm.SKey != "":
|
||||
sk, err := base64urldecode([]byte(itm.SKey))
|
||||
sk, err := base64urldecode(itm.SKey)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -736,7 +736,7 @@ func (m *Mega) addFSNode(itm FSNode) (*Node, error) {
|
|||
}
|
||||
|
||||
m.FS.skmap[itm.Hash] = itm.SKey
|
||||
buf, err := base64urldecode([]byte(args[1]))
|
||||
buf, err := base64urldecode(args[1])
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -751,7 +751,7 @@ func (m *Mega) addFSNode(itm FSNode) (*Node, error) {
|
|||
// Shared file
|
||||
default:
|
||||
k := m.FS.skmap[args[0]]
|
||||
b, err := base64urldecode([]byte(k))
|
||||
b, err := base64urldecode(k)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -763,7 +763,7 @@ func (m *Mega) addFSNode(itm FSNode) (*Node, error) {
|
|||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
buf, err := base64urldecode([]byte(args[1]))
|
||||
buf, err := base64urldecode(args[1])
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -779,6 +779,10 @@ func (m *Mega) addFSNode(itm FSNode) (*Node, error) {
|
|||
|
||||
switch {
|
||||
case itm.T == FILE:
|
||||
if len(compkey) < 8 {
|
||||
m.logf("ignoring item: compkey too short (%d): %#v", len(compkey), itm)
|
||||
return nil, nil
|
||||
}
|
||||
key = []uint32{compkey[0] ^ compkey[4], compkey[1] ^ compkey[5], compkey[2] ^ compkey[6], compkey[3] ^ compkey[7]}
|
||||
default:
|
||||
key = compkey
|
||||
|
@ -789,7 +793,7 @@ func (m *Mega) addFSNode(itm FSNode) (*Node, error) {
|
|||
// FIXME:
|
||||
attr.Name = "BAD ATTRIBUTE"
|
||||
} else {
|
||||
attr, err = decryptAttr(bkey, []byte(itm.Attr))
|
||||
attr, err = decryptAttr(bkey, itm.Attr)
|
||||
// FIXME:
|
||||
if err != nil {
|
||||
attr.Name = "BAD ATTRIBUTE"
|
||||
|
@ -978,7 +982,12 @@ func (m *Mega) NewDownload(src *Node) (*Download, error) {
|
|||
return nil, err
|
||||
}
|
||||
|
||||
_, err = decryptAttr(key, []byte(res[0].Attr))
|
||||
// DownloadResp has an embedded error in it for some reason
|
||||
if res[0].Err != 0 {
|
||||
return nil, parseError(res[0].Err)
|
||||
}
|
||||
|
||||
_, err = decryptAttr(key, res[0].Attr)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -1484,8 +1493,8 @@ func (u *Upload) Finish() (node *Node, err error) {
|
|||
cmsg[0].T = u.parenthash
|
||||
cmsg[0].N[0].H = string(u.completion_handle)
|
||||
cmsg[0].N[0].T = FILE
|
||||
cmsg[0].N[0].A = string(attr_data)
|
||||
cmsg[0].N[0].K = string(base64urlencode(buf))
|
||||
cmsg[0].N[0].A = attr_data
|
||||
cmsg[0].N[0].K = base64urlencode(buf)
|
||||
|
||||
request, err := json.Marshal(cmsg)
|
||||
if err != nil {
|
||||
|
@ -1662,8 +1671,8 @@ func (m *Mega) Rename(src *Node, name string) error {
|
|||
}
|
||||
|
||||
msg[0].Cmd = "a"
|
||||
msg[0].Attr = string(attr_data)
|
||||
msg[0].Key = string(base64urlencode(key))
|
||||
msg[0].Attr = attr_data
|
||||
msg[0].Key = base64urlencode(key)
|
||||
msg[0].N = src.hash
|
||||
msg[0].I, err = randString(10)
|
||||
if err != nil {
|
||||
|
@ -1723,8 +1732,8 @@ func (m *Mega) CreateDir(name string, parent *Node) (*Node, error) {
|
|||
msg[0].T = parent.hash
|
||||
msg[0].N[0].H = "xxxxxxxx"
|
||||
msg[0].N[0].T = FOLDER
|
||||
msg[0].N[0].A = string(attr_data)
|
||||
msg[0].N[0].K = string(base64urlencode(key))
|
||||
msg[0].N[0].A = attr_data
|
||||
msg[0].N[0].K = base64urlencode(key)
|
||||
msg[0].I, err = randString(10)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
@ -1817,7 +1826,7 @@ func (m *Mega) processUpdateNode(evRaw []byte) error {
|
|||
}
|
||||
|
||||
node := m.FS.hashLookup(ev.N)
|
||||
attr, err := decryptAttr(node.meta.key, []byte(ev.Attr))
|
||||
attr, err := decryptAttr(node.meta.key, ev.Attr)
|
||||
if err == nil {
|
||||
node.name = attr.Name
|
||||
} else {
|
||||
|
@ -1861,7 +1870,7 @@ func (m *Mega) pollEvents() {
|
|||
sleepTime = minSleepTime
|
||||
}
|
||||
|
||||
url := fmt.Sprintf("%s/sc?sn=%s&sid=%s", m.baseurl, m.ssn, string(m.sid))
|
||||
url := fmt.Sprintf("%s/sc?sn=%s&sid=%s", m.baseurl, m.ssn, m.sid)
|
||||
resp, err = m.client.Post(url, "application/xml", nil)
|
||||
if err != nil {
|
||||
m.logf("pollEvents: Error fetching status: %s", err)
|
||||
|
@ -2014,7 +2023,7 @@ func (m *Mega) Link(n *Node, includeKey bool) (string, error) {
|
|||
}
|
||||
if includeKey {
|
||||
m.FS.mutex.Lock()
|
||||
key := string(base64urlencode(n.meta.compkey))
|
||||
key := base64urlencode(n.meta.compkey)
|
||||
m.FS.mutex.Unlock()
|
||||
return fmt.Sprintf("%v/#!%v!%v", BASE_DOWNLOAD_URL, id, key), nil
|
||||
} else {
|
||||
|
|
8
vendor/github.com/t3rm1n4l/go-mega/messages.go
generated
vendored
8
vendor/github.com/t3rm1n4l/go-mega/messages.go
generated
vendored
|
@ -120,10 +120,10 @@ type DownloadMsg struct {
|
|||
}
|
||||
|
||||
type DownloadResp struct {
|
||||
G string `json:"g"`
|
||||
Size uint64 `json:"s"`
|
||||
Attr string `json:"at"`
|
||||
Err uint32 `json:"e"`
|
||||
G string `json:"g"`
|
||||
Size uint64 `json:"s"`
|
||||
Attr string `json:"at"`
|
||||
Err ErrorMsg `json:"e"`
|
||||
}
|
||||
|
||||
type UploadMsg struct {
|
||||
|
|
89
vendor/github.com/t3rm1n4l/go-mega/utils.go
generated
vendored
89
vendor/github.com/t3rm1n4l/go-mega/utils.go
generated
vendored
|
@ -66,48 +66,27 @@ func a32_to_bytes(a []uint32) ([]byte, error) {
|
|||
return buf.Bytes(), nil
|
||||
}
|
||||
|
||||
// base64urlencode encodes byte slice b using base64 url encoding.
|
||||
// It removes `=` padding when necessary
|
||||
func base64urlencode(b []byte) []byte {
|
||||
enc := base64.URLEncoding
|
||||
encSize := enc.EncodedLen(len(b))
|
||||
buf := make([]byte, encSize)
|
||||
enc.Encode(buf, b)
|
||||
|
||||
paddSize := 3 - len(b)%3
|
||||
if paddSize < 3 {
|
||||
encSize -= paddSize
|
||||
buf = buf[:encSize]
|
||||
}
|
||||
|
||||
return buf
|
||||
// base64urlencode encodes byte slice b using base64 url encoding
|
||||
// without `=` padding.
|
||||
func base64urlencode(b []byte) string {
|
||||
return base64.RawURLEncoding.EncodeToString(b)
|
||||
}
|
||||
|
||||
// base64urldecode decodes the byte slice b using base64 url decoding.
|
||||
// It adds required '=' padding before decoding.
|
||||
func base64urldecode(b []byte) ([]byte, error) {
|
||||
enc := base64.URLEncoding
|
||||
padSize := 4 - len(b)%4
|
||||
|
||||
switch padSize {
|
||||
case 1:
|
||||
b = append(b, '=')
|
||||
case 2:
|
||||
b = append(b, '=', '=')
|
||||
}
|
||||
|
||||
decSize := enc.DecodedLen(len(b))
|
||||
buf := make([]byte, decSize)
|
||||
n, err := enc.Decode(buf, b)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return buf[:n], err
|
||||
// base64urldecode decodes the byte slice b using unpadded base64 url
|
||||
// decoding. It also allows the characters from standard base64 to be
|
||||
// compatible with the mega decoder.
|
||||
func base64urldecode(s string) ([]byte, error) {
|
||||
enc := base64.RawURLEncoding
|
||||
// mega base64 decoder accepts the characters from both URLEncoding and StdEncoding
|
||||
// though nearly all strings are URL encoded
|
||||
s = strings.Replace(s, "+", "-", -1)
|
||||
s = strings.Replace(s, "/", "_", -1)
|
||||
return enc.DecodeString(s)
|
||||
}
|
||||
|
||||
// base64_to_a32 converts base64 encoded byte slice b to uint32 slice.
|
||||
func base64_to_a32(b []byte) ([]uint32, error) {
|
||||
d, err := base64urldecode(b)
|
||||
func base64_to_a32(s string) ([]uint32, error) {
|
||||
d, err := base64urldecode(s)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -115,10 +94,10 @@ func base64_to_a32(b []byte) ([]uint32, error) {
|
|||
}
|
||||
|
||||
// a32_to_base64 converts uint32 slice to base64 encoded byte slice.
|
||||
func a32_to_base64(a []uint32) ([]byte, error) {
|
||||
func a32_to_base64(a []uint32) (string, error) {
|
||||
d, err := a32_to_bytes(a)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return "", err
|
||||
}
|
||||
return base64urlencode(d), nil
|
||||
}
|
||||
|
@ -181,10 +160,10 @@ func password_key(p string) ([]byte, error) {
|
|||
|
||||
// stringhash computes generic string hash. Uses k as the key for AES
|
||||
// cipher.
|
||||
func stringhash(s string, k []byte) ([]byte, error) {
|
||||
func stringhash(s string, k []byte) (string, error) {
|
||||
a, err := bytes_to_a32(paddnull([]byte(s), 4))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return "", err
|
||||
}
|
||||
h := []uint32{0, 0, 0, 0}
|
||||
for i, v := range a {
|
||||
|
@ -193,18 +172,18 @@ func stringhash(s string, k []byte) ([]byte, error) {
|
|||
|
||||
hb, err := a32_to_bytes(h)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return "", err
|
||||
}
|
||||
cipher, err := aes.NewCipher(k)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return "", err
|
||||
}
|
||||
for i := 16384; i > 0; i-- {
|
||||
cipher.Encrypt(hb, hb)
|
||||
}
|
||||
ha, err := bytes_to_a32(paddnull(hb, 4))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return "", err
|
||||
}
|
||||
|
||||
return a32_to_base64([]uint32{ha[0], ha[2]})
|
||||
|
@ -272,24 +251,24 @@ func blockEncrypt(blk cipher.Block, dst, src []byte) error {
|
|||
|
||||
// decryptSeessionId decrypts the session id using the given private
|
||||
// key.
|
||||
func decryptSessionId(privk []byte, csid []byte, mk []byte) ([]byte, error) {
|
||||
func decryptSessionId(privk string, csid string, mk []byte) (string, error) {
|
||||
|
||||
block, err := aes.NewCipher(mk)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return "", err
|
||||
}
|
||||
pk, err := base64urldecode(privk)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return "", err
|
||||
}
|
||||
err = blockDecrypt(block, pk, pk)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return "", err
|
||||
}
|
||||
|
||||
c, err := base64urldecode(csid)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return "", err
|
||||
}
|
||||
|
||||
m, _ := getMPI(c)
|
||||
|
@ -328,7 +307,7 @@ func getChunkSizes(size int64) (chunks []chunkSize) {
|
|||
|
||||
var attrMatch = regexp.MustCompile(`{".*"}`)
|
||||
|
||||
func decryptAttr(key []byte, data []byte) (attr FileAttr, err error) {
|
||||
func decryptAttr(key []byte, data string) (attr FileAttr, err error) {
|
||||
err = EBADATTR
|
||||
block, err := aes.NewCipher(key)
|
||||
if err != nil {
|
||||
|
@ -340,7 +319,7 @@ func decryptAttr(key []byte, data []byte) (attr FileAttr, err error) {
|
|||
}
|
||||
mode := cipher.NewCBCDecrypter(block, iv)
|
||||
buf := make([]byte, len(data))
|
||||
ddata, err := base64urldecode([]byte(data))
|
||||
ddata, err := base64urldecode(data)
|
||||
if err != nil {
|
||||
return attr, err
|
||||
}
|
||||
|
@ -357,15 +336,15 @@ func decryptAttr(key []byte, data []byte) (attr FileAttr, err error) {
|
|||
return attr, err
|
||||
}
|
||||
|
||||
func encryptAttr(key []byte, attr FileAttr) (b []byte, err error) {
|
||||
func encryptAttr(key []byte, attr FileAttr) (b string, err error) {
|
||||
err = EBADATTR
|
||||
block, err := aes.NewCipher(key)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return "", err
|
||||
}
|
||||
data, err := json.Marshal(attr)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return "", err
|
||||
}
|
||||
attrib := []byte("MEGA")
|
||||
attrib = append(attrib, data...)
|
||||
|
@ -373,7 +352,7 @@ func encryptAttr(key []byte, attr FileAttr) (b []byte, err error) {
|
|||
|
||||
iv, err := a32_to_bytes([]uint32{0, 0, 0, 0})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return "", err
|
||||
}
|
||||
mode := cipher.NewCBCEncrypter(block, iv)
|
||||
mode.CryptBlocks(attrib, attrib)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue