Skip to content

Commit

Permalink
feat: Added support for tsh serverside encryption
Browse files Browse the repository at this point in the history
  • Loading branch information
WillFantom committed Sep 21, 2023
1 parent 861d55f commit 1fc4aaa
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
2 changes: 2 additions & 0 deletions cmd/sshare/sshare.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ var (
tshInstanceURL string = transfer.DefaultTransferBaseURL
transferDownloads int = 0
transferDays int = 0
password string = ""
sshAgentPath string = os.Getenv("SSH_AUTH_SOCK")
sshAgentPass string = ""
githubToken string = ""
Expand Down Expand Up @@ -146,5 +147,6 @@ func init() {
rootCmd.PersistentFlags().StringVar(&tshInstanceURL, "url", transfer.DefaultTransferBaseURL, "url of the target transfer.sh instance")
rootCmd.Flags().IntVarP(&transferDownloads, "max-downloads", "m", 10, "maximum number of times any content shared can be downloaded")
rootCmd.Flags().IntVarP(&transferDays, "max-days", "d", 2, "number of days that the content will remain available via transfer.sh")
rootCmd.Flags().StringVarP(&password, "encrypt", "e", password, "password for transfer.sh server-side encryption")
rootCmd.AddCommand(deleteCmd)
}
12 changes: 12 additions & 0 deletions internal/transfer/upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ type TransferSh struct {
fileName string
maxDownloads int
maxDays int
password string
}

const (
Expand Down Expand Up @@ -45,6 +46,7 @@ func NewTransferSh() *TransferSh {
fileName: "authorized_keys",
maxDownloads: 10,
maxDays: 2,
password: "",
}
}

Expand All @@ -68,6 +70,13 @@ func (tsh TransferSh) WithMaxDays(maxDays int) TransferSh {
return tsh
}

// WithPassword can be used to set the serverside encryption password for a
// transfer.sh file upload.
func (tsh TransferSh) WithPassword(password string) TransferSh {
tsh.password = password
return tsh
}

// Upload creates a new file with the contents of data and uploads it to
// transfer.sh. Returned are the URLs to both download/curl the file and to
// delete the file form transfer.sh. If the upload fails, an error is returned.
Expand All @@ -84,6 +93,9 @@ func (tsh TransferSh) Upload(data string) (*TransferShFile, error) {
req.Header.Set("Content-Type", "text/plain")
req.Header.Set("Max-Downloads", strconv.Itoa(tsh.maxDownloads))
req.Header.Set("Max-Days", strconv.Itoa(tsh.maxDays))
if tsh.password != "" {
req.Header.Set("X-Encrypt-Password", tsh.password)
}
resp, err := (&http.Client{}).Do(req)
if err != nil {
return nil, fmt.Errorf("failed to perform the upload request: %w", err)
Expand Down

0 comments on commit 1fc4aaa

Please sign in to comment.