summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/helsinki.at/rhimport/session_store.go31
1 files changed, 21 insertions, 10 deletions
diff --git a/src/helsinki.at/rhimport/session_store.go b/src/helsinki.at/rhimport/session_store.go
index b7ea3d9..5025d8c 100644
--- a/src/helsinki.at/rhimport/session_store.go
+++ b/src/helsinki.at/rhimport/session_store.go
@@ -25,11 +25,10 @@
package rhimport
import (
- "encoding/base32"
+ "crypto/rand"
+ "encoding/base64"
"fmt"
- "github.com/satori/go.uuid"
"net/http"
- "strings"
)
type newSessionResponse struct {
@@ -76,6 +75,14 @@ type SessionStore struct {
removeChan chan removeSessionRequest
}
+func generateSessionId() (string, error) {
+ var b [32]byte
+ if _, err := rand.Read(b[:]); err != nil {
+ return "", err
+ }
+ return base64.RawStdEncoding.EncodeToString(b[:]), nil
+}
+
func (self *SessionStore) new(ctx *ImportContext) (resp newSessionResponse) {
resp.responsecode = http.StatusOK
resp.errorstring = "OK"
@@ -90,14 +97,18 @@ func (self *SessionStore) new(ctx *ImportContext) (resp newSessionResponse) {
return
}
}
- b := uuid.NewV4().Bytes()
- resp.id = strings.ToLower(strings.TrimRight(base32.StdEncoding.EncodeToString(b), "="))
- if _, exists := self.store[ctx.UserName]; !exists {
- self.store[ctx.UserName] = make(map[string]*Session)
+ if id, err := generateSessionId(); err != nil {
+ resp.responsecode = http.StatusInternalServerError
+ resp.errorstring = err.Error()
+ } else {
+ resp.id = id
+ if _, exists := self.store[ctx.UserName]; !exists {
+ self.store[ctx.UserName] = make(map[string]*Session)
+ }
+ self.store[ctx.UserName][resp.id] = NewSession(ctx, func() { self.GetInterface().Remove(ctx.UserName, resp.id) })
+ resp.session = self.store[ctx.UserName][resp.id].getInterface()
+ rhdl.Printf("SessionStore: created session for '%s' -> %s", ctx.UserName, resp.id)
}
- self.store[ctx.UserName][resp.id] = NewSession(ctx, func() { self.GetInterface().Remove(ctx.UserName, resp.id) })
- resp.session = self.store[ctx.UserName][resp.id].getInterface()
- rhdl.Printf("SessionStore: created session for '%s' -> %s", ctx.UserName, resp.id)
return
}