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
p2p
go-p2p-tls
Commits
46b32041
Commit
46b32041
authored
Feb 20, 2019
by
Marten Seemann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add a command line flag to set the key type
parent
7b8ba831
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
43 additions
and
5 deletions
+43
-5
example/client/main.go
example/client/main.go
+22
-3
example/server/main.go
example/server/main.go
+21
-2
No files found.
example/client/main.go
View file @
46b32041
...
...
@@ -23,22 +23,41 @@ func main() {
func
startClient
()
error
{
port
:=
flag
.
Int
(
"p"
,
5533
,
"port"
)
peerIDString
:=
flag
.
String
(
"id"
,
""
,
"peer ID"
)
keyType
:=
flag
.
String
(
"key"
,
"ecdsa"
,
"rsa, ecdsa, ed25519 or secp256k1"
)
flag
.
Parse
()
peerID
,
err
:=
peer
.
IDB58Decode
(
*
peerIDString
)
var
priv
ic
.
PrivKey
var
err
error
switch
*
keyType
{
case
"rsa"
:
fmt
.
Printf
(
"Generated new peer with an RSA key."
)
priv
,
_
,
err
=
ic
.
GenerateRSAKeyPair
(
2048
,
rand
.
Reader
)
case
"ecdsa"
:
fmt
.
Printf
(
"Generated new peer with an ECDSA key."
)
priv
,
_
,
err
=
ic
.
GenerateECDSAKeyPair
(
rand
.
Reader
)
case
"ed25519"
:
fmt
.
Printf
(
"Generated new peer with an Ed25519 key."
)
priv
,
_
,
err
=
ic
.
GenerateEd25519Key
(
rand
.
Reader
)
case
"secp256k1"
:
fmt
.
Printf
(
"Generated new peer with an Secp256k1 key."
)
priv
,
_
,
err
=
ic
.
GenerateSecp256k1Key
(
rand
.
Reader
)
default
:
return
fmt
.
Errorf
(
"unknown key type: %s"
,
*
keyType
)
}
if
err
!=
nil
{
return
err
}
p
riv
,
_
,
err
:=
ic
.
GenerateECDSAKeyPair
(
rand
.
Reader
)
p
eerID
,
err
:=
peer
.
IDB58Decode
(
*
peerIDString
)
if
err
!=
nil
{
return
err
}
id
,
err
:=
peer
.
IDFromPrivateKey
(
priv
)
if
err
!=
nil
{
return
err
}
fmt
.
Printf
(
"
Generated new peer with an ECDSA key.
Peer ID: %s
\n
"
,
id
.
Pretty
())
fmt
.
Printf
(
" Peer ID: %s
\n
"
,
id
.
Pretty
())
tp
,
err
:=
libp2ptls
.
New
(
priv
)
if
err
!=
nil
{
return
err
...
...
example/server/main.go
View file @
46b32041
...
...
@@ -21,17 +21,36 @@ func main() {
func
startServer
()
error
{
port
:=
flag
.
Int
(
"p"
,
5533
,
"port"
)
keyType
:=
flag
.
String
(
"key"
,
"ecdsa"
,
"rsa, ecdsa, ed25519 or secp256k1"
)
flag
.
Parse
()
priv
,
_
,
err
:=
ic
.
GenerateECDSAKeyPair
(
rand
.
Reader
)
var
priv
ic
.
PrivKey
var
err
error
switch
*
keyType
{
case
"rsa"
:
fmt
.
Printf
(
"Generated new peer with an RSA key."
)
priv
,
_
,
err
=
ic
.
GenerateRSAKeyPair
(
2048
,
rand
.
Reader
)
case
"ecdsa"
:
fmt
.
Printf
(
"Generated new peer with an ECDSA key."
)
priv
,
_
,
err
=
ic
.
GenerateECDSAKeyPair
(
rand
.
Reader
)
case
"ed25519"
:
fmt
.
Printf
(
"Generated new peer with an Ed25519 key."
)
priv
,
_
,
err
=
ic
.
GenerateEd25519Key
(
rand
.
Reader
)
case
"secp256k1"
:
fmt
.
Printf
(
"Generated new peer with an Secp256k1 key."
)
priv
,
_
,
err
=
ic
.
GenerateSecp256k1Key
(
rand
.
Reader
)
default
:
return
fmt
.
Errorf
(
"unknown key type: %s"
,
*
keyType
)
}
if
err
!=
nil
{
return
err
}
id
,
err
:=
peer
.
IDFromPrivateKey
(
priv
)
if
err
!=
nil
{
return
err
}
fmt
.
Printf
(
"
Generated new peer with an ECDSA key.
Peer ID: %s
\n
"
,
id
.
Pretty
())
fmt
.
Printf
(
" Peer ID: %s
\n
"
,
id
.
Pretty
())
tp
,
err
:=
libp2ptls
.
New
(
priv
)
if
err
!=
nil
{
return
err
...
...
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