Commit 502b6c9d authored by Sietse Ringers's avatar Sietse Ringers
Browse files

Handle deserialization of messages in router of irmaserver

parent 9bd5bf62
......@@ -7,6 +7,7 @@ import (
"github.com/Sirupsen/logrus"
"github.com/go-errors/errors"
"github.com/mhe/gabi"
"github.com/privacybydesign/irmago"
"github.com/privacybydesign/irmago/irmaserver"
)
......@@ -114,8 +115,28 @@ func HandleProtocolMessage(
}
return failSession(session, irmaserver.ErrorInvalidRequest, "")
default:
if method == "POST" && (verb == "proofs" || (verb == "commitments" && session.action == irma.ActionIssuing)) {
return handlePostResponse(session, message)
if method == "POST" {
if verb == "commitments" && session.action == irma.ActionIssuing {
commitments := &gabi.IssueCommitmentMessage{}
if err := irma.UnmarshalValidate(message, commitments); err != nil {
return failSession(session, irmaserver.ErrorMalformedInput, "")
}
return handlePostCommitments(session, commitments)
}
if verb == "proofs" && session.action == irma.ActionDisclosing {
proofs := gabi.ProofList{}
if err := irma.UnmarshalValidate(message, &proofs); err != nil {
return failSession(session, irmaserver.ErrorMalformedInput, "")
}
return handlePostProofs(session, proofs)
}
if verb == "proofs" && session.action == irma.ActionSigning {
signature := &irma.SignedMessage{}
if err := irma.UnmarshalValidate(message, signature); err != nil {
return failSession(session, irmaserver.ErrorMalformedInput, "")
}
return handlePostSignature(session, signature)
}
}
if method == "GET" && verb == "status" {
return handleGetStatus(session)
......
......@@ -37,42 +37,21 @@ func handleGetStatus(session *session) (int, []byte, *irmaserver.SessionResult)
return http.StatusOK, b, nil
}
func handlePostResponse(session *session, message []byte) (int, []byte, *irmaserver.SessionResult) {
if !session.alive() {
return failSession(session, irmaserver.ErrorUnexpectedRequest, "")
}
switch session.action {
case irma.ActionSigning:
sig := &irma.SignedMessage{}
if err := irma.UnmarshalValidate(message, sig); err != nil {
return failSession(session, irmaserver.ErrorMalformedInput, "")
}
session.signature = sig
session.disclosed, session.proofStatus = sig.Verify(conf.IrmaConfiguration, session.request.(*irma.SignatureRequest))
s, b := responseJson(session.proofStatus)
return s, b, finishSession(session)
case irma.ActionDisclosing:
pl := gabi.ProofList{}
if err := irma.UnmarshalValidate(message, &pl); err != nil {
return failSession(session, irmaserver.ErrorMalformedInput, "")
}
session.disclosed, session.proofStatus = irma.ProofList(pl).Verify(conf.IrmaConfiguration, session.request.(*irma.DisclosureRequest))
s, b := responseJson(session.proofStatus)
return s, b, finishSession(session)
case irma.ActionIssuing:
commitments := &gabi.IssueCommitmentMessage{}
if err := irma.UnmarshalValidate(message, commitments); err != nil {
return failSession(session, irmaserver.ErrorMalformedInput, "")
}
return session.issue(commitments)
func handlePostCommitments(session *session, commitments *gabi.IssueCommitmentMessage) (int, []byte, *irmaserver.SessionResult) {
return session.issue(commitments)
}
}
func handlePostSignature(session *session, signature *irma.SignedMessage) (int, []byte, *irmaserver.SessionResult) {
session.signature = signature
session.disclosed, session.proofStatus = signature.Verify(conf.IrmaConfiguration, session.request.(*irma.SignatureRequest))
s, b := responseJson(session.proofStatus)
return s, b, finishSession(session)
}
return failSession(session, irmaserver.ErrorUnknown, "")
func handlePostProofs(session *session, proofs gabi.ProofList) (int, []byte, *irmaserver.SessionResult) {
session.disclosed, session.proofStatus = irma.ProofList(proofs).Verify(conf.IrmaConfiguration, session.request.(*irma.DisclosureRequest))
s, b := responseJson(session.proofStatus)
return s, b, finishSession(session)
}
func responseJson(v interface{}) (int, []byte) {
......
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