Skip to content

Commit f865e7f

Browse files
authored
Merge pull request #1509 from 0chain/feat/encryption-key
Add new version for encryption
2 parents 3e3d534 + fa53a22 commit f865e7f

File tree

6 files changed

+29
-15
lines changed

6 files changed

+29
-15
lines changed

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,10 @@ 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
57-
SignatureVersion int `json:"signature_version,omitempty"`
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"`
58+
EncryptionVersion int `json:"encryption_version,omitempty"`
5859

5960
ChunkStartIndex int `json:"chunk_start_index,omitempty"` // start index of chunks.
6061
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
@@ -107,6 +107,7 @@ func (nf *UpdateFileChanger) ApplyChange(ctx context.Context, rootRef *reference
107107
fileRef.IsPrecommit = true
108108
fileRef.FilestoreVersion = filestore.VERSION
109109
fileRef.SignatureVersion = nf.SignatureVersion
110+
fileRef.EncryptionVersion = nf.EncryptionVersion
110111

111112
return rootRef, nil
112113
}
@@ -175,6 +176,7 @@ func (nf *UpdateFileChanger) ApplyChangeV2(ctx context.Context, allocationRoot,
175176
NumBlocks: int64(math.Ceil(float64(nf.Size*1.0) / float64(nf.ChunkSize))),
176177
NumUpdates: refResult.NumUpdates + 1,
177178
SignatureVersion: nf.SignatureVersion,
179+
EncryptionVersion: nf.EncryptionVersion,
178180
}
179181
nf.storageVersion = 1
180182
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
@@ -131,6 +131,7 @@ func (nf *UploadFileChanger) applyChange(ctx context.Context, rootRef *reference
131131
IsPrecommit: true,
132132
FilestoreVersion: filestore.VERSION,
133133
SignatureVersion: nf.SignatureVersion,
134+
EncryptionVersion: nf.EncryptionVersion,
134135
}
135136

136137
fileID, ok := fileIDMeta[newFile.Path]
@@ -199,6 +200,7 @@ func (nf *UploadFileChanger) ApplyChangeV2(ctx context.Context, allocationRoot,
199200
NumBlocks: int64(math.Ceil(float64(nf.Size*1.0) / float64(nf.ChunkSize))),
200201
NumUpdates: 1,
201202
SignatureVersion: nf.SignatureVersion,
203+
EncryptionVersion: nf.EncryptionVersion,
202204
}
203205
nf.storageVersion = 1
204206
newFile.FileMetaHash = encryption.Hash(newFile.GetFileMetaHashDataV2())

code/go/0chain.net/blobbercore/readmarker/authticket.go

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,19 @@ const (
1515

1616
// swagger:model AuthTicket
1717
type AuthTicket struct {
18-
ClientID string `json:"client_id"`
19-
OwnerID string `json:"owner_id"`
20-
AllocationID string `json:"allocation_id"`
21-
FilePathHash string `json:"file_path_hash"`
22-
ActualFileHash string `json:"actual_file_hash"`
23-
FileName string `json:"file_name"`
24-
RefType string `json:"reference_type"`
25-
Expiration common.Timestamp `json:"expiration"`
26-
Timestamp common.Timestamp `json:"timestamp"`
27-
ReEncryptionKey string `json:"re_encryption_key"`
28-
Signature string `json:"signature"`
29-
Encrypted bool `json:"encrypted"`
18+
ClientID string `json:"client_id"`
19+
OwnerID string `json:"owner_id"`
20+
AllocationID string `json:"allocation_id"`
21+
FilePathHash string `json:"file_path_hash"`
22+
ActualFileHash string `json:"actual_file_hash"`
23+
FileName string `json:"file_name"`
24+
RefType string `json:"reference_type"`
25+
Expiration common.Timestamp `json:"expiration"`
26+
Timestamp common.Timestamp `json:"timestamp"`
27+
ReEncryptionKey string `json:"re_encryption_key"`
28+
Signature string `json:"signature"`
29+
Encrypted bool `json:"encrypted"`
30+
EncryptionPublicKey string `json:"encryption_public_key"`
3031
}
3132

3233
func (rm *AuthTicket) GetHashData() string {

code/go/0chain.net/blobbercore/reference/ref.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ type Ref struct {
9393
NumBlockDownloads int64 `gorm:"column:num_of_block_downloads" json:"num_of_block_downloads"`
9494
FilestoreVersion int `gorm:"column:filestore_version" json:"-"`
9595
SignatureVersion int `gorm:"column:signature_version" json:"signature_version" filelist:"signature_version"`
96+
EncryptionVersion int `gorm:"column:encryption_version" json:"encryption_version" filelist:"encryption_version"`
9697
IsEmpty bool `gorm:"-" dirlist:"is_empty"`
9798
HashToBeComputed bool `gorm:"-"`
9899
prevID int64 `gorm:"-"`
@@ -151,6 +152,7 @@ type PaginatedRef struct { //Gorm smart select fields.
151152
EncryptedKeyPoint string `gorm:"column:encrypted_key_point" json:"encrypted_key_point,omitempty"`
152153
FileMetaHash string `gorm:"column:file_meta_hash;size:64;not null" dirlist:"file_meta_hash" filelist:"file_meta_hash"`
153154
SignatureVersion int `gorm:"column:signature_version" json:"signature_version,omitempty" filelist:"signature_version"`
155+
EncryptionVersion int `gorm:"column:encryption_version" json:"encryption_version" filelist:"encryption_version"`
154156

155157
CreatedAt common.Timestamp `gorm:"column:created_at" json:"created_at,omitempty"`
156158
UpdatedAt common.Timestamp `gorm:"column:updated_at" json:"updated_at,omitempty"`
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
-- +goose Up
2+
-- +goose StatementBegin
3+
4+
ALTER TABLE reference_objects ADD COLUMN encryption_version smallint;
5+
6+
-- +goose StatementEnd

0 commit comments

Comments
 (0)