forked from keybase/client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
box.go
53 lines (44 loc) · 1.22 KB
/
box.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
package teams
import (
"encoding/base64"
"github.com/keybase/client/go/libkb"
"github.com/keybase/client/go/protocol/keybase1"
)
// TeamBox comes from api server team/get endpoint.
type TeamBox struct {
Nonce string
SenderKID keybase1.KID `json:"sender_kid"`
Generation keybase1.PerTeamKeyGeneration
Ctext string
PerUserKeySeqno keybase1.Seqno `json:"per_user_key_seqno"`
}
// Open decrypts Ctext using encKey.
func (t *TeamBox) Open(encKey *libkb.NaclDHKeyPair) (keybase1.PerTeamKeySeed, error) {
var ret keybase1.PerTeamKeySeed
nonce, err := t.nonceBytes()
if err != nil {
return ret, err
}
ctext, err := t.ctextBytes()
if err != nil {
return ret, err
}
nei := &libkb.NaclEncryptionInfo{
Ciphertext: ctext,
EncryptionType: libkb.KIDNaclDH,
Nonce: nonce,
Receiver: encKey.GetKID().ToBytes(),
Sender: t.SenderKID.ToBytes(),
}
plaintext, _, err := encKey.Decrypt(nei)
if err != nil {
return ret, err
}
return libkb.MakeByte32Soft(plaintext)
}
func (t *TeamBox) nonceBytes() ([]byte, error) {
return base64.StdEncoding.DecodeString(t.Nonce)
}
func (t *TeamBox) ctextBytes() ([]byte, error) {
return base64.StdEncoding.DecodeString(t.Ctext)
}