Commit a7fcdae3 authored by Sietse Ringers's avatar Sietse Ringers
Browse files

refactor: reuse existing function to generate new keyshare server usernames

parent d5a9ccea
......@@ -3,8 +3,6 @@ package keyshareserver
import (
"bytes"
"context"
"crypto/rand"
"encoding/base64"
"encoding/json"
"fmt"
"io/ioutil"
......@@ -484,7 +482,9 @@ func (s *Server) handleRegister(w http.ResponseWriter, r *http.Request) {
func (s *Server) doRegistration(msg irma.KeyshareEnrollment) (*irma.Qr, error) {
// Generate keyshare server account
username := generateUsername()
username := common.NewSessionToken() // TODO use newRandomString() for this when shoulder-surf is merged
username = username[:12]
coredata, err := s.core.GenerateKeyshareSecret(msg.Pin)
if err != nil {
s.conf.Logger.WithField("error", err).Error("Could not register user")
......@@ -572,28 +572,6 @@ func (s *Server) sendRegistrationEmail(user *KeyshareUser, language, email strin
return nil
}
// Generate a base62 "username".
// this is a direct port of what the old java server uses.
func generateUsername() string {
bts := make([]byte, 8)
_, err := rand.Read(bts)
if err != nil {
panic(err)
}
raw := make([]byte, 12)
base64.StdEncoding.Encode(raw, bts)
return strings.ReplaceAll(
strings.ReplaceAll(
strings.ReplaceAll(
string(raw),
"+",
""),
"/",
""),
"=",
"")
}
func (s *Server) userMiddleware(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
// Extract username from request
......
Supports Markdown
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