Skip to content
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
10 changes: 9 additions & 1 deletion cmd/cli-uploader/cliapi/cliapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ var ErrFileTooBig = errors.New("file too big")
// ErrE2eKeyIncorrect is returned when the e2e key is incorrect
var ErrE2eKeyIncorrect = errors.New("e2e key incorrect")

// ErrE2eNotSetUp is returned when end-to-end encryption has not been set up on the server yet
var ErrE2eNotSetUp = errors.New("e2e has not been set up on the server")

// Init initialises the API client with the given url and key.
// The key is used for authentication.
// The end2endKey is used for end-to-end encryption.
Expand Down Expand Up @@ -152,7 +155,6 @@ func UploadFile(uploadParams cliflags.FlagConfig) (models.FileApiOutput, error)
if err != nil {
return models.FileApiOutput{}, err
}
// TODO check for 401

if len(e2eKey) == 0 || !isE2e || uploadParams.DisableE2e {
isE2e = false
Expand Down Expand Up @@ -445,6 +447,9 @@ func uploadChunk(f io.Reader, uuid string, offset, chunkSize, filesize int64, pr
return err
}
response := string(bodyContent)
if resp.StatusCode == http.StatusUnauthorized {
return ErrUnauthorised
}
if resp.StatusCode != http.StatusOK {
return errors.New("failed to upload chunk: status code " + strconv.Itoa(resp.StatusCode) + ", response: " + response)
}
Expand Down Expand Up @@ -516,6 +521,9 @@ func GetE2eInfo(unlockLock bool) (models.E2EInfoPlainText, error) {
if err != nil {
return models.E2EInfoPlainText{}, err
}
if !result.HasBeenSetUp() {
return models.E2EInfoPlainText{}, ErrE2eNotSetUp
}
fileInfo, err = end2end.DecryptData(result, e2eKey)
if err != nil {
return models.E2EInfoPlainText{}, ErrE2eKeyIncorrect
Expand Down
4 changes: 3 additions & 1 deletion cmd/cli-uploader/cliconfig/cliconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,14 @@ func CreateLogin() {
if err != nil {
if errors.Is(cliapi.ErrE2eKeyIncorrect, err) {
fmt.Println("ERROR: Incorrect end-to-end encryption key")
} else if errors.Is(err, cliapi.ErrE2eNotSetUp) {
fmt.Println("ERROR: End-to-end encryption has not been set up on the server yet.")
fmt.Println("Please complete the E2E setup in the Gokapi web interface first, then try again.")
} else {
fmt.Println(err)
}
os.Exit(1)
}
// TODO check if key has not been generated yet
}

err = save(url, apikey, e2ekey)
Expand Down
Loading