Commit 02661ae6 authored by Sietse Ringers's avatar Sietse Ringers
Browse files

Rename SessionRequest -> BaseRequest and IrmaSession -> SessionRequest

parent 4b5f86fd
......@@ -4,8 +4,8 @@ import (
"crypto/rand"
"math/big"
"sort"
"time"
"strconv"
"time"
"github.com/credentials/go-go-gadget-paillier"
raven "github.com/getsentry/raven-go"
......@@ -533,7 +533,7 @@ func (client *Client) groupCredentials(choice *irma.DisclosureChoice) (map[irma.
}
// ProofBuilders constructs a list of proof builders for the specified attribute choice.
func (client *Client) ProofBuilders(choice *irma.DisclosureChoice, request irma.IrmaSession, issig bool) (gabi.ProofBuilderList, error) {
func (client *Client) ProofBuilders(choice *irma.DisclosureChoice, request irma.SessionRequest, issig bool) (gabi.ProofBuilderList, error) {
todisclose, err := client.groupCredentials(choice)
if err != nil {
return nil, err
......@@ -569,7 +569,7 @@ func (client *Client) ProofBuilders(choice *irma.DisclosureChoice, request irma.
}
// Proofs computes disclosure proofs containing the attributes specified by choice.
func (client *Client) Proofs(choice *irma.DisclosureChoice, request irma.IrmaSession, issig bool) (gabi.ProofList, error) {
func (client *Client) Proofs(choice *irma.DisclosureChoice, request irma.SessionRequest, issig bool) (gabi.ProofList, error) {
builders, err := client.ProofBuilders(choice, request, issig)
if err != nil {
return nil, err
......
......@@ -37,7 +37,7 @@ type keyshareSession struct {
sessionHandler keyshareSessionHandler
pinRequestor KeysharePinRequestor
builders gabi.ProofBuilderList
session irma.IrmaSession
session irma.SessionRequest
conf *irma.Configuration
keyshareServers map[irma.SchemeManagerIdentifier]*keyshareServer
keyshareServer *keyshareServer // The one keyshare server in use in case of issuance
......@@ -64,8 +64,8 @@ type keyshareEnrollment struct {
type keyshareChangepin struct {
Username string `json:"id"`
OldPin string `json:"oldpin"`
NewPin string `json:"newpin"`
OldPin string `json:"oldpin"`
NewPin string `json:"newpin"`
}
type keyshareAuthorization struct {
......@@ -153,7 +153,7 @@ func startKeyshareSession(
sessionHandler keyshareSessionHandler,
pin KeysharePinRequestor,
builders gabi.ProofBuilderList,
session irma.IrmaSession,
session irma.SessionRequest,
conf *irma.Configuration,
keyshareServers map[irma.SchemeManagerIdentifier]*keyshareServer,
state *issuanceState,
......
......@@ -54,7 +54,7 @@ func (entry *LogEntry) GetIssuedCredentials(conf *irma.Configuration) (list irma
if err != nil {
return
}
ir := jwt.IrmaSession().(*irma.IssuanceRequest)
ir := jwt.SessionRequest().(*irma.IssuanceRequest)
return ir.GetCredentialInfoList(conf, entry.Version)
}
......@@ -85,7 +85,7 @@ func (session *session) createLogEntry(response interface{}) (*LogEntry, error)
case irma.ActionSigning:
// Get the signed message and timestamp
request := session.irmaSession.(*irma.SignatureRequest)
request := session.request.(*irma.SignatureRequest)
entry.SignedMessage = []byte(request.Message)
entry.Timestamp = request.Timestamp
......
......@@ -56,10 +56,10 @@ type session struct {
Handler Handler
Version *irma.ProtocolVersion
choice *irma.DisclosureChoice
client *Client
irmaSession irma.IrmaSession
done bool
choice *irma.DisclosureChoice
client *Client
request irma.SessionRequest
done bool
// These are empty on manual sessions
ServerURL string
......@@ -121,11 +121,11 @@ func (session *session) getBuilders() (gabi.ProofBuilderList, error) {
switch session.Action {
case irma.ActionSigning:
builders, err = session.client.ProofBuilders(session.choice, session.irmaSession, true)
builders, err = session.client.ProofBuilders(session.choice, session.request, true)
case irma.ActionDisclosing:
builders, err = session.client.ProofBuilders(session.choice, session.irmaSession, false)
builders, err = session.client.ProofBuilders(session.choice, session.request, false)
case irma.ActionIssuing:
builders, err = session.client.IssuanceProofBuilders(session.irmaSession.(*irma.IssuanceRequest))
builders, err = session.client.IssuanceProofBuilders(session.request.(*irma.IssuanceRequest))
}
return builders, err
......@@ -137,11 +137,11 @@ func (session *session) getProof() (interface{}, error) {
switch session.Action {
case irma.ActionSigning:
message, err = session.client.Proofs(session.choice, session.irmaSession, true)
message, err = session.client.Proofs(session.choice, session.request, true)
case irma.ActionDisclosing:
message, err = session.client.Proofs(session.choice, session.irmaSession, false)
message, err = session.client.Proofs(session.choice, session.request, false)
case irma.ActionIssuing:
message, err = session.client.IssueCommitments(session.irmaSession.(*irma.IssuanceRequest))
message, err = session.client.IssueCommitments(session.request.(*irma.IssuanceRequest))
}
return message, err
......@@ -150,7 +150,7 @@ func (session *session) getProof() (interface{}, error) {
// checkKeyshareEnrollment checks if we are enrolled into all involved keyshare servers,
// and aborts the session if not
func (session *session) checkKeyshareEnrollment() bool {
for id := range session.irmaSession.Identifiers().SchemeManagers {
for id := range session.request.Identifiers().SchemeManagers {
manager, ok := session.client.Configuration.SchemeManagers[id]
if !ok {
session.Handler.Failure(session.Action, &irma.SessionError{ErrorType: irma.ErrorUnknownSchemeManager, Info: id.String()})
......@@ -175,7 +175,7 @@ func (session *session) panicFailure() {
}
func (session *session) checkAndUpateConfiguration() bool {
for id := range session.irmaSession.Identifiers().SchemeManagers {
for id := range session.request.Identifiers().SchemeManagers {
manager, contains := session.client.Configuration.SchemeManagers[id]
if !contains {
session.fail(&irma.SessionError{
......@@ -199,7 +199,7 @@ func (session *session) checkAndUpateConfiguration() bool {
}
// Download missing credential types/issuers/public keys from the scheme manager
downloaded, err := session.client.Configuration.Download(session.irmaSession)
downloaded, err := session.client.Configuration.Download(session.request)
if err != nil {
session.fail(&irma.SessionError{ErrorType: irma.ErrorConfigurationDownload, Err: err})
return false
......@@ -220,11 +220,11 @@ func (client *Client) NewManualSession(sigrequestJSONString string, handler Hand
}
session := &session{
Action: irma.ActionSigning, // TODO hardcoded for now
Handler: handler,
client: client,
Version: irma.NewVersion(2, 0), // TODO hardcoded for now
irmaSession: sigrequest,
Action: irma.ActionSigning, // TODO hardcoded for now
Handler: handler,
client: client,
Version: irma.NewVersion(2, 0), // TODO hardcoded for now
request: sigrequest,
}
session.Handler.StatusUpdate(session.Action, irma.StatusManualStarted)
......@@ -233,21 +233,21 @@ func (client *Client) NewManualSession(sigrequestJSONString string, handler Hand
return
}
candidates, missing := session.client.CheckSatisfiability(session.irmaSession.ToDisclose())
candidates, missing := session.client.CheckSatisfiability(session.request.ToDisclose())
if len(missing) > 0 {
session.Handler.UnsatisfiableRequest(session.Action, "E-mail request", missing)
return
}
session.irmaSession.SetCandidates(candidates)
session.request.SetCandidates(candidates)
// Ask for permission to execute the session
callback := PermissionHandler(func(proceed bool, choice *irma.DisclosureChoice) {
session.choice = choice
session.irmaSession.SetDisclosureChoice(choice)
session.request.SetDisclosureChoice(choice)
go session.do(proceed)
})
session.Handler.RequestSignaturePermission(
*session.irmaSession.(*irma.SignatureRequest), "E-mail request", callback)
*session.request.(*irma.SignatureRequest), "E-mail request", callback)
}
// NewSession creates and starts a new interactive IRMA session
......@@ -315,12 +315,12 @@ func (session *session) start() {
session.fail(&irma.SessionError{ErrorType: irma.ErrorInvalidJWT, Err: err})
return
}
session.irmaSession = session.jwt.IrmaSession()
session.irmaSession.SetContext(session.info.Context)
session.irmaSession.SetNonce(session.info.Nonce)
session.irmaSession.SetVersion(session.Version)
session.request = session.jwt.SessionRequest()
session.request.SetContext(session.info.Context)
session.request.SetNonce(session.info.Nonce)
session.request.SetVersion(session.Version)
if session.Action == irma.ActionIssuing {
ir := session.irmaSession.(*irma.IssuanceRequest)
ir := session.request.(*irma.IssuanceRequest)
// Store which public keys the server will use
for _, credreq := range ir.Credentials {
credreq.KeyCounter = session.info.Keys[credreq.CredentialTypeID.IssuerIdentifier()]
......@@ -332,7 +332,7 @@ func (session *session) start() {
}
if session.Action == irma.ActionIssuing {
ir := session.irmaSession.(*irma.IssuanceRequest)
ir := session.request.(*irma.IssuanceRequest)
_, err := ir.GetCredentialInfoList(session.client.Configuration, session.Version)
if err != nil {
session.fail(&irma.SessionError{ErrorType: irma.ErrorUnknownCredentialType, Err: err})
......@@ -348,30 +348,30 @@ func (session *session) start() {
}
}
candidates, missing := session.client.CheckSatisfiability(session.irmaSession.ToDisclose())
candidates, missing := session.client.CheckSatisfiability(session.request.ToDisclose())
if len(missing) > 0 {
session.Handler.UnsatisfiableRequest(session.Action, session.jwt.Requestor(), missing)
return
}
session.irmaSession.SetCandidates(candidates)
session.request.SetCandidates(candidates)
// Ask for permission to execute the session
callback := PermissionHandler(func(proceed bool, choice *irma.DisclosureChoice) {
session.choice = choice
session.irmaSession.SetDisclosureChoice(choice)
session.request.SetDisclosureChoice(choice)
go session.do(proceed)
})
session.Handler.StatusUpdate(session.Action, irma.StatusConnected)
switch session.Action {
case irma.ActionDisclosing:
session.Handler.RequestVerificationPermission(
*session.irmaSession.(*irma.DisclosureRequest), session.jwt.Requestor(), callback)
*session.request.(*irma.DisclosureRequest), session.jwt.Requestor(), callback)
case irma.ActionSigning:
session.Handler.RequestSignaturePermission(
*session.irmaSession.(*irma.SignatureRequest), session.jwt.Requestor(), callback)
*session.request.(*irma.SignatureRequest), session.jwt.Requestor(), callback)
case irma.ActionIssuing:
session.Handler.RequestIssuancePermission(
*session.irmaSession.(*irma.IssuanceRequest), session.jwt.Requestor(), callback)
*session.request.(*irma.IssuanceRequest), session.jwt.Requestor(), callback)
default:
panic("Invalid session type") // does not happen, session.Action has been checked earlier
}
......@@ -402,7 +402,7 @@ func (session *session) do(proceed bool) {
session,
session.Handler,
builders,
session.irmaSession,
session.request,
session.client.Configuration,
session.client.keyshareServers,
session.client.state,
......@@ -413,7 +413,7 @@ func (session *session) do(proceed bool) {
func (session *session) Distributed() bool {
var smi irma.SchemeManagerIdentifier
if session.Action == irma.ActionIssuing {
for _, credreq := range session.irmaSession.(*irma.IssuanceRequest).Credentials {
for _, credreq := range session.request.(*irma.IssuanceRequest).Credentials {
smi = credreq.CredentialTypeID.IssuerIdentifier().SchemeManagerIdentifier()
if session.client.Configuration.SchemeManagers[smi].Distributed() {
return true
......@@ -483,7 +483,7 @@ func (session *session) sendResponse(message interface{}) {
switch session.Action {
case irma.ActionSigning:
request, ok := session.irmaSession.(*irma.SignatureRequest)
request, ok := session.request.(*irma.SignatureRequest)
if !ok {
session.fail(&irma.SessionError{ErrorType: irma.ErrorSerialization, Info: "Type assertion failed"})
return
......@@ -530,7 +530,7 @@ func (session *session) sendResponse(message interface{}) {
session.fail(err.(*irma.SessionError))
return
}
if err = session.client.ConstructCredentials(response, session.irmaSession.(*irma.IssuanceRequest)); err != nil {
if err = session.client.ConstructCredentials(response, session.request.(*irma.IssuanceRequest)); err != nil {
session.fail(&irma.SessionError{ErrorType: irma.ErrorCrypto, Err: err})
return
}
......
......@@ -73,8 +73,8 @@ func (th TestHandler) RequestVerificationPermission(request irma.DisclosureReque
}
func (th TestHandler) RequestIssuancePermission(request irma.IssuanceRequest, ServerName string, callback PermissionHandler) {
dreq := irma.DisclosureRequest{
SessionRequest: request.SessionRequest,
Content: request.Disclose,
BaseRequest: request.BaseRequest,
Content: request.Disclose,
}
th.RequestVerificationPermission(dreq, ServerName, callback)
}
......@@ -101,7 +101,7 @@ func getSigningJwt(name string, id irma.AttributeTypeIdentifier) interface{} {
return irma.NewSignatureRequestorJwt(name, &irma.SignatureRequest{
Message: "test",
DisclosureRequest: irma.DisclosureRequest{
SessionRequest: irma.SessionRequest{
BaseRequest: irma.BaseRequest{
Nonce: big.NewInt(1),
Context: big.NewInt(1),
},
......
......@@ -137,7 +137,7 @@ var clientUpdates = []func(client *Client) error{
if err != nil {
return
}
for _, attr := range jwt.IrmaSession().(*irma.IssuanceRequest).Credentials[0].Attributes {
for _, attr := range jwt.SessionRequest().(*irma.IssuanceRequest).Credentials[0].Attributes {
if regexp.MustCompile("^\\w").Match([]byte(attr)) {
entry.Version = irma.NewVersion(2, 2)
} else {
......
......@@ -641,7 +641,7 @@ func (conf *Configuration) DownloadSchemeManagerSignature(manager *SchemeManager
// Download downloads the issuers, credential types and public keys specified in set
// if the current Configuration does not already have them, and checks their authenticity
// using the scheme manager index.
func (conf *Configuration) Download(session IrmaSession) (downloaded *IrmaIdentifierSet, err error) {
func (conf *Configuration) Download(session SessionRequest) (downloaded *IrmaIdentifierSet, err error) {
managers := make(map[string]struct{}) // Managers that we must update
downloaded = &IrmaIdentifierSet{
SchemeManagers: map[SchemeManagerIdentifier]struct{}{},
......@@ -669,7 +669,7 @@ func (conf *Configuration) Download(session IrmaSession) (downloaded *IrmaIdenti
return
}
func (conf *Configuration) checkCredentialTypes(session IrmaSession, managers map[string]struct{}) error {
func (conf *Configuration) checkCredentialTypes(session SessionRequest, managers map[string]struct{}) error {
var disjunctions AttributeDisjunctionList
var typ *CredentialType
var contains bool
......
......@@ -15,8 +15,8 @@ import (
"github.com/privacybydesign/irmago/internal/fs"
)
// SessionRequest contains the context and nonce for an IRMA session.
type SessionRequest struct {
// BaseRequest contains the context and nonce for an IRMA session.
type BaseRequest struct {
Context *big.Int `json:"context"`
Nonce *big.Int `json:"nonce"`
Candidates [][]*AttributeIdentifier `json:"-"`
......@@ -27,33 +27,33 @@ type SessionRequest struct {
version *ProtocolVersion
}
func (sr *SessionRequest) SetCandidates(candidates [][]*AttributeIdentifier) {
func (sr *BaseRequest) SetCandidates(candidates [][]*AttributeIdentifier) {
sr.Candidates = candidates
}
// DisclosureChoice returns the attributes to be disclosed in this session.
func (sr *SessionRequest) DisclosureChoice() *DisclosureChoice {
func (sr *BaseRequest) DisclosureChoice() *DisclosureChoice {
return sr.Choice
}
// SetDisclosureChoice sets the attributes to be disclosed in this session.
func (sr *SessionRequest) SetDisclosureChoice(choice *DisclosureChoice) {
func (sr *BaseRequest) SetDisclosureChoice(choice *DisclosureChoice) {
sr.Choice = choice
}
// ...
func (sr *SessionRequest) SetVersion(v *ProtocolVersion) {
func (sr *BaseRequest) SetVersion(v *ProtocolVersion) {
sr.version = v
}
// ...
func (sr *SessionRequest) GetVersion() *ProtocolVersion {
func (sr *BaseRequest) GetVersion() *ProtocolVersion {
return sr.version
}
// A DisclosureRequest is a request to disclose certain attributes.
type DisclosureRequest struct {
SessionRequest
BaseRequest
Content AttributeDisjunctionList `json:"content"`
}
......@@ -67,7 +67,7 @@ type SignatureRequest struct {
// An IssuanceRequest is a request to issue certain credentials,
// optionally also asking for certain attributes to be simultaneously disclosed.
type IssuanceRequest struct {
SessionRequest
BaseRequest
Credentials []*CredentialRequest `json:"credentials"`
Disclose AttributeDisjunctionList `json:"disclose"`
......@@ -125,8 +125,8 @@ type IdentityProviderJwt struct {
Request IdentityProviderRequest `json:"iprequest"`
}
// IrmaSession is an IRMA session.
type IrmaSession interface {
// SessionRequest is an IRMA session.
type SessionRequest interface {
GetNonce() *big.Int
SetNonce(*big.Int)
GetContext() *big.Int
......@@ -468,17 +468,17 @@ func NewIdentityProviderJwt(servername string, ir *IssuanceRequest) *IdentityPro
// A RequestorJwt contains an IRMA session object.
type RequestorJwt interface {
IrmaSession() IrmaSession
SessionRequest() SessionRequest
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 }
// SessionRequest returns an IRMA session object.
func (jwt *ServiceProviderJwt) SessionRequest() SessionRequest { return jwt.Request.Request }
// IrmaSession returns an IRMA session object.
func (jwt *SignatureRequestorJwt) IrmaSession() IrmaSession { return jwt.Request.Request }
// SessionRequest returns an IRMA session object.
func (jwt *SignatureRequestorJwt) SessionRequest() SessionRequest { return jwt.Request.Request }
// IrmaSession returns an IRMA session object.
func (jwt *IdentityProviderJwt) IrmaSession() IrmaSession { return jwt.Request.Request }
// SessionRequest returns an IRMA session object.
func (jwt *IdentityProviderJwt) SessionRequest() SessionRequest { return jwt.Request.Request }
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