/
crypto.go
271 lines (240 loc) · 8.71 KB
/
crypto.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
// Auto-generated by avdl-compiler v1.3.22 (https://github.com/keybase/node-avdl-compiler)
// Input file: avdl/keybase1/crypto.avdl
package keybase1
import (
"github.com/keybase/go-framed-msgpack-rpc/rpc"
context "golang.org/x/net/context"
)
type ED25519PublicKey [32]byte
func (o ED25519PublicKey) DeepCopy() ED25519PublicKey {
var ret ED25519PublicKey
copy(ret[:], o[:])
return ret
}
type ED25519Signature [64]byte
func (o ED25519Signature) DeepCopy() ED25519Signature {
var ret ED25519Signature
copy(ret[:], o[:])
return ret
}
type ED25519SignatureInfo struct {
Sig ED25519Signature `codec:"sig" json:"sig"`
PublicKey ED25519PublicKey `codec:"publicKey" json:"publicKey"`
}
func (o ED25519SignatureInfo) DeepCopy() ED25519SignatureInfo {
return ED25519SignatureInfo{
Sig: o.Sig.DeepCopy(),
PublicKey: o.PublicKey.DeepCopy(),
}
}
type EncryptedBytes32 [48]byte
func (o EncryptedBytes32) DeepCopy() EncryptedBytes32 {
var ret EncryptedBytes32
copy(ret[:], o[:])
return ret
}
type BoxNonce [24]byte
func (o BoxNonce) DeepCopy() BoxNonce {
var ret BoxNonce
copy(ret[:], o[:])
return ret
}
type BoxPublicKey [32]byte
func (o BoxPublicKey) DeepCopy() BoxPublicKey {
var ret BoxPublicKey
copy(ret[:], o[:])
return ret
}
type CiphertextBundle struct {
Kid KID `codec:"kid" json:"kid"`
Ciphertext EncryptedBytes32 `codec:"ciphertext" json:"ciphertext"`
Nonce BoxNonce `codec:"nonce" json:"nonce"`
PublicKey BoxPublicKey `codec:"publicKey" json:"publicKey"`
}
func (o CiphertextBundle) DeepCopy() CiphertextBundle {
return CiphertextBundle{
Kid: o.Kid.DeepCopy(),
Ciphertext: o.Ciphertext.DeepCopy(),
Nonce: o.Nonce.DeepCopy(),
PublicKey: o.PublicKey.DeepCopy(),
}
}
type UnboxAnyRes struct {
Kid KID `codec:"kid" json:"kid"`
Plaintext Bytes32 `codec:"plaintext" json:"plaintext"`
Index int `codec:"index" json:"index"`
}
func (o UnboxAnyRes) DeepCopy() UnboxAnyRes {
return UnboxAnyRes{
Kid: o.Kid.DeepCopy(),
Plaintext: o.Plaintext.DeepCopy(),
Index: o.Index,
}
}
type SignED25519Arg struct {
SessionID int `codec:"sessionID" json:"sessionID"`
Msg []byte `codec:"msg" json:"msg"`
Reason string `codec:"reason" json:"reason"`
}
type SignED25519ForKBFSArg struct {
SessionID int `codec:"sessionID" json:"sessionID"`
Msg []byte `codec:"msg" json:"msg"`
Reason string `codec:"reason" json:"reason"`
}
type SignToStringArg struct {
SessionID int `codec:"sessionID" json:"sessionID"`
Msg []byte `codec:"msg" json:"msg"`
Reason string `codec:"reason" json:"reason"`
}
type UnboxBytes32Arg struct {
SessionID int `codec:"sessionID" json:"sessionID"`
EncryptedBytes32 EncryptedBytes32 `codec:"encryptedBytes32" json:"encryptedBytes32"`
Nonce BoxNonce `codec:"nonce" json:"nonce"`
PeersPublicKey BoxPublicKey `codec:"peersPublicKey" json:"peersPublicKey"`
Reason string `codec:"reason" json:"reason"`
}
type UnboxBytes32AnyArg struct {
SessionID int `codec:"sessionID" json:"sessionID"`
Bundles []CiphertextBundle `codec:"bundles" json:"bundles"`
Reason string `codec:"reason" json:"reason"`
PromptPaper bool `codec:"promptPaper" json:"promptPaper"`
}
type CryptoInterface interface {
// Sign the given message (which should be small) using the device's private
// signing ED25519 key, and return the signature as well as the corresponding
// public key that can be used to verify the signature. The 'reason' parameter
// is used as part of the SecretEntryArg object passed into
// secretUi.getSecret().
SignED25519(context.Context, SignED25519Arg) (ED25519SignatureInfo, error)
// Same as the above except a KBFS-specific prefix is added to the payload to be signed.
SignED25519ForKBFS(context.Context, SignED25519ForKBFSArg) (ED25519SignatureInfo, error)
// Same as the above except the full marsheled and encoded NaclSigInfo.
SignToString(context.Context, SignToStringArg) (string, error)
// Decrypt exactly 32 bytes using nacl/box with the given nonce, the given
// peer's public key, and the device's private encryption key, and return the
// decrypted data. The 'reason' parameter is used as part of the
// SecretEntryArg object passed into secretUi.getSecret().
UnboxBytes32(context.Context, UnboxBytes32Arg) (Bytes32, error)
UnboxBytes32Any(context.Context, UnboxBytes32AnyArg) (UnboxAnyRes, error)
}
func CryptoProtocol(i CryptoInterface) rpc.Protocol {
return rpc.Protocol{
Name: "keybase.1.crypto",
Methods: map[string]rpc.ServeHandlerDescription{
"signED25519": {
MakeArg: func() interface{} {
ret := make([]SignED25519Arg, 1)
return &ret
},
Handler: func(ctx context.Context, args interface{}) (ret interface{}, err error) {
typedArgs, ok := args.(*[]SignED25519Arg)
if !ok {
err = rpc.NewTypeError((*[]SignED25519Arg)(nil), args)
return
}
ret, err = i.SignED25519(ctx, (*typedArgs)[0])
return
},
MethodType: rpc.MethodCall,
},
"signED25519ForKBFS": {
MakeArg: func() interface{} {
ret := make([]SignED25519ForKBFSArg, 1)
return &ret
},
Handler: func(ctx context.Context, args interface{}) (ret interface{}, err error) {
typedArgs, ok := args.(*[]SignED25519ForKBFSArg)
if !ok {
err = rpc.NewTypeError((*[]SignED25519ForKBFSArg)(nil), args)
return
}
ret, err = i.SignED25519ForKBFS(ctx, (*typedArgs)[0])
return
},
MethodType: rpc.MethodCall,
},
"signToString": {
MakeArg: func() interface{} {
ret := make([]SignToStringArg, 1)
return &ret
},
Handler: func(ctx context.Context, args interface{}) (ret interface{}, err error) {
typedArgs, ok := args.(*[]SignToStringArg)
if !ok {
err = rpc.NewTypeError((*[]SignToStringArg)(nil), args)
return
}
ret, err = i.SignToString(ctx, (*typedArgs)[0])
return
},
MethodType: rpc.MethodCall,
},
"unboxBytes32": {
MakeArg: func() interface{} {
ret := make([]UnboxBytes32Arg, 1)
return &ret
},
Handler: func(ctx context.Context, args interface{}) (ret interface{}, err error) {
typedArgs, ok := args.(*[]UnboxBytes32Arg)
if !ok {
err = rpc.NewTypeError((*[]UnboxBytes32Arg)(nil), args)
return
}
ret, err = i.UnboxBytes32(ctx, (*typedArgs)[0])
return
},
MethodType: rpc.MethodCall,
},
"unboxBytes32Any": {
MakeArg: func() interface{} {
ret := make([]UnboxBytes32AnyArg, 1)
return &ret
},
Handler: func(ctx context.Context, args interface{}) (ret interface{}, err error) {
typedArgs, ok := args.(*[]UnboxBytes32AnyArg)
if !ok {
err = rpc.NewTypeError((*[]UnboxBytes32AnyArg)(nil), args)
return
}
ret, err = i.UnboxBytes32Any(ctx, (*typedArgs)[0])
return
},
MethodType: rpc.MethodCall,
},
},
}
}
type CryptoClient struct {
Cli rpc.GenericClient
}
// Sign the given message (which should be small) using the device's private
// signing ED25519 key, and return the signature as well as the corresponding
// public key that can be used to verify the signature. The 'reason' parameter
// is used as part of the SecretEntryArg object passed into
// secretUi.getSecret().
func (c CryptoClient) SignED25519(ctx context.Context, __arg SignED25519Arg) (res ED25519SignatureInfo, err error) {
err = c.Cli.Call(ctx, "keybase.1.crypto.signED25519", []interface{}{__arg}, &res)
return
}
// Same as the above except a KBFS-specific prefix is added to the payload to be signed.
func (c CryptoClient) SignED25519ForKBFS(ctx context.Context, __arg SignED25519ForKBFSArg) (res ED25519SignatureInfo, err error) {
err = c.Cli.Call(ctx, "keybase.1.crypto.signED25519ForKBFS", []interface{}{__arg}, &res)
return
}
// Same as the above except the full marsheled and encoded NaclSigInfo.
func (c CryptoClient) SignToString(ctx context.Context, __arg SignToStringArg) (res string, err error) {
err = c.Cli.Call(ctx, "keybase.1.crypto.signToString", []interface{}{__arg}, &res)
return
}
// Decrypt exactly 32 bytes using nacl/box with the given nonce, the given
// peer's public key, and the device's private encryption key, and return the
// decrypted data. The 'reason' parameter is used as part of the
// SecretEntryArg object passed into secretUi.getSecret().
func (c CryptoClient) UnboxBytes32(ctx context.Context, __arg UnboxBytes32Arg) (res Bytes32, err error) {
err = c.Cli.Call(ctx, "keybase.1.crypto.unboxBytes32", []interface{}{__arg}, &res)
return
}
func (c CryptoClient) UnboxBytes32Any(ctx context.Context, __arg UnboxBytes32AnyArg) (res UnboxAnyRes, err error) {
err = c.Cli.Call(ctx, "keybase.1.crypto.unboxBytes32Any", []interface{}{__arg}, &res)
return
}