Commit 6d25eaad authored by Sietse Ringers's avatar Sietse Ringers
Browse files

fix: missing fields from session result JWT

parent 5578f2e2
Pipeline #27664 passed with stages
in 5 minutes and 5 seconds
...@@ -155,10 +155,10 @@ func (s *Server) newSession(action irma.Action, request irma.RequestorRequest) * ...@@ -155,10 +155,10 @@ func (s *Server) newSession(action irma.Action, request irma.RequestorRequest) *
conf: s.conf, conf: s.conf,
sessions: s.sessions, sessions: s.sessions,
result: &server.SessionResult{ result: &server.SessionResult{
Legacy: request.SessionRequest().Base().Legacy(), LegacySession: request.SessionRequest().Base().Legacy(),
Token: token, Token: token,
Type: action, Type: action,
Status: server.StatusInitialized, Status: server.StatusInitialized,
}, },
} }
......
...@@ -84,7 +84,7 @@ type SessionResult struct { ...@@ -84,7 +84,7 @@ type SessionResult struct {
Signature *irma.SignedMessage `json:"signature,omitempty"` Signature *irma.SignedMessage `json:"signature,omitempty"`
Err *irma.RemoteError `json:"error,omitempty"` Err *irma.RemoteError `json:"error,omitempty"`
Legacy bool `json:"-"` // true if request was started with legacy (i.e. pre-condiscon) session request LegacySession bool `json:"-"` // true if request was started with legacy (i.e. pre-condiscon) session request
} }
// Status is the status of an IRMA session. // Status is the status of an IRMA session.
...@@ -99,25 +99,23 @@ const ( ...@@ -99,25 +99,23 @@ const (
) )
// Remove this when dropping support for legacy pre-condiscon session requests // Remove this when dropping support for legacy pre-condiscon session requests
func (r *SessionResult) MarshalJSON() ([]byte, error) { type LegacySessionResult struct {
if !r.Legacy { Token string `json:"token"`
type tmpSessionResult SessionResult Status Status `json:"status"`
return json.Marshal((*tmpSessionResult)(r)) Type irma.Action `json:"type"`
} ProofStatus irma.ProofStatus `json:"proofStatus,omitempty"`
Disclosed []*irma.DisclosedAttribute `json:"disclosed,omitempty"`
Signature *irma.SignedMessage `json:"signature,omitempty"`
Err *irma.RemoteError `json:"error,omitempty"`
}
// Remove this when dropping support for legacy pre-condiscon session requests
func (r *SessionResult) Legacy() *LegacySessionResult {
var disclosed []*irma.DisclosedAttribute var disclosed []*irma.DisclosedAttribute
for _, l := range r.Disclosed { for _, l := range r.Disclosed {
disclosed = append(disclosed, l[0]) disclosed = append(disclosed, l[0])
} }
return json.Marshal(struct { return &LegacySessionResult{r.Token, r.Status, r.Type, r.ProofStatus, disclosed, r.Signature, r.Err}
Token string `json:"token"`
Status Status `json:"status"`
Type irma.Action `json:"type"'`
ProofStatus irma.ProofStatus `json:"proofStatus,omitempty"`
Disclosed []*irma.DisclosedAttribute `json:"disclosed,omitempty"`
Signature *irma.SignedMessage `json:"signature,omitempty"`
Err *irma.RemoteError `json:"error,omitempty"`
}{r.Token, r.Status, r.Type, r.ProofStatus, disclosed, r.Signature, r.Err})
} }
func (conf *Configuration) PrivateKey(id irma.IssuerIdentifier) (sk *gabi.PrivateKey, err error) { func (conf *Configuration) PrivateKey(id irma.IssuerIdentifier) (sk *gabi.PrivateKey, err error) {
......
...@@ -387,7 +387,11 @@ func (s *Server) handleResult(w http.ResponseWriter, r *http.Request) { ...@@ -387,7 +387,11 @@ func (s *Server) handleResult(w http.ResponseWriter, r *http.Request) {
server.WriteError(w, server.ErrorSessionUnknown, "") server.WriteError(w, server.ErrorSessionUnknown, "")
return return
} }
server.WriteJson(w, res) if res.LegacySession {
server.WriteJson(w, res.Legacy())
} else {
server.WriteJson(w, res)
}
} }
func (s *Server) handleJwtResult(w http.ResponseWriter, r *http.Request) { func (s *Server) handleJwtResult(w http.ResponseWriter, r *http.Request) {
...@@ -495,20 +499,25 @@ func (s *Server) handlePublicKey(w http.ResponseWriter, r *http.Request) { ...@@ -495,20 +499,25 @@ func (s *Server) handlePublicKey(w http.ResponseWriter, r *http.Request) {
} }
func (s *Server) resultJwt(sessionresult *server.SessionResult) (string, error) { func (s *Server) resultJwt(sessionresult *server.SessionResult) (string, error) {
claims := struct { standardclaims := jwt.StandardClaims{
jwt.StandardClaims Issuer: s.conf.JwtIssuer,
*server.SessionResult IssuedAt: time.Now().Unix(),
}{ Subject: string(sessionresult.Type) + "_result",
StandardClaims: jwt.StandardClaims{
Issuer: s.conf.JwtIssuer,
IssuedAt: time.Now().Unix(),
Subject: string(sessionresult.Type) + "_result",
},
SessionResult: sessionresult,
} }
validity := s.irmaserv.GetRequest(sessionresult.Token).Base().ResultJwtValidity validity := s.irmaserv.GetRequest(sessionresult.Token).Base().ResultJwtValidity
if validity != 0 { standardclaims.ExpiresAt = time.Now().Unix() + int64(validity)
claims.ExpiresAt = time.Now().Unix() + int64(validity)
var claims jwt.Claims
if sessionresult.LegacySession {
claims = struct {
jwt.StandardClaims
*server.LegacySessionResult
}{standardclaims, sessionresult.Legacy()}
} else {
claims = struct {
jwt.StandardClaims
*server.SessionResult
}{standardclaims, sessionresult}
} }
// Sign the jwt and return it // Sign the jwt and return it
......
...@@ -7,7 +7,7 @@ package irma ...@@ -7,7 +7,7 @@ package irma
import "github.com/timshannon/bolthold" import "github.com/timshannon/bolthold"
// Version of the IRMA command line and libraries // Version of the IRMA command line and libraries
const Version = "0.3.0" const Version = "0.3.1"
// go-atum requires a version of bolthold newer than the latest release v1.1, but go-atum does not // go-atum requires a version of bolthold newer than the latest release v1.1, but go-atum does not
// use dep, so by default dep fetches v1.1 which breaks the build. We make bolthold an explicit // use dep, so by default dep fetches v1.1 which breaks the build. We make bolthold an explicit
......
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