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
303c9f59
Commit
303c9f59
authored
Jul 25, 2018
by
Sietse Ringers
Browse files
Unify manual and interactive session construction functions into one
Co-authored-by:
Confiks
<
confiks@scriptbase.org
>
parent
081c4b1f
Changes
2
Hide whitespace changes
Inline
Side-by-side
irmaclient/manual_session_test.go
View file @
303c9f59
...
...
@@ -71,7 +71,7 @@ func TestManualSession(t *testing.T) {
ms
:=
createManualSessionHandler
(
request
,
request
,
t
)
client
=
parseStorage
(
t
)
client
.
New
Manual
Session
(
request
,
&
ms
)
client
.
NewSession
(
request
,
&
ms
)
if
err
:=
<-
ms
.
errorChannel
;
err
!=
nil
{
test
.
ClearTestStorage
(
t
)
...
...
@@ -99,7 +99,7 @@ func TestManualSessionUnsatisfiable(t *testing.T) {
ms
:=
createManualSessionHandler
(
request
,
request
,
t
)
client
=
parseStorage
(
t
)
client
.
New
Manual
Session
(
request
,
&
ms
)
client
.
NewSession
(
request
,
&
ms
)
// Fail test if we won't get UnsatisfiableRequest error
if
err
:=
<-
ms
.
errorChannel
;
err
.
ErrorType
!=
irma
.
ErrorType
(
"UnsatisfiableRequest"
)
{
...
...
@@ -119,7 +119,7 @@ func TestManualSessionInvalidNonce(t *testing.T) {
ms
:=
createManualSessionHandler
(
request
,
invalidRequest
,
t
)
client
=
parseStorage
(
t
)
client
.
New
Manual
Session
(
request
,
&
ms
)
client
.
NewSession
(
request
,
&
ms
)
if
err
:=
<-
ms
.
errorChannel
;
err
!=
nil
{
test
.
ClearTestStorage
(
t
)
...
...
@@ -144,7 +144,7 @@ func TestManualSessionInvalidRequest(t *testing.T) {
ms
:=
createManualSessionHandler
(
request
,
invalidRequest
,
t
)
client
=
parseStorage
(
t
)
client
.
New
Manual
Session
(
request
,
&
ms
)
client
.
NewSession
(
request
,
&
ms
)
if
err
:=
<-
ms
.
errorChannel
;
err
!=
nil
{
test
.
ClearTestStorage
(
t
)
...
...
@@ -181,7 +181,7 @@ func TestManualSessionInvalidAttributeValue(t *testing.T) {
ms
:=
createManualSessionHandler
(
request
,
invalidRequest
,
t
)
client
=
parseStorage
(
t
)
client
.
New
Manual
Session
(
request
,
&
ms
)
client
.
NewSession
(
request
,
&
ms
)
if
err
:=
<-
ms
.
errorChannel
;
err
!=
nil
{
test
.
ClearTestStorage
(
t
)
...
...
@@ -209,7 +209,7 @@ func TestManualKeyShareSession(t *testing.T) {
ms
:=
createManualSessionHandler
(
request
,
request
,
t
)
client
=
parseStorage
(
t
)
client
.
New
Manual
Session
(
request
,
&
ms
)
client
.
NewSession
(
request
,
&
ms
)
if
err
:=
<-
ms
.
errorChannel
;
err
!=
nil
{
test
.
ClearTestStorage
(
t
)
...
...
@@ -241,7 +241,7 @@ func TestManualSessionMultiProof(t *testing.T) {
ms
:=
createManualSessionHandler
(
request
,
request
,
t
)
client
.
New
Manual
Session
(
request
,
&
ms
)
client
.
NewSession
(
request
,
&
ms
)
if
err
:=
<-
ms
.
errorChannel
;
err
!=
nil
{
test
.
ClearTestStorage
(
t
)
...
...
@@ -272,7 +272,7 @@ func TestManualSessionInvalidProof(t *testing.T) {
ms
:=
createManualSessionHandler
(
request
,
request
,
t
)
client
=
parseStorage
(
t
)
client
.
New
Manual
Session
(
request
,
&
ms
)
client
.
NewSession
(
request
,
&
ms
)
if
err
:=
<-
ms
.
errorChannel
;
err
!=
nil
{
test
.
ClearTestStorage
(
t
)
...
...
irmaclient/session.go
View file @
303c9f59
...
...
@@ -81,15 +81,53 @@ var supportedVersions = map[int][]int{
// Session constructors
// NewManualSession starts a manual session, given a signature request in JSON and a handler to pass messages to
func
(
client
*
Client
)
NewManualSession
(
sigrequestJSONString
string
,
handler
Handler
)
{
var
err
error
sigrequest
:=
&
irma
.
SignatureRequest
{}
if
err
=
json
.
Unmarshal
([]
byte
(
sigrequestJSONString
),
sigrequest
);
err
!=
nil
{
handler
.
Failure
(
irma
.
ActionUnknown
,
&
irma
.
SessionError
{
Err
:
err
})
return
// NewSession starts a new IRMA session, given (along with a handler to pass feedback to)
// either an *irma.QR; a string that contains a JSON-serialized irma.QR;
// or a string that contains a serialized *irma.SignatureRequest.
// In any other case it calls the Failure method of the specified Handler.
func
(
client
*
Client
)
NewSession
(
info
interface
{},
handler
Handler
)
SessionDismisser
{
parsed
:=
map
[
string
]
interface
{}{}
switch
x
:=
info
.
(
type
)
{
case
*
irma
.
Qr
:
// Just start the session directly
return
client
.
newQrSession
(
x
,
handler
)
case
irma
.
Qr
:
return
client
.
newQrSession
(
&
x
,
handler
)
// We assume the string contains a JSON object
// Deserialize it into a temp to see which fields it contains, and infer from that what kind of object it is
case
string
:
bts
:=
[]
byte
(
x
)
if
err
:=
json
.
Unmarshal
(
bts
,
&
parsed
);
err
!=
nil
{
handler
.
Failure
(
irma
.
ActionUnknown
,
&
irma
.
SessionError
{
Err
:
err
})
return
nil
}
if
_
,
isqr
:=
parsed
[
"irmaqr"
];
isqr
{
qr
:=
&
irma
.
Qr
{}
if
err
:=
json
.
Unmarshal
(
bts
,
qr
);
err
!=
nil
{
handler
.
Failure
(
irma
.
ActionUnknown
,
&
irma
.
SessionError
{
Err
:
err
})
return
nil
}
return
client
.
newQrSession
(
qr
,
handler
)
}
if
_
,
isSigRequest
:=
parsed
[
"message"
];
isSigRequest
{
sigrequest
:=
&
irma
.
SignatureRequest
{}
if
err
:=
json
.
Unmarshal
([]
byte
(
x
),
sigrequest
);
err
!=
nil
{
handler
.
Failure
(
irma
.
ActionUnknown
,
&
irma
.
SessionError
{
Err
:
err
})
return
nil
}
return
client
.
newManualSession
(
sigrequest
,
handler
)
}
}
handler
.
Failure
(
irma
.
ActionUnknown
,
&
irma
.
SessionError
{
Err
:
errors
.
New
(
"Info specified of unsupported type"
)})
return
nil
}
// newManualSession starts a manual session, given a signature request in JSON and a handler to pass messages to
func
(
client
*
Client
)
newManualSession
(
sigrequest
*
irma
.
SignatureRequest
,
handler
Handler
)
SessionDismisser
{
session
:=
&
session
{
Action
:
irma
.
ActionSigning
,
// TODO hardcoded for now
Handler
:
handler
,
...
...
@@ -101,13 +139,13 @@ func (client *Client) NewManualSession(sigrequestJSONString string, handler Hand
session
.
Handler
.
StatusUpdate
(
session
.
Action
,
irma
.
StatusManualStarted
)
if
!
session
.
checkAndUpateConfiguration
()
{
return
return
nil
}
candidates
,
missing
:=
session
.
client
.
CheckSatisfiability
(
session
.
request
.
ToDisclose
())
if
len
(
missing
)
>
0
{
session
.
Handler
.
UnsatisfiableRequest
(
session
.
Action
,
"E-mail request"
,
missing
)
return
return
nil
}
session
.
request
.
SetCandidates
(
candidates
)
...
...
@@ -119,10 +157,12 @@ func (client *Client) NewManualSession(sigrequestJSONString string, handler Hand
})
session
.
Handler
.
RequestSignaturePermission
(
*
session
.
request
.
(
*
irma
.
SignatureRequest
),
"E-mail request"
,
callback
)
return
session
}
//
N
ewSession creates and starts a new interactive IRMA session
func
(
client
*
Client
)
N
ewSession
(
qr
*
irma
.
Qr
,
handler
Handler
)
SessionDismisser
{
//
n
ew
Qr
Session creates and starts a new interactive IRMA session
func
(
client
*
Client
)
n
ew
Qr
Session
(
qr
*
irma
.
Qr
,
handler
Handler
)
SessionDismisser
{
session
:=
&
session
{
ServerURL
:
qr
.
URL
,
transport
:
irma
.
NewHTTPTransport
(
qr
.
URL
),
...
...
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