This commit is contained in:
bel
2020-01-13 03:37:51 +00:00
commit c8eb52f9ba
2023 changed files with 702080 additions and 0 deletions

28
.rclone_repo/vendor/github.com/t3rm1n4l/go-mega/.travis.yml generated vendored Executable file
View File

@@ -0,0 +1,28 @@
language: go
sudo: false
osx_image: xcode7.3
os:
- linux
go:
- 1.7.6
- 1.8.7
- 1.9.5
- "1.10.1"
- tip
install:
- make build_dep
script:
- make check
- make test
matrix:
allow_failures:
- go: tip
include:
- os: osx
go: "1.10.1"
env:
global:
- secure: RzsF80V1i69FVJwKSF8WrFzk5bRUKtPxRkhjiLOO0b1usFg0EIY6XFp3s/VTR6oT91LRXml3Bp7wHHrkPvGnHyUyuxj6loj3gIrsX8cZHUtjyQX/Szfi9MOJpbdJvfCcHByEh9YGldAz//9zvEo5oGuI29Luur3cv+BJNJElmHg=
- secure: Eu3kWJbxpKyioitPQo75gI3gL/HKEHVMdp6YLxxcmlrbG2xyXdlFhTB2YkkmnC8jNvf7XJWdtYnhlWM9MrNY1fUiRyGSAmpSlzzCa9XQ9lCv0hUH57+D3PAcH6gdgKn6q1iOk26CxOCKAHVaj5xdDMIyCc4mD+sLyTDQhBIHABc=
notifications:
email: false

18
.rclone_repo/vendor/github.com/t3rm1n4l/go-mega/Makefile generated vendored Executable file
View File

@@ -0,0 +1,18 @@
build:
go build
test:
go test -cpu 4 -v -race
# Get the build dependencies
build_dep:
go get -u github.com/kisielk/errcheck
go get -u golang.org/x/tools/cmd/goimports
-#go get -u github.com/golang/lint/golint
# Do source code quality checks
check:
go vet
errcheck
goimports -d . | grep . ; test $$? -eq 1
-#golint

65
.rclone_repo/vendor/github.com/t3rm1n4l/go-mega/README.md generated vendored Executable file
View File

@@ -0,0 +1,65 @@
go-mega
=======
A client library in go for mega.co.nz storage service.
An implementation of command-line utility can be found at [https://github.com/t3rm1n4l/megacmd](https://github.com/t3rm1n4l/megacmd)
[![Build Status](https://secure.travis-ci.org/t3rm1n4l/go-mega.png?branch=master)](http://travis-ci.org/t3rm1n4l/go-mega)
### What can i do with this library?
This is an API client library for MEGA storage service. Currently, the library supports the basic APIs and operations as follows:
- User login
- Fetch filesystem tree
- Upload file
- Download file
- Create directory
- Move file or directory
- Rename file or directory
- Delete file or directory
- Parallel split download and upload
- Filesystem events auto sync
- Unit tests
### API methods
Please find full doc at [http://godoc.org/github.com/t3rm1n4l/go-mega](http://godoc.org/github.com/t3rm1n4l/go-mega)
### Testing
export MEGA_USER=<user_email>
export MEGA_PASSWD=<user_passwd>
$ make test
go test -v
=== RUN TestLogin
--- PASS: TestLogin (1.90 seconds)
=== RUN TestGetUser
--- PASS: TestGetUser (1.65 seconds)
=== RUN TestUploadDownload
--- PASS: TestUploadDownload (12.28 seconds)
=== RUN TestMove
--- PASS: TestMove (9.31 seconds)
=== RUN TestRename
--- PASS: TestRename (9.16 seconds)
=== RUN TestDelete
--- PASS: TestDelete (3.87 seconds)
=== RUN TestCreateDir
--- PASS: TestCreateDir (2.34 seconds)
=== RUN TestConfig
--- PASS: TestConfig (0.01 seconds)
=== RUN TestPathLookup
--- PASS: TestPathLookup (8.54 seconds)
=== RUN TestEventNotify
--- PASS: TestEventNotify (19.65 seconds)
PASS
ok github.com/t3rm1n4l/go-mega68.745s
### TODO
- Implement APIs for public download url generation
- Implement download from public url
- Add shared user content management APIs
- Add contact list management APIs
### License
MIT

85
.rclone_repo/vendor/github.com/t3rm1n4l/go-mega/errors.go generated vendored Executable file
View File

@@ -0,0 +1,85 @@
package mega
import (
"errors"
"fmt"
)
var (
// General errors
EINTERNAL = errors.New("Internal error occured")
EARGS = errors.New("Invalid arguments")
EAGAIN = errors.New("Try again")
ERATELIMIT = errors.New("Rate limit reached")
EBADRESP = errors.New("Bad response from server")
// Upload errors
EFAILED = errors.New("The upload failed. Please restart it from scratch")
ETOOMANY = errors.New("Too many concurrent IP addresses are accessing this upload target URL")
ERANGE = errors.New("The upload file packet is out of range or not starting and ending on a chunk boundary")
EEXPIRED = errors.New("The upload target URL you are trying to access has expired. Please request a fresh one")
// Filesystem/Account errors
ENOENT = errors.New("Object (typically, node or user) not found")
ECIRCULAR = errors.New("Circular linkage attempted")
EACCESS = errors.New("Access violation")
EEXIST = errors.New("Trying to create an object that already exists")
EINCOMPLETE = errors.New("Trying to access an incomplete resource")
EKEY = errors.New("A decryption operation failed")
ESID = errors.New("Invalid or expired user session, please relogin")
EBLOCKED = errors.New("User blocked")
EOVERQUOTA = errors.New("Request over quota")
ETEMPUNAVAIL = errors.New("Resource temporarily not available, please try again later")
EMACMISMATCH = errors.New("MAC verification failed")
EBADATTR = errors.New("Bad node attribute")
// Config errors
EWORKER_LIMIT_EXCEEDED = errors.New("Maximum worker limit exceeded")
)
type ErrorMsg int
func parseError(errno ErrorMsg) error {
switch {
case errno == 0:
return nil
case errno == -1:
return EINTERNAL
case errno == -2:
return EARGS
case errno == -3:
return EAGAIN
case errno == -4:
return ERATELIMIT
case errno == -5:
return EFAILED
case errno == -6:
return ETOOMANY
case errno == -7:
return ERANGE
case errno == -8:
return EEXPIRED
case errno == -9:
return ENOENT
case errno == -10:
return ECIRCULAR
case errno == -11:
return EACCESS
case errno == -12:
return EEXIST
case errno == -13:
return EINCOMPLETE
case errno == -14:
return EKEY
case errno == -15:
return ESID
case errno == -16:
return EBLOCKED
case errno == -17:
return EOVERQUOTA
case errno == -18:
return ETEMPUNAVAIL
}
return fmt.Errorf("Unknown mega error %d", errno)
}

1785
.rclone_repo/vendor/github.com/t3rm1n4l/go-mega/mega.go generated vendored Executable file

File diff suppressed because it is too large Load Diff

200
.rclone_repo/vendor/github.com/t3rm1n4l/go-mega/messages.go generated vendored Executable file
View File

@@ -0,0 +1,200 @@
package mega
import "encoding/json"
type LoginMsg struct {
Cmd string `json:"a"`
User string `json:"user"`
Handle string `json:"uh"`
}
type LoginResp struct {
Csid string `json:"csid"`
Privk string `json:"privk"`
Key string `json:"k"`
}
type UserMsg struct {
Cmd string `json:"a"`
}
type UserResp struct {
U string `json:"u"`
S int `json:"s"`
Email string `json:"email"`
Name string `json:"name"`
Key string `json:"k"`
C int `json:"c"`
Pubk string `json:"pubk"`
Privk string `json:"privk"`
Terms string `json:"terms"`
TS string `json:"ts"`
}
type QuotaMsg struct {
// Action, should be "uq" for quota request
Cmd string `json:"a"`
// xfer should be 1
Xfer int `json:"xfer"`
// Without strg=1 only reports total capacity for account
Strg int `json:"strg,omitempty"`
}
type QuotaResp struct {
// Mstrg is total capacity in bytes
Mstrg uint64 `json:"mstrg"`
// Cstrg is used capacity in bytes
Cstrg uint64 `json:"cstrg"`
// Per folder usage in bytes?
Cstrgn map[string][]int64 `json:"cstrgn"`
}
type FilesMsg struct {
Cmd string `json:"a"`
C int `json:"c"`
}
type FSNode struct {
Hash string `json:"h"`
Parent string `json:"p"`
User string `json:"u"`
T int `json:"t"`
Attr string `json:"a"`
Key string `json:"k"`
Ts int64 `json:"ts"`
SUser string `json:"su"`
SKey string `json:"sk"`
Sz int64 `json:"s"`
}
type FilesResp struct {
F []FSNode `json:"f"`
Ok []struct {
Hash string `json:"h"`
Key string `json:"k"`
} `json:"ok"`
S []struct {
Hash string `json:"h"`
User string `json:"u"`
} `json:"s"`
User []struct {
User string `json:"u"`
C int `json:"c"`
Email string `json:"m"`
} `json:"u"`
Sn string `json:"sn"`
}
type FileAttr struct {
Name string `json:"n"`
}
type GetLinkMsg struct {
Cmd string `json:"a"`
N string `json:"n"`
}
type DownloadMsg struct {
Cmd string `json:"a"`
G int `json:"g"`
P string `json:"p,omitempty"`
N string `json:"n,omitempty"`
}
type DownloadResp struct {
G string `json:"g"`
Size uint64 `json:"s"`
Attr string `json:"at"`
Err uint32 `json:"e"`
}
type UploadMsg struct {
Cmd string `json:"a"`
S int64 `json:"s"`
}
type UploadResp struct {
P string `json:"p"`
}
type UploadCompleteMsg struct {
Cmd string `json:"a"`
T string `json:"t"`
N [1]struct {
H string `json:"h"`
T int `json:"t"`
A string `json:"a"`
K string `json:"k"`
} `json:"n"`
I string `json:"i,omitempty"`
}
type UploadCompleteResp struct {
F []FSNode `json:"f"`
}
type FileInfoMsg struct {
Cmd string `json:"a"`
F int `json:"f"`
P string `json:"p"`
}
type MoveFileMsg struct {
Cmd string `json:"a"`
N string `json:"n"`
T string `json:"t"`
I string `json:"i"`
}
type FileAttrMsg struct {
Cmd string `json:"a"`
Attr string `json:"attr"`
Key string `json:"key"`
N string `json:"n"`
I string `json:"i"`
}
type FileDeleteMsg struct {
Cmd string `json:"a"`
N string `json:"n"`
I string `json:"i"`
}
// GenericEvent is a generic event for parsing the Cmd type before
// decoding more specifically
type GenericEvent struct {
Cmd string `json:"a"`
}
// FSEvent - event for various file system events
//
// Delete (a=d)
// Update attr (a=u)
// New nodes (a=t)
type FSEvent struct {
Cmd string `json:"a"`
T struct {
Files []FSNode `json:"f"`
} `json:"t"`
Owner string `json:"ou"`
N string `json:"n"`
User string `json:"u"`
Attr string `json:"at"`
Key string `json:"k"`
Ts int64 `json:"ts"`
I string `json:"i"`
}
// Events is received from a poll of the server to read the events
//
// Each event can be an error message or a different field so we delay
// decoding
type Events struct {
W string `json:"w"`
Sn string `json:"sn"`
E []json.RawMessage `json:"a"`
}

336
.rclone_repo/vendor/github.com/t3rm1n4l/go-mega/utils.go generated vendored Executable file
View File

@@ -0,0 +1,336 @@
package mega
import (
"bytes"
"crypto/aes"
"crypto/cipher"
"crypto/rand"
"encoding/base64"
"encoding/binary"
"encoding/json"
"errors"
"math/big"
"net"
"net/http"
"regexp"
"strings"
"time"
)
func newHttpClient(timeout time.Duration) *http.Client {
// TODO: Need to test this out
// Doesn't seem to work as expected
c := &http.Client{
Transport: &http.Transport{
Dial: func(netw, addr string) (net.Conn, error) {
c, err := net.DialTimeout(netw, addr, timeout)
if err != nil {
return nil, err
}
return c, nil
},
Proxy: http.ProxyFromEnvironment,
},
}
return c
}
// bytes_to_a32 converts the byte slice b to uint32 slice considering
// the bytes to be in big endian order.
func bytes_to_a32(b []byte) []uint32 {
length := len(b) + 3
a := make([]uint32, length/4)
buf := bytes.NewBuffer(b)
for i, _ := range a {
_ = binary.Read(buf, binary.BigEndian, &a[i])
}
return a
}
// a32_to_bytes converts the uint32 slice a to byte slice where each
// uint32 is decoded in big endian order.
func a32_to_bytes(a []uint32) []byte {
buf := new(bytes.Buffer)
buf.Grow(len(a) * 4) // To prevent reallocations in Write
for _, v := range a {
_ = binary.Write(buf, binary.BigEndian, v)
}
return buf.Bytes()
}
// 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
}
// base64urldecode decodes the byte slice b using base64 url decoding.
// It adds required '=' padding before decoding.
func base64urldecode(b []byte) []byte {
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, _ := enc.Decode(buf, b)
return buf[:n]
}
// base64_to_a32 converts base64 encoded byte slice b to uint32 slice.
func base64_to_a32(b []byte) []uint32 {
return bytes_to_a32(base64urldecode(b))
}
// a32_to_base64 converts uint32 slice to base64 encoded byte slice.
func a32_to_base64(a []uint32) []byte {
return base64urlencode(a32_to_bytes(a))
}
// paddnull pads byte slice b such that the size of resulting byte
// slice is a multiple of q.
func paddnull(b []byte, q int) []byte {
if rem := len(b) % q; rem != 0 {
l := q - rem
for i := 0; i < l; i++ {
b = append(b, 0)
}
}
return b
}
// password_key calculates password hash from the user password.
func password_key(p string) []byte {
a := bytes_to_a32(paddnull([]byte(p), 4))
pkey := a32_to_bytes([]uint32{0x93C467E3, 0x7DB0C7A4, 0xD1BE3F81, 0x0152CB56})
n := (len(a) + 3) / 4
ciphers := make([]cipher.Block, n)
for j := 0; j < len(a); j += 4 {
key := []uint32{0, 0, 0, 0}
for k := 0; k < 4; k++ {
if j+k < len(a) {
key[k] = a[k+j]
}
}
ciphers[j/4], _ = aes.NewCipher(a32_to_bytes(key)) // Uses AES in ECB mode
}
for i := 65536; i > 0; i-- {
for j := 0; j < n; j++ {
ciphers[j].Encrypt(pkey, pkey)
}
}
return pkey
}
// stringhash computes generic string hash. Uses k as the key for AES
// cipher.
func stringhash(s string, k []byte) []byte {
a := bytes_to_a32(paddnull([]byte(s), 4))
h := []uint32{0, 0, 0, 0}
for i, v := range a {
h[i&3] ^= v
}
hb := a32_to_bytes(h)
cipher, _ := aes.NewCipher(k)
for i := 16384; i > 0; i-- {
cipher.Encrypt(hb, hb)
}
ha := bytes_to_a32(paddnull(hb, 4))
return a32_to_base64([]uint32{ha[0], ha[2]})
}
// getMPI returns the length encoded Int and the next slice.
func getMPI(b []byte) (*big.Int, []byte) {
p := new(big.Int)
plen := (uint64(b[0])*256 + uint64(b[1]) + 7) >> 3
p.SetBytes(b[2 : plen+2])
b = b[plen+2:]
return p, b
}
// getRSAKey decodes the RSA Key from the byte slice b.
func getRSAKey(b []byte) (*big.Int, *big.Int, *big.Int) {
p, b := getMPI(b)
q, b := getMPI(b)
d, _ := getMPI(b)
return p, q, d
}
// decryptRSA decrypts message m using RSA private key (p,q,d)
func decryptRSA(m, p, q, d *big.Int) []byte {
n := new(big.Int)
r := new(big.Int)
n.Mul(p, q)
r.Exp(m, d, n)
return r.Bytes()
}
// blockDecrypt decrypts using the block cipher blk in ECB mode.
func blockDecrypt(blk cipher.Block, dst, src []byte) error {
if len(src) > len(dst) || len(src)%blk.BlockSize() != 0 {
return errors.New("Block decryption failed")
}
l := len(src) - blk.BlockSize()
for i := 0; i <= l; i += blk.BlockSize() {
blk.Decrypt(dst[i:], src[i:])
}
return nil
}
// blockEncrypt encrypts using the block cipher blk in ECB mode.
func blockEncrypt(blk cipher.Block, dst, src []byte) error {
if len(src) > len(dst) || len(src)%blk.BlockSize() != 0 {
return errors.New("Block encryption failed")
}
l := len(src) - blk.BlockSize()
for i := 0; i <= l; i += blk.BlockSize() {
blk.Encrypt(dst[i:], src[i:])
}
return nil
}
// decryptSeessionId decrypts the session id using the given private
// key.
func decryptSessionId(privk []byte, csid []byte, mk []byte) ([]byte, error) {
block, _ := aes.NewCipher(mk)
pk := base64urldecode(privk)
err := blockDecrypt(block, pk, pk)
if err != nil {
return nil, err
}
c := base64urldecode(csid)
m, _ := getMPI(c)
p, q, d := getRSAKey(pk)
r := decryptRSA(m, p, q, d)
return base64urlencode(r[:43]), nil
}
// chunkSize describes a size and position of chunk
type chunkSize struct {
position int64
size int
}
func getChunkSizes(size int64) (chunks []chunkSize) {
p := int64(0)
for i := 1; size > 0; i++ {
var chunk int
if i <= 8 {
chunk = i * 131072
} else {
chunk = 1048576
}
if size < int64(chunk) {
chunk = int(size)
}
chunks = append(chunks, chunkSize{position: p, size: chunk})
p += int64(chunk)
size -= int64(chunk)
}
return chunks
}
var attrMatch = regexp.MustCompile(`{".*"}`)
func decryptAttr(key []byte, data []byte) (attr FileAttr, err error) {
err = EBADATTR
block, err := aes.NewCipher(key)
if err != nil {
return attr, err
}
iv := a32_to_bytes([]uint32{0, 0, 0, 0})
mode := cipher.NewCBCDecrypter(block, iv)
buf := make([]byte, len(data))
mode.CryptBlocks(buf, base64urldecode([]byte(data)))
if string(buf[:4]) == "MEGA" {
str := strings.TrimRight(string(buf[4:]), "\x00")
trimmed := attrMatch.FindString(str)
if trimmed != "" {
str = trimmed
}
err = json.Unmarshal([]byte(str), &attr)
}
return attr, err
}
func encryptAttr(key []byte, attr FileAttr) (b []byte, err error) {
err = EBADATTR
block, err := aes.NewCipher(key)
if err != nil {
return nil, err
}
data, err := json.Marshal(attr)
if err != nil {
return nil, err
}
attrib := []byte("MEGA")
attrib = append(attrib, data...)
attrib = paddnull(attrib, 16)
iv := a32_to_bytes([]uint32{0, 0, 0, 0})
mode := cipher.NewCBCEncrypter(block, iv)
mode.CryptBlocks(attrib, attrib)
b = base64urlencode(attrib)
return b, nil
}
func randString(l int) (string, error) {
encoding := "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AB"
b := make([]byte, l)
_, err := rand.Read(b)
if err != nil {
return "", err
}
enc := base64.NewEncoding(encoding)
d := make([]byte, enc.EncodedLen(len(b)))
enc.Encode(d, b)
d = d[:l]
return string(d), nil
}