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
3 changes: 1 addition & 2 deletions code/go/0chain.net/blobbercore/handler/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down
10 changes: 3 additions & 7 deletions code/go/0chain.net/blobbercore/handler/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions code/go/0chain.net/blobbercore/handler/storage_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
2 changes: 1 addition & 1 deletion code/go/0chain.net/blobbercore/readmarker/protocol.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand Down
2 changes: 1 addition & 1 deletion code/go/0chain.net/blobbercore/writemarker/protocol.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand Down
2 changes: 2 additions & 0 deletions code/go/0chain.net/core/encryption/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
27 changes: 27 additions & 0 deletions code/go/0chain.net/core/encryption/keys_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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)


}
3 changes: 1 addition & 2 deletions code/go/0chain.net/validatorcore/storage/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down