Commit 9f7626c7 authored by Sietse Ringers's avatar Sietse Ringers
Browse files

Fix always empty requestor name

parent 2403cfcd
......@@ -198,7 +198,7 @@ func TestUnmarshaling(t *testing.T) {
entry := newlogs[len(newlogs)-1]
require.NotNil(t, entry)
sessionjwt, _, err := entry.Jwt()
sessionjwt, err := entry.Jwt()
require.NoError(t, err)
require.Equal(t, "testip", sessionjwt.(*IdentityProviderJwt).ServerName)
require.NoError(t, err)
......
......@@ -408,8 +408,7 @@ func (ks *keyshareSession) finishDisclosureOrSigning(challenge *big.Int, respons
msg := struct {
ProofP *gabi.ProofP
}{}
_, err := jwtDecode(responses[managerID], &msg)
if err != nil {
if err := jwtDecode(responses[managerID], &msg); err != nil {
ks.sessionHandler.KeyshareError(err)
return
}
......
......@@ -90,7 +90,7 @@ func (session *session) createLogEntry(response interface{}) (*LogEntry, error)
return entry, nil
}
func (entry *LogEntry) Jwt() (RequestorJwt, string, error) {
func (entry *LogEntry) Jwt() (RequestorJwt, error) {
return parseRequestorJwt(entry.Type, entry.SessionInfo.Jwt)
}
......
......@@ -112,31 +112,19 @@ func (e *SessionError) Error() string {
return string(e.ErrorType)
}
func jwtDecode(jwt string, body interface{}) (string, error) {
func jwtDecode(jwt string, body interface{}) error {
jwtparts := strings.Split(jwt, ".")
if jwtparts == nil || len(jwtparts) < 2 {
return "", errors.New("Not a JWT")
return errors.New("Not a JWT")
}
headerbytes, err := base64.RawStdEncoding.DecodeString(jwtparts[0])
if err != nil {
return "", err
}
var header struct {
Issuer string `json:"iss"`
}
err = json.Unmarshal([]byte(headerbytes), &header)
if err != nil {
return "", err
}
bodybytes, err := base64.RawStdEncoding.DecodeString(jwtparts[1])
if err != nil {
return "", err
return err
}
return header.Issuer, json.Unmarshal(bodybytes, body)
return json.Unmarshal(bodybytes, body)
}
func parseRequestorJwt(action Action, jwt string) (RequestorJwt, string, error) {
func parseRequestorJwt(action Action, jwt string) (RequestorJwt, error) {
var retval RequestorJwt
switch action {
case ActionDisclosing:
......@@ -146,11 +134,11 @@ func parseRequestorJwt(action Action, jwt string) (RequestorJwt, string, error)
case ActionIssuing:
retval = &IdentityProviderJwt{}
default:
return nil, "", errors.New("Invalid session type")
return nil, errors.New("Invalid session type")
}
server, err := jwtDecode(jwt, retval)
err := jwtDecode(jwt, retval)
if err != nil {
return nil, "", err
return nil, err
}
return retval, server, nil
return retval, nil
}
......@@ -337,8 +337,11 @@ func NewIdentityProviderJwt(servername string, ir *IssuanceRequest) *IdentityPro
// A RequestorJwt contains an IRMA session object.
type RequestorJwt interface {
IrmaSession() IrmaSession
Requestor() string
}
func (jwt *ServerJwt) Requestor() string { return jwt.ServerName }
// IrmaSession returns an IRMA session object.
func (jwt *ServiceProviderJwt) IrmaSession() IrmaSession { return jwt.Request.Request }
......
......@@ -166,9 +166,8 @@ func (session *session) start() {
return
}
var server string
var err error
session.jwt, server, err = parseRequestorJwt(session.Action, session.info.Jwt)
session.jwt, err = parseRequestorJwt(session.Action, session.info.Jwt)
if err != nil {
session.fail(&SessionError{ErrorType: ErrorInvalidJWT, Err: err})
return
......@@ -233,11 +232,14 @@ func (session *session) start() {
session.Handler.StatusUpdate(session.Action, StatusConnected)
switch session.Action {
case ActionDisclosing:
session.Handler.RequestVerificationPermission(*session.irmaSession.(*DisclosureRequest), server, callback)
session.Handler.RequestVerificationPermission(
*session.irmaSession.(*DisclosureRequest), session.jwt.Requestor(), callback)
case ActionSigning:
session.Handler.RequestSignaturePermission(*session.irmaSession.(*SignatureRequest), server, callback)
session.Handler.RequestSignaturePermission(
*session.irmaSession.(*SignatureRequest), session.jwt.Requestor(), callback)
case ActionIssuing:
session.Handler.RequestIssuancePermission(*session.irmaSession.(*IssuanceRequest), server, callback)
session.Handler.RequestIssuancePermission(
*session.irmaSession.(*IssuanceRequest), session.jwt.Requestor(), callback)
default:
panic("Invalid session type") // does not happen, session.Action has been checked earlier
}
......
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