Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
mybee
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
vicotor
mybee
Commits
f220749a
Unverified
Commit
f220749a
authored
Sep 26, 2020
by
Janoš Guljaš
Committed by
GitHub
Sep 26, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
expose swarm public key in logs and debugapi (#750)
parent
d3be5d46
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
49 additions
and
15 deletions
+49
-15
start.go
cmd/bee/cmd/start.go
+8
-4
SwarmCommon.yaml
openapi/SwarmCommon.yaml
+7
-0
crypto.go
pkg/crypto/crypto.go
+5
-0
debugapi.go
pkg/debugapi/debugapi.go
+4
-1
debugapi_test.go
pkg/debugapi/debugapi_test.go
+3
-1
p2p.go
pkg/debugapi/p2p.go
+8
-4
p2p_test.go
pkg/debugapi/p2p_test.go
+11
-3
node.go
pkg/node/node.go
+3
-2
No files found.
cmd/bee/cmd/start.go
View file @
f220749a
...
...
@@ -7,6 +7,7 @@ package cmd
import
(
"bytes"
"context"
"crypto/ecdsa"
"fmt"
"io/ioutil"
...
...
@@ -130,6 +131,7 @@ Welcome to the Swarm.... Bzzz Bzzzz Bzzzz
var
signer
crypto
.
Signer
var
address
swarm
.
Address
var
publicKey
*
ecdsa
.
PublicKey
if
c
.
config
.
GetBool
(
optionNameClefSignerEnable
)
{
endpoint
:=
c
.
config
.
GetString
(
optionNameClefSignerEndpoint
)
...
...
@@ -155,7 +157,7 @@ Welcome to the Swarm.... Bzzz Bzzzz Bzzzz
return
err
}
publicKey
,
err
:
=
signer
.
PublicKey
()
publicKey
,
err
=
signer
.
PublicKey
()
if
err
!=
nil
{
return
err
}
...
...
@@ -172,9 +174,9 @@ Welcome to the Swarm.... Bzzz Bzzzz Bzzzz
return
fmt
.
Errorf
(
"swarm key: %w"
,
err
)
}
signer
=
crypto
.
NewDefaultSigner
(
swarmPrivateKey
)
publicKey
:=
swarmPrivateKey
.
PublicKey
publicKey
=
&
swarmPrivateKey
.
PublicKey
address
,
err
=
crypto
.
NewOverlayAddress
(
publicKey
,
c
.
config
.
GetUint64
(
optionNameNetworkID
))
address
,
err
=
crypto
.
NewOverlayAddress
(
*
publicKey
,
c
.
config
.
GetUint64
(
optionNameNetworkID
))
if
err
!=
nil
{
return
err
}
...
...
@@ -186,7 +188,9 @@ Welcome to the Swarm.... Bzzz Bzzzz Bzzzz
}
}
b
,
err
:=
node
.
NewBee
(
c
.
config
.
GetString
(
optionNameP2PAddr
),
address
,
keystore
,
signer
,
c
.
config
.
GetUint64
(
optionNameNetworkID
),
logger
,
node
.
Options
{
logger
.
Infof
(
"swarm public key %x"
,
crypto
.
EncodeSecp256k1PublicKey
(
publicKey
))
b
,
err
:=
node
.
NewBee
(
c
.
config
.
GetString
(
optionNameP2PAddr
),
address
,
*
publicKey
,
keystore
,
signer
,
c
.
config
.
GetUint64
(
optionNameNetworkID
),
logger
,
node
.
Options
{
DataDir
:
c
.
config
.
GetString
(
optionNameDataDir
),
DBCapacity
:
c
.
config
.
GetUint64
(
optionNameDBCapacity
),
Password
:
password
,
...
...
openapi/SwarmCommon.yaml
View file @
f220749a
...
...
@@ -28,6 +28,8 @@ components:
type
:
array
items
:
$ref
:
'
#/components/schemas/P2PUnderlay'
public_key
:
$ref
:
'
#/components/schemas/PublicKey'
Balance
:
type
:
object
...
...
@@ -190,6 +192,11 @@ components:
pattern
:
'
^[A-Fa-f0-9]{64}$'
example
:
"
36b7efd913ca4cf880b8eeac5093fa27b0825906c600685b6abdd6566e6cfe8f"
PublicKey
:
type
:
string
pattern
:
'
^[A-Fa-f0-9]{66}$'
example
:
"
02ab7473879005929d10ce7d4f626412dad9fe56b0a6622038931d26bd79abf0a4"
SwarmEncryptedReference
:
type
:
string
pattern
:
'
^[A-Fa-f0-9]{128}$'
...
...
pkg/crypto/crypto.go
View file @
f220749a
...
...
@@ -52,6 +52,11 @@ func EncodeSecp256k1PrivateKey(k *ecdsa.PrivateKey) []byte {
return
(
*
btcec
.
PrivateKey
)(
k
)
.
Serialize
()
}
// EncodeSecp256k1PublicKey encodes raw ECDSA public key in a 33-byte compressed format.
func
EncodeSecp256k1PublicKey
(
k
*
ecdsa
.
PublicKey
)
[]
byte
{
return
(
*
btcec
.
PublicKey
)(
k
)
.
SerializeCompressed
()
}
// DecodeSecp256k1PrivateKey decodes raw ECDSA private key.
func
DecodeSecp256k1PrivateKey
(
data
[]
byte
)
(
*
ecdsa
.
PrivateKey
,
error
)
{
if
l
:=
len
(
data
);
l
!=
btcec
.
PrivKeyBytesLen
{
...
...
pkg/debugapi/debugapi.go
View file @
f220749a
...
...
@@ -5,6 +5,7 @@
package
debugapi
import
(
"crypto/ecdsa"
"net/http"
"github.com/ethersphere/bee/pkg/accounting"
...
...
@@ -28,6 +29,7 @@ type Service interface {
type
server
struct
{
Overlay
swarm
.
Address
PublicKey
ecdsa
.
PublicKey
P2P
p2p
.
DebugService
Pingpong
pingpong
.
Interface
TopologyDriver
topology
.
Driver
...
...
@@ -43,9 +45,10 @@ type server struct {
metricsRegistry
*
prometheus
.
Registry
}
func
New
(
overlay
swarm
.
Address
,
p2p
p2p
.
DebugService
,
pingpong
pingpong
.
Interface
,
topologyDriver
topology
.
Driver
,
storer
storage
.
Storer
,
logger
logging
.
Logger
,
tracer
*
tracing
.
Tracer
,
tags
*
tags
.
Tags
,
accounting
accounting
.
Interface
,
settlement
settlement
.
Interface
,
chequebookEnabled
bool
,
chequebook
chequebook
.
Service
)
Service
{
func
New
(
overlay
swarm
.
Address
,
p
ublicKey
ecdsa
.
PublicKey
,
p
2p
p2p
.
DebugService
,
pingpong
pingpong
.
Interface
,
topologyDriver
topology
.
Driver
,
storer
storage
.
Storer
,
logger
logging
.
Logger
,
tracer
*
tracing
.
Tracer
,
tags
*
tags
.
Tags
,
accounting
accounting
.
Interface
,
settlement
settlement
.
Interface
,
chequebookEnabled
bool
,
chequebook
chequebook
.
Service
)
Service
{
s
:=
&
server
{
Overlay
:
overlay
,
PublicKey
:
publicKey
,
P2P
:
p2p
,
Pingpong
:
pingpong
,
TopologyDriver
:
topologyDriver
,
...
...
pkg/debugapi/debugapi_test.go
View file @
f220749a
...
...
@@ -5,6 +5,7 @@
package
debugapi_test
import
(
"crypto/ecdsa"
"io/ioutil"
"net/http"
"net/http/httptest"
...
...
@@ -29,6 +30,7 @@ import (
type
testServerOptions
struct
{
Overlay
swarm
.
Address
PublicKey
ecdsa
.
PublicKey
P2P
*
p2pmock
.
Service
Pingpong
pingpong
.
Interface
Storer
storage
.
Storer
...
...
@@ -50,7 +52,7 @@ func newTestServer(t *testing.T, o testServerOptions) *testServer {
acc
:=
accountingmock
.
NewAccounting
(
o
.
AccountingOpts
...
)
settlement
:=
settlementmock
.
NewSettlement
(
o
.
SettlementOpts
...
)
chequebook
:=
chequebookmock
.
NewChequebook
(
o
.
ChequebookOpts
...
)
s
:=
debugapi
.
New
(
o
.
Overlay
,
o
.
P2P
,
o
.
Pingpong
,
topologyDriver
,
o
.
Storer
,
logging
.
New
(
ioutil
.
Discard
,
0
),
nil
,
o
.
Tags
,
acc
,
settlement
,
true
,
chequebook
)
s
:=
debugapi
.
New
(
o
.
Overlay
,
o
.
P
ublicKey
,
o
.
P
2P
,
o
.
Pingpong
,
topologyDriver
,
o
.
Storer
,
logging
.
New
(
ioutil
.
Discard
,
0
),
nil
,
o
.
Tags
,
acc
,
settlement
,
true
,
chequebook
)
ts
:=
httptest
.
NewServer
(
s
)
t
.
Cleanup
(
ts
.
Close
)
...
...
pkg/debugapi/p2p.go
View file @
f220749a
...
...
@@ -5,16 +5,19 @@
package
debugapi
import
(
"encoding/hex"
"net/http"
"github.com/ethersphere/bee/pkg/crypto"
"github.com/ethersphere/bee/pkg/jsonhttp"
"github.com/ethersphere/bee/pkg/swarm"
"github.com/multiformats/go-multiaddr"
)
type
addressesResponse
struct
{
Overlay
swarm
.
Address
`json:"overlay"`
Underlay
[]
multiaddr
.
Multiaddr
`json:"underlay"`
Overlay
swarm
.
Address
`json:"overlay"`
Underlay
[]
multiaddr
.
Multiaddr
`json:"underlay"`
PublicKey
string
`json:"public_key"`
}
func
(
s
*
server
)
addressesHandler
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
...
...
@@ -25,7 +28,8 @@ func (s *server) addressesHandler(w http.ResponseWriter, r *http.Request) {
return
}
jsonhttp
.
OK
(
w
,
addressesResponse
{
Overlay
:
s
.
Overlay
,
Underlay
:
underlay
,
Overlay
:
s
.
Overlay
,
Underlay
:
underlay
,
PublicKey
:
hex
.
EncodeToString
(
crypto
.
EncodeSecp256k1PublicKey
(
&
s
.
PublicKey
)),
})
}
pkg/debugapi/p2p_test.go
View file @
f220749a
...
...
@@ -5,10 +5,12 @@
package
debugapi_test
import
(
"encoding/hex"
"errors"
"net/http"
"testing"
"github.com/ethersphere/bee/pkg/crypto"
"github.com/ethersphere/bee/pkg/debugapi"
"github.com/ethersphere/bee/pkg/jsonhttp"
"github.com/ethersphere/bee/pkg/jsonhttp/jsonhttptest"
...
...
@@ -18,6 +20,10 @@ import (
)
func
TestAddresses
(
t
*
testing
.
T
)
{
privateKey
,
err
:=
crypto
.
GenerateSecp256k1Key
()
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
overlay
:=
swarm
.
MustParseHexAddress
(
"ca1e9f3938cc1425c6061b96ad9eb93e134dfe8734ad490164ef20af9d1cf59c"
)
addresses
:=
[]
multiaddr
.
Multiaddr
{
mustMultiaddr
(
t
,
"/ip4/127.0.0.1/tcp/7071/p2p/16Uiu2HAmTBuJT9LvNmBiQiNoTsxE5mtNy6YG3paw79m94CRa9sRb"
),
...
...
@@ -26,7 +32,8 @@ func TestAddresses(t *testing.T) {
}
testServer
:=
newTestServer
(
t
,
testServerOptions
{
Overlay
:
overlay
,
PublicKey
:
privateKey
.
PublicKey
,
Overlay
:
overlay
,
P2P
:
mock
.
New
(
mock
.
WithAddressesFunc
(
func
()
([]
multiaddr
.
Multiaddr
,
error
)
{
return
addresses
,
nil
})),
...
...
@@ -35,8 +42,9 @@ func TestAddresses(t *testing.T) {
t
.
Run
(
"ok"
,
func
(
t
*
testing
.
T
)
{
jsonhttptest
.
Request
(
t
,
testServer
.
Client
,
http
.
MethodGet
,
"/addresses"
,
http
.
StatusOK
,
jsonhttptest
.
WithExpectedJSONResponse
(
debugapi
.
AddressesResponse
{
Overlay
:
overlay
,
Underlay
:
addresses
,
Overlay
:
overlay
,
Underlay
:
addresses
,
PublicKey
:
hex
.
EncodeToString
(
crypto
.
EncodeSecp256k1PublicKey
(
&
privateKey
.
PublicKey
)),
}),
)
})
...
...
pkg/node/node.go
View file @
f220749a
...
...
@@ -6,6 +6,7 @@ package node
import
(
"context"
"crypto/ecdsa"
"errors"
"fmt"
"io"
...
...
@@ -108,7 +109,7 @@ type Options struct {
SwapEnable
bool
}
func
NewBee
(
addr
string
,
swarmAddress
swarm
.
Address
,
keystore
keystore
.
Service
,
signer
crypto
.
Signer
,
networkID
uint64
,
logger
logging
.
Logger
,
o
Options
)
(
*
Bee
,
error
)
{
func
NewBee
(
addr
string
,
swarmAddress
swarm
.
Address
,
publicKey
ecdsa
.
PublicKey
,
keystore
keystore
.
Service
,
signer
crypto
.
Signer
,
networkID
uint64
,
logger
logging
.
Logger
,
o
Options
)
(
*
Bee
,
error
)
{
tracer
,
tracerCloser
,
err
:=
tracing
.
NewTracer
(
&
tracing
.
Options
{
Enabled
:
o
.
TracingEnabled
,
Endpoint
:
o
.
TracingEndpoint
,
...
...
@@ -437,7 +438,7 @@ func NewBee(addr string, swarmAddress swarm.Address, keystore keystore.Service,
if
o
.
DebugAPIAddr
!=
""
{
// Debug API server
debugAPIService
:=
debugapi
.
New
(
swarmAddress
,
p2ps
,
pingPong
,
kad
,
storer
,
logger
,
tracer
,
tagg
,
acc
,
settlement
,
o
.
SwapEnable
,
chequebookService
)
debugAPIService
:=
debugapi
.
New
(
swarmAddress
,
p
ublicKey
,
p
2ps
,
pingPong
,
kad
,
storer
,
logger
,
tracer
,
tagg
,
acc
,
settlement
,
o
.
SwapEnable
,
chequebookService
)
// register metrics from components
debugAPIService
.
MustRegisterMetrics
(
p2ps
.
Metrics
()
...
)
debugAPIService
.
MustRegisterMetrics
(
pingPong
.
Metrics
()
...
)
...
...
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