Commit 808ddb58 authored by Sietse Ringers's avatar Sietse Ringers
Browse files

Make server and session request struct naming more consistent

parent bd85535a
...@@ -21,8 +21,8 @@ func TestTimestamp(t *testing.T) { ...@@ -21,8 +21,8 @@ func TestTimestamp(t *testing.T) {
require.Equal(t, time.Time(*timestruct.Time).Unix(), int64(1500000000)) require.Equal(t, time.Time(*timestruct.Time).Unix(), int64(1500000000))
} }
func TestServiceProviderRequest(t *testing.T) { func TestServiceProvider(t *testing.T) {
var sprequest ServiceProviderRequest var spjwt ServiceProviderJwt
var spjson = `{ var spjson = `{
"sprequest": { "sprequest": {
...@@ -39,16 +39,16 @@ func TestServiceProviderRequest(t *testing.T) { ...@@ -39,16 +39,16 @@ func TestServiceProviderRequest(t *testing.T) {
} }
}` }`
require.NoError(t, json.Unmarshal([]byte(spjson), &sprequest)) require.NoError(t, json.Unmarshal([]byte(spjson), &spjwt))
require.NotNil(t, sprequest.Request.Request.Content) require.NotNil(t, spjwt.Request.Request.Content)
require.NotEmpty(t, sprequest.Request.Request.Content) require.NotEmpty(t, spjwt.Request.Request.Content)
require.NotNil(t, sprequest.Request.Request.Content[0]) require.NotNil(t, spjwt.Request.Request.Content[0])
require.NotEmpty(t, sprequest.Request.Request.Content[0]) require.NotEmpty(t, spjwt.Request.Request.Content[0])
require.NotNil(t, sprequest.Request.Request.Content[0].Attributes) require.NotNil(t, spjwt.Request.Request.Content[0].Attributes)
require.NotEmpty(t, sprequest.Request.Request.Content[0].Attributes) require.NotEmpty(t, spjwt.Request.Request.Content[0].Attributes)
require.Equal(t, sprequest.Request.Request.Content[0].Attributes[0].Name(), "studentID") require.Equal(t, spjwt.Request.Request.Content[0].Attributes[0].Name(), "studentID")
require.NotNil(t, sprequest.Request.Request.Content.Find(irmago.NewAttributeTypeIdentifier("irma-demo.RU.studentCard.studentID"))) require.NotNil(t, spjwt.Request.Request.Content.Find(irmago.NewAttributeTypeIdentifier("irma-demo.RU.studentCard.studentID")))
} }
func TestTransport(t *testing.T) { func TestTransport(t *testing.T) {
......
...@@ -28,6 +28,12 @@ type SignatureRequest struct { ...@@ -28,6 +28,12 @@ type SignatureRequest struct {
MessageType string `json:"messageType"` MessageType string `json:"messageType"`
} }
type IssuanceRequest struct {
SessionRequest
Credentials []CredentialRequest `json:"credentials"`
Disclose irmago.AttributeDisjunctionList `json:"disclose"`
}
type CredentialRequest struct { type CredentialRequest struct {
Validity *Timestamp Validity *Timestamp
KeyCounter int KeyCounter int
...@@ -35,55 +41,51 @@ type CredentialRequest struct { ...@@ -35,55 +41,51 @@ type CredentialRequest struct {
Attributes map[string]string Attributes map[string]string
} }
type ServerRequest struct { type ServerJwt struct {
ServerName string `json:"iss"` ServerName string `json:"iss"`
IssuedAt *Timestamp `json:"iat"` IssuedAt *Timestamp `json:"iat"`
Type string `json:"sub"` Type string `json:"sub"`
} }
type IssuanceRequest struct { type ServiceProviderRequest struct {
SessionRequest Request DisclosureRequest `json:"request"`
Credentials []CredentialRequest `json:"credentials"`
Disclose irmago.AttributeDisjunctionList `json:"disclose"`
} }
type DisclosureRequestContainer struct { type SignatureServerRequest struct {
Request DisclosureRequest `json:"request"` Request SignatureRequest `json:"request"`
} }
type ServiceProviderRequest struct { type IdentityProviderRequest struct {
ServerRequest Request IssuanceRequest `json:"request"`
Request DisclosureRequestContainer `json:"sprequest"` }
type ServiceProviderJwt struct {
ServerJwt
Request ServiceProviderRequest `json:"sprequest"`
}
type SignatureServerJwt struct {
ServerJwt
Request SignatureServerRequest `json:"sigrequest"`
}
type IdentityProviderJwt struct {
ServerJwt
Request IdentityProviderRequest `json:"iprequest"`
} }
func NewServiceProviderRequest(servername string, dr DisclosureRequest) *ServiceProviderRequest { func NewServiceProviderJwt(servername string, dr DisclosureRequest) *ServiceProviderJwt {
now := Timestamp(time.Now()) now := Timestamp(time.Now())
return &ServiceProviderRequest{ return &ServiceProviderJwt{
ServerRequest: ServerRequest{ ServerJwt: ServerJwt{
ServerName: servername, ServerName: servername,
IssuedAt: &now, IssuedAt: &now,
Type: "verification_request", Type: "verification_request",
}, },
Request: DisclosureRequestContainer{ Request: ServiceProviderRequest{Request: dr},
Request: dr,
},
} }
} }
type SignatureServerRequest struct {
ServerRequest
Request struct {
Request SignatureRequest `json:"request"`
} `json:"sigrequest"`
}
type IdentityProviderRequest struct {
ServerRequest
Request struct {
Request IssuanceRequest `json:"request"`
} `json:"iprequest"`
}
func (dr *DisclosureRequest) GetContext() *big.Int { func (dr *DisclosureRequest) GetContext() *big.Int {
return dr.Context return dr.Context
} }
...@@ -110,14 +112,14 @@ func (sr *SignatureRequest) GetNonce() *big.Int { ...@@ -110,14 +112,14 @@ func (sr *SignatureRequest) GetNonce() *big.Int {
return new(big.Int).SetBytes(asn1hash[:]) return new(big.Int).SetBytes(asn1hash[:])
} }
func (spr *ServiceProviderRequest) DisjunctionList() irmago.AttributeDisjunctionList { func (spr *ServiceProviderJwt) DisjunctionList() irmago.AttributeDisjunctionList {
return spr.Request.Request.Content return spr.Request.Request.Content
} }
func (ssr *SignatureServerRequest) DisjunctionList() irmago.AttributeDisjunctionList { func (ssr *SignatureServerJwt) DisjunctionList() irmago.AttributeDisjunctionList {
return ssr.Request.Request.Content return ssr.Request.Request.Content
} }
func (ipr *IdentityProviderRequest) DisjunctionList() irmago.AttributeDisjunctionList { func (ipr *IdentityProviderJwt) DisjunctionList() irmago.AttributeDisjunctionList {
return ipr.Request.Request.Disclose return ipr.Request.Request.Disclose
} }
...@@ -33,9 +33,9 @@ type Session struct { ...@@ -33,9 +33,9 @@ type Session struct {
Handler Handler Handler Handler
request irmago.DisjunctionListContainer request irmago.DisjunctionListContainer
spRequest *ServiceProviderRequest spRequest *ServiceProviderJwt
ipRequest *IdentityProviderRequest ipRequest *IdentityProviderJwt
ssRequest *SignatureServerRequest ssRequest *SignatureServerJwt
transport *HTTPTransport transport *HTTPTransport
nonce *big.Int nonce *big.Int
...@@ -106,13 +106,13 @@ func (session *Session) start() { ...@@ -106,13 +106,13 @@ func (session *Session) start() {
switch session.Action { switch session.Action {
case ActionDisclosing: case ActionDisclosing:
session.spRequest = &ServiceProviderRequest{} session.spRequest = &ServiceProviderJwt{}
session.request = session.spRequest session.request = session.spRequest
case ActionSigning: case ActionSigning:
session.ssRequest = &SignatureServerRequest{} session.ssRequest = &SignatureServerJwt{}
session.request = session.ssRequest session.request = session.ssRequest
case ActionIssuing: case ActionIssuing:
session.ipRequest = &IdentityProviderRequest{} session.ipRequest = &IdentityProviderJwt{}
session.request = session.ipRequest session.request = session.ipRequest
default: default:
panic("Invalid session type") // does not happen, session.Action has been checked earlier panic("Invalid session type") // does not happen, session.Action has been checked earlier
...@@ -120,7 +120,7 @@ func (session *Session) start() { ...@@ -120,7 +120,7 @@ func (session *Session) start() {
if session.Action == ActionIssuing { if session.Action == ActionIssuing {
// Store which public keys the server will use // Store which public keys the server will use
for _, credreq := range session.request.(*IdentityProviderRequest).Request.Request.Credentials { for _, credreq := range session.request.(*IdentityProviderJwt).Request.Request.Credentials {
credreq.KeyCounter = info.Keys[credreq.Credential.IssuerIdentifier()] credreq.KeyCounter = info.Keys[credreq.Credential.IssuerIdentifier()]
} }
} }
......
...@@ -48,7 +48,7 @@ func TestSession(t *testing.T) { ...@@ -48,7 +48,7 @@ func TestSession(t *testing.T) {
url := "https://demo.irmacard.org/tomcat/irma_api_server/api/v2" url := "https://demo.irmacard.org/tomcat/irma_api_server/api/v2"
name := "testsp" name := "testsp"
spRequest := NewServiceProviderRequest(name, DisclosureRequest{ spRequest := NewServiceProviderJwt(name, DisclosureRequest{
Content: irmago.AttributeDisjunctionList([]*irmago.AttributeDisjunction{ Content: irmago.AttributeDisjunctionList([]*irmago.AttributeDisjunction{
&irmago.AttributeDisjunction{ &irmago.AttributeDisjunction{
Label: "foo", Label: "foo",
......
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