Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
IRMA
Github mirrors
irmago
Commits
c3bfa3aa
Commit
c3bfa3aa
authored
Jul 27, 2018
by
Sietse Ringers
Browse files
Remove superfluous session type parameter to most session handler callbacks
Co-authored-by:
Confiks
<
confiks@scriptbase.org
>
parent
ad58103c
Changes
4
Hide whitespace changes
Inline
Side-by-side
irmaclient/handlers.go
View file @
c3bfa3aa
...
...
@@ -36,12 +36,12 @@ func (h *keyshareEnrollmentHandler) RequestPin(remainingAttempts int, callback P
}
}
func
(
h
*
keyshareEnrollmentHandler
)
Success
(
action
irma
.
Action
,
result
string
)
{
func
(
h
*
keyshareEnrollmentHandler
)
Success
(
result
string
)
{
_
=
h
.
client
.
storage
.
StoreKeyshareServers
(
h
.
client
.
keyshareServers
)
// TODO handle err?
h
.
client
.
handler
.
EnrollmentSuccess
(
h
.
kss
.
SchemeManagerIdentifier
)
}
func
(
h
*
keyshareEnrollmentHandler
)
Failure
(
action
irma
.
Action
,
err
*
irma
.
SessionError
)
{
func
(
h
*
keyshareEnrollmentHandler
)
Failure
(
err
*
irma
.
SessionError
)
{
h
.
fail
(
err
)
}
...
...
@@ -64,7 +64,7 @@ func (h *keyshareEnrollmentHandler) RequestSignaturePermission(request irma.Sign
func
(
h
*
keyshareEnrollmentHandler
)
RequestSchemeManagerPermission
(
manager
*
irma
.
SchemeManager
,
callback
func
(
proceed
bool
))
{
callback
(
false
)
}
func
(
h
*
keyshareEnrollmentHandler
)
Cancelled
(
action
irma
.
Action
)
{
func
(
h
*
keyshareEnrollmentHandler
)
Cancelled
()
{
h
.
fail
(
errors
.
New
(
"Keyshare enrollment session unexpectedly cancelled"
))
}
func
(
h
*
keyshareEnrollmentHandler
)
KeyshareBlocked
(
manager
irma
.
SchemeManagerIdentifier
,
duration
int
)
{
...
...
@@ -79,6 +79,6 @@ func (h *keyshareEnrollmentHandler) KeyshareEnrollmentDeleted(manager irma.Schem
func
(
h
*
keyshareEnrollmentHandler
)
KeyshareEnrollmentMissing
(
manager
irma
.
SchemeManagerIdentifier
)
{
h
.
fail
(
errors
.
New
(
"Keyshare enrollment failed: unenrolled"
))
}
func
(
h
*
keyshareEnrollmentHandler
)
UnsatisfiableRequest
(
action
irma
.
Action
,
ServerName
string
,
missing
irma
.
AttributeDisjunctionList
)
{
func
(
h
*
keyshareEnrollmentHandler
)
UnsatisfiableRequest
(
ServerName
string
,
missing
irma
.
AttributeDisjunctionList
)
{
h
.
fail
(
errors
.
New
(
"Keyshare enrollment failed: unsatisfiable"
))
}
irmaclient/manual_session_test.go
View file @
c3bfa3aa
...
...
@@ -287,28 +287,30 @@ func TestManualSessionInvalidProof(t *testing.T) {
test
.
ClearTestStorage
(
t
)
}
func
(
sh
*
ManualSessionHandler
)
Success
(
irmaAction
irma
.
Action
,
result
string
)
{
switch
irmaAction
{
case
irma
.
ActionSigning
:
// Make proof corrupt if we want to test invalid proofs
resultBytes
:=
corruptAndConvertProofString
(
result
)
irmaSignedMessage
:=
&
irma
.
SignedMessage
{}
if
err
:=
json
.
Unmarshal
(
resultBytes
,
irmaSignedMessage
);
err
!=
nil
{
sh
.
errorChannel
<-
&
irma
.
SessionError
{
Err
:
err
,
ErrorType
:
irma
.
ErrorSerialization
,
}
return
}
func
(
sh
*
ManualSessionHandler
)
Success
(
result
string
)
{
if
len
(
result
)
==
0
{
sh
.
errorChannel
<-
nil
return
}
// Make proof corrupt if we want to test invalid proofs
resultBytes
:=
corruptAndConvertProofString
(
result
)
irmaSignedMessage
:=
&
irma
.
SignedMessage
{}
go
func
()
{
sh
.
resultChannel
<-
irmaSignedMessage
.
Verify
(
client
.
Configuration
,
sh
.
sigVerifyRequest
)
}()
if
err
:=
json
.
Unmarshal
(
resultBytes
,
irmaSignedMessage
);
err
!=
nil
{
sh
.
errorChannel
<-
&
irma
.
SessionError
{
Err
:
err
,
ErrorType
:
irma
.
ErrorSerialization
,
}
return
}
go
func
()
{
sh
.
resultChannel
<-
irmaSignedMessage
.
Verify
(
client
.
Configuration
,
sh
.
sigVerifyRequest
)
}()
sh
.
errorChannel
<-
nil
}
func
(
sh
*
ManualSessionHandler
)
UnsatisfiableRequest
(
irmaAction
irma
.
Action
,
serverName
string
,
missingAttributes
irma
.
AttributeDisjunctionList
)
{
func
(
sh
*
ManualSessionHandler
)
UnsatisfiableRequest
(
serverName
string
,
missingAttributes
irma
.
AttributeDisjunctionList
)
{
// This function is called from main thread, which blocks go channel, so need go routine here
go
func
()
{
sh
.
errorChannel
<-
&
irma
.
SessionError
{
...
...
@@ -335,7 +337,7 @@ func (sh *ManualSessionHandler) RequestIssuancePermission(request irma.IssuanceR
}
// These handlers should not be called, fail test if they are called
func
(
sh
*
ManualSessionHandler
)
Cancelled
(
irmaAction
irma
.
Action
)
{
func
(
sh
*
ManualSessionHandler
)
Cancelled
()
{
sh
.
errorChannel
<-
&
irma
.
SessionError
{
Err
:
errors
.
New
(
"Session was cancelled"
)}
}
func
(
sh
*
ManualSessionHandler
)
MissingKeyshareEnrollment
(
manager
irma
.
SchemeManagerIdentifier
)
{
...
...
@@ -347,7 +349,7 @@ func (sh *ManualSessionHandler) RequestSchemeManagerPermission(manager *irma.Sch
func
(
sh
*
ManualSessionHandler
)
RequestVerificationPermission
(
request
irma
.
DisclosureRequest
,
verifierName
string
,
ph
PermissionHandler
)
{
sh
.
errorChannel
<-
&
irma
.
SessionError
{
Err
:
errors
.
New
(
"Unexpected session type"
)}
}
func
(
sh
*
ManualSessionHandler
)
Failure
(
irmaAction
irma
.
Action
,
err
*
irma
.
SessionError
)
{
func
(
sh
*
ManualSessionHandler
)
Failure
(
err
*
irma
.
SessionError
)
{
fmt
.
Println
(
err
.
Err
)
sh
.
errorChannel
<-
err
}
...
...
irmaclient/session.go
View file @
c3bfa3aa
...
...
@@ -27,10 +27,10 @@ type PinHandler func(proceed bool, pin string)
// A Handler contains callbacks for communication to the user.
type
Handler
interface
{
StatusUpdate
(
action
irma
.
Action
,
status
irma
.
Status
)
Success
(
action
irma
.
Action
,
result
string
)
Cancelled
(
action
irma
.
Action
)
Failure
(
action
irma
.
Action
,
err
*
irma
.
SessionError
)
UnsatisfiableRequest
(
action
irma
.
Action
,
ServerName
string
,
missing
irma
.
AttributeDisjunctionList
)
Success
(
result
string
)
Cancelled
()
Failure
(
err
*
irma
.
SessionError
)
UnsatisfiableRequest
(
ServerName
string
,
missing
irma
.
AttributeDisjunctionList
)
KeyshareBlocked
(
manager
irma
.
SchemeManagerIdentifier
,
duration
int
)
KeyshareEnrollmentIncomplete
(
manager
irma
.
SchemeManagerIdentifier
)
...
...
@@ -97,7 +97,7 @@ func (client *Client) NewSession(sessionrequest string, handler Handler) Session
return
client
.
newManualSession
(
sigrequest
,
handler
)
}
handler
.
Failure
(
irma
.
ActionUnknown
,
&
irma
.
SessionError
{
Err
:
errors
.
New
(
"Session request could not be parsed"
)})
handler
.
Failure
(
&
irma
.
SessionError
{
Err
:
errors
.
New
(
"Session request could not be parsed"
)})
return
nil
}
...
...
@@ -110,9 +110,9 @@ func (client *Client) newManualSession(sigrequest *irma.SignatureRequest, handle
Version
:
irma
.
NewVersion
(
2
,
0
),
// TODO hardcoded for now
request
:
sigrequest
,
}
session
.
Handler
.
StatusUpdate
(
session
.
Action
,
irma
.
StatusManualStarted
)
sigrequest
.
RequestorName
=
"Email request"
session
.
Handler
.
StatusUpdate
(
session
.
Action
,
irma
.
StatusManualStarted
)
session
.
processSessionInfo
()
return
session
}
...
...
@@ -126,7 +126,9 @@ func (client *Client) newQrSession(qr *irma.Qr, handler Handler) SessionDismisse
Handler
:
handler
,
client
:
client
,
}
session
.
Handler
.
StatusUpdate
(
session
.
Action
,
irma
.
StatusCommunicating
)
// TODO move this
if
session
.
Action
==
irma
.
ActionSchemeManager
{
go
session
.
managerSession
()
return
session
...
...
@@ -216,7 +218,7 @@ func (session *session) processSessionInfo() {
candidates
,
missing
:=
session
.
client
.
CheckSatisfiability
(
session
.
request
.
ToDisclose
())
if
len
(
missing
)
>
0
{
session
.
Handler
.
UnsatisfiableRequest
(
session
.
Action
,
session
.
request
.
GetRequestorName
(),
missing
)
session
.
Handler
.
UnsatisfiableRequest
(
session
.
request
.
GetRequestorName
(),
missing
)
return
}
session
.
request
.
SetCandidates
(
candidates
)
...
...
@@ -350,7 +352,7 @@ func (session *session) sendResponse(message interface{}) {
session
.
client
.
handler
.
UpdateAttributes
()
}
session
.
done
=
true
session
.
Handler
.
Success
(
session
.
Action
,
string
(
messageJson
))
session
.
Handler
.
Success
(
string
(
messageJson
))
}
// managerSession performs a "session" in which a new scheme manager is added (asking for permission first).
...
...
@@ -362,17 +364,17 @@ func (session *session) managerSession() {
// when asking installation permission.
manager
,
err
:=
irma
.
DownloadSchemeManager
(
session
.
ServerURL
)
if
err
!=
nil
{
session
.
Handler
.
Failure
(
session
.
Action
,
&
irma
.
SessionError
{
ErrorType
:
irma
.
ErrorConfigurationDownload
,
Err
:
err
})
session
.
Handler
.
Failure
(
&
irma
.
SessionError
{
ErrorType
:
irma
.
ErrorConfigurationDownload
,
Err
:
err
})
return
}
session
.
Handler
.
RequestSchemeManagerPermission
(
manager
,
func
(
proceed
bool
)
{
if
!
proceed
{
session
.
Handler
.
Cancelled
(
session
.
Action
)
// No need to DELETE session here
session
.
Handler
.
Cancelled
()
// No need to DELETE session here
return
}
if
err
:=
session
.
client
.
Configuration
.
InstallSchemeManager
(
manager
);
err
!=
nil
{
session
.
Handler
.
Failure
(
session
.
Action
,
&
irma
.
SessionError
{
ErrorType
:
irma
.
ErrorConfigurationDownload
,
Err
:
err
})
session
.
Handler
.
Failure
(
&
irma
.
SessionError
{
ErrorType
:
irma
.
ErrorConfigurationDownload
,
Err
:
err
})
return
}
...
...
@@ -384,7 +386,7 @@ func (session *session) managerSession() {
CredentialTypes
:
map
[
irma
.
CredentialTypeIdentifier
]
struct
{}{},
},
)
session
.
Handler
.
Success
(
session
.
Action
,
""
)
session
.
Handler
.
Success
(
""
)
})
return
}
...
...
@@ -455,7 +457,7 @@ func (session *session) checkKeyshareEnrollment() bool {
for
id
:=
range
session
.
request
.
Identifiers
()
.
SchemeManagers
{
manager
,
ok
:=
session
.
client
.
Configuration
.
SchemeManagers
[
id
]
if
!
ok
{
session
.
Handler
.
Failure
(
session
.
Action
,
&
irma
.
SessionError
{
ErrorType
:
irma
.
ErrorUnknownSchemeManager
,
Info
:
id
.
String
()})
session
.
Handler
.
Failure
(
&
irma
.
SessionError
{
ErrorType
:
irma
.
ErrorUnknownSchemeManager
,
Info
:
id
.
String
()})
return
false
}
distributed
:=
manager
.
Distributed
()
...
...
@@ -540,7 +542,7 @@ func (session *session) Distributed() bool {
func
(
session
*
session
)
recoverFromPanic
()
{
if
e
:=
recover
();
e
!=
nil
{
if
session
.
Handler
!=
nil
{
session
.
Handler
.
Failure
(
session
.
Action
,
panicToError
(
e
))
session
.
Handler
.
Failure
(
panicToError
(
e
))
}
}
}
...
...
@@ -575,13 +577,13 @@ func (session *session) delete() bool {
func
(
session
*
session
)
fail
(
err
*
irma
.
SessionError
)
{
if
session
.
delete
()
{
err
.
Err
=
errors
.
Wrap
(
err
.
Err
,
0
)
session
.
Handler
.
Failure
(
session
.
Action
,
err
)
session
.
Handler
.
Failure
(
err
)
}
}
func
(
session
*
session
)
cancel
()
{
if
session
.
delete
()
{
session
.
Handler
.
Cancelled
(
session
.
Action
)
session
.
Handler
.
Cancelled
()
}
}
...
...
irmaclient/session_test.go
View file @
c3bfa3aa
...
...
@@ -23,36 +23,36 @@ type TestHandler struct {
}
func
(
th
TestHandler
)
KeyshareEnrollmentIncomplete
(
manager
irma
.
SchemeManagerIdentifier
)
{
th
.
Failure
(
irma
.
ActionUnknown
,
&
irma
.
SessionError
{
Err
:
errors
.
New
(
"KeyshareEnrollmentIncomplete"
)})
th
.
Failure
(
&
irma
.
SessionError
{
Err
:
errors
.
New
(
"KeyshareEnrollmentIncomplete"
)})
}
func
(
th
TestHandler
)
KeyshareBlocked
(
manager
irma
.
SchemeManagerIdentifier
,
duration
int
)
{
th
.
Failure
(
irma
.
ActionUnknown
,
&
irma
.
SessionError
{
Err
:
errors
.
New
(
"KeyshareBlocked"
)})
th
.
Failure
(
&
irma
.
SessionError
{
Err
:
errors
.
New
(
"KeyshareBlocked"
)})
}
func
(
th
TestHandler
)
KeyshareEnrollmentMissing
(
manager
irma
.
SchemeManagerIdentifier
)
{
th
.
Failure
(
irma
.
ActionUnknown
,
&
irma
.
SessionError
{
Err
:
errors
.
Errorf
(
"Missing keyshare server %s"
,
manager
.
String
())})
th
.
Failure
(
&
irma
.
SessionError
{
Err
:
errors
.
Errorf
(
"Missing keyshare server %s"
,
manager
.
String
())})
}
func
(
th
TestHandler
)
KeyshareEnrollmentDeleted
(
manager
irma
.
SchemeManagerIdentifier
)
{
th
.
Failure
(
irma
.
ActionUnknown
,
&
irma
.
SessionError
{
Err
:
errors
.
Errorf
(
"Keyshare enrollment deleted for %s"
,
manager
.
String
())})
th
.
Failure
(
&
irma
.
SessionError
{
Err
:
errors
.
Errorf
(
"Keyshare enrollment deleted for %s"
,
manager
.
String
())})
}
func
(
th
TestHandler
)
StatusUpdate
(
action
irma
.
Action
,
status
irma
.
Status
)
{}
func
(
th
TestHandler
)
Success
(
action
irma
.
Action
,
result
string
)
{
func
(
th
TestHandler
)
Success
(
result
string
)
{
th
.
c
<-
nil
}
func
(
th
TestHandler
)
Cancelled
(
action
irma
.
Action
)
{
func
(
th
TestHandler
)
Cancelled
()
{
th
.
c
<-
&
irma
.
SessionError
{}
}
func
(
th
TestHandler
)
Failure
(
action
irma
.
Action
,
err
*
irma
.
SessionError
)
{
func
(
th
TestHandler
)
Failure
(
err
*
irma
.
SessionError
)
{
select
{
case
th
.
c
<-
err
:
default
:
th
.
t
.
Fatal
(
err
)
}
}
func
(
th
TestHandler
)
UnsatisfiableRequest
(
action
irma
.
Action
,
serverName
string
,
missing
irma
.
AttributeDisjunctionList
)
{
func
(
th
TestHandler
)
UnsatisfiableRequest
(
serverName
string
,
missing
irma
.
AttributeDisjunctionList
)
{
th
.
c
<-
&
irma
.
SessionError
{
ErrorType
:
irma
.
ErrorType
(
"UnsatisfiableRequest"
),
}
...
...
@@ -65,7 +65,7 @@ func (th TestHandler) RequestVerificationPermission(request irma.DisclosureReque
for
_
,
disjunction
:=
range
request
.
Content
{
candidates
=
th
.
client
.
Candidates
(
disjunction
)
if
len
(
candidates
)
==
0
{
th
.
Failure
(
irma
.
ActionUnknown
,
&
irma
.
SessionError
{
Err
:
errors
.
New
(
"No disclosure candidates found"
)})
th
.
Failure
(
&
irma
.
SessionError
{
Err
:
errors
.
New
(
"No disclosure candidates found"
)})
}
choice
.
Attributes
=
append
(
choice
.
Attributes
,
candidates
[
0
])
}
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment