mirror of
https://github.com/passbolt/go-passbolt.git
synced 2025-09-13 14:29:09 +00:00
Added ServerVerification Functions, Minor Cleanup
This commit is contained in:
parent
8bccb80cb2
commit
43193345fa
6 changed files with 128 additions and 68 deletions
28
api/misc.go
28
api/misc.go
|
@ -1,7 +1,10 @@
|
|||
package api
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"math/rand"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
const letterBytes = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
||||
|
@ -13,3 +16,28 @@ func randStringBytesRmndr(length int) string {
|
|||
}
|
||||
return string(b)
|
||||
}
|
||||
|
||||
func checkAuthTokenFormat(authToken string) error {
|
||||
splitAuthToken := strings.Split(authToken, "|")
|
||||
if len(splitAuthToken) != 4 {
|
||||
return fmt.Errorf("Auth Token Has Wrong amount of Fields")
|
||||
}
|
||||
|
||||
if splitAuthToken[0] != splitAuthToken[3] {
|
||||
return fmt.Errorf("Auth Token Version Fields Don't match")
|
||||
}
|
||||
|
||||
if !strings.HasPrefix(splitAuthToken[0], "gpgauth") {
|
||||
return fmt.Errorf("Auth Token Version does not start with 'gpgauth'")
|
||||
}
|
||||
|
||||
length, err := strconv.Atoi(splitAuthToken[1])
|
||||
if err != nil {
|
||||
return fmt.Errorf("Cannot Convert Auth Token Length Field to int: %w", err)
|
||||
}
|
||||
|
||||
if len(splitAuthToken[2]) != length {
|
||||
return fmt.Errorf("Auth Token Data Length does not Match Length Field")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue