Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix auth ticket #1341

Merged
merged 3 commits into from
Dec 5, 2023
Merged
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 @@ -4,6 +4,7 @@
package handler

import (
"encoding/base64"
"encoding/json"
"fmt"
"net/http"
Expand Down Expand Up @@ -482,7 +483,7 @@ func TestHandlers_Download(t *testing.T) {
r.Header.Set("X-Verify-Download", fmt.Sprint(true))
r.Header.Set("X-Connection-ID", connectionID)
r.Header.Set("X-Mode", DownloadContentFull)
r.Header.Set("X-Auth-Token", authTicket)
r.Header.Set("X-Auth-Token", base64.StdEncoding.EncodeToString([]byte(authTicket)))
r.Header.Set(common.ClientSignatureHeader, sign)
r.Header.Set(common.ClientHeader, guestClient.ClientID)
r.Header.Set(common.ClientKeyHeader, guestClient.ClientKey)
Expand Down Expand Up @@ -563,7 +564,7 @@ func TestHandlers_Download(t *testing.T) {
r.Header.Set("X-Verify-Download", fmt.Sprint(true))
r.Header.Set("X-Connection-ID", connectionID)
r.Header.Set("X-Mode", DownloadContentFull)
r.Header.Set("X-Auth-Token", authTicket)
r.Header.Set("X-Auth-Token", base64.StdEncoding.EncodeToString([]byte(authTicket)))
r.Header.Set(common.ClientSignatureHeader, sign)
r.Header.Set(common.ClientHeader, guestClient.ClientID)
r.Header.Set(common.ClientKeyHeader, guestClient.ClientKey)
Expand Down Expand Up @@ -677,7 +678,7 @@ func TestHandlers_Download(t *testing.T) {
r.Header.Set("X-Verify-Download", fmt.Sprint(true))
r.Header.Set("X-Connection-ID", connectionID)
r.Header.Set("X-Mode", DownloadContentFull)
r.Header.Set("X-Auth-Token", authTicket)
r.Header.Set("X-Auth-Token", base64.StdEncoding.EncodeToString([]byte(authTicket)))
r.Header.Set(common.ClientSignatureHeader, sign)
r.Header.Set(common.ClientHeader, guestClient.ClientID)
r.Header.Set(common.ClientKeyHeader, guestClient.ClientKey)
Expand Down Expand Up @@ -797,7 +798,7 @@ func TestHandlers_Download(t *testing.T) {
r.Header.Set("X-Verify-Download", fmt.Sprint(true))
r.Header.Set("X-Connection-ID", connectionID)
r.Header.Set("X-Mode", DownloadContentFull)
r.Header.Set("X-Auth-Token", authTicket)
r.Header.Set("X-Auth-Token", base64.StdEncoding.EncodeToString([]byte(authTicket)))
r.Header.Set(common.ClientSignatureHeader, sign)
r.Header.Set(common.ClientHeader, guestClient.ClientID)
r.Header.Set(common.ClientKeyHeader, guestClient.ClientKey)
Expand Down Expand Up @@ -916,7 +917,7 @@ func TestHandlers_Download(t *testing.T) {
r.Header.Set("X-Verify-Download", fmt.Sprint(true))
r.Header.Set("X-Connection-ID", connectionID)
r.Header.Set("X-Mode", DownloadContentFull)
r.Header.Set("X-Auth-Token", authTicket)
r.Header.Set("X-Auth-Token", base64.StdEncoding.EncodeToString([]byte(authTicket)))
r.Header.Set(common.ClientSignatureHeader, sign)
r.Header.Set(common.ClientHeader, guestClient.ClientID)
r.Header.Set(common.ClientKeyHeader, guestClient.ClientKey)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package handler

import (
"context"
"encoding/base64"
"encoding/hex"
"encoding/json"
"errors"
Expand Down Expand Up @@ -316,12 +317,15 @@ func (fsh *StorageHandler) DownloadFile(ctx context.Context, r *http.Request) (i
var shareInfo *reference.ShareInfo

if !isOwner {
authTokenString := dr.AuthToken
if authTokenString == "" {
if dr.AuthToken == "" {
return nil, common.NewError("invalid_authticket", "authticket is required")
}
authTokenString, err := base64.StdEncoding.DecodeString(dr.AuthToken)
if err != nil {
return nil, common.NewError("invalid_authticket", err.Error())
}

if authToken, err = fsh.verifyAuthTicket(ctx, authTokenString, alloc, fileref, clientID, false); authToken == nil {
if authToken, err = fsh.verifyAuthTicket(ctx, string(authTokenString), alloc, fileref, clientID, false); authToken == nil {
return nil, common.NewErrorf("invalid_authticket", "cannot verify auth ticket: %v", err)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package handler
import (
"context"
"database/sql/driver"
"encoding/base64"
"encoding/json"
"fmt"
"log"
Expand Down Expand Up @@ -127,7 +128,8 @@ func TestDownloadFile(t *testing.T) {
require.NoError(t, authTicket.Sign())
require.NoError(t, client.PopulateClient(mockClientWallet, "bls0chain"))
authTicketBytes, _ := json.Marshal(authTicket)
req.Header.Set("X-Auth-Token", string(authTicketBytes))
auth := base64.StdEncoding.EncodeToString(authTicketBytes)
req.Header.Set("X-Auth-Token", auth)
}
if len(p.inData.contentMode) > 0 {
req.Header.Set("X-Mode", p.inData.contentMode)
Expand Down
Loading