Commit 6057cb78 authored by David Venhoek's avatar David Venhoek Committed by Sietse Ringers
Browse files

Removed duplicate NewSessionToken from server.

parent 3faa02a4
......@@ -2,7 +2,6 @@ package server
import (
"bytes"
"crypto/rand"
"crypto/rsa"
"encoding/hex"
"encoding/json"
......@@ -526,21 +525,3 @@ func LogMiddleware(typ string, opts LogOptions) func(next http.Handler) http.Han
})
}
}
const sessionChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
func NewSessionToken() string {
count := 20
r := make([]byte, count)
_, err := rand.Read(r)
if err != nil {
panic(err)
}
b := make([]byte, count)
for i := range b {
b[i] = sessionChars[r[i]%byte(len(sessionChars))]
}
return string(b)
}
......@@ -151,8 +151,8 @@ func (s *memorySessionStore) deleteExpired() {
var one *big.Int = big.NewInt(1)
func (s *Server) newSession(action irma.Action, request irma.RequestorRequest) *session {
token := server.NewSessionToken()
clientToken := server.NewSessionToken()
token := common.NewSessionToken()
clientToken := common.NewSessionToken()
ses := &session{
action: action,
......
......@@ -18,6 +18,7 @@ import (
irma "github.com/privacybydesign/irmago"
"github.com/sirupsen/logrus"
"github.com/privacybydesign/irmago/internal/common"
"github.com/privacybydesign/irmago/internal/keysharecore"
"github.com/privacybydesign/irmago/server"
"github.com/privacybydesign/irmago/server/irmaserver"
......@@ -521,7 +522,7 @@ func (s *Server) handleRegister(w http.ResponseWriter, r *http.Request) {
}
// Generate token
token := server.NewSessionToken()
token := common.NewSessionToken()
// Add it to the database
err = s.db.AddEmailVerification(user, *msg.Email, token)
......
......@@ -10,6 +10,7 @@ import (
"github.com/go-chi/chi"
"github.com/jasonlvhit/gocron"
"github.com/privacybydesign/irmago/internal/common"
"github.com/privacybydesign/irmago/server"
irma "github.com/privacybydesign/irmago"
......@@ -222,7 +223,7 @@ func (s *Server) handleEmailLogin(w http.ResponseWriter, r *http.Request) {
return
}
token := server.NewSessionToken()
token := common.NewSessionToken()
err = s.db.AddEmailLoginToken(request.Email, token)
if err == ErrUserNotFound {
server.WriteError(w, server.ErrorUserNotRegistered, "")
......
......@@ -4,6 +4,7 @@ import (
"sync"
"time"
"github.com/privacybydesign/irmago/internal/common"
"github.com/privacybydesign/irmago/server"
)
......@@ -42,7 +43,7 @@ func NewMemorySessionStore(sessionLifetime time.Duration) SessionStore {
func (s *MemorySessionStore) create() *Sessiondata {
s.Lock()
defer s.Unlock()
token := server.NewSessionToken()
token := common.NewSessionToken()
s.data[token] = &Sessiondata{
token: token,
expiry: time.Now().Add(s.sessionLifetime),
......
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