Commit 00d4304b authored by Sietse Ringers's avatar Sietse Ringers
Browse files

feat: return pre-condiscon session result in server sessions started with legacy requests

parent 621ab863
...@@ -155,6 +155,7 @@ func (s *Server) newSession(action irma.Action, request irma.RequestorRequest) * ...@@ -155,6 +155,7 @@ 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(),
Token: token, Token: token,
Type: action, Type: action,
Status: server.StatusInitialized, Status: server.StatusInitialized,
......
...@@ -460,6 +460,7 @@ func TestSessionRequests(t *testing.T) { ...@@ -460,6 +460,7 @@ func TestSessionRequests(t *testing.T) {
for _, tst := range tests { for _, tst := range tests {
require.NoError(t, json.Unmarshal([]byte(tst.oldJson), tst.old)) require.NoError(t, json.Unmarshal([]byte(tst.oldJson), tst.old))
require.NoError(t, json.Unmarshal([]byte(tst.currentJson), tst.current)) require.NoError(t, json.Unmarshal([]byte(tst.currentJson), tst.current))
tst.old.Base().legacy = false
require.True(t, reflect.DeepEqual(tst.old, tst.expected), "Legacy %s did not unmarshal to expected value", reflect.TypeOf(tst.old).String()) require.True(t, reflect.DeepEqual(tst.old, tst.expected), "Legacy %s did not unmarshal to expected value", reflect.TypeOf(tst.old).String())
require.True(t, reflect.DeepEqual(tst.current, tst.expected), "%s did not unmarshal to expected value", reflect.TypeOf(tst.old).String()) require.True(t, reflect.DeepEqual(tst.current, tst.expected), "%s did not unmarshal to expected value", reflect.TypeOf(tst.old).String())
......
...@@ -198,6 +198,7 @@ func (dr *DisclosureRequest) UnmarshalJSON(bts []byte) (err error) { ...@@ -198,6 +198,7 @@ func (dr *DisclosureRequest) UnmarshalJSON(bts []byte) (err error) {
return err return err
} }
dr.BaseRequest = legacy.BaseRequest dr.BaseRequest = legacy.BaseRequest
dr.legacy = true
dr.Version = 2 dr.Version = 2
dr.Disclose, dr.Labels = convertDisjunctions(legacy.Content) dr.Disclose, dr.Labels = convertDisjunctions(legacy.Content)
...@@ -255,6 +256,7 @@ func (sr *SignatureRequest) UnmarshalJSON(bts []byte) (err error) { ...@@ -255,6 +256,7 @@ func (sr *SignatureRequest) UnmarshalJSON(bts []byte) (err error) {
return err return err
} }
sr.BaseRequest = legacy.BaseRequest sr.BaseRequest = legacy.BaseRequest
sr.legacy = true
sr.Version = 2 sr.Version = 2
sr.Disclose, sr.Labels = convertDisjunctions(legacy.Content) sr.Disclose, sr.Labels = convertDisjunctions(legacy.Content)
sr.Message = legacy.Message sr.Message = legacy.Message
...@@ -307,6 +309,7 @@ func (ir *IssuanceRequest) UnmarshalJSON(bts []byte) (err error) { ...@@ -307,6 +309,7 @@ func (ir *IssuanceRequest) UnmarshalJSON(bts []byte) (err error) {
return err return err
} }
ir.BaseRequest = legacy.BaseRequest ir.BaseRequest = legacy.BaseRequest
ir.legacy = true
ir.Version = 2 ir.Version = 2
ir.Credentials = legacy.Credentials ir.Credentials = legacy.Credentials
ir.Disclose, ir.Labels = convertDisjunctions(legacy.Disclose) ir.Disclose, ir.Labels = convertDisjunctions(legacy.Disclose)
......
...@@ -27,8 +27,8 @@ type BaseRequest struct { ...@@ -27,8 +27,8 @@ type BaseRequest struct {
Nonce *big.Int `json:"nonce,omitempty"` Nonce *big.Int `json:"nonce,omitempty"`
ProtocolVersion *ProtocolVersion `json:"protocolVersion,omitempty"` ProtocolVersion *ProtocolVersion `json:"protocolVersion,omitempty"`
// cache for Identifiers() method ids *IrmaIdentifierSet // cache for Identifiers() method
ids *IrmaIdentifierSet legacy bool
} }
// An AttributeCon is only satisfied if all of its containing attribute requests are satisfied. // An AttributeCon is only satisfied if all of its containing attribute requests are satisfied.
...@@ -177,6 +177,10 @@ var ( ...@@ -177,6 +177,10 @@ var (
bigOne = big.NewInt(1) bigOne = big.NewInt(1)
) )
func (b *BaseRequest) Legacy() bool {
return b.legacy
}
func (b *BaseRequest) GetContext() *big.Int { func (b *BaseRequest) GetContext() *big.Int {
if b.Context == nil { if b.Context == nil {
return bigOne return bigOne
......
...@@ -82,6 +82,8 @@ type SessionResult struct { ...@@ -82,6 +82,8 @@ type SessionResult struct {
Disclosed [][]*irma.DisclosedAttribute `json:"disclosed,omitempty"` Disclosed [][]*irma.DisclosedAttribute `json:"disclosed,omitempty"`
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
} }
// Status is the status of an IRMA session. // Status is the status of an IRMA session.
...@@ -95,6 +97,28 @@ const ( ...@@ -95,6 +97,28 @@ const (
StatusTimeout Status = "TIMEOUT" // Session timed out StatusTimeout Status = "TIMEOUT" // Session timed out
) )
// Remove this when dropping support for legacy pre-condiscon session requests
func (r *SessionResult) MarshalJSON() ([]byte, error) {
if !r.Legacy {
type tmpSessionResult SessionResult
return json.Marshal((*tmpSessionResult)(r))
}
var disclosed []*irma.DisclosedAttribute
for _, l := range r.Disclosed {
disclosed = append(disclosed, l[0])
}
return json.Marshal(struct {
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) {
sk = conf.IssuerPrivateKeys[id] sk = conf.IssuerPrivateKeys[id]
if sk == nil { if sk == nil {
......
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