Skip to content

Commit 1c3fddd

Browse files
authored
Merge pull request #1497 from 0chain/revert-1496-revert-1494-feat/session-key
Session key
2 parents b1ef274 + 84b7d56 commit 1c3fddd

File tree

25 files changed

+207
-113
lines changed

25 files changed

+207
-113
lines changed

code/go/0chain.net/blobbercore/allocation/entity.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,9 @@ type Allocation struct {
6262
TimeUnit time.Duration `gorm:"column:time_unit;not null;default:172800000000000"`
6363
StartTime common.Timestamp `gorm:"column:start_time;not null"`
6464
// Ending and cleaning
65-
CleanedUp bool `gorm:"column:cleaned_up;not null;default:false"`
66-
Finalized bool `gorm:"column:finalized;not null;default:false"`
65+
CleanedUp bool `gorm:"column:cleaned_up;not null;default:false"`
66+
Finalized bool `gorm:"column:finalized;not null;default:false"`
67+
OwnerSigningPublicKey string `gorm:"column:owner_signing_public_key;size:512;not null" json:"owner_signing_public_key"`
6768

6869
// FileOptions to define file restrictions on an allocation for third-parties
6970
// default 00000000 for all crud operations suggesting only owner has the below listed abilities.

code/go/0chain.net/blobbercore/allocation/file_changer_base.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,9 @@ type BaseFileChanger struct {
5252
EncryptedKeyPoint string `json:"encrypted_key_point,omitempty"`
5353
CustomMeta string `json:"custom_meta,omitempty"`
5454

55-
ChunkSize int64 `json:"chunk_size,omitempty"` // the size of achunk. 64*1024 is default
56-
IsFinal bool `json:"is_final,omitempty"` // current chunk is last or not
55+
ChunkSize int64 `json:"chunk_size,omitempty"` // the size of achunk. 64*1024 is default
56+
IsFinal bool `json:"is_final,omitempty"` // current chunk is last or not
57+
SignatureVersion int `json:"signature_version,omitempty"`
5758

5859
ChunkStartIndex int `json:"chunk_start_index,omitempty"` // start index of chunks.
5960
ChunkEndIndex int `json:"chunk_end_index,omitempty"` // end index of chunks. all chunks MUST be uploaded one by one because of CompactMerkleTree

code/go/0chain.net/blobbercore/allocation/file_changer_update.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ func (nf *UpdateFileChanger) ApplyChange(ctx context.Context, rootRef *reference
106106
fileRef.ChunkSize = nf.ChunkSize
107107
fileRef.IsPrecommit = true
108108
fileRef.FilestoreVersion = filestore.VERSION
109+
fileRef.SignatureVersion = nf.SignatureVersion
109110

110111
return rootRef, nil
111112
}
@@ -173,6 +174,7 @@ func (nf *UpdateFileChanger) ApplyChangeV2(ctx context.Context, allocationRoot,
173174
PathLevel: len(strings.Split(strings.TrimRight(nf.Path, "/"), "/")),
174175
NumBlocks: int64(math.Ceil(float64(nf.Size*1.0) / float64(nf.ChunkSize))),
175176
NumUpdates: refResult.NumUpdates + 1,
177+
SignatureVersion: nf.SignatureVersion,
176178
}
177179
nf.storageVersion = 1
178180
newFile.FileMetaHash = encryption.Hash(newFile.GetFileMetaHashDataV2())

code/go/0chain.net/blobbercore/allocation/file_changer_upload.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ func (nf *UploadFileChanger) applyChange(ctx context.Context, rootRef *reference
130130
HashToBeComputed: true,
131131
IsPrecommit: true,
132132
FilestoreVersion: filestore.VERSION,
133+
SignatureVersion: nf.SignatureVersion,
133134
}
134135

135136
fileID, ok := fileIDMeta[newFile.Path]
@@ -197,6 +198,7 @@ func (nf *UploadFileChanger) ApplyChangeV2(ctx context.Context, allocationRoot,
197198
PathLevel: len(strings.Split(strings.TrimRight(nf.Path, "/"), "/")),
198199
NumBlocks: int64(math.Ceil(float64(nf.Size*1.0) / float64(nf.ChunkSize))),
199200
NumUpdates: 1,
201+
SignatureVersion: nf.SignatureVersion,
200202
}
201203
nf.storageVersion = 1
202204
newFile.FileMetaHash = encryption.Hash(newFile.GetFileMetaHashDataV2())

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

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"github.com/0chain/blobber/code/go/0chain.net/core/logging"
1414
"github.com/0chain/blobber/code/go/0chain.net/core/node"
1515
"github.com/0chain/blobber/code/go/0chain.net/core/transaction"
16+
"go.uber.org/zap"
1617
"gorm.io/gorm"
1718
)
1819

@@ -110,8 +111,9 @@ func FetchAllocationFromEventsDB(ctx context.Context, allocationID string, alloc
110111
a.TimeUnit = sa.TimeUnit
111112
a.FileOptions = sa.FileOptions
112113
a.StartTime = sa.StartTime
113-
// Only for testing purpose
114114
a.StorageVersion = uint8(sa.StorageVersion)
115+
a.OwnerSigningPublicKey = sa.OwnerSigningPublicKey
116+
logging.Logger.Info("OwnerSigningPublicKey", zap.String("OwnerSigningPublicKey", a.OwnerSigningPublicKey), zap.String("allocation_id", a.ID))
115117

116118
m := map[string]interface{}{
117119
"allocation_id": a.ID,
@@ -139,23 +141,24 @@ func FetchAllocationFromEventsDB(ctx context.Context, allocationID string, alloc
139141
return a, nil
140142
}
141143

142-
logging.Logger.Info("Saving the allocation to DB")
144+
logging.Logger.Info("Saving the allocation to DB", zap.String("allocation_id", a.ID))
143145

144146
if !isExist {
145147
err = Repo.Save(ctx, a)
146148
} else {
147149
updateMap := map[string]interface{}{
148-
"tx": a.Tx,
149-
"expiration_date": a.Expiration,
150-
"owner_id": a.OwnerID,
151-
"owner_public_key": a.OwnerPublicKey,
152-
"repairer_id": a.RepairerID,
153-
"size": a.TotalSize,
154-
"finalized": a.Finalized,
155-
"time_unit": a.TimeUnit,
156-
"file_options": a.FileOptions,
157-
"start_time": a.StartTime,
158-
"blobber_size": a.BlobberSize,
150+
"tx": a.Tx,
151+
"expiration_date": a.Expiration,
152+
"owner_id": a.OwnerID,
153+
"owner_public_key": a.OwnerPublicKey,
154+
"repairer_id": a.RepairerID,
155+
"size": a.TotalSize,
156+
"finalized": a.Finalized,
157+
"time_unit": a.TimeUnit,
158+
"file_options": a.FileOptions,
159+
"start_time": a.StartTime,
160+
"blobber_size": a.BlobberSize,
161+
"owner_signing_public_key": a.OwnerSigningPublicKey,
159162
}
160163

161164
updateOption := func(alloc *Allocation) {
@@ -170,6 +173,7 @@ func FetchAllocationFromEventsDB(ctx context.Context, allocationID string, alloc
170173
alloc.FileOptions = a.FileOptions
171174
alloc.StartTime = a.StartTime
172175
alloc.BlobberSize = a.BlobberSize
176+
alloc.OwnerSigningPublicKey = a.OwnerSigningPublicKey
173177
}
174178
err = Repo.UpdateAllocation(ctx, a, updateMap, updateOption)
175179
}

code/go/0chain.net/blobbercore/allocation/workers.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,7 @@ func updateAllocationInDB(ctx context.Context, a *Allocation, sa *transaction.St
246246
a.Tx = sa.Tx
247247
a.OwnerID = sa.OwnerID
248248
a.OwnerPublicKey = sa.OwnerPublicKey
249+
a.OwnerSigningPublicKey = sa.OwnerSigningPublicKey
249250

250251
// // update fields
251252
a.Expiration = sa.Expiration
@@ -263,6 +264,7 @@ func updateAllocationInDB(ctx context.Context, a *Allocation, sa *transaction.St
263264
updateMap["finalized"] = a.Finalized
264265
updateMap["file_options"] = a.FileOptions
265266
updateMap["blobber_size"] = a.BlobberSize
267+
updateMap["owner_signing_public_key"] = a.OwnerSigningPublicKey
266268

267269
updateOption := func(alloc *Allocation) {
268270
alloc.Tx = a.Tx
@@ -273,6 +275,7 @@ func updateAllocationInDB(ctx context.Context, a *Allocation, sa *transaction.St
273275
alloc.Finalized = a.Finalized
274276
alloc.FileOptions = a.FileOptions
275277
alloc.BlobberSize = a.BlobberSize
278+
alloc.OwnerSigningPublicKey = a.OwnerSigningPublicKey
276279
}
277280

278281
// update terms

code/go/0chain.net/blobbercore/allocation/zcn.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ func SyncAllocation(allocationId string) (*Allocation, error) {
5252
alloc.Finalized = sa.Finalized
5353
alloc.TimeUnit = sa.TimeUnit
5454
alloc.FileOptions = sa.FileOptions
55+
alloc.StorageVersion = uint8(sa.StorageVersion)
56+
alloc.OwnerSigningPublicKey = sa.OwnerSigningPublicKey
5557

5658
// related terms
5759
terms := make([]*Terms, 0, len(sa.BlobberDetails))

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,14 @@ import (
55
"encoding/hex"
66
"encoding/json"
77
"errors"
8-
"github.com/0chain/blobber/code/go/0chain.net/core/transaction"
9-
coreTxn "github.com/0chain/gosdk/core/transaction"
108
"math/rand"
119
"strings"
1210
"sync"
1311
"time"
1412

13+
"github.com/0chain/blobber/code/go/0chain.net/core/transaction"
14+
coreTxn "github.com/0chain/gosdk/core/transaction"
15+
1516
"github.com/0chain/blobber/code/go/0chain.net/blobbercore/allocation"
1617
"github.com/0chain/blobber/code/go/0chain.net/blobbercore/datastore"
1718
"github.com/0chain/blobber/code/go/0chain.net/blobbercore/filestore"
@@ -366,6 +367,7 @@ func (cr *ChallengeEntity) getPostDataV2(ctx context.Context, allocationObj *all
366367
FixedMerkleRoot: ref.FixedMerkleRoot,
367368
Size: ref.Size,
368369
FileMetaHash: ref.FileMetaHash,
370+
SignatureVersion: ref.SignatureVersion,
369371
}
370372
postData["meta"] = metaRef
371373
}

code/go/0chain.net/blobbercore/config/config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ func SetupDefaultConfig() {
5353

5454
viper.SetDefault("max_dirs_files", 50000)
5555
viper.SetDefault("max_objects_dir", 1000)
56-
viper.SetDefault("max_objects_per_gb", 100000)
56+
viper.SetDefault("max_objects_per_gb", 1000)
5757
viper.SetDefault("kv.pebble_dir", "/pebble/data")
5858
viper.SetDefault("kv.pebble_wal_dir", "/pebble/wal")
5959
viper.SetDefault("kv.pebble_cache", 4*1024*1024*1024)

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,15 @@ func (cmd *UpdateFileCommand) ProcessContent(ctx context.Context, allocationObj
155155
hashData := fmt.Sprintf("%s:%s:%s:%s", cmd.fileChanger.ActualHash, cmd.fileChanger.ValidationRoot, cmd.fileChanger.FixedMerkleRoot, node.Self.ID)
156156
hash = encryption.Hash(hashData)
157157
}
158-
verify, err := encryption.Verify(allocationObj.OwnerPublicKey, cmd.fileChanger.ValidationRootSignature, hash)
158+
var (
159+
err error
160+
verify bool
161+
)
162+
if cmd.fileChanger.SignatureVersion == reference.SignatureV2 {
163+
verify, err = encryption.VerifyEd25519(allocationObj.OwnerSigningPublicKey, cmd.fileChanger.ValidationRootSignature, hash)
164+
} else {
165+
verify, err = encryption.Verify(allocationObj.OwnerPublicKey, cmd.fileChanger.ValidationRootSignature, hash)
166+
}
159167
if err != nil || !verify {
160168
logging.Logger.Error("UpdateFileCommand.VerifySignature", zap.Error(err))
161169
return result, common.NewError("update_error", "Failed to verify validation root signature. ")

0 commit comments

Comments
 (0)