Skip to content
GitLab
Menu
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
d27ed345
Commit
d27ed345
authored
Aug 13, 2018
by
Sietse Ringers
Browse files
Remove frontend session store
Co-authored-by:
Confiks
<
confiks@scriptbase.org
>
parent
5180c461
Changes
5
Hide whitespace changes
Inline
Side-by-side
irmaserver/api.go
View file @
d27ed345
...
@@ -15,11 +15,12 @@ type Configuration struct {
...
@@ -15,11 +15,12 @@ type Configuration struct {
}
}
type
SessionResult
struct
{
type
SessionResult
struct
{
Token
string
Token
string
Status
irma
.
ProofStatus
Status
Status
Disclosed
[]
*
irma
.
DisclosedAttribute
ProofStatus
irma
.
ProofStatus
Signature
*
irma
.
SignedMessage
Disclosed
[]
*
irma
.
DisclosedAttribute
Err
*
irma
.
RemoteError
Signature
*
irma
.
SignedMessage
Err
*
irma
.
RemoteError
}
}
type
Status
string
type
Status
string
...
...
irmaserver/backend/api.go
View file @
d27ed345
...
@@ -63,6 +63,14 @@ func StartSession(request irma.SessionRequest) (*irma.Qr, string, error) {
...
@@ -63,6 +63,14 @@ func StartSession(request irma.SessionRequest) (*irma.Qr, string, error) {
},
session
.
token
,
nil
},
session
.
token
,
nil
}
}
func
GetSessionResult
(
token
string
)
*
irmaserver
.
SessionResult
{
session
:=
sessions
.
get
(
token
)
if
session
!=
nil
{
return
nil
}
return
session
.
result
}
func
HandleProtocolMessage
(
func
HandleProtocolMessage
(
path
string
,
path
string
,
method
string
,
method
string
,
...
...
irmaserver/backend/handle.go
View file @
d27ed345
...
@@ -19,8 +19,7 @@ func (session *session) handleDelete() {
...
@@ -19,8 +19,7 @@ func (session *session) handleDelete() {
}
}
session
.
markAlive
()
session
.
markAlive
()
// TODO const ProofStatusCancelled = irma.ProofStatus("CANCELLED") ?
session
.
result
=
&
irmaserver
.
SessionResult
{
Token
:
session
.
token
,
Status
:
irmaserver
.
StatusCancelled
}
session
.
result
=
&
irmaserver
.
SessionResult
{
Token
:
session
.
token
}
session
.
setStatus
(
irmaserver
.
StatusCancelled
)
session
.
setStatus
(
irmaserver
.
StatusCancelled
)
}
}
...
@@ -47,10 +46,10 @@ func (session *session) handlePostSignature(signature *irma.SignedMessage) (*irm
...
@@ -47,10 +46,10 @@ func (session *session) handlePostSignature(signature *irma.SignedMessage) (*irm
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
.
Proof
Status
=
signature
.
Verify
(
conf
.
IrmaConfiguration
,
session
.
request
.
(
*
irma
.
SignatureRequest
))
conf
.
IrmaConfiguration
,
session
.
request
.
(
*
irma
.
SignatureRequest
))
session
.
setStatus
(
irmaserver
.
StatusDone
)
session
.
setStatus
(
irmaserver
.
StatusDone
)
return
&
session
.
result
.
Status
,
nil
return
&
session
.
result
.
Proof
Status
,
nil
}
}
func
(
session
*
session
)
handlePostProofs
(
proofs
gabi
.
ProofList
)
(
*
irma
.
ProofStatus
,
*
irma
.
RemoteError
)
{
func
(
session
*
session
)
handlePostProofs
(
proofs
gabi
.
ProofList
)
(
*
irma
.
ProofStatus
,
*
irma
.
RemoteError
)
{
...
@@ -59,10 +58,10 @@ func (session *session) handlePostProofs(proofs gabi.ProofList) (*irma.ProofStat
...
@@ -59,10 +58,10 @@ func (session *session) handlePostProofs(proofs gabi.ProofList) (*irma.ProofStat
}
}
session
.
markAlive
()
session
.
markAlive
()
session
.
result
.
Disclosed
,
session
.
result
.
Status
=
irma
.
ProofList
(
proofs
)
.
Verify
(
session
.
result
.
Disclosed
,
session
.
result
.
Proof
Status
=
irma
.
ProofList
(
proofs
)
.
Verify
(
conf
.
IrmaConfiguration
,
session
.
request
.
(
*
irma
.
DisclosureRequest
))
conf
.
IrmaConfiguration
,
session
.
request
.
(
*
irma
.
DisclosureRequest
))
session
.
setStatus
(
irmaserver
.
StatusDone
)
session
.
setStatus
(
irmaserver
.
StatusDone
)
return
&
session
.
result
.
Status
,
nil
return
&
session
.
result
.
Proof
Status
,
nil
}
}
func
(
session
*
session
)
handlePostCommitments
(
commitments
*
gabi
.
IssueCommitmentMessage
)
([]
*
gabi
.
IssueSignatureMessage
,
*
irma
.
RemoteError
)
{
func
(
session
*
session
)
handlePostCommitments
(
commitments
*
gabi
.
IssueCommitmentMessage
)
([]
*
gabi
.
IssueSignatureMessage
,
*
irma
.
RemoteError
)
{
...
@@ -103,9 +102,9 @@ func (session *session) handlePostCommitments(commitments *gabi.IssueCommitmentM
...
@@ -103,9 +102,9 @@ func (session *session) handlePostCommitments(commitments *gabi.IssueCommitmentM
}
}
// Verify all proofs and check disclosed attributes, if any, against request
// Verify all proofs and check disclosed attributes, if any, against request
session
.
result
.
Disclosed
,
session
.
result
.
Status
=
irma
.
ProofList
(
commitments
.
Proofs
)
.
VerifyAgainstDisjunctions
(
session
.
result
.
Disclosed
,
session
.
result
.
Proof
Status
=
irma
.
ProofList
(
commitments
.
Proofs
)
.
VerifyAgainstDisjunctions
(
conf
.
IrmaConfiguration
,
request
.
Disclose
,
request
.
Context
,
request
.
Nonce
,
pubkeys
,
false
)
conf
.
IrmaConfiguration
,
request
.
Disclose
,
request
.
Context
,
request
.
Nonce
,
pubkeys
,
false
)
if
session
.
result
.
Status
!=
irma
.
ProofStatusValid
{
if
session
.
result
.
Proof
Status
!=
irma
.
ProofStatusValid
{
return
nil
,
session
.
fail
(
irmaserver
.
ErrorInvalidProofs
,
""
)
return
nil
,
session
.
fail
(
irmaserver
.
ErrorInvalidProofs
,
""
)
}
}
...
...
irmaserver/backend/helpers.go
View file @
d27ed345
...
@@ -27,12 +27,13 @@ func (session *session) markAlive() {
...
@@ -27,12 +27,13 @@ func (session *session) markAlive() {
func
(
session
*
session
)
setStatus
(
status
irmaserver
.
Status
)
{
func
(
session
*
session
)
setStatus
(
status
irmaserver
.
Status
)
{
session
.
status
=
status
session
.
status
=
status
session
.
result
.
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
.
setStatus
(
irmaserver
.
StatusCancelled
)
session
.
setStatus
(
irmaserver
.
StatusCancelled
)
session
.
result
=
&
irmaserver
.
SessionResult
{
Err
:
rerr
,
Token
:
session
.
token
}
session
.
result
=
&
irmaserver
.
SessionResult
{
Err
:
rerr
,
Token
:
session
.
token
,
Status
:
irmaserver
.
StatusCancelled
}
return
rerr
return
rerr
}
}
...
...
irmaserver/irmarequestor/main.go
View file @
d27ed345
...
@@ -3,7 +3,6 @@ package irmarequestor
...
@@ -3,7 +3,6 @@ package irmarequestor
import
(
import
(
"io/ioutil"
"io/ioutil"
"net/http"
"net/http"
"sync"
"github.com/privacybydesign/irmago"
"github.com/privacybydesign/irmago"
"github.com/privacybydesign/irmago/irmaserver"
"github.com/privacybydesign/irmago/irmaserver"
...
@@ -12,43 +11,27 @@ import (
...
@@ -12,43 +11,27 @@ import (
type
SessionHandler
func
(
*
irmaserver
.
SessionResult
)
type
SessionHandler
func
(
*
irmaserver
.
SessionResult
)
type
SessionStore
interface
{
var
handlers
=
make
(
map
[
string
]
SessionHandler
)
Get
(
token
string
)
*
irmaserver
.
SessionResult
Add
(
token
string
,
result
*
irmaserver
.
SessionResult
)
GetHandler
(
token
string
)
SessionHandler
SetHandler
(
token
string
,
handler
SessionHandler
)
SupportHandlers
()
bool
}
var
Sessions
SessionStore
=
&
MemorySessionStore
{
m
:
make
(
map
[
string
]
*
irmaserver
.
SessionResult
),
h
:
make
(
map
[
string
]
SessionHandler
),
}
type
MemorySessionStore
struct
{
sync
.
RWMutex
m
map
[
string
]
*
irmaserver
.
SessionResult
h
map
[
string
]
SessionHandler
}
func
Initialize
(
configuration
*
irmaserver
.
Configuration
)
error
{
func
Initialize
(
configuration
*
irmaserver
.
Configuration
)
error
{
return
backend
.
Initialize
(
configuration
)
return
backend
.
Initialize
(
configuration
)
}
}
func
StartSession
(
request
irma
.
SessionRequest
,
handler
SessionHandler
)
(
*
irma
.
Qr
,
string
,
error
)
{
func
StartSession
(
request
irma
.
SessionRequest
,
handler
SessionHandler
)
(
*
irma
.
Qr
,
string
,
error
)
{
if
handler
!=
nil
&&
!
Sessions
.
SupportHandlers
()
{
panic
(
"Handlers not supported"
)
}
qr
,
token
,
err
:=
backend
.
StartSession
(
request
)
qr
,
token
,
err
:=
backend
.
StartSession
(
request
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
""
,
err
return
nil
,
""
,
err
}
}
if
handler
!=
nil
{
if
handler
!=
nil
{
Sessions
.
SetH
andler
(
token
,
handler
)
h
andler
s
[
token
]
=
handler
}
}
return
qr
,
token
,
nil
return
qr
,
token
,
nil
}
}
func
GetSessionResult
(
token
string
)
*
irmaserver
.
SessionResult
{
return
backend
.
GetSessionResult
(
token
)
}
func
HttpHandlerFunc
(
prefix
string
)
http
.
HandlerFunc
{
func
HttpHandlerFunc
(
prefix
string
)
http
.
HandlerFunc
{
if
len
(
prefix
)
!=
0
&&
prefix
[
0
]
!=
'/'
{
if
len
(
prefix
)
!=
0
&&
prefix
[
0
]
!=
'/'
{
prefix
=
"/"
+
prefix
prefix
=
"/"
+
prefix
...
@@ -65,39 +48,9 @@ func HttpHandlerFunc(prefix string) http.HandlerFunc {
...
@@ -65,39 +48,9 @@ func HttpHandlerFunc(prefix string) http.HandlerFunc {
w
.
WriteHeader
(
status
)
w
.
WriteHeader
(
status
)
w
.
Write
(
response
)
w
.
Write
(
response
)
if
result
!=
nil
{
if
result
!=
nil
{
Sessions
.
Add
(
result
.
Token
,
result
)
if
handler
,
ok
:=
handlers
[
result
.
Token
];
ok
{
if
handler
:=
Sessions
.
GetHandler
(
result
.
Token
);
handler
!=
nil
{
go
handler
(
result
)
go
handler
(
result
)
}
}
}
}
}
}
}
}
func
(
s
MemorySessionStore
)
Get
(
token
string
)
*
irmaserver
.
SessionResult
{
s
.
RLock
()
defer
s
.
RUnlock
()
return
s
.
m
[
token
]
}
func
(
s
MemorySessionStore
)
Add
(
token
string
,
result
*
irmaserver
.
SessionResult
)
{
s
.
Lock
()
defer
s
.
Unlock
()
if
_
,
contains
:=
s
.
m
[
token
];
contains
{
return
}
s
.
m
[
token
]
=
result
}
func
(
s
MemorySessionStore
)
GetHandler
(
token
string
)
SessionHandler
{
s
.
RLock
()
defer
s
.
RUnlock
()
return
s
.
h
[
token
]
}
func
(
s
MemorySessionStore
)
SetHandler
(
token
string
,
handler
SessionHandler
)
{
s
.
Lock
()
defer
s
.
Unlock
()
s
.
h
[
token
]
=
handler
}
func
(
s
MemorySessionStore
)
SupportHandlers
()
bool
{
return
true
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a 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