mirror of
https://github.com/ipfs/kubo.git
synced 2025-07-01 10:49:24 +08:00
fix(ipfs2/init) identity
This commit is contained in:

committed by
Juan Batiz-Benet

parent
62fd9166ce
commit
e305e45e81
@ -3,6 +3,7 @@ package main
|
|||||||
import (
|
import (
|
||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
"errors"
|
"errors"
|
||||||
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
@ -92,7 +93,11 @@ func doInit(configRoot string, dspath string, force bool, nBitsForKeypair int) e
|
|||||||
}
|
}
|
||||||
cfg.Datastore = ds
|
cfg.Datastore = ds
|
||||||
|
|
||||||
cfg.Identity = config.Identity{}
|
identity, err := identityConfig(nBitsForKeypair)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
cfg.Identity = identity
|
||||||
|
|
||||||
// setup the node addresses.
|
// setup the node addresses.
|
||||||
cfg.Addresses = config.Addresses{
|
cfg.Addresses = config.Addresses{
|
||||||
@ -106,31 +111,6 @@ func doInit(configRoot string, dspath string, force bool, nBitsForKeypair int) e
|
|||||||
IPNS: "/ipns",
|
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
|
cfg.Bootstrap = defaultPeers
|
||||||
|
|
||||||
// tracking ipfs version used to generate the init folder and adding update checker default setting.
|
// 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
|
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
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user