Commit 3f4c5d6c authored by Sietse Ringers's avatar Sietse Ringers
Browse files

Fix session status checking and handling

parent 548a7249
...@@ -97,7 +97,7 @@ func HandleProtocolMessage( ...@@ -97,7 +97,7 @@ func HandleProtocolMessage(
return return
} }
// However we return, if the session has been cancelled by any of the handlers // However we return, if the session has been finished or cancelled by any of the handlers
// then we should inform the user by returning a SessionResult - but only if we have not // then we should inform the user by returning a SessionResult - but only if we have not
// already done this in the past, e.g. by a previous HTTP call handled by this function // already done this in the past, e.g. by a previous HTTP call handled by this function
defer func() { defer func() {
......
...@@ -20,17 +20,22 @@ func (session *session) handleDelete() { ...@@ -20,17 +20,22 @@ func (session *session) handleDelete() {
session.markAlive() session.markAlive()
// TODO const ProofStatusCancelled = irma.ProofStatus("CANCELLED") ? // TODO const ProofStatusCancelled = irma.ProofStatus("CANCELLED") ?
session.result = &irmaserver.SessionResult{Token: session.token} session.result = &irmaserver.SessionResult{Token: session.token}
session.status = irmaserver.StatusCancelled session.setStatus(irmaserver.StatusCancelled)
} }
func (session *session) handleGetRequest(min, max *irma.ProtocolVersion) (irma.SessionRequest, *irma.RemoteError) { func (session *session) handleGetRequest(min, max *irma.ProtocolVersion) (irma.SessionRequest, *irma.RemoteError) {
if session.status != irmaserver.StatusInitialized {
return nil, getError(irmaserver.ErrorUnexpectedRequest, "Session already started")
}
session.markAlive()
var err error var err error
if session.version, err = chooseProtocolVersion(min, max); err != nil { if session.version, err = chooseProtocolVersion(min, max); err != nil {
return nil, session.fail(irmaserver.ErrorProtocolVersion, "") return nil, session.fail(irmaserver.ErrorProtocolVersion, "")
} }
session.markAlive()
session.status = irmaserver.StatusConnected
session.request.SetVersion(session.version) session.request.SetVersion(session.version)
session.setStatus(irmaserver.StatusConnected)
return session.request, nil return session.request, nil
} }
...@@ -38,21 +43,29 @@ func handleGetStatus(session *session) irmaserver.Status { ...@@ -38,21 +43,29 @@ func handleGetStatus(session *session) irmaserver.Status {
return session.status return session.status
} }
func (session *session) handlePostSignature(signature *irma.SignedMessage) (irma.ProofStatus, *irma.RemoteError) { func (session *session) handlePostSignature(signature *irma.SignedMessage) (*irma.ProofStatus, *irma.RemoteError) {
if session.status != irmaserver.StatusConnected {
return nil, getError(irmaserver.ErrorUnexpectedRequest, "Session not yet started or already finished")
}
session.markAlive() session.markAlive()
session.result.Signature = signature session.result.Signature = signature
session.result.Disclosed, session.result.Status = signature.Verify( session.result.Disclosed, session.result.Status = signature.Verify(
conf.IrmaConfiguration, session.request.(*irma.SignatureRequest)) conf.IrmaConfiguration, session.request.(*irma.SignatureRequest))
session.finish() session.setStatus(irmaserver.StatusDone)
return session.result.Status, nil return &session.result.Status, nil
} }
func (session *session) handlePostProofs(proofs gabi.ProofList) (irma.ProofStatus, *irma.RemoteError) { func (session *session) handlePostProofs(proofs gabi.ProofList) (*irma.ProofStatus, *irma.RemoteError) {
if session.status != irmaserver.StatusConnected {
return nil, getError(irmaserver.ErrorUnexpectedRequest, "Session not yet started or already finished")
}
session.markAlive() session.markAlive()
session.result.Disclosed, session.result.Status = irma.ProofList(proofs).Verify( session.result.Disclosed, session.result.Status = irma.ProofList(proofs).Verify(
conf.IrmaConfiguration, session.request.(*irma.DisclosureRequest)) conf.IrmaConfiguration, session.request.(*irma.DisclosureRequest))
session.finish() session.setStatus(irmaserver.StatusDone)
return session.result.Status, nil return &session.result.Status, nil
} }
// Session helpers // Session helpers
...@@ -61,17 +74,17 @@ func (session *session) finished() bool { ...@@ -61,17 +74,17 @@ func (session *session) finished() bool {
return session.status == irmaserver.StatusDone || session.status == irmaserver.StatusCancelled return session.status == irmaserver.StatusDone || session.status == irmaserver.StatusCancelled
} }
func (session *session) finish() {
session.status = irmaserver.StatusDone
}
func (session *session) markAlive() { func (session *session) markAlive() {
session.lastActive = time.Now() session.lastActive = time.Now()
} }
func (session *session) setStatus(status irmaserver.Status) {
session.status = status
}
func (session *session) fail(err irmaserver.Error, message string) *irma.RemoteError { func (session *session) fail(err irmaserver.Error, message string) *irma.RemoteError {
rerr := getError(err, message) rerr := getError(err, message)
session.status = irmaserver.StatusCancelled session.setStatus(irmaserver.StatusCancelled)
session.result = &irmaserver.SessionResult{Err: rerr, Token: session.token} session.result = &irmaserver.SessionResult{Err: rerr, Token: session.token}
return rerr return rerr
} }
......
...@@ -84,6 +84,11 @@ func (session *session) getProofP(commitments *gabi.IssueCommitmentMessage, sche ...@@ -84,6 +84,11 @@ func (session *session) getProofP(commitments *gabi.IssueCommitmentMessage, sche
} }
func (session *session) handlePostCommitments(commitments *gabi.IssueCommitmentMessage) ([]*gabi.IssueSignatureMessage, *irma.RemoteError) { func (session *session) handlePostCommitments(commitments *gabi.IssueCommitmentMessage) ([]*gabi.IssueSignatureMessage, *irma.RemoteError) {
if session.status != irmaserver.StatusConnected {
return nil, getError(irmaserver.ErrorUnexpectedRequest, "Session not yet started or already finished")
}
session.markAlive()
request := session.request.(*irma.IssuanceRequest) request := session.request.(*irma.IssuanceRequest)
discloseCount := len(request.Disclose) discloseCount := len(request.Disclose)
if len(commitments.Proofs) != len(request.Credentials)+discloseCount { if len(commitments.Proofs) != len(request.Credentials)+discloseCount {
...@@ -140,6 +145,6 @@ func (session *session) handlePostCommitments(commitments *gabi.IssueCommitmentM ...@@ -140,6 +145,6 @@ func (session *session) handlePostCommitments(commitments *gabi.IssueCommitmentM
sigs = append(sigs, sig) sigs = append(sigs, sig)
} }
session.finish() session.setStatus(irmaserver.StatusDone)
return sigs, nil return sigs, nil
} }
...@@ -19,8 +19,8 @@ type session struct { ...@@ -19,8 +19,8 @@ type session struct {
token string token string
version *irma.ProtocolVersion version *irma.ProtocolVersion
request irma.SessionRequest request irma.SessionRequest
status irmaserver.Status
status irmaserver.Status
lastActive time.Time lastActive time.Time
returned bool returned bool
result *irmaserver.SessionResult result *irmaserver.SessionResult
...@@ -104,13 +104,13 @@ func newSession(action irma.Action, request irma.SessionRequest) *session { ...@@ -104,13 +104,13 @@ func newSession(action irma.Action, request irma.SessionRequest) *session {
s := &session{ s := &session{
action: action, action: action,
request: request, request: request,
status: irmaserver.StatusInitialized,
lastActive: time.Now(), lastActive: time.Now(),
token: token, token: token,
result: &irmaserver.SessionResult{ result: &irmaserver.SessionResult{
Token: token, Token: token,
}, },
} }
s.setStatus(irmaserver.StatusInitialized)
nonce, _ := gabi.RandomBigInt(gabi.DefaultSystemParameters[2048].Lstatzk) nonce, _ := gabi.RandomBigInt(gabi.DefaultSystemParameters[2048].Lstatzk)
request.SetNonce(nonce) request.SetNonce(nonce)
request.SetContext(one) request.SetContext(one)
......
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