-
-
Notifications
You must be signed in to change notification settings - Fork 7
/
vault.go
47 lines (41 loc) · 1.06 KB
/
vault.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
package lastpass
import (
"bytes"
)
type Account struct {
Id string `json:"id"`
Name string `json:"name"`
Username string `json:"username"`
Password string `json:"password"`
Url string `json:"url"`
Group string `json:"group"`
Notes string `json:"notes"`
}
type Vault struct {
Accounts []*Account `json:"accounts"`
}
func CreateVault(username, password string) (*Vault, error) {
session, err := login(username, password)
if err != nil {
return nil, err
}
blob, err := fetch(session)
if err != nil {
return nil, err
}
chunks, err := extractChunks(bytes.NewReader(blob.bytes), []uint32{chunkIdFromString("ACCT")})
if err != nil {
return nil, err
}
accountChunks := chunks[chunkIdFromString("ACCT")]
vault := &Vault{Accounts: make([]*Account, len(accountChunks))}
encryptionKey := makeKey(username, password, blob.keyIterationCount)
for i, chunk := range accountChunks {
account, err := parseAccount(bytes.NewReader(chunk), encryptionKey)
if err != nil {
return nil, err
}
vault.Accounts[i] = account
}
return vault, nil
}