Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion code/go/0chain.net/blobbercore/handler/storage_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -700,7 +700,7 @@ func (fsh *StorageHandler) CalculateHash(ctx context.Context, r *http.Request) (

// verifySignatureFromRequest verifyes signature passed as common.ClientSignatureHeader header.
func verifySignatureFromRequest(r *http.Request, pbK string) (bool, error) {
sign := r.Header.Get(common.ClientSignatureHeader)
sign := encryption.MiraclToHerumiSig(r.Header.Get(common.ClientSignatureHeader))
if len(sign) < 64 {
return false, nil
}
Expand Down
29 changes: 29 additions & 0 deletions code/go/0chain.net/core/encryption/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package encryption
import (
"bufio"
"io"
"strings"

"0chain.net/core/common"
"0chain.net/core/config"
Expand Down Expand Up @@ -66,3 +67,31 @@ func MiraclToHerumiPK(pk string) string {
}
return p.SerializeToHexStr()
}

// Converts signature 'sig' to format that the herumi/bls library likes.
// zwallets are using MIRACL library which send a MIRACL signature not herumi
// lib.
//
// If the 'sig' was not in MIRACL format, we just return the original sig.
const miraclExampleSig = `(0d4dbad6d2586d5e01b6b7fbad77e4adfa81212c52b4a0b885e19c58e0944764,110061aa16d5ba36eef0ad4503be346908d3513c0a2aedfd0d2923411b420eca)`
func MiraclToHerumiSig(sig string) string {
if len(sig) <= 2 {
return sig
}
if sig[0] != miraclExampleSig[0] {
return sig
}
withoutParens := sig[1: (len(sig)-1) ]
comma := strings.Index(withoutParens, ",")
if comma < 0 {
return "00"
}
n1 := withoutParens[0:comma]
n2 := withoutParens[(comma+1):]
var sign bls.Sign
err := sign.SetHexString("1 " + n1 + " " + n2)
if err != nil {
Logger.Error("MiraclToHerumiSig: " + err.Error())
}
return sign.SerializeToHexStr()
}
18 changes: 18 additions & 0 deletions code/go/0chain.net/core/encryption/keys_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,21 @@ func TestMiraclToHerumiPK(t *testing.T) {
err := pk.DeserializeHexStr(pk1)
require.NoError(t, err)
}

func TestMiraclToHerumiSig(t *testing.T) {
miraclsig1 := `(0d4dbad6d2586d5e01b6b7fbad77e4adfa81212c52b4a0b885e19c58e0944764,110061aa16d5ba36eef0ad4503be346908d3513c0a2aedfd0d2923411b420eca)`
sig1 := MiraclToHerumiSig(miraclsig1)

require.EqualValues(t, sig1, "644794e0589ce185b8a0b4522c2181faade477adfbb7b6015e6d58d2d6ba4d0d")

// Assert DeserializeHexStr works on the output of MiraclToHerumiSig
var sig bls.Sign
err := sig.DeserializeHexStr(sig1)
require.NoError(t, err)

// Test that passing in normal herumi sig just gets back the original.
sig2 := MiraclToHerumiSig(sig1)
if sig1 != sig2 {
panic("Signatures should be the same.")
}
}