Commit 211671ba authored by Sietse Ringers's avatar Sietse Ringers
Browse files

refactor: use common.NewRandomString() for generating keyshareserver usernames

parent a9c3094e
......@@ -26,9 +26,10 @@ var Logger *logrus.Logger
var ForceHTTPS = true
const (
sessionChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
AlphanumericChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
NumericChars = "0123456789"
sessionTokenLength = 20
pairingCodeChars = "0123456789"
pairingCodeLength = 4
)
......@@ -276,14 +277,14 @@ type SSECtx struct {
}
func NewSessionToken() string {
return newRandomString(sessionTokenLength, sessionChars)
return NewRandomString(sessionTokenLength, AlphanumericChars)
}
func NewPairingCode() string {
return newRandomString(pairingCodeLength, pairingCodeChars)
return NewRandomString(pairingCodeLength, NumericChars)
}
func newRandomString(count int, characterSet string) string {
func NewRandomString(count int, characterSet string) string {
r := make([]byte, count)
_, err := rand.Read(r)
if err != nil {
......
......@@ -456,8 +456,7 @@ func (s *Server) handleRegister(w http.ResponseWriter, r *http.Request) {
func (s *Server) register(msg irma.KeyshareEnrollment) (*irma.Qr, error) {
// Generate keyshare server account
username := common.NewSessionToken() // TODO use newRandomString() for this when shoulder-surf is merged
username = username[:12]
username := common.NewRandomString(12, common.AlphanumericChars)
secrets, err := s.core.NewUserSecrets(msg.Pin)
if err != nil {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment