@@ -15,6 +15,7 @@ import (
1515 "net/http"
1616 "net/url"
1717 "os"
18+ "regexp"
1819 "strconv"
1920
2021 "crypto/sha256"
@@ -5728,8 +5729,9 @@ func FindUser(ctx context.Context, username string) ([]User, error) {
57285729 return newUsers , nil
57295730}
57305731
5731- func GetUser (ctx context.Context , username string ) (* User , error ) {
5732+ func GetUser (ctx context.Context , username string , returnEncrypted ... bool ) (* User , error ) {
57325733 curUser := & User {}
5734+ uuidRegex := regexp .MustCompile (`^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$` )
57335735
57345736 parsedKey := strings .ToLower (username )
57355737 cacheKey := fmt .Sprintf ("user_%s" , parsedKey )
@@ -5739,6 +5741,21 @@ func GetUser(ctx context.Context, username string) (*User, error) {
57395741 cacheData := []byte (cache .([]uint8 ))
57405742 err = json .Unmarshal (cacheData , & curUser )
57415743 if err == nil {
5744+ // uuid or not
5745+ if len (returnEncrypted ) == 0 || ! returnEncrypted [0 ] {
5746+ if len (curUser .ApiKey ) > 0 && ! uuidRegex .MatchString (curUser .ApiKey ) {
5747+ decryptedApiKey , decErr := HandleKeyDecryption ([]byte (curUser .ApiKey ), "apikey" )
5748+ if decErr == nil {
5749+ curUser .ApiKey = string (decryptedApiKey )
5750+ }
5751+ }
5752+ if len (curUser .Session ) > 0 && ! uuidRegex .MatchString (curUser .Session ) {
5753+ decryptedSession , decErr := HandleKeyDecryption ([]byte (curUser .Session ), "session" )
5754+ if decErr == nil {
5755+ curUser .Session = string (decryptedSession )
5756+ }
5757+ }
5758+ }
57425759 return curUser , nil
57435760 }
57445761 } else {
@@ -5805,6 +5822,19 @@ func GetUser(ctx context.Context, username string) (*User, error) {
58055822 data , err := json .Marshal (curUser )
58065823 if err != nil {
58075824 log .Printf ("[WARNING] Failed marshalling user: %s" , err )
5825+ // uuid check
5826+ if len (returnEncrypted ) == 0 || ! returnEncrypted [0 ] {
5827+ if len (curUser .ApiKey ) > 0 && ! uuidRegex .MatchString (curUser .ApiKey ) {
5828+ if decrypted , decErr := HandleKeyDecryption ([]byte (curUser .ApiKey ), "apikey" ); decErr == nil {
5829+ curUser .ApiKey = string (decrypted )
5830+ }
5831+ }
5832+ if len (curUser .Session ) > 0 && ! uuidRegex .MatchString (curUser .Session ) {
5833+ if decrypted , decErr := HandleKeyDecryption ([]byte (curUser .Session ), "session" ); decErr == nil {
5834+ curUser .Session = string (decrypted )
5835+ }
5836+ }
5837+ }
58085838 return curUser , nil
58095839 }
58105840
@@ -5814,6 +5844,21 @@ func GetUser(ctx context.Context, username string) (*User, error) {
58145844 }
58155845 }
58165846
5847+ if len (returnEncrypted ) == 0 || ! returnEncrypted [0 ] {
5848+ if len (curUser .ApiKey ) > 0 && ! uuidRegex .MatchString (curUser .ApiKey ) {
5849+ decryptedApiKey , err := HandleKeyDecryption ([]byte (curUser .ApiKey ), "apikey" )
5850+ if err == nil {
5851+ curUser .ApiKey = string (decryptedApiKey )
5852+ }
5853+ }
5854+ if len (curUser .Session ) > 0 && ! uuidRegex .MatchString (curUser .Session ) {
5855+ decryptedSession , err := HandleKeyDecryption ([]byte (curUser .Session ), "session" )
5856+ if err == nil {
5857+ curUser .Session = string (decryptedSession )
5858+ }
5859+ }
5860+ }
5861+
58175862 return curUser , nil
58185863}
58195864
0 commit comments