Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
coreNetwork "github.com/0chain/gosdk/core/conf"
"github.com/0chain/gosdk/core/zcncrypto"
zencryption "github.com/0chain/gosdk/zboxcore/encryption"
"github.com/0chain/gosdk/zboxcore/fileref"
"github.com/0chain/gosdk/zcncore"
"github.com/DATA-DOG/go-sqlmock"
mocket "github.com/selvatico/go-mocket"
Expand All @@ -37,13 +38,19 @@ func resetMockFileBlock() {

var encscheme zencryption.EncryptionScheme

// getLookupHash generates a deterministic lookup hash for testing
func getLookupHash() string {
return fileref.GetReferenceLookup("test-allocation-id", "/test/file/path")
}

func setupEncryptionScheme() {
encscheme = zencryption.NewEncryptionScheme()
mnemonic := client.GetClient().Mnemonic
if _, err := encscheme.Initialize(mnemonic); err != nil {
panic("initialize encscheme")
}
encscheme.InitForEncryption("filetype:audio")
lookupHash := getLookupHash()
encscheme.InitForEncryption(lookupHash)
}

func setup(t *testing.T) {
Expand Down
3 changes: 2 additions & 1 deletion code/go/0chain.net/blobbercore/handler/chunk_encoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ type PREChunkEncoder struct {
EncryptedKey string
ReEncryptionKey string
ClientEncryptionPublicKey string
LookupHash string
}

// Encode encode chunk data with PREEncryptionScheme for subscriber to download it
Expand All @@ -36,7 +37,7 @@ func (r *PREChunkEncoder) Encode(chunkSize int, data []byte) ([]byte, error) {
return nil, err
}

if err := encscheme.InitForDecryption("filetype:audio", r.EncryptedKey); err != nil {
if err := encscheme.InitForDecryption(r.LookupHash, r.EncryptedKey); err != nil {
return nil, err
}

Expand Down
17 changes: 13 additions & 4 deletions code/go/0chain.net/blobbercore/handler/handler_download_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,18 @@ func setupDownloadHandlers() (*mux.Router, map[string]string) {
}
}

// getLookupHash generates a deterministic lookup hash for testing
func getLookupHash() string {
return fileref.GetReferenceLookup("test-allocation-id", "/test/file/path")
}

func getEncryptionScheme(mnemonic string) (zencryption.EncryptionScheme, error) {
encscheme := zencryption.NewEncryptionScheme()
if _, err := encscheme.Initialize(mnemonic); err != nil {
return nil, err
}
encscheme.InitForEncryption("filetype:audio")
lookupHash := getLookupHash()
encscheme.InitForEncryption(lookupHash)
return encscheme, nil
}

Expand Down Expand Up @@ -623,7 +629,8 @@ func TestHandlers_Download(t *testing.T) {
if err != nil {
t.Fatal(err)
}
reEncryptionKey, err := ownerScheme.GetReGenKey(guestPublicEncryptedKey, "filetype:audio")
lookupHash := getLookupHash()
reEncryptionKey, err := ownerScheme.GetReGenKey(guestPublicEncryptedKey, lookupHash)

if err != nil {
t.Fatal(err)
Expand Down Expand Up @@ -746,7 +753,8 @@ func TestHandlers_Download(t *testing.T) {
t.Fatal(err)
}

reEncryptionKey, _ := ownerScheme.GetReGenKey(gpbk, "filetype:audio")
lookupHash := getLookupHash()
reEncryptionKey, _ := ownerScheme.GetReGenKey(gpbk, lookupHash)
mock.ExpectQuery(regexp.QuoteMeta(`SELECT * FROM "marketplace_share_info" WHERE`)).
WithArgs(guestClient.ClientID, rootPathHash).
WillReturnRows(
Expand Down Expand Up @@ -866,7 +874,8 @@ func TestHandlers_Download(t *testing.T) {
t.Fatal(err)
}

reEncryptionKey, _ := ownerScheme.GetReGenKey(gpbk, "filetype:audio")
lookupHash := getLookupHash()
reEncryptionKey, _ := ownerScheme.GetReGenKey(gpbk, lookupHash)
mock.ExpectQuery(regexp.QuoteMeta(`SELECT * FROM "marketplace_share_info" WHERE`)).
WithArgs(guestClient.ClientID, rootPathHash).
WillReturnRows(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,7 @@ func (fsh *StorageHandler) DownloadFile(ctx context.Context, r *http.Request) (i
EncryptedKey: fileref.EncryptedKey,
ReEncryptionKey: shareInfo.ReEncryptionKey,
ClientEncryptionPublicKey: shareInfo.ClientEncryptionPublicKey,
LookupHash: fileref.LookupHash,
}
} else {
chunkEncoder = &RawChunkEncoder{}
Expand Down
2 changes: 0 additions & 2 deletions code/go/0chain.net/blobbercore/readmarker/authticket.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ type AuthTicket struct {
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"`
Expand All @@ -41,7 +40,6 @@ func (rm *AuthTicket) GetHashData() string {
rm.ReEncryptionKey,
rm.Expiration,
rm.Timestamp,
rm.ActualFileHash,
rm.Encrypted,
)
return hashData
Expand Down
Loading