Commit c1f78a8e authored by Sietse Ringers's avatar Sietse Ringers
Browse files

Use hostname instead of requestor name


Co-authored-by: Tomas's avatarConfiks <confiks@scriptbase.org>
parent b836f687
......@@ -3,6 +3,7 @@ package irmaclient
import (
"encoding/json"
"fmt"
"net/url"
"sort"
"strings"
......@@ -51,9 +52,10 @@ type SessionDismisser interface {
}
type session struct {
Action irma.Action
Handler Handler
Version *irma.ProtocolVersion
Action irma.Action
Handler Handler
Version *irma.ProtocolVersion
ServerName string
choice *irma.DisclosureChoice
client *Client
......@@ -106,15 +108,15 @@ func (client *Client) NewSession(sessionrequest string, handler Handler) Session
// newManualSession starts a manual session, given a signature request in JSON and a handler to pass messages to
func (client *Client) newManualSession(sigrequest *irma.SignatureRequest, handler Handler) SessionDismisser {
session := &session{
Action: irma.ActionSigning, // TODO hardcoded for now
Handler: handler,
client: client,
Version: irma.NewVersion(2, 0), // TODO hardcoded for now
request: sigrequest,
Action: irma.ActionSigning, // TODO hardcoded for now
Handler: handler,
client: client,
Version: irma.NewVersion(2, 0), // TODO hardcoded for now
ServerName: "Email request",
request: sigrequest,
}
session.Handler.StatusUpdate(session.Action, irma.StatusManualStarted)
sigrequest.RequestorName = "Email request"
session.processSessionInfo()
return session
}
......@@ -135,12 +137,14 @@ func (client *Client) newSchemeSession(qr *irma.SchemeManagerRequest, handler Ha
// newQrSession creates and starts a new interactive IRMA session
func (client *Client) newQrSession(qr *irma.Qr, handler Handler) SessionDismisser {
u, _ := url.ParseRequestURI(qr.URL) // Qr validator already checked this for errors
session := &session{
ServerURL: qr.URL,
transport: irma.NewHTTPTransport(qr.URL),
Action: irma.Action(qr.Type),
Handler: handler,
client: client,
ServerURL: qr.URL,
ServerName: u.Hostname(),
transport: irma.NewHTTPTransport(qr.URL),
Action: irma.Action(qr.Type),
Handler: handler,
client: client,
}
session.Handler.StatusUpdate(session.Action, irma.StatusCommunicating)
......@@ -228,7 +232,7 @@ func (session *session) processSessionInfo() {
candidates, missing := session.client.CheckSatisfiability(session.request.ToDisclose())
if len(missing) > 0 {
session.Handler.UnsatisfiableRequest(session.request.GetRequestorName(), missing)
session.Handler.UnsatisfiableRequest(session.ServerName, missing)
return
}
session.request.SetCandidates(candidates)
......@@ -243,13 +247,13 @@ func (session *session) processSessionInfo() {
switch session.Action {
case irma.ActionDisclosing:
session.Handler.RequestVerificationPermission(
*session.request.(*irma.DisclosureRequest), session.request.GetRequestorName(), callback)
*session.request.(*irma.DisclosureRequest), session.ServerName, callback)
case irma.ActionSigning:
session.Handler.RequestSignaturePermission(
*session.request.(*irma.SignatureRequest), session.request.GetRequestorName(), callback)
*session.request.(*irma.SignatureRequest), session.ServerName, callback)
case irma.ActionIssuing:
session.Handler.RequestIssuancePermission(
*session.request.(*irma.IssuanceRequest), session.request.GetRequestorName(), callback)
*session.request.(*irma.IssuanceRequest), session.ServerName, callback)
default:
panic("Invalid session type") // does not happen, session.Action has been checked earlier
}
......
......@@ -16,6 +16,10 @@ import (
"github.com/stretchr/testify/require"
)
func init() {
irma.ForceHttps = false
}
func getDisclosureJwt(name string, id irma.AttributeTypeIdentifier) interface{} {
return irma.NewServiceProviderJwt(name, &irma.DisclosureRequest{
Content: irma.AttributeDisjunctionList([]*irma.AttributeDisjunction{{
......
......@@ -17,6 +17,8 @@ import (
// Status encodes the status of an IRMA session (e.g., connected).
type Status string
var ForceHttps bool = true
// ProtocolVersion encodes the IRMA protocol version of an IRMA session.
type ProtocolVersion struct {
Major int
......@@ -251,13 +253,17 @@ func ParseRequestorJwt(action Action, jwt string) (RequestorJwt, error) {
return retval, nil
}
func (qr *Qr) Validate() error {
func (qr *Qr) Validate() (err error) {
if qr.URL == "" {
return errors.New("No URL specified")
}
if _, err := url.ParseRequestURI(qr.URL); err != nil {
var u *url.URL
if u, err = url.ParseRequestURI(qr.URL); err != nil {
return errors.Errorf("Invalid URL: %s", err.Error())
}
if ForceHttps && u.Scheme != "https" {
return errors.Errorf("URL did not begin with https")
}
switch qr.Type {
case ActionDisclosing: // nop
......
......@@ -17,10 +17,9 @@ import (
// BaseRequest contains the context and nonce for an IRMA session.
type BaseRequest struct {
Context *big.Int `json:"context"`
Nonce *big.Int `json:"nonce"`
RequestorName string `json:"requestorName"`
Type Action `json:"type"`
Context *big.Int `json:"context"`
Nonce *big.Int `json:"nonce"`
Type Action `json:"type"`
Candidates [][]*AttributeIdentifier `json:"-"`
Choice *DisclosureChoice `json:"-"`
......@@ -53,14 +52,6 @@ func (sr *BaseRequest) GetVersion() *ProtocolVersion {
return sr.Version
}
func (sr *BaseRequest) GetRequestorName() string {
return sr.RequestorName
}
func (sr *BaseRequest) SetRequestorName(name string) {
sr.RequestorName = name
}
// A DisclosureRequest is a request to disclose certain attributes.
type DisclosureRequest struct {
BaseRequest
......@@ -145,8 +136,6 @@ type SessionRequest interface {
SetContext(*big.Int)
GetVersion() *ProtocolVersion
SetVersion(*ProtocolVersion)
GetRequestorName() string
SetRequestorName(string)
ToDisclose() AttributeDisjunctionList
DisclosureChoice() *DisclosureChoice
SetDisclosureChoice(choice *DisclosureChoice)
......
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