@@ -267,15 +267,16 @@ func (fsh *StorageHandler) DownloadFile(ctx context.Context, r *http.Request) (i
267
267
// get client and allocation ids
268
268
269
269
var (
270
- clientID = ctx .Value (constants .ContextKeyClient ).(string )
271
- allocationTx = ctx .Value (constants .ContextKeyAllocation ).(string )
272
- allocationID = ctx .Value (constants .ContextKeyAllocationID ).(string )
273
- alloc * allocation.Allocation
274
- blobberID = node .Self .ID
275
- quotaManager = getQuotaManager ()
270
+ clientID = ctx .Value (constants .ContextKeyClient ).(string )
271
+ clientPublicKey = ctx .Value (constants .ContextKeyClientKey ).(string )
272
+ allocationTx = ctx .Value (constants .ContextKeyAllocation ).(string )
273
+ allocationID = ctx .Value (constants .ContextKeyAllocationID ).(string )
274
+ alloc * allocation.Allocation
275
+ blobberID = node .Self .ID
276
+ quotaManager = getQuotaManager ()
276
277
)
277
278
278
- if clientID == "" {
279
+ if clientID == "" || clientPublicKey == "" {
279
280
return nil , common .NewError ("download_file" , "invalid client" )
280
281
}
281
282
@@ -320,6 +321,12 @@ func (fsh *StorageHandler) DownloadFile(ctx context.Context, r *http.Request) (i
320
321
if dr .AuthToken == "" {
321
322
return nil , common .NewError ("invalid_authticket" , "authticket is required" )
322
323
}
324
+ if dr .Version == "v2" {
325
+ valid , err := verifySignatureFromRequest (allocationTx , r .Header .Get (common .ClientSignatureHeader ), r .Header .Get (common .ClientSignatureHeaderV2 ), clientPublicKey )
326
+ if ! valid || err != nil {
327
+ return nil , common .NewError ("invalid_signature" , "Invalid signature" )
328
+ }
329
+ }
323
330
authTokenString , err := base64 .StdEncoding .DecodeString (dr .AuthToken )
324
331
if err != nil {
325
332
return nil , common .NewError ("invalid_authticket" , err .Error ())
@@ -343,6 +350,13 @@ func (fsh *StorageHandler) DownloadFile(ctx context.Context, r *http.Request) (i
343
350
return nil , common .NewErrorf ("download_file" , "the file is not available until: %v" , shareInfo .AvailableAt .UTC ().Format ("2006-01-02T15:04:05" ))
344
351
}
345
352
353
+ } else {
354
+ if dr .Version == "v2" {
355
+ valid , err := verifySignatureFromRequest (allocationTx , r .Header .Get (common .ClientSignatureHeader ), r .Header .Get (common .ClientSignatureHeaderV2 ), alloc .OwnerPublicKey )
356
+ if ! valid || err != nil {
357
+ return nil , common .NewError ("invalid_signature" , "Invalid signature" )
358
+ }
359
+ }
346
360
}
347
361
348
362
isReadFree := alloc .IsReadFree (blobberID )
@@ -464,7 +478,7 @@ func (fsh *StorageHandler) CreateConnection(ctx context.Context, r *http.Request
464
478
return nil , common .NewError ("invalid_operation" , "Operation needs to be performed by the owner or the payer of the allocation" )
465
479
}
466
480
467
- valid , err := verifySignatureFromRequest (allocationTx , r .Header .Get (common .ClientSignatureHeader ), allocationObj .OwnerPublicKey )
481
+ valid , err := verifySignatureFromRequest (allocationTx , r .Header .Get (common .ClientSignatureHeader ), r . Header . Get ( common . ClientSignatureHeaderV2 ), allocationObj .OwnerPublicKey )
468
482
if ! valid || err != nil {
469
483
return nil , common .NewError ("invalid_signature" , "Invalid signature" )
470
484
}
@@ -766,8 +780,7 @@ func (fsh *StorageHandler) RenameObject(ctx context.Context, r *http.Request) (i
766
780
767
781
clientID := ctx .Value (constants .ContextKeyClient ).(string )
768
782
_ = ctx .Value (constants .ContextKeyClientKey ).(string )
769
-
770
- valid , err := verifySignatureFromRequest (allocationTx , r .Header .Get (common .ClientSignatureHeader ), allocationObj .OwnerPublicKey )
783
+ valid , err := verifySignatureFromRequest (allocationTx , r .Header .Get (common .ClientSignatureHeader ), r .Header .Get (common .ClientSignatureHeaderV2 ), allocationObj .OwnerPublicKey )
771
784
if ! valid || err != nil {
772
785
return nil , common .NewError ("invalid_signature" , "Invalid signature" )
773
786
}
@@ -848,7 +861,7 @@ func (fsh *StorageHandler) CopyObject(ctx context.Context, r *http.Request) (int
848
861
return nil , common .NewError ("prohibited_allocation_file_options" , "Cannot copy data from this allocation." )
849
862
}
850
863
851
- valid , err := verifySignatureFromRequest (allocationTx , r .Header .Get (common .ClientSignatureHeader ), allocationObj .OwnerPublicKey )
864
+ valid , err := verifySignatureFromRequest (allocationTx , r .Header .Get (common .ClientSignatureHeader ), r . Header . Get ( common . ClientSignatureHeaderV2 ), allocationObj .OwnerPublicKey )
852
865
if ! valid || err != nil {
853
866
return nil , common .NewError ("invalid_signature" , "Invalid signature" )
854
867
}
@@ -957,8 +970,7 @@ func (fsh *StorageHandler) MoveObject(ctx context.Context, r *http.Request) (int
957
970
return nil , common .NewError ("prohibited_allocation_file_options" , "Cannot move data in this allocation." )
958
971
}
959
972
960
- valid , err := verifySignatureFromRequest (
961
- allocationTx , r .Header .Get (common .ClientSignatureHeader ), allocationObj .OwnerPublicKey )
973
+ valid , err := verifySignatureFromRequest (allocationTx , r .Header .Get (common .ClientSignatureHeader ), r .Header .Get (common .ClientSignatureHeaderV2 ), allocationObj .OwnerPublicKey )
962
974
if ! valid || err != nil {
963
975
return nil , common .NewError ("invalid_signature" , "Invalid signature" )
964
976
}
@@ -1109,7 +1121,7 @@ func (fsh *StorageHandler) CreateDir(ctx context.Context, r *http.Request) (*all
1109
1121
return nil , common .NewError ("invalid_parameters" , "Invalid allocation id passed." + err .Error ())
1110
1122
}
1111
1123
1112
- valid , err := verifySignatureFromRequest (allocationTx , r .Header .Get (common .ClientSignatureHeader ), allocationObj .OwnerPublicKey )
1124
+ valid , err := verifySignatureFromRequest (allocationTx , r .Header .Get (common .ClientSignatureHeader ), r . Header . Get ( common . ClientSignatureHeaderV2 ), allocationObj .OwnerPublicKey )
1113
1125
if ! valid || err != nil {
1114
1126
return nil , common .NewError ("invalid_signature" , "Invalid signature" )
1115
1127
}
@@ -1240,7 +1252,7 @@ func (fsh *StorageHandler) WriteFile(ctx context.Context, r *http.Request) (*all
1240
1252
st = time .Now ()
1241
1253
publicKey := allocationObj .OwnerPublicKey
1242
1254
1243
- valid , err := verifySignatureFromRequest (allocationTx , r .Header .Get (common .ClientSignatureHeader ), publicKey )
1255
+ valid , err := verifySignatureFromRequest (allocationTx , r .Header .Get (common .ClientSignatureHeader ), r . Header . Get ( common . ClientSignatureHeaderV2 ), publicKey )
1244
1256
1245
1257
if ! valid || err != nil {
1246
1258
return nil , common .NewError ("invalid_signature" , "Invalid signature" )
0 commit comments