Commit 496920ce authored by Sietse Ringers's avatar Sietse Ringers
Browse files

Add new KeyshareRegistrationIncomplete message to session handler interface

parent f81d74b1
......@@ -25,6 +25,7 @@ type keyshareSessionHandler interface {
KeyshareDone(message interface{})
KeyshareCancelled()
KeyshareBlocked(manager irma.SchemeManagerIdentifier, duration int)
KeyshareRegistrationIncomplete(manager irma.SchemeManagerIdentifier)
// In errors the manager may be nil, as not all keyshare errors have a clearly associated scheme manager
KeyshareError(manager *irma.SchemeManagerIdentifier, err error)
KeysharePin()
......@@ -193,7 +194,7 @@ func startKeyshareSession(
authstatus := &keyshareAuthorization{}
err := transport.Post("users/isAuthorized", authstatus, "")
if err != nil {
ks.sessionHandler.KeyshareError(&managerID, err)
ks.fail(managerID, err)
return
}
switch authstatus.Status {
......@@ -214,6 +215,28 @@ func startKeyshareSession(
}
}
func (ks *keyshareSession) fail(manager irma.SchemeManagerIdentifier, err error) {
serr, ok := err.(*irma.SessionError)
if ok {
if serr.ApiError != nil && len(serr.ApiError.ErrorName) > 0 {
switch serr.ApiError.ErrorName {
case "USER_NOT_REGISTERED":
ks.sessionHandler.KeyshareRegistrationIncomplete(manager)
case "USER_BLOCKED":
duration, err := strconv.Atoi(serr.ApiError.Message)
if err != nil { // Not really clear what to do with duration, but should never happen anyway
duration = -1
}
ks.sessionHandler.KeyshareBlocked(manager, duration)
default:
ks.sessionHandler.KeyshareError(&manager, err)
}
}
} else {
ks.sessionHandler.KeyshareError(&manager, err)
}
}
// Ask for a pin, repeatedly if necessary, and either continue the keyshare protocol
// with authorization, or stop the keyshare protocol and inform of failure.
func (ks *keyshareSession) VerifyPin(attempts int) {
......
......@@ -90,3 +90,6 @@ func (sh *ManualSessionHandler) Failure(irmaAction irma.Action, err *irma.Sessio
func (sh *ManualSessionHandler) KeyshareBlocked(manager irma.SchemeManagerIdentifier, duration int) {
sh.Failure(irma.ActionUnknown, &irma.SessionError{ErrorType: irma.ErrorKeyshareBlocked})
}
func (sh *ManualSessionHandler) KeyshareRegistrationIncomplete(manager irma.SchemeManagerIdentifier) {
sh.c <- &irma.SessionError{Err: errors.New("KeyshareRegistrationIncomplete")}
}
......@@ -34,6 +34,7 @@ type Handler interface {
MissingKeyshareEnrollment(manager irma.SchemeManagerIdentifier)
KeyshareBlocked(manager irma.SchemeManagerIdentifier, duration int)
KeyshareRegistrationIncomplete(manager irma.SchemeManagerIdentifier)
RequestIssuancePermission(request irma.IssuanceRequest, ServerName string, callback PermissionHandler)
RequestVerificationPermission(request irma.DisclosureRequest, ServerName string, callback PermissionHandler)
......@@ -87,6 +88,10 @@ type manualSession struct {
session
}
func (session *session) KeyshareRegistrationIncomplete(manager irma.SchemeManagerIdentifier) {
session.Handler.KeyshareRegistrationIncomplete(manager)
}
// We implement the handler for the keyshare protocol
var _ keyshareSessionHandler = (*interactiveSession)(nil)
var _ keyshareSessionHandler = (*manualSession)(nil)
......
......@@ -19,8 +19,12 @@ type TestHandler struct {
client *Client
}
func (th TestHandler) KeyshareRegistrationIncomplete(manager irma.SchemeManagerIdentifier) {
th.Failure(irma.ActionUnknown, &irma.SessionError{Err: errors.New("KeyshareRegistrationIncomplete")})
}
func (th TestHandler) KeyshareBlocked(manager irma.SchemeManagerIdentifier, duration int) {
th.Failure(irma.ActionUnknown, &irma.SessionError{ErrorType: irma.ErrorKeyshareBlocked})
th.Failure(irma.ActionUnknown, &irma.SessionError{Err: errors.New("KeyshareBlocked")})
}
func (th TestHandler) MissingKeyshareEnrollment(manager irma.SchemeManagerIdentifier) {
......
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