Commit 5e82e425 authored by Sietse Ringers's avatar Sietse Ringers
Browse files

Renaming variables and urls in server


Co-authored-by: Tomas's avatarConfiks <confiks@scriptbase.org>
parent 12dbf5a9
......@@ -62,9 +62,9 @@ var JwtServerConfiguration = &irmaserver.Configuration{
AuthenticationKey: filepath.Join(testdata, "jwtkeys", "requestor1.pem"),
},
"requestor2": {
AuthenticationMethod: irmaserver.AuthenticationMethodPSK,
AuthenticationMethod: irmaserver.AuthenticationMethodToken,
AuthenticationKey: "xa6=*&9?8jeUu5>.f-%rVg`f63pHim",
},
},
PrivateKey: filepath.Join(testdata, "jwtkeys", "sk.pem"),
JwtPrivateKey: filepath.Join(testdata, "jwtkeys", "sk.pem"),
}
......@@ -123,12 +123,12 @@ func startSession(t *testing.T, request irma.SessionRequest, sessiontype string)
qr.URL = url + "/" + qr.URL
case "irmaserver-jwt":
url := "http://localhost:48682"
err = irma.NewHTTPTransport(url).Post("create", &qr, getJwt(t, request, sessiontype, true))
err = irma.NewHTTPTransport(url).Post("session", &qr, getJwt(t, request, sessiontype, true))
token = qr.URL
qr.URL = url + "/irma/" + qr.URL
case "irmaserver":
url := "http://localhost:48682"
err = irma.NewHTTPTransport(url).Post("create", &qr, request)
err = irma.NewHTTPTransport(url).Post("session", &qr, request)
token = qr.URL
qr.URL = url + "/irma/" + qr.URL
default:
......
......@@ -136,7 +136,7 @@ func HandleProtocolMessage(
// Fetch the session
token := matches[1]
verb := matches[2]
noun := matches[2]
session := sessions.get(token)
if session == nil {
conf.Logger.Warnf("Session not found: %s", token)
......@@ -158,7 +158,7 @@ func HandleProtocolMessage(
}()
// Route to handler
switch len(verb) {
switch len(noun) {
case 0:
if method == http.MethodDelete {
session.handleDelete()
......@@ -188,7 +188,7 @@ func HandleProtocolMessage(
return
}
if verb == "commitments" && session.action == irma.ActionIssuing {
if noun == "commitments" && session.action == irma.ActionIssuing {
commitments := &gabi.IssueCommitmentMessage{}
if err := irma.UnmarshalValidate(message, commitments); err != nil {
status, output = server.JsonResponse(nil, session.fail(server.ErrorMalformedInput, ""))
......@@ -197,7 +197,7 @@ func HandleProtocolMessage(
status, output = server.JsonResponse(session.handlePostCommitments(commitments))
return
}
if verb == "proofs" && session.action == irma.ActionDisclosing {
if noun == "proofs" && session.action == irma.ActionDisclosing {
proofs := gabi.ProofList{}
if err := irma.UnmarshalValidate(message, &proofs); err != nil {
status, output = server.JsonResponse(nil, session.fail(server.ErrorMalformedInput, ""))
......@@ -206,7 +206,7 @@ func HandleProtocolMessage(
status, output = server.JsonResponse(session.handlePostProofs(proofs))
return
}
if verb == "proofs" && session.action == irma.ActionSigning {
if noun == "proofs" && session.action == irma.ActionSigning {
signature := &irma.SignedMessage{}
if err := irma.UnmarshalValidate(message, signature); err != nil {
status, output = server.JsonResponse(nil, session.fail(server.ErrorMalformedInput, ""))
......
......@@ -37,7 +37,7 @@ type AuthenticationMethod string
// Currently supported requestor authentication methods
const (
AuthenticationMethodPublicKey = "publickey"
AuthenticationMethodPSK = "psk"
AuthenticationMethodToken = "token"
AuthenticationMethodNone = "none"
)
......
......@@ -24,10 +24,10 @@ type Configuration struct {
Requestors map[string]Requestor // Requestor-specific permission and authentication configuration
GlobalPermissions Permissions // Disclosing, signing or issuance permissions that apply to all requestors
JwtIssuer string // Used in the "iss" field of result JWTs from /result-jwt and /getproof
PrivateKey string // Private key to sign result JWTs with. If absent, /result-jwt and /getproof are disabled.
JwtIssuer string // Used in the "iss" field of result JWTs from /result-jwt and /getproof
JwtPrivateKey string // Private key to sign result JWTs with. If absent, /result-jwt and /getproof are disabled.
privateKey *rsa.PrivateKey
jwtPrivateKey *rsa.PrivateKey
}
// Permissions specify which attributes or credential a requestor may verify or issue.
......@@ -131,7 +131,7 @@ func (conf *Configuration) initialize() error {
authenticators = map[AuthenticationMethod]Authenticator{
AuthenticationMethodPublicKey: &PublicKeyAuthenticator{publickeys: map[string]*rsa.PublicKey{}},
AuthenticationMethodPSK: &PresharedKeyAuthenticator{presharedkeys: map[string]string{}},
AuthenticationMethodToken: &PresharedKeyAuthenticator{presharedkeys: map[string]string{}},
}
// Initialize authenticators
......@@ -149,24 +149,24 @@ func (conf *Configuration) initialize() error {
}
func (conf *Configuration) readPrivateKey() error {
if conf.PrivateKey == "" {
if conf.JwtPrivateKey == "" {
return nil
}
var keybytes []byte
var err error
if strings.HasPrefix(conf.PrivateKey, "-----BEGIN") {
keybytes = []byte(conf.PrivateKey)
if strings.HasPrefix(conf.JwtPrivateKey, "-----BEGIN") {
keybytes = []byte(conf.JwtPrivateKey)
} else {
if err = fs.AssertPathExists(conf.PrivateKey); err != nil {
if err = fs.AssertPathExists(conf.JwtPrivateKey); err != nil {
return err
}
if keybytes, err = ioutil.ReadFile(conf.PrivateKey); err != nil {
if keybytes, err = ioutil.ReadFile(conf.JwtPrivateKey); err != nil {
return err
}
}
conf.privateKey, err = jwt.ParseRSAPrivateKeyFromPEM(keybytes)
conf.jwtPrivateKey, err = jwt.ParseRSAPrivateKeyFromPEM(keybytes)
return err
}
......
......@@ -56,13 +56,13 @@ func Handler(config *Configuration) (http.Handler, error) {
router.Mount("/irma/", irmarequestor.HttpHandlerFunc("/irma/"))
// Server routes
router.Post("/create", handleCreate)
router.Get("/status/{token}", handleStatus)
router.Get("/result/{token}", handleResult)
router.Post("/session", handleCreate)
router.Get("/session/{token}/status", handleStatus)
router.Get("/session/{token}/result", handleResult)
// Routes for getting signed JWTs containing the session result. Only work if configuration has a private key
router.Get("/result-jwt/{token}", handleJwtResult)
router.Get("/getproof/{token}", handleJwtProofs) // irma_api_server-compatible JWT
router.Get("/session/{token}/result-jwt", handleJwtResult)
router.Get("/session/{token}/getproof", handleJwtProofs) // irma_api_server-compatible JWT
return router, nil
}
......@@ -145,7 +145,7 @@ func handleResult(w http.ResponseWriter, r *http.Request) {
}
func handleJwtResult(w http.ResponseWriter, r *http.Request) {
if conf.privateKey == nil {
if conf.jwtPrivateKey == nil {
server.WriteError(w, server.ErrorUnknown, "JWT signing not supported")
return
}
......@@ -168,7 +168,7 @@ func handleJwtResult(w http.ResponseWriter, r *http.Request) {
// Sign the jwt and return it
token := jwt.NewWithClaims(jwt.SigningMethodRS256, claims)
resultJwt, err := token.SignedString(conf.privateKey)
resultJwt, err := token.SignedString(conf.jwtPrivateKey)
if err != nil {
server.WriteError(w, server.ErrorUnknown, err.Error())
return
......@@ -177,7 +177,7 @@ func handleJwtResult(w http.ResponseWriter, r *http.Request) {
}
func handleJwtProofs(w http.ResponseWriter, r *http.Request) {
if conf.privateKey == nil {
if conf.jwtPrivateKey == nil {
server.WriteError(w, server.ErrorUnknown, "JWT signing not supported")
return
}
......@@ -220,7 +220,7 @@ func handleJwtProofs(w http.ResponseWriter, r *http.Request) {
// Sign the jwt and return it
token := jwt.NewWithClaims(jwt.SigningMethodRS256, claims)
resultJwt, err := token.SignedString(conf.privateKey)
resultJwt, err := token.SignedString(conf.jwtPrivateKey)
if err != nil {
server.WriteError(w, server.ErrorUnknown, err.Error())
return
......
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