Skip to content

Commit e451fac

Browse files
authored
Merge pull request #1525 from 0chain/sprint-1.19
Sprint 1.19
2 parents c42f0f8 + 148fbfa commit e451fac

File tree

12 files changed

+117
-43
lines changed

12 files changed

+117
-43
lines changed

code/go/0chain.net/blobber/flags.go

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,32 @@ import (
66
)
77

88
var (
9-
deploymentMode int
10-
keysFile string
11-
mountPoint string
12-
metadataDB string
13-
logDir string
14-
httpPort int
15-
hostname string
16-
configDir string
17-
grpcPort int
18-
httpsPort int
19-
httpsKeyFile string
20-
httpsCertFile string
21-
hostUrl string
9+
deploymentMode int
10+
keysFile string
11+
keysFilePublicKey string
12+
keysFilePrivateKey string
13+
keysFileClientKey string
14+
keysFileIsSplit bool
15+
mountPoint string
16+
metadataDB string
17+
logDir string
18+
httpPort int
19+
hostname string
20+
configDir string
21+
grpcPort int
22+
httpsPort int
23+
httpsKeyFile string
24+
httpsCertFile string
25+
hostUrl string
2226
)
2327

2428
func init() {
2529
flag.IntVar(&deploymentMode, "deployment_mode", 2, "deployment mode: 0=dev,1=test, 2=mainnet")
2630
flag.StringVar(&keysFile, "keys_file", "", "keys_file")
31+
flag.StringVar(&keysFilePublicKey, "keys_file_public_key", "", "keys_file_public_key")
32+
flag.StringVar(&keysFilePrivateKey, "keys_file_private_key", "", "keys_file_private_key")
33+
flag.StringVar(&keysFileClientKey, "keys_file_client_key", "", "keys_file_client_key")
34+
flag.BoolVar(&keysFileIsSplit, "keys_file_is_split", false, "keys_file_is_split")
2735
flag.StringVar(&mountPoint, "files_dir", "", "Mounted partition where all files will be stored")
2836
flag.StringVar(&metadataDB, "db_dir", "", "db_dir")
2937
flag.StringVar(&logDir, "log_dir", "", "log_dir")

code/go/0chain.net/blobber/node.go

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package main
22

33
import (
4+
"bytes"
45
"errors"
56
"fmt"
67
"os"
@@ -13,23 +14,37 @@ import (
1314
"go.uber.org/zap"
1415
)
1516

16-
var publicKey, privateKey string
17+
var clientKey, publicKey, privateKey string
1718

1819
func setupNode() error {
1920
fmt.Println("> setup blobber")
2021

21-
err := readKeysFromAws()
22-
if err != nil {
23-
err = readKeysFromFile(&keysFile)
24-
if err != nil {
25-
panic(err)
22+
var err error
23+
24+
if keysFilePrivateKey != "" || keysFilePublicKey != "" {
25+
privateKey = keysFilePrivateKey
26+
publicKey = keysFilePublicKey
27+
28+
if keysFileIsSplit {
29+
clientKey = keysFileClientKey
2630
}
27-
fmt.Println("using blobber keys from local")
31+
32+
fmt.Println("using blobber keys from local string")
2833
} else {
29-
fmt.Println("using blobber keys from aws")
34+
err = readKeysFromAws()
35+
if err != nil {
36+
err = readKeysFromFile(&keysFile)
37+
if err != nil {
38+
panic(err)
39+
}
40+
fmt.Println("using blobber keys from local")
41+
} else {
42+
fmt.Println("using blobber keys from aws")
43+
}
3044
}
3145

32-
node.Self.SetKeys(publicKey, privateKey)
46+
node.Self.SetKeys(clientKey, publicKey, privateKey, keysFileIsSplit)
47+
3348
if node.Self.ID == "" {
3449
return errors.New("node definition for self node doesn't exist")
3550
} else {
@@ -72,6 +87,12 @@ func readKeysFromAws() error {
7287
return nil
7388
}
7489

90+
func readKeysFromString(keyFileRaw *string) error {
91+
publicKey, privateKey, _, _ = encryption.ReadKeys(
92+
bytes.NewBufferString(*keyFileRaw))
93+
return nil
94+
}
95+
7596
func readKeysFromFile(keysFile *string) error {
7697
reader, err := os.Open(*keysFile)
7798
if err != nil {
@@ -80,4 +101,4 @@ func readKeysFromFile(keysFile *string) error {
80101
defer reader.Close()
81102
publicKey, privateKey, _, _ = encryption.ReadKeys(reader)
82103
return nil
83-
}
104+
}

code/go/0chain.net/blobber/zcn.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,10 @@ func setupServerChain() error {
103103
return err
104104
}
105105

106+
if node.Self.GetWallet().IsSplit {
107+
zcncore.RegisterZauthServer(serverChain.ZauthServer)
108+
}
109+
106110
fmt.Print(" [OK]\n")
107111
return nil
108112
}

code/go/0chain.net/blobbercore/handler/auth_ticket.go

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,11 @@ package handler
22

33
import (
44
"context"
5+
"fmt"
6+
"github.com/0chain/blobber/code/go/0chain.net/core/encryption"
57
"github.com/0chain/blobber/code/go/0chain.net/core/node"
68
"github.com/0chain/common/core/common"
9+
"github.com/0chain/gosdk/zcncore"
710
"net/http"
811
)
912

@@ -19,24 +22,34 @@ type AuthTicketResponse struct {
1922
//
2023
// parameters:
2124
//
22-
// +name: Zbox-Signature
23-
// in: header
24-
// type: string
25-
// description: Digital signature to verify that the sender is 0box service.
26-
// +name: client_id
27-
// type: string
28-
// in: query
29-
// description: Client ID is used as a payload to the token generated. The token represents a signed version of this string by the blobber's private key.
25+
// +name: Zbox-Signature
26+
// in: header
27+
// type: string
28+
// description: Digital signature to verify that the sender is 0box service.
29+
// +name: client_id
30+
// type: string
31+
// in: query
32+
// description: Client ID is used as a payload to the token generated. The token represents a signed version of this string by the blobber's private key.
3033
//
3134
// responses:
32-
// 200: AuthTicketResponse
35+
//
36+
// 200: AuthTicketResponse
3337
func GenerateAuthTicket(ctx context.Context, r *http.Request) (interface{}, error) {
38+
3439
clientID := r.URL.Query().Get("client_id")
3540
if clientID == "" {
3641
return nil, common.NewError("missing_client_id", "client_id is required")
3742
}
3843

39-
signature, err := node.Self.Sign(clientID)
44+
round := r.URL.Query().Get("round")
45+
46+
payload := encryption.Hash(fmt.Sprintf("%s_%s", clientID, round))
47+
48+
if isActivated, err := zcncore.IsHardforkActivated("hermes"); err != nil || !isActivated {
49+
payload = clientID
50+
}
51+
52+
signature, err := node.Self.Sign(payload)
4053
if err != nil {
4154
return nil, common.NewError("signature_failed", "signature failed")
4255
}

code/go/0chain.net/blobbercore/handler/protocol.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@ package handler
33
import (
44
"context"
55
"errors"
6+
"sync"
7+
68
"github.com/0chain/gosdk/core/client"
79
coreTxn "github.com/0chain/gosdk/core/transaction"
8-
"sync"
910

1011
"github.com/0chain/blobber/code/go/0chain.net/blobbercore/allocation"
1112
"github.com/0chain/blobber/code/go/0chain.net/blobbercore/config"

code/go/0chain.net/core/chain/entity.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ func NewChainFromConfig() *Chain {
5151
chain.ID = common.ToKey(config.Configuration.ChainID)
5252
chain.OwnerID = viper.GetString("server_chain.owner")
5353
chain.BlockWorker = viper.GetString("block_worker")
54+
chain.ZauthServer = viper.GetString("zauth_server")
5455
return chain
5556
}
5657

code/go/0chain.net/core/node/self_node.go

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"encoding/hex"
55
"encoding/json"
66
"fmt"
7+
78
"github.com/0chain/blobber/code/go/0chain.net/core/common"
89
"github.com/0chain/blobber/code/go/0chain.net/core/config"
910
"github.com/0chain/gosdk/core/zcncrypto"
@@ -19,20 +20,43 @@ type SelfNode struct {
1920
}
2021

2122
/*SetKeys - setter */
22-
func (sn *SelfNode) SetKeys(publicKey, privateKey string) {
23-
publicKeyBytes, err := hex.DecodeString(publicKey)
23+
func (sn *SelfNode) SetKeys(clientKey, publicKey, privateKey string, isSplit bool) {
24+
var (
25+
publicKeyBytes []byte
26+
err error
27+
)
28+
29+
if isSplit {
30+
publicKeyBytes, err = hex.DecodeString(clientKey)
31+
} else {
32+
publicKeyBytes, err = hex.DecodeString(publicKey)
33+
}
34+
2435
if err != nil {
2536
panic(err)
2637
}
38+
2739
sn.wallet = &zcncrypto.Wallet{}
2840
sn.wallet.ClientID = Hash(publicKeyBytes)
29-
sn.wallet.ClientKey = publicKey
41+
42+
if isSplit {
43+
sn.wallet.ClientKey = clientKey
44+
} else {
45+
sn.wallet.ClientKey = publicKey
46+
}
47+
3048
sn.wallet.Keys = make([]zcncrypto.KeyPair, 1)
3149
sn.wallet.Keys[0].PublicKey = publicKey
3250
sn.wallet.Keys[0].PrivateKey = privateKey
3351
sn.wallet.Version = zcncrypto.CryptoVersion
52+
sn.wallet.IsSplit = isSplit
53+
54+
if isSplit {
55+
sn.PublicKey = clientKey
56+
} else {
57+
sn.PublicKey = publicKey
58+
}
3459

35-
sn.PublicKey = publicKey
3660
sn.ID = sn.wallet.ClientID
3761
}
3862

code/go/0chain.net/validator/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ func main() {
107107
fmt.Println("using validator keys from aws")
108108
}
109109

110-
node.Self.SetKeys(publicKey, privateKey)
110+
node.Self.SetKeys("", publicKey, privateKey, false)
111111

112112
if len(*hostUrl) > 0 {
113113
node.Self.URL = *hostUrl

code/go/0chain.net/validatorcore/storage/models_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -659,6 +659,6 @@ func setupModelsTest(t *testing.T) error {
659659
return err
660660
}
661661

662-
node.Self.SetKeys(wallet.Keys[0].PublicKey, wallet.Keys[0].PrivateKey)
662+
node.Self.SetKeys("", wallet.Keys[0].PublicKey, wallet.Keys[0].PrivateKey, false)
663663
return nil
664664
}

config/0chain_blobber.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ min_confirmation: 10
4545

4646
block_worker: https://dev.0chain.net/dns
4747

48+
zauth_server: https://zauth.dev.0chain.net/
49+
4850
rate_limiters:
4951
# Rate limiters will use this duration to clean unused token buckets.
5052
# If it is 0 then token will expire in 10 years.

0 commit comments

Comments
 (0)