2
2
3
3
** Authors(s):**
4
4
- [ whyrusleeping] ( github.com/whyrusleeping )
5
+ - [ Hector Sanjuan] ( github.com/hsanjuan )
5
6
6
7
* * *
7
8
8
9
** Abstract**
9
10
10
- TODO
11
+ This spec provides definitions and operations for the keystore feature in IPFS.
11
12
12
13
# Table of Contents
13
14
14
15
TODO
15
16
16
17
## Goals:
17
18
18
- To have a secure, simple and user-friendly way of storing and managing keypairs
19
+ To have a secure, simple and user-friendly way of storing and managing keys
19
20
for use by ipfs. As well as the ability to share these keys, encrypt, decrypt,
20
21
sign and verify data.
21
22
22
23
## Planned Implementation
23
- ### Storage
24
24
25
- Keys will be stored in a directory named ` keys ` under the ` $IPFS_PATH `
26
- directory. Each named keypair will be stored across two files, the private key
27
- in ` $NAME ` and the public key in ` $NAME.pub ` . They will be encoded in PEM (or
28
- similar) format, and optionally password encrypted. Upon starting the ipfs daemon,
29
- keys will be lazily loaded as needed. If a given key is password protected, the user
30
- should be prompted for the password at the time of loading the key. The ` $IPFS_PATH/keys `
31
- directory should be readable only be the owner, with unix permissions of ` 700 ` . Keys
32
- in the directory should be readonly, by the owner ` 400 ` .
25
+ ### Key storage
26
+
27
+ Storage layout and format is defined in the [ ` REPO_FS ` ] ( REPO_FS.md ) part of the spec.
33
28
34
29
### Interface
35
- Several additions and modifications will need to be made to the ipfs toolchain to
36
- accommodate the changes. First, the creation of two subcommands ` ipfs key ` and
37
- ` ipfs crypt ` :
30
+
31
+ #### ipfs key
38
32
39
33
```
40
34
@@ -45,11 +39,11 @@ SUBCOMMANDS:
45
39
ipfs key gen - Generates a new named ipfs keypair
46
40
ipfs key list - Lists out all local keypairs
47
41
ipfs key info <key> - Get information about a given key
48
- ipfs key rm <key> - Delete a given key from your keystore
49
- ipfs key rename <key> <name> - Renames a given key
50
- ipfs key show <key> - Print out a given key
42
+ ipfs key rm <key> - Delete a given key from your keystore
43
+ ipfs key rename <key> <name> - Renames a given key
44
+ ipfs key show <key> - Print out a given key
51
45
52
- ipfs key send <key> <peer> - Shares a specified private key with the given peer
46
+ ipfs key send <key> <peer> - Shares a specified private key with the given peer
53
47
54
48
Use 'ipfs key <subcmd> --help' for more information about each command.
55
49
@@ -59,9 +53,10 @@ DESCRIPTION:
59
53
60
54
```
61
55
62
- ```
56
+ #### ipfs crypt
63
57
64
- ipfs crypt - Perform cryptographic operations using ipfs keypairs
58
+ ```
59
+ ipfs crypt - Perform cryptographic operations using ipfs keypairs
65
60
66
61
SUBCOMMANDS:
67
62
@@ -72,33 +67,27 @@ SUBCOMMANDS:
72
67
73
68
DESCRIPTION:
74
69
75
- `ipfs crypt` is a command used to perform various cryptographic operations
76
- using ipfs keypairs, including: signing, verifying, encrypting and decrypting.
70
+ `ipfs crypt` is a command used to perform various cryptographic operations
71
+ using ipfs keypairs, including: signing, verifying, encrypting and decrypting.
77
72
```
78
73
79
74
#### Some subcommands:
80
75
81
- ##### Key Gen
82
- ```
76
+ ##### ipfs key Gen
83
77
84
- ipfs key gen - Generate a new ipfs keypair
85
78
86
- OPTIONS:
79
+ ```
80
+ ipfs key gen <name> - Generate a new ipfs keypair
87
81
88
- -t, -type string - Specify the type and size of key to generate (i.e. rsa-4096)
89
- -p, -passphrase string - Passphrase for encrypting the private key on disk
90
- -n, -name string - Specify a name for the key
82
+ OPTIONS:
83
+ -t, -type string - Specify the type and size of key to generate (i.e. rsa)
84
+ -s. -size int - Size of the key to generate
85
+ -p, -passphrase string - Passphrase for encrypting the private key on disk
91
86
92
87
DESCRIPTION:
93
88
94
89
'ipfs key gen' is a command used to generate new keypairs.
95
- If any options are not given, the command will go into interactive mode and prompt
96
- the user for the missing fields.
97
-
98
90
```
99
- ##### Comments:
100
-
101
- Similar to ssh's ` ssh-keygen ` with the ` -t ` option and interactive prompts.
102
91
103
92
* * *
104
93
@@ -109,18 +98,18 @@ Similar to ssh's `ssh-keygen` with the `-t` option and interactive prompts.
109
98
110
99
OPTIONS:
111
100
112
- -y, -yes bool - Yes to the prompt
101
+ -y, -yes bool - Yes to the prompt
113
102
114
103
DESCRIPTION:
115
104
116
105
'ipfs key send' is a command used to share keypairs with other trusted users.
117
106
118
- It will first look up the peer specified and print out their information and
119
- prompt the user "are you sure? [y/n]" before sending the keypair. The target
120
- peer must be online and dialable in order for the key to be sent.
107
+ It will first look up the peer specified and print out their information and
108
+ prompt the user "are you sure? [y/n]" before sending the keypair. The target
109
+ peer must be online and dialable in order for the key to be sent.
121
110
122
- Note: while it is still managed through the keystore, ipfs will prevent you from
123
- sharing your nodes private key with anyone else.
111
+ Note: while it is still managed through the keystore, ipfs will prevent you from
112
+ sharing your nodes private key with anyone else.
124
113
125
114
```
126
115
@@ -137,19 +126,19 @@ Ensure that the user knows the implications of sending a key.
137
126
138
127
ARGUMENTS:
139
128
140
- data - The filename of the data to be encrypted ("-" for stdin)
129
+ data - The filename of the data to be encrypted ("-" for stdin)
141
130
142
131
OPTIONS:
143
132
144
- -k, -key string - The name of the key to use for encryption (default: localkey)
145
- -o, -output string - The name of the output file (default: stdout)
146
- -c, -cipher string - The cipher to use for the operation
147
- -m, -mode string - The block cipher mode to use for the operation
133
+ -k, -key string - The name of the key to use for encryption (default: localkey)
134
+ -o, -output string - The name of the output file (default: stdout)
135
+ -c, -cipher string - The cipher to use for the operation
136
+ -m, -mode string - The block cipher mode to use for the operation
148
137
149
138
DESCRIPTION:
150
139
151
- 'ipfs crypt encrypt' is a command used to encrypt data so that only holders of a certain
152
- key can read it.
140
+ 'ipfs crypt encrypt' is a command used to encypt data so that only holders of a certain
141
+ key can read it.
153
142
154
143
```
155
144
@@ -165,8 +154,8 @@ We will also need to make additions to support keys in other commands, these cha
165
154
166
155
- ` ipfs add `
167
156
- Support for a ` -encrypt-key ` option, for block encrypting the file being added with the key
168
- - also adds an 'encrypted' node above the root unixfs node
169
- - Support for a `-sign-key` option to attach a signature node above the root unixfs node
157
+ - also adds an 'encrypted' node above the root unixfs node
158
+ - Support for a ` -sign-key ` option to attach a signature node above the root unixfs node
170
159
171
160
- ` ipfs block put `
172
161
- Support for a ` -encrypt-key ` option, for encrypting the block before hashing and storing
@@ -175,28 +164,30 @@ We will also need to make additions to support keys in other commands, these cha
175
164
- Support for a ` -encrypt-key ` option, for encrypting the object before hashing and storing
176
165
177
166
- ` ipfs name publish `
178
- - Support for a `-key` option to select which keyspace to publish to
179
-
180
- ### Code Changes/Additions
181
- An outline of which packages or submodules will be affected.
182
-
183
- #### Repo
184
-
185
- - add ` keystore ` concept to repo, load/store keys securely
186
- - needs to understand PEM (or $CHOSEN_FORMAT) encoding
187
-
188
- Expected Interface: (very wip)
189
-
190
- ```
191
- type KeyStore interface {
192
- // Get a key from the cache
193
- GetKey(name string) (ci.PrivKey, error)
194
-
195
- // Save a new key into the cache, and write to disk
196
- StoreKey(name string, key ci.PrivKey) error
197
-
198
- // LoadKey reads the key from its file on disk, and stores it in the cache
199
- LoadKey(name string, password []byte) error
167
+ - Support for a ` -key ` option to select which keyspace to publish to
168
+
169
+ ### Code changes and additions
170
+
171
+ This sections outlines code organization around this feature.
172
+
173
+ #### Keystore package
174
+
175
+ The fsrepo carries a ` keystore ` that can be used to load/store keys. The keystore is implemented following this interface:
176
+
177
+ ``` go
178
+ // Keystore provides a key management interface
179
+ type Keystore interface {
180
+ // Has returns whether or not a key exist in the Keystore
181
+ Has (string ) (bool , error )
182
+ // Put stores a key in the Keystore, if a key with the same name already exists, returns ErrKeyExists
183
+ Put (string , ci.PrivKey ) error
184
+ // Get retrieves a key from the Keystore if it exists, and returns ErrNoSuchKey
185
+ // otherwise.
186
+ Get (string ) (ci.PrivKey , error )
187
+ // Delete removes a key from the Keystore
188
+ Delete (string ) error
189
+ // List returns a list of key identifier
190
+ List () ([]string , error )
200
191
}
201
192
```
202
193
@@ -210,14 +201,14 @@ does not linger in memory.
210
201
- if new node types are not unixfs nodes, special consideration must be given to the interop
211
202
212
203
- DagReader needs to be able to access keystore to seamlessly stream encrypted data we have keys for
213
- - also needs to be able to verify signatures
204
+ - also needs to be able to verify signatures
214
205
215
206
#### Importer
216
207
217
208
- DagBuilderHelper needs to be able to encrypt blocks
218
- - Dag Nodes should be generated like normal, then encrypted, and their parents should
219
- link to the hash of the encrypted node
220
- - DagBuilderParams should have extra parameters to accommodate creating a DBH that encrypts the blocks
209
+ - Dag Nodes should be generated like normal, then encrypted, and their parents should
210
+ link to the hash of the encrypted node
211
+ - DagBuilderParams should have extra parameters to acommodate creating a DBH that encrypts the blocks
221
212
222
213
#### New 'Encrypt' package
223
214
@@ -235,33 +226,33 @@ Some tentative mockups (in json) of the new DAG structures for signing and encry
235
226
Signed DAG:
236
227
```
237
228
{
238
- "Links" : [
239
- {
240
- "Name":"@content",
241
- "Hash":"QmTheContent",
242
- }
243
- ],
244
- "Data": protobuf{
245
- "Type":"Signed DAG",
246
- "Signature": "thesignature",
247
- "PubKeyID": "QmPubKeyHash",
248
- }
229
+ "Links" : [
230
+ {
231
+ "Name":"@content",
232
+ "Hash":"QmTheContent",
233
+ }
234
+ ],
235
+ "Data": protobuf{
236
+ "Type":"Signed DAG",
237
+ "Signature": "thesignature",
238
+ "PubKeyID": "QmPubKeyHash",
239
+ }
249
240
}
250
241
```
251
242
252
243
Encrypted DAG:
253
244
```
254
245
{
255
- "Links" : [
256
- {
257
- "Name":"@content",
258
- "Hash":"QmRawEncryptedDag",
259
- }
260
- ],
261
- "Data": protobuf{
262
- "Type":"Encrypted DAG",
263
- "PubKeyID": "QmPubKeyHash",
264
- "Key": "ephemeral symmetric key, encrypted with public key",
265
- }
246
+ "Links" : [
247
+ {
248
+ "Name":"@content",
249
+ "Hash":"QmRawEncryptedDag",
250
+ }
251
+ ],
252
+ "Data": protobuf{
253
+ "Type":"Encrypted DAG",
254
+ "PubKeyID": "QmPubKeyHash",
255
+ "Key": "ephemeral symmetric key, encrypted with public key",
256
+ }
266
257
}
267
258
```
0 commit comments