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

Prepend configurable server url to QR url field


Co-authored-by: Tomas's avatarConfiks <confiks@scriptbase.org>
parent 9b632683
......@@ -16,6 +16,7 @@ var Logger *logrus.Logger = logrus.StandardLogger()
type Configuration struct {
IrmaConfigurationPath string `json:"irmaconf" mapstructure:"irmaconf"`
IssuerPrivateKeysPath string `json:"privatekeys" mapstructure:"privatekeys"`
Url string `json:"url" mapstructure:"url"`
Logger *logrus.Logger `json:"-"`
IssuerPrivateKeys map[irma.IssuerIdentifier]*gabi.PrivateKey `json:"-"`
IrmaConfiguration *irma.Configuration `json:"-"`
......
......@@ -71,6 +71,14 @@ func Initialize(configuration *server.Configuration) error {
}
}
if conf.Url != "" {
if !strings.HasSuffix(conf.Url, "/") {
conf.Url = conf.Url + "/"
}
} else {
conf.Logger.Warn("No url parameter specified in configuration; unless an url is elsewhere prepended in the QR, the IRMA client will not be able to connect")
}
return nil
}
......@@ -98,7 +106,7 @@ func StartSession(request irma.SessionRequest) (*irma.Qr, string, error) {
conf.Logger.Infof("%s session started, token %s", action, session.token)
return &irma.Qr{
Type: action,
URL: session.token,
URL: conf.Url + session.token,
}, session.token, nil
}
......
......@@ -61,6 +61,7 @@ func setFlags(cmd *cobra.Command) error {
flags.StringP("privatekeys", "k", "", "path to IRMA private keys")
flags.StringP("jwtissuer", "j", "irmaserver", "JWT issuer")
flags.StringP("jwtprivatekey", "w", "", "JWT private key or path to it")
flags.StringP("url", "u", "", "External URL to server to which the IRMA client connects")
flags.IntP("port", "p", 8088, "Port at which to listen")
flags.Bool("noauth", false, "Whether or not to authenticate requestors")
flags.String("requestors", "", "Requestor configuration (in JSON)")
......@@ -110,7 +111,7 @@ func configure() error {
}
logger.Debug("Configuring")
logger.Debug("Log level ", logger.Level.String())
logger.Debug("Log level: ", logger.Level.String())
if err != nil {
if _, notfound := err.(viper.ConfigFileNotFoundError); notfound {
logger.Info("No configuration file found")
......@@ -126,7 +127,8 @@ func configure() error {
Configuration: &server.Configuration{
IrmaConfigurationPath: viper.GetString("irmaconf"),
IssuerPrivateKeysPath: viper.GetString("privatekeys"),
Logger: logger,
Url: viper.GetString("url"),
Logger: logger,
},
Port: viper.GetInt("port"),
DisableRequestorAuthentication: viper.GetBool("noauth"),
......
......@@ -32,8 +32,8 @@ type Configuration struct {
// Private key to sign result JWTs with. If absent, /result-jwt and /getproof are disabled.
JwtPrivateKey string `json:"jwtprivatekey" mapstructure:"jwtprivatekey"`
Verbose int
Quiet bool
Verbose int `json:"verbose" mapstructure:"verbose"`
Quiet bool `json:"quiet" mapstructure:"quiet"`
jwtPrivateKey *rsa.PrivateKey
}
......@@ -134,23 +134,29 @@ func (conf *Configuration) initialize() error {
conf.Logger.Info("No issuance whitelist found: allowing issuance of any credential (for which private keys are installed)")
conf.GlobalPermissions.Issuing = []string{"*"}
}
return nil
}
} else {
authenticators = map[AuthenticationMethod]Authenticator{
AuthenticationMethodPublicKey: &PublicKeyAuthenticator{publickeys: map[string]*rsa.PublicKey{}},
AuthenticationMethodToken: &PresharedKeyAuthenticator{presharedkeys: map[string]string{}},
}
authenticators = map[AuthenticationMethod]Authenticator{
AuthenticationMethodPublicKey: &PublicKeyAuthenticator{publickeys: map[string]*rsa.PublicKey{}},
AuthenticationMethodToken: &PresharedKeyAuthenticator{presharedkeys: map[string]string{}},
// Initialize authenticators
for name, requestor := range conf.Requestors {
authenticator, ok := authenticators[requestor.AuthenticationMethod]
if !ok {
return errors.Errorf("Requestor %s has unsupported authentication type")
}
if err := authenticator.Initialize(name, requestor); err != nil {
return err
}
}
}
// Initialize authenticators
for name, requestor := range conf.Requestors {
authenticator, ok := authenticators[requestor.AuthenticationMethod]
if !ok {
return errors.Errorf("Requestor %s has unsupported authentication type")
}
if err := authenticator.Initialize(name, requestor); err != nil {
return err
if conf.Url != "" {
if !strings.HasSuffix(conf.Url, "/") {
conf.Url = conf.Url + "/"
}
conf.Url = conf.Url + "irma/"
}
return nil
......
......@@ -44,10 +44,10 @@ func Stop() {
// and IRMA client messages.
func Handler(config *Configuration) (http.Handler, error) {
conf = config
if err := irmarequestor.Initialize(conf.Configuration); err != nil {
if err := conf.initialize(); err != nil {
return nil, err
}
if err := conf.initialize(); err != nil {
if err := irmarequestor.Initialize(conf.Configuration); err != nil {
return nil, err
}
......
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