| 1 |
package proton |
| 2 |
|
| 3 |
import "github.com/ProtonMail/gopenpgp/v2/crypto" |
| 4 |
|
| 5 |
type ShareMetadata struct { |
| 6 |
ShareID string // Encrypted share ID |
| 7 |
LinkID string // Encrypted link ID to which the share points (root of share). |
| 8 |
VolumeID string // Encrypted volume ID on which the share is mounted |
| 9 |
|
| 10 |
Type ShareType // Type of share |
| 11 |
State ShareState // The state of the share (active, deleted) |
| 12 |
|
| 13 |
CreationTime int64 // Creation time of the share in Unix time |
| 14 |
ModifyTime int64 // Last modification time of the share in Unix time |
| 15 |
|
| 16 |
Creator string // Creator email address |
| 17 |
Flags ShareFlags // The flag bitmap |
| 18 |
Locked bool // Whether the share is locked |
| 19 |
VolumeSoftDeleted bool // Was the volume soft deleted |
| 20 |
} |
| 21 |
|
| 22 |
// Share is an entry point to a location in the file structure (Volume). |
| 23 |
// It points to a file or folder anywhere in the tree and holds a key called the ShareKey. |
| 24 |
// To access a file or folder in Drive, a user must be a member of a share. |
| 25 |
// The membership information is tied to a specific address, and key. |
| 26 |
// This key then allows the user to decrypt the share key, giving access to the file system rooted at that share. |
| 27 |
type Share struct { |
| 28 |
ShareMetadata |
| 29 |
|
| 30 |
AddressID string // Encrypted address ID |
| 31 |
AddressKeyID string // Encrypted address key ID |
| 32 |
|
| 33 |
Key string // The private ShareKey, encrypted with a passphrase |
| 34 |
Passphrase string // The encrypted passphrase |
| 35 |
PassphraseSignature string // The signature of the passphrase |
| 36 |
} |
| 37 |
|
| 38 |
func (s Share) GetKeyRing(addrKR *crypto.KeyRing) (*crypto.KeyRing, error) { |
| 39 |
enc, err := crypto.NewPGPMessageFromArmored(s.Passphrase) |
| 40 |
if err != nil { |
| 41 |
return nil, err |
| 42 |
} |
| 43 |
|
| 44 |
dec, err := addrKR.Decrypt(enc, nil, crypto.GetUnixTime()) |
| 45 |
if err != nil { |
| 46 |
return nil, err |
| 47 |
} |
| 48 |
|
| 49 |
sig, err := crypto.NewPGPSignatureFromArmored(s.PassphraseSignature) |
| 50 |
if err != nil { |
| 51 |
return nil, err |
| 52 |
} |
| 53 |
|
| 54 |
if err := addrKR.VerifyDetached(dec, sig, crypto.GetUnixTime()); err != nil { |
| 55 |
return nil, err |
| 56 |
} |
| 57 |
|
| 58 |
lockedKey, err := crypto.NewKeyFromArmored(s.Key) |
| 59 |
if err != nil { |
| 60 |
return nil, err |
| 61 |
} |
| 62 |
|
| 63 |
unlockedKey, err := lockedKey.Unlock(dec.GetBinary()) |
| 64 |
if err != nil { |
| 65 |
return nil, err |
| 66 |
} |
| 67 |
|
| 68 |
return crypto.NewKeyRing(unlockedKey) |
| 69 |
} |
| 70 |
|
| 71 |
type ShareType int |
| 72 |
|
| 73 |
const ( |
| 74 |
ShareTypeMain ShareType = 1 |
| 75 |
ShareTypeStandard ShareType = 2 |
| 76 |
ShareTypeDevice ShareType = 3 |
| 77 |
) |
| 78 |
|
| 79 |
type ShareState int |
| 80 |
|
| 81 |
const ( |
| 82 |
ShareStateActive ShareState = 1 |
| 83 |
ShareStateDeleted ShareState = 2 |
| 84 |
) |
| 85 |
|
| 86 |
type ShareFlags int |
| 87 |
|
| 88 |
const ( |
| 89 |
NoFlags ShareFlags = iota |
| 90 |
PrimaryShare |
| 91 |
) |