Commit 7cfadff8 authored by Sietse Ringers's avatar Sietse Ringers
Browse files

refactor: remove KeyshareUser/KeyshareUserData distinction

parent 94e22459
...@@ -21,7 +21,7 @@ var keyshareServ *http.Server ...@@ -21,7 +21,7 @@ var keyshareServ *http.Server
func StartKeyshareServer(t *testing.T, l *logrus.Logger) { func StartKeyshareServer(t *testing.T, l *logrus.Logger) {
db := keyshareserver.NewMemoryDatabase() db := keyshareserver.NewMemoryDatabase()
_, err := db.NewUser(keyshareserver.KeyshareUserData{ err := db.NewUser(&keyshareserver.KeyshareUser{
Username: "", Username: "",
Coredata: keysharecore.EncryptedKeysharePacket{}, Coredata: keysharecore.EncryptedKeysharePacket{},
}) })
...@@ -30,7 +30,7 @@ func StartKeyshareServer(t *testing.T, l *logrus.Logger) { ...@@ -30,7 +30,7 @@ func StartKeyshareServer(t *testing.T, l *logrus.Logger) {
p, err := base64.StdEncoding.DecodeString("YWJjZK4w5SC+7D4lDrhiJGvB1iwxSeF90dGGPoGqqG7g3ivbfHibOdkKoOTZPbFlttBzn2EJgaEsL24Re8OWWWw5pd31/GCd14RXcb9Wy2oWhbr0pvJDLpIxXZt/qiQC0nJiIAYWLGZOdj5o0irDfqP1CSfw3IoKkVEl4lHRj0LCeINJIOpEfGlFtl4DHlWu8SMQFV1AIm3Gv64XzGncdkclVd41ti7cicBrcK8N2u9WvY/jCS4/Lxa2syp/O4IY") p, err := base64.StdEncoding.DecodeString("YWJjZK4w5SC+7D4lDrhiJGvB1iwxSeF90dGGPoGqqG7g3ivbfHibOdkKoOTZPbFlttBzn2EJgaEsL24Re8OWWWw5pd31/GCd14RXcb9Wy2oWhbr0pvJDLpIxXZt/qiQC0nJiIAYWLGZOdj5o0irDfqP1CSfw3IoKkVEl4lHRj0LCeINJIOpEfGlFtl4DHlWu8SMQFV1AIm3Gv64XzGncdkclVd41ti7cicBrcK8N2u9WvY/jCS4/Lxa2syp/O4IY")
require.NoError(t, err) require.NoError(t, err)
copy(ep[:], p) copy(ep[:], p)
_, err = db.NewUser(keyshareserver.KeyshareUserData{ err = db.NewUser(&keyshareserver.KeyshareUser{
Username: "testusername", Username: "testusername",
Coredata: ep, Coredata: ep,
}) })
......
...@@ -28,36 +28,31 @@ const ( ...@@ -28,36 +28,31 @@ const (
// - postgresdb (postgresdb.go) storing all data in a postgres database // - postgresdb (postgresdb.go) storing all data in a postgres database
type KeyshareDB interface { type KeyshareDB interface {
// User management // User management
NewUser(user KeyshareUserData) (KeyshareUser, error) NewUser(user *KeyshareUser) error
User(username string) (KeyshareUser, error) User(username string) (*KeyshareUser, error)
UpdateUser(user KeyshareUser) error UpdateUser(user *KeyshareUser) error
// Pin checking logic // Pin checking logic
// Reserve returns (allow, tries, wait, error) // Reserve returns (allow, tries, wait, error)
// where allow is whether we can do the actual pin check // where allow is whether we can do the actual pin check
// tries is how many tries are remaining after doing so // tries is how many tries are remaining after doing so
// wait is how long to wait if tries is 0 or allow false // wait is how long to wait if tries is 0 or allow false
ReservePincheck(user KeyshareUser) (bool, int, int64, error) ReservePincheck(user *KeyshareUser) (bool, int, int64, error)
ClearPincheck(user KeyshareUser) error ClearPincheck(user *KeyshareUser) error
// User activity registration // User activity registration
// SetSeen calls are used to track when a users account was last active, for deleting old accounts // SetSeen calls are used to track when a users account was last active, for deleting old accounts
SetSeen(user KeyshareUser) error SetSeen(user *KeyshareUser) error
AddLog(user KeyshareUser, eventType LogEntryType, param interface{}) error AddLog(user *KeyshareUser, eventType LogEntryType, param interface{}) error
// Store email verification tokens on registration // Store email verification tokens on registration
AddEmailVerification(user KeyshareUser, emailAddress, token string) error AddEmailVerification(user *KeyshareUser, emailAddress, token string) error
}
// We wrap KeyshareUserData in an interface to allow implementation-specific data
// to also be returned. This is used in postgresdb to deal with database identifiers
type KeyshareUser interface {
Data() *KeyshareUserData
} }
// Actual data on a user used by this server. // Actual data on a user used by this server.
type KeyshareUserData struct { type KeyshareUser struct {
Username string Username string
Language string Language string
Coredata keysharecore.EncryptedKeysharePacket Coredata keysharecore.EncryptedKeysharePacket
id int64
} }
...@@ -15,19 +15,11 @@ type keyshareMemoryDB struct { ...@@ -15,19 +15,11 @@ type keyshareMemoryDB struct {
users map[string]keysharecore.EncryptedKeysharePacket users map[string]keysharecore.EncryptedKeysharePacket
} }
type keyshareMemoryUser struct {
KeyshareUserData
}
func (m *keyshareMemoryUser) Data() *KeyshareUserData {
return &m.KeyshareUserData
}
func NewMemoryDatabase() KeyshareDB { func NewMemoryDatabase() KeyshareDB {
return &keyshareMemoryDB{users: map[string]keysharecore.EncryptedKeysharePacket{}} return &keyshareMemoryDB{users: map[string]keysharecore.EncryptedKeysharePacket{}}
} }
func (db *keyshareMemoryDB) User(username string) (KeyshareUser, error) { func (db *keyshareMemoryDB) User(username string) (*KeyshareUser, error) {
// Ensure access to database is single-threaded // Ensure access to database is single-threaded
db.lock.Lock() db.lock.Lock()
defer db.lock.Unlock() defer db.lock.Unlock()
...@@ -37,10 +29,10 @@ func (db *keyshareMemoryDB) User(username string) (KeyshareUser, error) { ...@@ -37,10 +29,10 @@ func (db *keyshareMemoryDB) User(username string) (KeyshareUser, error) {
if !ok { if !ok {
return nil, ErrUserNotFound return nil, ErrUserNotFound
} }
return &keyshareMemoryUser{KeyshareUserData{Username: username, Coredata: data}}, nil return &KeyshareUser{Username: username, Coredata: data}, nil
} }
func (db *keyshareMemoryDB) NewUser(user KeyshareUserData) (KeyshareUser, error) { func (db *keyshareMemoryDB) NewUser(user *KeyshareUser) error {
// Ensure access to database is single-threaded // Ensure access to database is single-threaded
db.lock.Lock() db.lock.Lock()
defer db.lock.Unlock() defer db.lock.Unlock()
...@@ -48,49 +40,47 @@ func (db *keyshareMemoryDB) NewUser(user KeyshareUserData) (KeyshareUser, error) ...@@ -48,49 +40,47 @@ func (db *keyshareMemoryDB) NewUser(user KeyshareUserData) (KeyshareUser, error)
// Check and insert user // Check and insert user
_, exists := db.users[user.Username] _, exists := db.users[user.Username]
if exists { if exists {
return nil, ErrUserAlreadyExists return ErrUserAlreadyExists
} }
db.users[user.Username] = user.Coredata db.users[user.Username] = user.Coredata
return &keyshareMemoryUser{KeyshareUserData: user}, nil return nil
} }
func (db *keyshareMemoryDB) UpdateUser(user KeyshareUser) error { func (db *keyshareMemoryDB) UpdateUser(user *KeyshareUser) error {
userdata := user.(*keyshareMemoryUser)
// Ensure access to database is single-threaded // Ensure access to database is single-threaded
db.lock.Lock() db.lock.Lock()
defer db.lock.Unlock() defer db.lock.Unlock()
// Check and update user. // Check and update user.
_, exists := db.users[userdata.Username] _, exists := db.users[user.Username]
if !exists { if !exists {
return ErrUserNotFound return ErrUserNotFound
} }
db.users[userdata.Username] = userdata.Coredata db.users[user.Username] = user.Coredata
return nil return nil
} }
func (db *keyshareMemoryDB) ReservePincheck(user KeyshareUser) (bool, int, int64, error) { func (db *keyshareMemoryDB) ReservePincheck(user *KeyshareUser) (bool, int, int64, error) {
// Since this is a testing DB, implementing anything more than always allow creates hastle // Since this is a testing DB, implementing anything more than always allow creates hastle
return true, 1, 0, nil return true, 1, 0, nil
} }
func (db *keyshareMemoryDB) ClearPincheck(user KeyshareUser) error { func (db *keyshareMemoryDB) ClearPincheck(user *KeyshareUser) error {
// Since this is a testing DB, implementing anything more than always allow creates hastle // Since this is a testing DB, implementing anything more than always allow creates hastle
return nil return nil
} }
func (db *keyshareMemoryDB) SetSeen(user KeyshareUser) error { func (db *keyshareMemoryDB) SetSeen(user *KeyshareUser) error {
// We don't need to do anything here, as this information cannot be extracted locally // We don't need to do anything here, as this information cannot be extracted locally
return nil return nil
} }
func (db *keyshareMemoryDB) AddLog(user KeyshareUser, eventType LogEntryType, param interface{}) error { func (db *keyshareMemoryDB) AddLog(user *KeyshareUser, eventType LogEntryType, param interface{}) error {
// We don't need to do anything here, as this information cannot be extracted locally // We don't need to do anything here, as this information cannot be extracted locally
return nil return nil
} }
func (db *keyshareMemoryDB) AddEmailVerification(user KeyshareUser, emailAddress, token string) error { func (db *keyshareMemoryDB) AddEmailVerification(user *KeyshareUser, emailAddress, token string) error {
// We don't need to do anything here, as this information cannot be extracted locally // We don't need to do anything here, as this information cannot be extracted locally
return nil return nil
} }
...@@ -10,18 +10,20 @@ import ( ...@@ -10,18 +10,20 @@ import (
func TestMemoryDBUserManagement(t *testing.T) { func TestMemoryDBUserManagement(t *testing.T) {
db := NewMemoryDatabase() db := NewMemoryDatabase()
user, err := db.NewUser(KeyshareUserData{Username: "testuser"}) user := &KeyshareUser{Username: "testuser"}
err := db.NewUser(user)
require.NoError(t, err) require.NoError(t, err)
assert.Equal(t, "testuser", user.Data().Username) assert.Equal(t, "testuser", user.Username)
nuser, err := db.User("testuser") nuser, err := db.User("testuser")
require.NoError(t, err) require.NoError(t, err)
assert.Equal(t, "testuser", nuser.Data().Username) assert.Equal(t, "testuser", nuser.Username)
_, err = db.User("nonexistent") _, err = db.User("nonexistent")
assert.Error(t, err) assert.Error(t, err)
_, err = db.NewUser(KeyshareUserData{Username: "testuser"}) user = &KeyshareUser{Username: "testuser"}
err = db.NewUser(user)
assert.Error(t, err) assert.Error(t, err)
err = db.UpdateUser(nuser) err = db.UpdateUser(nuser)
......
...@@ -17,16 +17,6 @@ type keysharePostgresDatabase struct { ...@@ -17,16 +17,6 @@ type keysharePostgresDatabase struct {
db *sql.DB db *sql.DB
} }
// For easy access in the database, we store the row id also in the returned user data
type keysharePostgresUser struct {
KeyshareUserData
id int64
}
func (m *keysharePostgresUser) Data() *KeyshareUserData {
return &m.KeyshareUserData
}
const MAX_PIN_TRIES = 3 // Number of tries allowed on pin before we start with exponential backoff const MAX_PIN_TRIES = 3 // Number of tries allowed on pin before we start with exponential backoff
const EMAIL_TOKEN_VALIDITY = 24 // Ammount of time user's email validation token is valid (in hours) const EMAIL_TOKEN_VALIDITY = 24 // Ammount of time user's email validation token is valid (in hours)
...@@ -44,28 +34,29 @@ func NewPostgresDatabase(connstring string) (KeyshareDB, error) { ...@@ -44,28 +34,29 @@ func NewPostgresDatabase(connstring string) (KeyshareDB, error) {
}, nil }, nil
} }
func (db *keysharePostgresDatabase) NewUser(user KeyshareUserData) (KeyshareUser, error) { func (db *keysharePostgresDatabase) NewUser(user *KeyshareUser) error {
res, err := db.db.Query("INSERT INTO irma.users (username, language, coredata, last_seen, pin_counter, pin_block_date) VALUES ($1, $2, $3, $4, 0, 0) RETURNING id", res, err := db.db.Query("INSERT INTO irma.users (username, language, coredata, last_seen, pin_counter, pin_block_date) VALUES ($1, $2, $3, $4, 0, 0) RETURNING id",
user.Username, user.Username,
user.Language, user.Language,
user.Coredata[:], user.Coredata[:],
time.Now().Unix()) time.Now().Unix())
if err != nil { if err != nil {
return nil, err return err
} }
defer common.Close(res) defer common.Close(res)
if !res.Next() { if !res.Next() {
return nil, ErrUserAlreadyExists return ErrUserAlreadyExists
} }
var id int64 var id int64
err = res.Scan(&id) err = res.Scan(&id)
if err != nil { if err != nil {
return nil, err return err
} }
return &keysharePostgresUser{KeyshareUserData: user, id: id}, nil user.id = id
return nil
} }
func (db *keysharePostgresDatabase) User(username string) (KeyshareUser, error) { func (db *keysharePostgresDatabase) User(username string) (*KeyshareUser, error) {
rows, err := db.db.Query("SELECT id, username, language, coredata FROM irma.users WHERE username = $1 AND coredata IS NOT NULL", username) rows, err := db.db.Query("SELECT id, username, language, coredata FROM irma.users WHERE username = $1 AND coredata IS NOT NULL", username)
if err != nil { if err != nil {
return nil, err return nil, err
...@@ -74,7 +65,7 @@ func (db *keysharePostgresDatabase) User(username string) (KeyshareUser, error) ...@@ -74,7 +65,7 @@ func (db *keysharePostgresDatabase) User(username string) (KeyshareUser, error)
if !rows.Next() { if !rows.Next() {
return nil, ErrUserNotFound return nil, ErrUserNotFound
} }
var result keysharePostgresUser var result KeyshareUser
var ep []byte var ep []byte
err = rows.Scan(&result.id, &result.Username, &result.Language, &ep) err = rows.Scan(&result.id, &result.Username, &result.Language, &ep)
if err != nil { if err != nil {
...@@ -87,21 +78,17 @@ func (db *keysharePostgresDatabase) User(username string) (KeyshareUser, error) ...@@ -87,21 +78,17 @@ func (db *keysharePostgresDatabase) User(username string) (KeyshareUser, error)
return &result, nil return &result, nil
} }
func (db *keysharePostgresDatabase) UpdateUser(user KeyshareUser) error { func (db *keysharePostgresDatabase) UpdateUser(user *KeyshareUser) error {
userdata := user.(*keysharePostgresUser)
return db.updateUser( return db.updateUser(
"UPDATE irma.users SET username=$1, language=$2, coredata=$3 WHERE id=$4", "UPDATE irma.users SET username=$1, language=$2, coredata=$3 WHERE id=$4",
userdata.Username, user.Username,
userdata.Language, user.Language,
userdata.Coredata[:], user.Coredata[:],
userdata.id, user.id,
) )
} }
func (db *keysharePostgresDatabase) ReservePincheck(user KeyshareUser) (bool, int, int64, error) { func (db *keysharePostgresDatabase) ReservePincheck(user *KeyshareUser) (bool, int, int64, error) {
// Extract data
userdata := user.(*keysharePostgresUser)
// Check that account is not blocked already, and if not, // Check that account is not blocked already, and if not,
// update pinCounter and pinBlockDate // update pinCounter and pinBlockDate
uprows, err := db.db.Query(` uprows, err := db.db.Query(`
...@@ -113,7 +100,7 @@ func (db *keysharePostgresDatabase) ReservePincheck(user KeyshareUser) (bool, in ...@@ -113,7 +100,7 @@ func (db *keysharePostgresDatabase) ReservePincheck(user KeyshareUser) (bool, in
time.Now().Unix()-1-BACKOFF_START, // Grace time of 2 seconds on pinBlockDate set time.Now().Unix()-1-BACKOFF_START, // Grace time of 2 seconds on pinBlockDate set
BACKOFF_START, BACKOFF_START,
MAX_PIN_TRIES-2, MAX_PIN_TRIES-2,
userdata.id, user.id,
time.Now().Unix()) time.Now().Unix())
if err != nil { if err != nil {
return false, 0, 0, err return false, 0, 0, err
...@@ -128,7 +115,7 @@ func (db *keysharePostgresDatabase) ReservePincheck(user KeyshareUser) (bool, in ...@@ -128,7 +115,7 @@ func (db *keysharePostgresDatabase) ReservePincheck(user KeyshareUser) (bool, in
if !uprows.Next() { if !uprows.Next() {
// if no results, then account either does not exist (which would be weird here) or is blocked // if no results, then account either does not exist (which would be weird here) or is blocked
// so request wait timeout // so request wait timeout
pinrows, err := db.db.Query("SELECT pin_block_date FROM irma.users WHERE id=$1 AND coredata IS NOT NULL", userdata.id) pinrows, err := db.db.Query("SELECT pin_block_date FROM irma.users WHERE id=$1 AND coredata IS NOT NULL", user.id)
if err != nil { if err != nil {
return false, 0, 0, err return false, 0, 0, err
} }
...@@ -161,18 +148,18 @@ func (db *keysharePostgresDatabase) ReservePincheck(user KeyshareUser) (bool, in ...@@ -161,18 +148,18 @@ func (db *keysharePostgresDatabase) ReservePincheck(user KeyshareUser) (bool, in
return allowed, tries, wait, nil return allowed, tries, wait, nil
} }
func (db *keysharePostgresDatabase) ClearPincheck(user KeyshareUser) error { func (db *keysharePostgresDatabase) ClearPincheck(user *KeyshareUser) error {
return db.updateUser( return db.updateUser(
"UPDATE irma.users SET pin_counter=0, pin_block_date=0 WHERE id=$1", "UPDATE irma.users SET pin_counter=0, pin_block_date=0 WHERE id=$1",
user.(*keysharePostgresUser).id, user.id,
) )
} }
func (db *keysharePostgresDatabase) SetSeen(user KeyshareUser) error { func (db *keysharePostgresDatabase) SetSeen(user *KeyshareUser) error {
return db.updateUser( return db.updateUser(
"UPDATE irma.users SET last_seen = $1 WHERE id = $2", "UPDATE irma.users SET last_seen = $1 WHERE id = $2",
time.Now().Unix(), time.Now().Unix(),
user.(*keysharePostgresUser).id, user.id,
) )
} }
...@@ -191,9 +178,7 @@ func (db *keysharePostgresDatabase) updateUser(query string, args ...interface{} ...@@ -191,9 +178,7 @@ func (db *keysharePostgresDatabase) updateUser(query string, args ...interface{}
return nil return nil
} }
func (db *keysharePostgresDatabase) AddLog(user KeyshareUser, eventType LogEntryType, param interface{}) error { func (db *keysharePostgresDatabase) AddLog(user *KeyshareUser, eventType LogEntryType, param interface{}) error {
userdata := user.(*keysharePostgresUser)
var encodedParamString *string var encodedParamString *string
if param != nil { if param != nil {
encodedParam, err := json.Marshal(param) encodedParam, err := json.Marshal(param)
...@@ -208,17 +193,15 @@ func (db *keysharePostgresDatabase) AddLog(user KeyshareUser, eventType LogEntry ...@@ -208,17 +193,15 @@ func (db *keysharePostgresDatabase) AddLog(user KeyshareUser, eventType LogEntry
time.Now().Unix(), time.Now().Unix(),
eventType, eventType,
encodedParamString, encodedParamString,
userdata.id) user.id)
return err return err
} }
func (db *keysharePostgresDatabase) AddEmailVerification(user KeyshareUser, emailAddress, token string) error { func (db *keysharePostgresDatabase) AddEmailVerification(user *KeyshareUser, emailAddress, token string) error {
userdata := user.(*keysharePostgresUser)
_, err := db.db.Exec("INSERT INTO irma.email_verification_tokens (token, email, user_id, expiry) VALUES ($1, $2, $3, $4)", _, err := db.db.Exec("INSERT INTO irma.email_verification_tokens (token, email, user_id, expiry) VALUES ($1, $2, $3, $4)",
token, token,
emailAddress, emailAddress,
userdata.id, user.id,
time.Now().Add(EMAIL_TOKEN_VALIDITY*time.Hour).Unix()) time.Now().Add(EMAIL_TOKEN_VALIDITY*time.Hour).Unix())
return err return err
} }
...@@ -22,13 +22,14 @@ func TestPostgresDBUserManagement(t *testing.T) { ...@@ -22,13 +22,14 @@ func TestPostgresDBUserManagement(t *testing.T) {
db, err := NewPostgresDatabase(postgresTestUrl) db, err := NewPostgresDatabase(postgresTestUrl)
require.NoError(t, err) require.NoError(t, err)
user, err := db.NewUser(KeyshareUserData{Username: "testuser"}) user := &KeyshareUser{Username: "testuser"}
err = db.NewUser(user)
require.NoError(t, err) require.NoError(t, err)
assert.Equal(t, "testuser", user.Data().Username) assert.Equal(t, "testuser", user.Username)
nuser, err := db.User("testuser") nuser, err := db.User("testuser")
require.NoError(t, err) require.NoError(t, err)
assert.Equal(t, "testuser", nuser.Data().Username) assert.Equal(t, "testuser", nuser.Username)
_, err = db.User("notexist") _, err = db.User("notexist")
assert.Error(t, err) assert.Error(t, err)
...@@ -36,7 +37,8 @@ func TestPostgresDBUserManagement(t *testing.T) { ...@@ -36,7 +37,8 @@ func TestPostgresDBUserManagement(t *testing.T) {
err = db.UpdateUser(nuser) err = db.UpdateUser(nuser)
assert.NoError(t, err) assert.NoError(t, err)
_, err = db.NewUser(KeyshareUserData{Username: "testuser"}) user = &KeyshareUser{Username: "testuser"}
err = db.NewUser(user)
assert.Error(t, err) assert.Error(t, err)
err = db.AddLog(nuser, PinCheckFailed, 15) err = db.AddLog(nuser, PinCheckFailed, 15)
...@@ -58,7 +60,8 @@ func TestPostgresDBPinReservation(t *testing.T) { ...@@ -58,7 +60,8 @@ func TestPostgresDBPinReservation(t *testing.T) {
db, err := NewPostgresDatabase(postgresTestUrl) db, err := NewPostgresDatabase(postgresTestUrl)
require.NoError(t, err) require.NoError(t, err)
user, err := db.NewUser(KeyshareUserData{Username: "testuser"}) user := &KeyshareUser{Username: "testuser"}
err = db.NewUser(user)
require.NoError(t, err) require.NoError(t, err)
ok, tries, wait, err := db.ReservePincheck(user) ok, tries, wait, err := db.ReservePincheck(user)
......
...@@ -162,7 +162,7 @@ func (s *Server) LoadIdemixKeys(conf *irma.Configuration) { ...@@ -162,7 +162,7 @@ func (s *Server) LoadIdemixKeys(conf *irma.Configuration) {
// /prove/getCommitments // /prove/getCommitments
func (s *Server) handleCommitments(w http.ResponseWriter, r *http.Request) { func (s *Server) handleCommitments(w http.ResponseWriter, r *http.Request) {
// Fetch from context // Fetch from context
user := r.Context().Value("user").(KeyshareUser) user := r.Context().Value("user").(*KeyshareUser)
authorization := r.Context().Value("authorization").(string) authorization := r.Context().Value("authorization").(string)
// Read keys // Read keys
...@@ -200,9 +200,9 @@ func (s *Server) handleCommitments(w http.ResponseWriter, r *http.Request) { ...@@ -200,9 +200,9 @@ func (s *Server) handleCommitments(w http.ResponseWriter, r *http.Request) {
server.WriteJson(w, commitments) server.WriteJson(w, commitments)
} }
func (s *Server) generateCommitments(user KeyshareUser, authorization string, keys []irma.PublicKeyIdentifier) (*irma.ProofPCommitmentMap, error) { func (s *Server) generateCommitments(user *KeyshareUser, authorization string, keys []irma.PublicKeyIdentifier) (*irma.ProofPCommitmentMap, error) {
// Generate commitments // Generate commitments
commitments, commitID, err := s.core.GenerateCommitments(user.Data().Coredata, authorization, keys) commitments, commitID, err := s.core.GenerateCommitments(user.Coredata, authorization, keys)
if err != nil { if err != nil {
s.conf.Logger.WithField("error", err).Warn("Could not generate commitments for request") s.conf.Logger.WithField("error", err).Warn("Could not generate commitments for request")
return nil, err return nil, err
...@@ -219,7 +219,7 @@ func (s *Server) generateCommitments(user KeyshareUser, authorization string, ke ...@@ -219,7 +219,7 @@ func (s *Server) generateCommitments(user KeyshareUser, authorization string, ke
} }
// Store needed data for later requests. // Store needed data for later requests.
username := user.Data().Username username := user.Username
s.sessionLock.Lock() s.sessionLock.Lock()
if _, ok := s.sessions[username]; !ok { if _, ok := s.sessions[username]; !ok {
s.sessions[username] = &SessionData{} s.sessions[username] = &SessionData{}
...@@ -240,8 +240,8 @@ func (s *Server) generateCommitments(user KeyshareUser, authorization string, ke ...@@ -240,8 +240,8 @@ func (s *Server) generateCommitments(user KeyshareUser, authorization string, ke
// /prove/getResponse // /prove/getResponse
func (s *Server) handleResponse(w http.ResponseWriter, r *http.Request) { func (s *Server) handleResponse(w http.ResponseWriter, r *http.Request) {
// Fetch from context