This commit is contained in:
programmer10110 2020-11-02 12:56:40 +03:00
parent e27c67b86a
commit a928ccc79f
8 changed files with 42 additions and 18 deletions

View File

@ -3,7 +3,6 @@ package airgapped
import ( import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"github.com/corestario/kyber/pairing" "github.com/corestario/kyber/pairing"
"github.com/corestario/kyber/sign/bls" "github.com/corestario/kyber/sign/bls"
@ -111,6 +110,7 @@ func (am *Machine) reconstructThresholdSignature(o *client.Operation) error {
Data: payload.SrcPayload, Data: payload.SrcPayload,
Signature: reconstructedSignature, Signature: reconstructedSignature,
DKGRoundID: o.DKGIdentifier, DKGRoundID: o.DKGIdentifier,
SigningID: payload.SigningId,
} }
respBz, err := json.Marshal(response) respBz, err := json.Marshal(response)
if err != nil { if err != nil {

View File

@ -294,8 +294,8 @@ func (c *BaseClient) GetSignatures(dkgID string) (map[string][]types.Reconstruct
} }
//GetSignatureByDataHash returns a list of reconstructed signatures of the signed data broadcasted by users //GetSignatureByDataHash returns a list of reconstructed signatures of the signed data broadcasted by users
func (c *BaseClient) GetSignatureByDataHash(dkgID, sigID string) ([]types.ReconstructedSignature, error) { func (c *BaseClient) GetSignatureByID(dkgID, sigID string) ([]types.ReconstructedSignature, error) {
return c.state.GetSignatureByDataHash(dkgID, sigID) return c.state.GetSignatureByID(dkgID, sigID)
} }
// getOperationJSON returns a specific JSON-encoded operation // getOperationJSON returns a specific JSON-encoded operation

View File

@ -143,7 +143,7 @@ func RemoveContents(dir, mask string) error {
func TestFullFlow(t *testing.T) { func TestFullFlow(t *testing.T) {
_ = RemoveContents("/tmp", "dc4bc_*") _ = RemoveContents("/tmp", "dc4bc_*")
defer func() { _ = RemoveContents("/tmp", "dc4bc_*") }() //defer func() { _ = RemoveContents("/tmp", "dc4bc_*") }()
var numNodes = 4 var numNodes = 4
var threshold = 2 var threshold = 2

View File

@ -70,7 +70,7 @@ func (c *BaseClient) StartHTTPServer(listenAddr string) error {
mux.HandleFunc("/getOperationQRPath", c.getOperationQRPathHandler) mux.HandleFunc("/getOperationQRPath", c.getOperationQRPathHandler)
mux.HandleFunc("/getSignatures", c.getSignaturesHandler) mux.HandleFunc("/getSignatures", c.getSignaturesHandler)
mux.HandleFunc("/getSignatureByDataHash", c.getSignatureByDataHashHandler) mux.HandleFunc("/getSignatureByID", c.getSignatureByIDHandler)
mux.HandleFunc("/getOperationQR", c.getOperationQRToBodyHandler) mux.HandleFunc("/getOperationQR", c.getOperationQRToBodyHandler)
mux.HandleFunc("/handleProcessedOperationJSON", c.handleJSONOperationHandler) mux.HandleFunc("/handleProcessedOperationJSON", c.handleJSONOperationHandler)
@ -237,13 +237,13 @@ func (c *BaseClient) getSignaturesHandler(w http.ResponseWriter, r *http.Request
successResponse(w, signatures) successResponse(w, signatures)
} }
func (c *BaseClient) getSignatureByDataHashHandler(w http.ResponseWriter, r *http.Request) { func (c *BaseClient) getSignatureByIDHandler(w http.ResponseWriter, r *http.Request) {
if r.Method != http.MethodGet { if r.Method != http.MethodGet {
errorResponse(w, http.StatusBadRequest, "Wrong HTTP method") errorResponse(w, http.StatusBadRequest, "Wrong HTTP method")
return return
} }
signature, err := c.GetSignatureByDataHash(r.URL.Query().Get("dkgID"), r.URL.Query().Get("hash")) signature, err := c.GetSignatureByID(r.URL.Query().Get("dkgID"), r.URL.Query().Get("hash"))
if err != nil { if err != nil {
errorResponse(w, http.StatusInternalServerError, fmt.Sprintf("failed to get signature: %v", err)) errorResponse(w, http.StatusInternalServerError, fmt.Sprintf("failed to get signature: %v", err))
return return

View File

@ -1,9 +1,7 @@
package client package client
import ( import (
"crypto/md5"
"encoding/binary" "encoding/binary"
"encoding/hex"
"encoding/json" "encoding/json"
"errors" "errors"
"fmt" "fmt"
@ -39,7 +37,7 @@ type State interface {
GetOperationByID(operationID string) (*types.Operation, error) GetOperationByID(operationID string) (*types.Operation, error)
SaveSignature(signature types.ReconstructedSignature) error SaveSignature(signature types.ReconstructedSignature) error
GetSignatureByDataHash(dkgID, signatureID string) ([]types.ReconstructedSignature, error) GetSignatureByID(dkgID, signatureID string) ([]types.ReconstructedSignature, error)
GetSignatures(dkgID string) (map[string][]types.ReconstructedSignature, error) GetSignatures(dkgID string) (map[string][]types.ReconstructedSignature, error)
} }
@ -311,7 +309,7 @@ func (s *LevelDBState) GetSignatures(dkgID string) (map[string][]types.Reconstru
return s.getSignatures(dkgID) return s.getSignatures(dkgID)
} }
func (s *LevelDBState) GetSignatureByDataHash(dkgID, signatureID string) ([]types.ReconstructedSignature, error) { func (s *LevelDBState) GetSignatureByID(dkgID, signatureID string) ([]types.ReconstructedSignature, error) {
s.Lock() s.Lock()
defer s.Unlock() defer s.Unlock()
@ -340,12 +338,9 @@ func (s *LevelDBState) SaveSignature(signature types.ReconstructedSignature) err
signatures = make(map[string][]types.ReconstructedSignature) signatures = make(map[string][]types.ReconstructedSignature)
} }
dataHash := md5.Sum(signature.Data) sig := signatures[signature.SigningID]
dataHashString := hex.EncodeToString(dataHash[:])
sig := signatures[dataHashString]
sig = append(sig, signature) sig = append(sig, signature)
signatures[dataHashString] = sig signatures[signature.SigningID] = sig
signaturesJSON, err := json.Marshal(signatures) signaturesJSON, err := json.Marshal(signatures)
if err != nil { if err != nil {

View File

@ -23,6 +23,7 @@ const (
) )
type ReconstructedSignature struct { type ReconstructedSignature struct {
SigningID string
Data []byte Data []byte
Signature []byte Signature []byte
Participant string Participant string

View File

@ -63,6 +63,7 @@ func main() {
getOffsetCommand(), getOffsetCommand(),
getFSMStatusCommand(), getFSMStatusCommand(),
getFSMListCommand(), getFSMListCommand(),
getSignatureDataCommand(),
) )
if err := rootCmd.Execute(); err != nil { if err := rootCmd.Execute(); err != nil {
log.Fatalf("Failed to execute root command: %v", err) log.Fatalf("Failed to execute root command: %v", err)
@ -121,6 +122,7 @@ func getOperationsCommand() *cobra.Command {
} }
msgHash := md5.Sum(payload.SrcPayload) msgHash := md5.Sum(payload.SrcPayload)
fmt.Printf("Hash of the message to sign - %s\n", hex.EncodeToString(msgHash[:])) fmt.Printf("Hash of the message to sign - %s\n", hex.EncodeToString(msgHash[:]))
fmt.Printf("Signing ID: %s", payload.SigningId)
} }
fmt.Println("-----------------------------------------------------") fmt.Println("-----------------------------------------------------")
} }
@ -198,7 +200,7 @@ func getSignatureRequest(host string, dkgID, dataHash string) (*SignatureRespons
func getSignatureCommand() *cobra.Command { func getSignatureCommand() *cobra.Command {
return &cobra.Command{ return &cobra.Command{
Use: "get_signature [dkgID] [hash_of_the_signed_data]", Use: "get_signature [dkgID] [signing_id]",
Args: cobra.ExactArgs(2), Args: cobra.ExactArgs(2),
Short: "returns a list of reconstructed signatures of the signed data broadcasted by users", Short: "returns a list of reconstructed signatures of the signed data broadcasted by users",
RunE: func(cmd *cobra.Command, args []string) error { RunE: func(cmd *cobra.Command, args []string) error {
@ -223,6 +225,31 @@ func getSignatureCommand() *cobra.Command {
} }
} }
func getSignatureDataCommand() *cobra.Command {
return &cobra.Command{
Use: "get_signature_data [dkgID] [signing_id]",
Args: cobra.ExactArgs(2),
Short: "returns a data which was signed",
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)
}
signatures, err := getSignatureRequest(listenAddr, args[0], args[1])
if err != nil {
return fmt.Errorf("failed to get signatures: %w", err)
}
if signatures.ErrorMessage != "" {
return fmt.Errorf("failed to get signatures: %s", signatures.ErrorMessage)
}
if len(signatures.Result) > 0 {
fmt.Println(string(signatures.Result[0].Data))
}
return nil
},
}
}
func getOperationRequest(host string, operationID string) (*OperationResponse, error) { func getOperationRequest(host string, operationID string) (*OperationResponse, error) {
resp, err := http.Get(fmt.Sprintf("http://%s/getOperation?operationID=%s", host, operationID)) resp, err := http.Get(fmt.Sprintf("http://%s/getOperation?operationID=%s", host, operationID))
if err != nil { if err != nil {

View File

@ -182,7 +182,8 @@ func startClientCommand() *cobra.Command {
log.Fatalf("Failed to init state client: %v", err) log.Fatalf("Failed to init state client: %v", err)
} }
stg, err := storage.NewKafkaStorage(ctx, cfg.StorageDBDSN, cfg.StorageTopic) stg, err := storage.NewFileStorage("/tmp/dc4bc_storage")
//stg, err := storage.NewKafkaStorage(ctx, cfg.StorageDBDSN, cfg.StorageTopic)
if err != nil { if err != nil {
log.Fatalf("Failed to init storage client: %v", err) log.Fatalf("Failed to init storage client: %v", err)
} }