Merge branch 'master' into feat/airgapped-keys-encryption

This commit is contained in:
programmer10110 2020-09-21 12:12:35 +03:00
commit 49949ba7fc
9 changed files with 37 additions and 60 deletions

View File

@ -85,15 +85,10 @@ $ ./dc4bc_d start --username john_doe --key_store_dbdsn /tmp/dc4bc_john_doe_key_
```
Start the airgapped machine:
```
# First print your node's address; you will be prompted to enter it.
$ ./dc4bc_cli get_address --listen_addr localhost:8080
e0d8083f8a2d18f310bfbdc9649a83664470f46053ab53c105a054b08f9eff85
$ ./dc4bc_airgapped --db_path /tmp/dc4bc_john_doe_airgapped_state --password_expiration 10m
```
Print your address, communication public key and encryption public key and save it somewhere for later use:
Print your communication public key and encryption public key and save it somewhere for later use:
```
$ ./dc4bc_cli get_address --listen_addr localhost:8080
e0d8083f8a2d18f310bfbdc9649a83664470f46053ab53c105a054b08f9eff85
$ ./dc4bc_cli get_pubkey --listen_addr localhost:8080
EcVs+nTi4iFERVeBHUPePDmvknBx95co7csKj0sZNuo=
# Inside the airgapped shell:

View File

@ -132,10 +132,15 @@ func TestAirgappedAllSteps(t *testing.T) {
var initReq responses.SignatureProposalParticipantInvitationsResponse
for _, n := range tr.nodes {
pubKey, err := n.Machine.pubKey.MarshalBinary()
if err != nil {
t.Fatalf("failed to marshal dkg pubkey: %v", err)
}
entry := &responses.SignatureProposalParticipantInvitationEntry{
ParticipantId: n.ParticipantID,
Addr: n.Participant,
Threshold: threshold,
DkgPubKey: pubKey,
}
initReq = append(initReq, entry)
}

View File

@ -41,13 +41,17 @@ func (am *AirgappedMachine) handleStateAwaitParticipantsConfirmations(o *client.
pid := -1
for _, r := range payload {
if r.Addr == am.ParticipantAddress {
pubkey := am.suite.Point()
if err := pubkey.UnmarshalBinary(r.DkgPubKey); err != nil {
return fmt.Errorf("failed to unmarshal dkg pubkey: %w", err)
}
if am.pubKey.Equal(pubkey) {
pid = r.ParticipantId
break
}
}
if pid < 0 {
return fmt.Errorf("failed to determine participant id for DKG with participant address %s", am.ParticipantAddress)
return fmt.Errorf("failed to determine participant id for DKG #%s", o.DKGIdentifier)
}
if _, ok := am.dkgInstances[o.DKGIdentifier]; ok {

View File

@ -34,7 +34,7 @@ const (
)
type Poller interface {
GetAddr() string
GetUsername() string
GetPubKey() ed25519.PublicKey
Poll() error
SendMessage(message storage.Message) error
@ -49,7 +49,6 @@ type Client struct {
sync.Mutex
Logger *logger
userName string
address string
pubKey ed25519.PublicKey
ctx context.Context
state State
@ -75,7 +74,6 @@ func NewClient(
ctx: ctx,
Logger: newLogger(userName),
userName: userName,
address: keyPair.GetAddr(),
pubKey: keyPair.Pub,
state: state,
storage: storage,
@ -88,8 +86,8 @@ func (c *Client) GetLogger() *logger {
return c.Logger
}
func (c *Client) GetAddr() string {
return c.address
func (c *Client) GetUsername() string {
return c.userName
}
func (c *Client) GetPubKey() ed25519.PublicKey {
@ -112,7 +110,7 @@ func (c *Client) Poll() error {
}
for _, message := range messages {
if message.RecipientAddr == "" || message.RecipientAddr == c.GetAddr() {
if message.RecipientAddr == "" || message.RecipientAddr == c.GetUsername() {
c.Logger.Log("Handling message with offset %d, type %s", message.Offset, message.Event)
if err := c.ProcessMessage(message); err != nil {
c.Logger.Log("Failed to process message with offset %d: %v", message.Offset, err)
@ -289,7 +287,7 @@ func (c *Client) handleProcessedOperation(operation types.Operation) error {
}
for _, message := range operation.ResultMsgs {
message.SenderAddr = c.GetAddr()
message.SenderAddr = c.GetUsername()
sig, err := c.signMessage(message.Bytes())
if err != nil {

View File

@ -193,7 +193,6 @@ func TestFullFlow(t *testing.T) {
if err != nil {
t.Fatalf("node %d failed to init client: %v\n", nodeID, err)
}
airgappedMachine.SetAddress(clt.GetAddr())
airgappedMachine.SetEncryptionKey(clt.GetPubKey()) //just for testing
if err = airgappedMachine.InitKeys(); err != nil {
t.Errorf(err.Error())
@ -235,7 +234,7 @@ func TestFullFlow(t *testing.T) {
log.Fatalln("failed to get DKG pubKey:", err.Error())
}
participants = append(participants, &requests.SignatureProposalParticipantsEntry{
Addr: node.client.GetAddr(),
Addr: node.client.GetUsername(),
PubKey: node.client.GetPubKey(),
DkgPubKey: dkgPubKey,
})

View File

@ -60,7 +60,7 @@ func successResponse(w http.ResponseWriter, response interface{}) {
func (c *Client) StartHTTPServer(listenAddr string) error {
mux := http.NewServeMux()
mux.HandleFunc("/getAddress", c.getAddressHandler)
mux.HandleFunc("/getUsername", c.getUsernameHandler)
mux.HandleFunc("/getPubKey", c.getPubkeyHandler)
mux.HandleFunc("/sendMessage", c.sendMessageHandler)
@ -78,12 +78,12 @@ func (c *Client) StartHTTPServer(listenAddr string) error {
return http.ListenAndServe(listenAddr, mux)
}
func (c *Client) getAddressHandler(w http.ResponseWriter, r *http.Request) {
func (c *Client) getUsernameHandler(w http.ResponseWriter, r *http.Request) {
if r.Method != http.MethodGet {
errorResponse(w, http.StatusBadRequest, "Wrong HTTP method")
return
}
successResponse(w, c.GetAddr())
successResponse(w, c.GetUsername())
}
func (c *Client) getPubkeyHandler(w http.ResponseWriter, r *http.Request) {
@ -303,7 +303,7 @@ func (c *Client) buildMessage(dkgRoundID string, event fsm.Event, data []byte) (
DkgRoundID: dkgRoundID,
Event: string(event),
Data: data,
SenderAddr: c.GetAddr(),
SenderAddr: c.GetUsername(),
}
signature, err := c.signMessage(message.Bytes())
if err != nil {

View File

@ -46,14 +46,6 @@ func NewTerminal(machine *airgapped.AirgappedMachine) *terminal {
commandHandler: t.showDKGPubKeyCommand,
description: "shows a dkg pub key",
})
t.addCommand("show_address", &terminalCommand{
commandHandler: t.showAddressCommand,
description: "shows an airgapped address",
})
t.addCommand("set_address", &terminalCommand{
commandHandler: t.setAddressCommand,
description: "set an airgapped address",
})
t.addCommand("show_finished_dkg", &terminalCommand{
commandHandler: t.showFinishedDKGCommand,
description: "shows a list of finished dkg rounds",
@ -89,23 +81,6 @@ func (t *terminal) showDKGPubKeyCommand() error {
return nil
}
func (t *terminal) showAddressCommand() error {
fmt.Println(t.airgapped.GetAddress())
return nil
}
func (t *terminal) setAddressCommand() error {
fmt.Printf("Enter your client's address: ")
address, err := t.reader.ReadString('\n')
if err != nil {
return fmt.Errorf("failed to read address from stdin: %w", err)
}
if err = t.airgapped.SetAddress(strings.Trim(address, "\n")); err != nil {
return fmt.Errorf("failed to save address")
}
return nil
}
func (t *terminal) helpCommand() error {
fmt.Println("Available commands:")
for commandName, command := range t.commands {
@ -153,13 +128,6 @@ func (t *terminal) enterEncryptionPasswordIfNeeded() error {
}
func (t *terminal) run() error {
if t.airgapped.GetAddress() == "" {
fmt.Println("At first, you need to set address" +
" of your airgapped machine (should be equal to the client address)")
if err := t.setAddressCommand(); err != nil {
return err
}
}
if err := t.enterEncryptionPasswordIfNeeded(); err != nil {
return err
}

View File

@ -43,7 +43,7 @@ func main() {
readOperationFromCameraCommand(),
startDKGCommand(),
proposeSignMessageCommand(),
getAddressCommand(),
getUsernameCommand(),
getPubKeyCommand(),
getHashOfStartDKGCommand(),
)
@ -198,22 +198,22 @@ func getPubKeyCommand() *cobra.Command {
}
}
func getAddressCommand() *cobra.Command {
func getUsernameCommand() *cobra.Command {
return &cobra.Command{
Use: "get_address",
Short: "returns client's address",
Use: "get_username",
Short: "returns client's username",
RunE: func(cmd *cobra.Command, args []string) error {
listenAddr, err := cmd.Flags().GetString(flagListenAddr)
if err != nil {
return fmt.Errorf("failed to read configuration: %v", err)
}
resp, err := rawGetRequest(fmt.Sprintf("http://%s//getAddress", listenAddr))
resp, err := rawGetRequest(fmt.Sprintf("http://%s//getUsername", listenAddr))
if err != nil {
return fmt.Errorf("failed to get client's address: %w", err)
return fmt.Errorf("failed to get client's username: %w", err)
}
if resp.ErrorMessage != "" {
return fmt.Errorf("failed to get client's address: %w", resp.ErrorMessage)
return fmt.Errorf("failed to get client's username: %w", resp.ErrorMessage)
}
fmt.Println(resp.Result.(string))
return nil

View File

@ -20,6 +20,14 @@ func (r *SignatureProposalParticipantsListRequest) Validate() error {
return errors.New("{SigningThreshold} cannot be higher than {ParticipantsCount}")
}
uniqueAddresses := make(map[string]bool)
for _, participant := range r.Participants {
if _, ok := uniqueAddresses[participant.Addr]; ok {
return errors.New("{Addr} must be unique")
}
uniqueAddresses[participant.Addr] = true
}
for _, participant := range r.Participants {
if len(participant.Addr) < 3 {
return errors.New("{Addr} minimum length is {3}")