Skip to content

Commit

Permalink
Merge pull request #1509 from 0chain/feat/encryption-key
Browse files Browse the repository at this point in the history
Add new version for encryption
  • Loading branch information
dabasov authored Nov 21, 2024
2 parents 3e3d534 + fa53a22 commit f865e7f
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,10 @@ type BaseFileChanger struct {
EncryptedKeyPoint string `json:"encrypted_key_point,omitempty"`
CustomMeta string `json:"custom_meta,omitempty"`

ChunkSize int64 `json:"chunk_size,omitempty"` // the size of achunk. 64*1024 is default
IsFinal bool `json:"is_final,omitempty"` // current chunk is last or not
SignatureVersion int `json:"signature_version,omitempty"`
ChunkSize int64 `json:"chunk_size,omitempty"` // the size of achunk. 64*1024 is default
IsFinal bool `json:"is_final,omitempty"` // current chunk is last or not
SignatureVersion int `json:"signature_version,omitempty"`
EncryptionVersion int `json:"encryption_version,omitempty"`

ChunkStartIndex int `json:"chunk_start_index,omitempty"` // start index of chunks.
ChunkEndIndex int `json:"chunk_end_index,omitempty"` // end index of chunks. all chunks MUST be uploaded one by one because of CompactMerkleTree
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ func (nf *UpdateFileChanger) ApplyChange(ctx context.Context, rootRef *reference
fileRef.IsPrecommit = true
fileRef.FilestoreVersion = filestore.VERSION
fileRef.SignatureVersion = nf.SignatureVersion
fileRef.EncryptionVersion = nf.EncryptionVersion

return rootRef, nil
}
Expand Down Expand Up @@ -175,6 +176,7 @@ func (nf *UpdateFileChanger) ApplyChangeV2(ctx context.Context, allocationRoot,
NumBlocks: int64(math.Ceil(float64(nf.Size*1.0) / float64(nf.ChunkSize))),
NumUpdates: refResult.NumUpdates + 1,
SignatureVersion: nf.SignatureVersion,
EncryptionVersion: nf.EncryptionVersion,
}
nf.storageVersion = 1
newFile.FileMetaHash = encryption.Hash(newFile.GetFileMetaHashDataV2())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ func (nf *UploadFileChanger) applyChange(ctx context.Context, rootRef *reference
IsPrecommit: true,
FilestoreVersion: filestore.VERSION,
SignatureVersion: nf.SignatureVersion,
EncryptionVersion: nf.EncryptionVersion,
}

fileID, ok := fileIDMeta[newFile.Path]
Expand Down Expand Up @@ -199,6 +200,7 @@ func (nf *UploadFileChanger) ApplyChangeV2(ctx context.Context, allocationRoot,
NumBlocks: int64(math.Ceil(float64(nf.Size*1.0) / float64(nf.ChunkSize))),
NumUpdates: 1,
SignatureVersion: nf.SignatureVersion,
EncryptionVersion: nf.EncryptionVersion,
}
nf.storageVersion = 1
newFile.FileMetaHash = encryption.Hash(newFile.GetFileMetaHashDataV2())
Expand Down
25 changes: 13 additions & 12 deletions code/go/0chain.net/blobbercore/readmarker/authticket.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,19 @@ const (

// swagger:model AuthTicket
type AuthTicket struct {
ClientID string `json:"client_id"`
OwnerID string `json:"owner_id"`
AllocationID string `json:"allocation_id"`
FilePathHash string `json:"file_path_hash"`
ActualFileHash string `json:"actual_file_hash"`
FileName string `json:"file_name"`
RefType string `json:"reference_type"`
Expiration common.Timestamp `json:"expiration"`
Timestamp common.Timestamp `json:"timestamp"`
ReEncryptionKey string `json:"re_encryption_key"`
Signature string `json:"signature"`
Encrypted bool `json:"encrypted"`
ClientID string `json:"client_id"`
OwnerID string `json:"owner_id"`
AllocationID string `json:"allocation_id"`
FilePathHash string `json:"file_path_hash"`
ActualFileHash string `json:"actual_file_hash"`
FileName string `json:"file_name"`
RefType string `json:"reference_type"`
Expiration common.Timestamp `json:"expiration"`
Timestamp common.Timestamp `json:"timestamp"`
ReEncryptionKey string `json:"re_encryption_key"`
Signature string `json:"signature"`
Encrypted bool `json:"encrypted"`
EncryptionPublicKey string `json:"encryption_public_key"`
}

func (rm *AuthTicket) GetHashData() string {
Expand Down
2 changes: 2 additions & 0 deletions code/go/0chain.net/blobbercore/reference/ref.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ type Ref struct {
NumBlockDownloads int64 `gorm:"column:num_of_block_downloads" json:"num_of_block_downloads"`
FilestoreVersion int `gorm:"column:filestore_version" json:"-"`
SignatureVersion int `gorm:"column:signature_version" json:"signature_version" filelist:"signature_version"`
EncryptionVersion int `gorm:"column:encryption_version" json:"encryption_version" filelist:"encryption_version"`
IsEmpty bool `gorm:"-" dirlist:"is_empty"`
HashToBeComputed bool `gorm:"-"`
prevID int64 `gorm:"-"`
Expand Down Expand Up @@ -151,6 +152,7 @@ type PaginatedRef struct { //Gorm smart select fields.
EncryptedKeyPoint string `gorm:"column:encrypted_key_point" json:"encrypted_key_point,omitempty"`
FileMetaHash string `gorm:"column:file_meta_hash;size:64;not null" dirlist:"file_meta_hash" filelist:"file_meta_hash"`
SignatureVersion int `gorm:"column:signature_version" json:"signature_version,omitempty" filelist:"signature_version"`
EncryptionVersion int `gorm:"column:encryption_version" json:"encryption_version" filelist:"encryption_version"`

CreatedAt common.Timestamp `gorm:"column:created_at" json:"created_at,omitempty"`
UpdatedAt common.Timestamp `gorm:"column:updated_at" json:"updated_at,omitempty"`
Expand Down
6 changes: 6 additions & 0 deletions goose/migrations/1731740380_encryption__version.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
-- +goose Up
-- +goose StatementBegin

ALTER TABLE reference_objects ADD COLUMN encryption_version smallint;

-- +goose StatementEnd

0 comments on commit f865e7f

Please sign in to comment.