diff --git a/code/go/0chain.net/blobbercore/handler/handler.go b/code/go/0chain.net/blobbercore/handler/handler.go index 2a5f51563..49da5ac50 100644 --- a/code/go/0chain.net/blobbercore/handler/handler.go +++ b/code/go/0chain.net/blobbercore/handler/handler.go @@ -14,7 +14,6 @@ import ( "0chain.net/blobbercore/datastore" "0chain.net/blobbercore/stats" "0chain.net/core/common" - "0chain.net/core/encryption" . "0chain.net/core/logging" "go.uber.org/zap" @@ -106,7 +105,7 @@ func setupHandlerContext(ctx context.Context, r *http.Request) context.Context { ctx = context.WithValue(ctx, constants.CLIENT_CONTEXT_KEY, r.Header.Get(common.ClientHeader)) ctx = context.WithValue(ctx, constants.CLIENT_KEY_CONTEXT_KEY, - encryption.MiraclToHerumiPK(r.Header.Get(common.ClientKeyHeader))) + r.Header.Get(common.ClientKeyHeader)) ctx = context.WithValue(ctx, constants.ALLOCATION_CONTEXT_KEY, vars["allocation"]) // signature is not requered for all requests, but if header is empty it won`t affect anything diff --git a/code/go/0chain.net/blobbercore/handler/handler_integration_tests.go b/code/go/0chain.net/blobbercore/handler/handler_integration_tests.go index f94b30354..d386f15b1 100644 --- a/code/go/0chain.net/blobbercore/handler/handler_integration_tests.go +++ b/code/go/0chain.net/blobbercore/handler/handler_integration_tests.go @@ -18,7 +18,6 @@ import ( "0chain.net/blobbercore/datastore" "0chain.net/blobbercore/stats" "0chain.net/core/common" - "0chain.net/core/encryption" "0chain.net/core/node" "github.com/gorilla/mux" @@ -100,7 +99,7 @@ func setupHandlerContext(ctx context.Context, r *http.Request) context.Context { ctx = context.WithValue(ctx, constants.CLIENT_CONTEXT_KEY, r.Header.Get(common.ClientHeader)) ctx = context.WithValue(ctx, constants.CLIENT_KEY_CONTEXT_KEY, - encryption.MiraclToHerumiPK(r.Header.Get(common.ClientKeyHeader))) + r.Header.Get(common.ClientKeyHeader)) ctx = context.WithValue(ctx, constants.ALLOCATION_CONTEXT_KEY, vars["allocation"]) return ctx diff --git a/code/go/0chain.net/blobbercore/handler/helper.go b/code/go/0chain.net/blobbercore/handler/helper.go index c6afa5b96..4cced3dbb 100644 --- a/code/go/0chain.net/blobbercore/handler/helper.go +++ b/code/go/0chain.net/blobbercore/handler/helper.go @@ -13,16 +13,12 @@ import ( "0chain.net/blobbercore/blobbergrpc" "0chain.net/blobbercore/constants" - "0chain.net/core/encryption" ) func setupGRPCHandlerContext(ctx context.Context, r *blobbergrpc.RequestContext) context.Context { - ctx = context.WithValue(ctx, constants.CLIENT_CONTEXT_KEY, - r.Client) - ctx = context.WithValue(ctx, constants.CLIENT_KEY_CONTEXT_KEY, - encryption.MiraclToHerumiPK(r.ClientKey)) - ctx = context.WithValue(ctx, constants.ALLOCATION_CONTEXT_KEY, - r.Allocation) + ctx = context.WithValue(ctx, constants.CLIENT_CONTEXT_KEY, r.Client) + ctx = context.WithValue(ctx, constants.CLIENT_KEY_CONTEXT_KEY, r.ClientKey) + ctx = context.WithValue(ctx, constants.ALLOCATION_CONTEXT_KEY, r.Allocation) return ctx } diff --git a/code/go/0chain.net/blobbercore/handler/object_operation_handler.go b/code/go/0chain.net/blobbercore/handler/object_operation_handler.go index 1c092cdd7..59e6ddd26 100644 --- a/code/go/0chain.net/blobbercore/handler/object_operation_handler.go +++ b/code/go/0chain.net/blobbercore/handler/object_operation_handler.go @@ -416,8 +416,7 @@ func (fsh *StorageHandler) CommitWrite(ctx context.Context, r *http.Request) (*C } allocationTx := ctx.Value(constants.ALLOCATION_CONTEXT_KEY).(string) clientID := ctx.Value(constants.CLIENT_CONTEXT_KEY).(string) - clientKey := encryption.MiraclToHerumiPK( - ctx.Value(constants.CLIENT_KEY_CONTEXT_KEY).(string)) + clientKey := ctx.Value(constants.CLIENT_KEY_CONTEXT_KEY).(string) clientKeyBytes, _ := hex.DecodeString(clientKey) allocationObj, err := fsh.verifyAllocation(ctx, allocationTx, false) diff --git a/code/go/0chain.net/blobbercore/handler/storage_handler.go b/code/go/0chain.net/blobbercore/handler/storage_handler.go index b4517bd31..ebb50d5d5 100644 --- a/code/go/0chain.net/blobbercore/handler/storage_handler.go +++ b/code/go/0chain.net/blobbercore/handler/storage_handler.go @@ -712,6 +712,7 @@ func verifySignatureFromRequest(r *http.Request, pbK string) (bool, error) { } hash := encryption.Hash(data) + pbK = encryption.MiraclToHerumiPK(pbK) return encryption.Verify(pbK, sign, hash) } diff --git a/code/go/0chain.net/blobbercore/readmarker/protocol.go b/code/go/0chain.net/blobbercore/readmarker/protocol.go index 9a5fa4653..1089a7dc9 100644 --- a/code/go/0chain.net/blobbercore/readmarker/protocol.go +++ b/code/go/0chain.net/blobbercore/readmarker/protocol.go @@ -35,7 +35,7 @@ func (rm *ReadMarkerEntity) VerifyMarker(ctx context.Context, sa *allocation.All return common.NewError("read_marker_validation_failed", "Read Marker is not for the blobber") } - clientPublicKey := encryption.MiraclToHerumiPK(ctx.Value(constants.CLIENT_KEY_CONTEXT_KEY).(string)) + clientPublicKey := ctx.Value(constants.CLIENT_KEY_CONTEXT_KEY).(string) if len(clientPublicKey) == 0 || clientPublicKey != rm.LatestRM.ClientPublicKey { return common.NewError("read_marker_validation_failed", "Could not get the public key of the client") } diff --git a/code/go/0chain.net/blobbercore/writemarker/protocol.go b/code/go/0chain.net/blobbercore/writemarker/protocol.go index c88d2de89..c152adde2 100644 --- a/code/go/0chain.net/blobbercore/writemarker/protocol.go +++ b/code/go/0chain.net/blobbercore/writemarker/protocol.go @@ -48,7 +48,7 @@ func (wm *WriteMarkerEntity) VerifyMarker(ctx context.Context, sa *allocation.Al return common.NewError("write_marker_validation_failed", "Write Marker size does not match the connection size") } - clientPublicKey := encryption.MiraclToHerumiPK(ctx.Value(constants.CLIENT_KEY_CONTEXT_KEY).(string)) + clientPublicKey := ctx.Value(constants.CLIENT_KEY_CONTEXT_KEY).(string) if len(clientPublicKey) == 0 { return common.NewError("write_marker_validation_failed", "Could not get the public key of the client") } diff --git a/code/go/0chain.net/core/encryption/keys.go b/code/go/0chain.net/core/encryption/keys.go index e6e874fe6..7000c2560 100644 --- a/code/go/0chain.net/core/encryption/keys.go +++ b/code/go/0chain.net/core/encryption/keys.go @@ -31,6 +31,8 @@ func ReadKeys(reader io.Reader) (publicKey string, privateKey string, publicIp s //Verify - given a public key and a signature and the hash used to create the signature, verify the signature func Verify(publicKey string, signature string, hash string) (bool, error) { + publicKey = MiraclToHerumiPK(publicKey) + signature = MiraclToHerumiSig(signature) signScheme := zcncrypto.NewSignatureScheme(config.Configuration.SignatureScheme) if signScheme != nil { err := signScheme.SetPublicKey(publicKey) diff --git a/code/go/0chain.net/core/encryption/keys_test.go b/code/go/0chain.net/core/encryption/keys_test.go index 309c8616b..f53ed6207 100644 --- a/code/go/0chain.net/core/encryption/keys_test.go +++ b/code/go/0chain.net/core/encryption/keys_test.go @@ -4,6 +4,9 @@ import ( "testing" "github.com/herumi/bls-go-binary/bls" "github.com/stretchr/testify/require" + + "fmt" + "encoding/hex" ) func TestMiraclToHerumiPK(t *testing.T) { @@ -35,3 +38,27 @@ func TestMiraclToHerumiSig(t *testing.T) { panic("Signatures should be the same.") } } + +// Helper code to print out expected values of Hash and conversion functions. +func TestDebugOnly(t *testing.T) { + + // clientKey := "536d2ecfe5aab6c343e8c2e7ee9daa60c43eecc53f4b1c07a6cb2648d9e66c14f2e3fcd43875be40722992f56570fe3c751caacbc7d859b309c787f654bd5a97" + // // => 5c2fdfa03fc013cff0e4b716f0529b914e18fd2bc6cdfed49df13b6e3dc4684d + + clientKey := "0416c528570ce46eb83584cd604a9ed62644ef4f71a86587d57e4ab91953ff4699107374870799ad4550c4f3833cca2a4d5de75436d67caf89097f1e7d6d7de6d424cb5a08b9dca8957ea7c81a23d066b93a27500954cd29733149ec1f8a8abd540d08f9f81bb24b83ff27e24f173e639573e10a22ed7b0ca326a1aa9dc03e1eef" + // => bd3adcacc78ed4352931b138729986a07d2bf0e0a3bf2c885b37a9a0e649dd87 + // Looking for bd3adcacc78ed4352931b138729986a07d2bf0e0a3bf2c885b37a9a0e649dd87 + + clientKeyBytes, _ := hex.DecodeString(clientKey) + h := Hash(clientKeyBytes) + + fmt.Println("hash ", h) + + herumipk := MiraclToHerumiPK(clientKey) + fmt.Println("herumipk ", herumipk) + clientKeyBytes2, _ := hex.DecodeString(herumipk) + h = Hash(clientKeyBytes2) + fmt.Println("hash2 ", h) + + +} diff --git a/code/go/0chain.net/validatorcore/storage/context.go b/code/go/0chain.net/validatorcore/storage/context.go index d033b5e03..2a761fe4a 100644 --- a/code/go/0chain.net/validatorcore/storage/context.go +++ b/code/go/0chain.net/validatorcore/storage/context.go @@ -5,14 +5,13 @@ import ( "net/http" "0chain.net/core/common" - "0chain.net/core/encryption" ) func SetupContext(handler common.JSONResponderF) common.JSONResponderF { return func(ctx context.Context, r *http.Request) (interface{}, error) { ctx = context.WithValue(ctx, CLIENT_CONTEXT_KEY, r.Header.Get(common.ClientHeader)) ctx = context.WithValue(ctx, CLIENT_KEY_CONTEXT_KEY, - encryption.MiraclToHerumiPK(r.Header.Get(common.ClientKeyHeader))) + r.Header.Get(common.ClientKeyHeader)) res, err := handler(ctx, r) return res, err }