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