Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
dms3
go-dms3
Commits
e305e45e
Commit
e305e45e
authored
Nov 04, 2014
by
Brian Tiger Chow
Committed by
Juan Batiz-Benet
Nov 14, 2014
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix(ipfs2/init) identity
parent
62fd9166
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
36 additions
and
26 deletions
+36
-26
cmd/ipfs2/init.go
cmd/ipfs2/init.go
+36
-26
No files found.
cmd/ipfs2/init.go
View file @
e305e45e
...
...
@@ -3,6 +3,7 @@ package main
import
(
"encoding/base64"
"errors"
"fmt"
"os"
"path/filepath"
...
...
@@ -92,7 +93,11 @@ func doInit(configRoot string, dspath string, force bool, nBitsForKeypair int) e
}
cfg
.
Datastore
=
ds
cfg
.
Identity
=
config
.
Identity
{}
identity
,
err
:=
identityConfig
(
nBitsForKeypair
)
if
err
!=
nil
{
return
err
}
cfg
.
Identity
=
identity
// setup the node addresses.
cfg
.
Addresses
=
config
.
Addresses
{
...
...
@@ -106,31 +111,6 @@ func doInit(configRoot string, dspath string, force bool, nBitsForKeypair int) e
IPNS
:
"/ipns"
,
}
// TODO guard higher up
if
nBitsForKeypair
<
1024
{
return
errors
.
New
(
"Bitsize less than 1024 is considered unsafe."
)
}
u
.
POut
(
"generating key pair
\n
"
)
sk
,
pk
,
err
:=
ci
.
GenerateKeyPair
(
ci
.
RSA
,
nBitsForKeypair
)
if
err
!=
nil
{
return
err
}
// currently storing key unencrypted. in the future we need to encrypt it.
// TODO(security)
skbytes
,
err
:=
sk
.
Bytes
()
if
err
!=
nil
{
return
err
}
cfg
.
Identity
.
PrivKey
=
base64
.
StdEncoding
.
EncodeToString
(
skbytes
)
id
,
err
:=
peer
.
IDFromPubKey
(
pk
)
if
err
!=
nil
{
return
err
}
cfg
.
Identity
.
PeerID
=
id
.
Pretty
()
cfg
.
Bootstrap
=
defaultPeers
// tracking ipfs version used to generate the init folder and adding update checker default setting.
...
...
@@ -172,3 +152,33 @@ func datastoreConfig(dspath string) (config.Datastore, error) {
return
ds
,
nil
}
func
identityConfig
(
nbits
int
)
(
config
.
Identity
,
error
)
{
// TODO guard higher up
ident
:=
config
.
Identity
{}
if
nbits
<
1024
{
return
ident
,
errors
.
New
(
"Bitsize less than 1024 is considered unsafe."
)
}
fmt
.
Println
(
"generating key pair..."
)
sk
,
pk
,
err
:=
ci
.
GenerateKeyPair
(
ci
.
RSA
,
nbits
)
if
err
!=
nil
{
return
ident
,
err
}
// currently storing key unencrypted. in the future we need to encrypt it.
// TODO(security)
skbytes
,
err
:=
sk
.
Bytes
()
if
err
!=
nil
{
return
ident
,
err
}
ident
.
PrivKey
=
base64
.
StdEncoding
.
EncodeToString
(
skbytes
)
id
,
err
:=
peer
.
IDFromPubKey
(
pk
)
if
err
!=
nil
{
return
ident
,
err
}
ident
.
PeerID
=
id
.
Pretty
()
return
ident
,
nil
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment