mirror of
https://github.com/tgdrive/teldrive.git
synced 2025-09-12 09:25:37 +08:00
check for encrpytion key
This commit is contained in:
parent
d5c2387212
commit
72a4ceecd0
1 changed files with 12 additions and 1 deletions
|
@ -5,6 +5,7 @@ import (
|
||||||
"crypto/rand"
|
"crypto/rand"
|
||||||
"crypto/sha256"
|
"crypto/sha256"
|
||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
|
"errors"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
@ -128,6 +129,16 @@ func (us *UploadService) UploadFile(c *gin.Context) (*schemas.UploadPartOut, *ty
|
||||||
return nil, us.logAndReturn("UploadFile", err, http.StatusBadRequest)
|
return nil, us.logAndReturn("UploadFile", err, http.StatusBadRequest)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var encryptedKey string
|
||||||
|
|
||||||
|
if uploadQuery.Encrypted {
|
||||||
|
encryptedKey = config.GetConfig().EncryptionKey
|
||||||
|
|
||||||
|
if encryptedKey == "" {
|
||||||
|
return nil, us.logAndReturn("UploadFile", errors.New("encryption key not set"), http.StatusInternalServerError)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
userId, session := getUserAuth(c)
|
userId, session := getUserAuth(c)
|
||||||
|
|
||||||
uploadId := c.Param("id")
|
uploadId := c.Param("id")
|
||||||
|
@ -180,7 +191,7 @@ func (us *UploadService) UploadFile(c *gin.Context) (*schemas.UploadPartOut, *ty
|
||||||
|
|
||||||
//gen random Salt
|
//gen random Salt
|
||||||
salt, _ = generateRandomSalt()
|
salt, _ = generateRandomSalt()
|
||||||
cipher, _ := crypt.NewCipher(config.GetConfig().EncryptionKey, salt)
|
cipher, _ := crypt.NewCipher(encryptedKey, salt)
|
||||||
fileSize = crypt.EncryptedSize(fileSize)
|
fileSize = crypt.EncryptedSize(fileSize)
|
||||||
fileStream, _ = cipher.EncryptData(fileStream)
|
fileStream, _ = cipher.EncryptData(fileStream)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue