feat: allow to password protect shares (#1252)

This changes allows to password protect shares. It works by:
* Allowing to optionally pass a password when creating a share
* If set, the password + salt that is configured via a new flag will be
  hashed via bcrypt and the hash stored together with the rest of the
  share
* Additionally, a random 96 byte long token gets generated and stored
  as part of the share
* When the backend retrieves an unauthenticated request for a share that
  has authentication configured, it will return a http 401
* The frontend detects this and will show a login prompt
* The actual download links are protected via an url arg that contains
  the previously generated token. This allows us to avoid buffering the
  download in the browser and allows pasting the link without breaking
  it
This commit is contained in:
Alvaro Aleman
2021-03-02 06:00:18 -05:00
committed by GitHub
parent 977ec33918
commit d8f415f8ab
22 changed files with 340 additions and 41 deletions

View File

@@ -17,6 +17,15 @@ type StorageBackend interface {
DeleteByUsername(string) error
}
type Store interface {
Get(baseScope string, id interface{}) (user *User, err error)
Gets(baseScope string) ([]*User, error)
Update(user *User, fields ...string) error
Save(user *User) error
Delete(id interface{}) error
LastUpdate(id uint) int64
}
// Storage is a users storage.
type Storage struct {
back StorageBackend

4
users/storage_test.go Normal file
View File

@@ -0,0 +1,4 @@
package users
// Interface is implemented by storage
var _ Store = &Storage{}