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
393b2dbd
Commit
393b2dbd
authored
Jul 27, 2018
by
Sietse Ringers
Browse files
Split scheme manager request handling from generic session request handling
parent
c3bfa3aa
Changes
3
Hide whitespace changes
Inline
Side-by-side
irmaclient/irmaclient_test.go
View file @
393b2dbd
...
...
@@ -447,12 +447,13 @@ func TestDownloadSchemeManager(t *testing.T) {
require
.
NotContains
(
t
,
client
.
Configuration
.
SchemeManagers
,
irmademo
)
// Do an add-scheme-manager-session
qr
:=
&
irma
.
Qr
{
c
:=
make
(
chan
*
irma
.
SessionError
)
qr
,
err
:=
json
.
Marshal
(
&
irma
.
SchemeManagerRequest
{
Type
:
irma
.
ActionSchemeManager
,
URL
:
"http://localhost:48681/irma_configuration/irma-demo"
,
}
c
:=
make
(
chan
*
irma
.
SessionErro
r
)
client
.
n
ew
Qr
Session
(
qr
,
TestHandler
{
t
,
c
,
client
})
}
)
require
.
NoError
(
t
,
er
r
)
client
.
N
ewSession
(
string
(
qr
)
,
TestHandler
{
t
,
c
,
client
})
if
err
:=
<-
c
;
err
!=
nil
{
t
.
Fatal
(
*
err
)
}
...
...
irmaclient/session.go
View file @
393b2dbd
...
...
@@ -79,22 +79,24 @@ var supportedVersions = map[int][]int{
// Session constructors
// NewSession starts a new IRMA session, given (along with a handler to pass feedback to)
// either an irma.QR or *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.
// NewSession starts a new IRMA session, given (along with a handler to pass feedback to) a session request.
// When the request is not suitable to start an IRMA session from, it calls the Failure method of the specified Handler.
func
(
client
*
Client
)
NewSession
(
sessionrequest
string
,
handler
Handler
)
SessionDismisser
{
bts
:=
[]
byte
(
sessionrequest
)
// Try to deserialize it as a Qr or SignatureRequest
qr
:=
&
irma
.
Qr
{}
if
err
:=
irma
.
UnmarshalValidate
(
bts
,
qr
);
err
==
nil
{
return
client
.
newQrSession
(
qr
,
handler
)
}
sigrequest
:=
&
irma
.
SignatureRequest
{}
if
err
:=
irma
.
UnmarshalValidate
(
bts
,
sigrequest
);
err
==
nil
{
return
client
.
newManualSession
(
sigrequest
,
handler
)
schemeRequest
:=
&
irma
.
SchemeManagerRequest
{}
if
err
:=
irma
.
UnmarshalValidate
(
bts
,
schemeRequest
);
err
==
nil
{
return
client
.
newSchemeSession
(
schemeRequest
,
handler
)
}
sigRequest
:=
&
irma
.
SignatureRequest
{}
if
err
:=
irma
.
UnmarshalValidate
(
bts
,
sigRequest
);
err
==
nil
{
return
client
.
newManualSession
(
sigRequest
,
handler
)
}
handler
.
Failure
(
&
irma
.
SessionError
{
Err
:
errors
.
New
(
"Session request could not be parsed"
)})
...
...
@@ -117,6 +119,20 @@ func (client *Client) newManualSession(sigrequest *irma.SignatureRequest, handle
return
session
}
func
(
client
*
Client
)
newSchemeSession
(
qr
*
irma
.
SchemeManagerRequest
,
handler
Handler
)
SessionDismisser
{
session
:=
&
session
{
ServerURL
:
qr
.
URL
,
transport
:
irma
.
NewHTTPTransport
(
qr
.
URL
),
Action
:
irma
.
ActionSchemeManager
,
Handler
:
handler
,
client
:
client
,
}
session
.
Handler
.
StatusUpdate
(
session
.
Action
,
irma
.
StatusCommunicating
)
go
session
.
managerSession
()
return
session
}
// newQrSession creates and starts a new interactive IRMA session
func
(
client
*
Client
)
newQrSession
(
qr
*
irma
.
Qr
,
handler
Handler
)
SessionDismisser
{
session
:=
&
session
{
...
...
@@ -128,12 +144,6 @@ func (client *Client) newQrSession(qr *irma.Qr, handler Handler) SessionDismisse
}
session
.
Handler
.
StatusUpdate
(
session
.
Action
,
irma
.
StatusCommunicating
)
// TODO move this
if
session
.
Action
==
irma
.
ActionSchemeManager
{
go
session
.
managerSession
()
return
session
}
// Check if the action is one of the supported types
switch
session
.
Action
{
case
irma
.
ActionDisclosing
:
...
...
messages.go
View file @
393b2dbd
...
...
@@ -127,6 +127,8 @@ type Qr struct {
ProtocolMaxVersion
ProtocolVersion
`json:"vmax"`
}
type
SchemeManagerRequest
Qr
// Statuses
const
(
StatusConnected
=
Status
(
"connected"
)
...
...
@@ -250,21 +252,33 @@ func ParseRequestorJwt(action Action, jwt string) (RequestorJwt, error) {
}
func
(
qr
*
Qr
)
Validate
()
error
{
if
_
,
err
:=
url
.
ParseRequestURI
(
qr
.
URL
);
err
!=
nil
{
return
errors
.
Errorf
(
"Invalid URL: %s"
,
err
.
Error
())
}
if
qr
.
URL
==
""
{
return
errors
.
New
(
"No URL specified"
)
}
if
_
,
err
:=
url
.
ParseRequestURI
(
qr
.
URL
);
err
!=
nil
{
return
errors
.
Errorf
(
"Invalid URL: %s"
,
err
.
Error
())
}
switch
qr
.
Type
{
case
ActionDisclosing
:
// nop
case
ActionIssuing
:
// nop
case
ActionSigning
:
// nop
case
ActionSchemeManager
:
// nop
default
:
return
errors
.
New
(
"Unsupported session type"
)
}
return
nil
}
func
(
smr
*
SchemeManagerRequest
)
Validate
()
error
{
if
smr
.
Type
!=
ActionSchemeManager
{
return
errors
.
New
(
"Not a scheme manager request"
)
}
if
smr
.
URL
==
""
{
return
errors
.
New
(
"No URL specified"
)
}
if
_
,
err
:=
url
.
ParseRequestURI
(
smr
.
URL
);
err
!=
nil
{
return
errors
.
Errorf
(
"Invalid URL: %s"
,
err
.
Error
())
}
return
nil
}
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