Support for all key types
This commit is contained in:
@@ -21,6 +21,8 @@
|
||||
package io.kamax.mxisd.http.undertow.handler.identity.v1;
|
||||
|
||||
import io.kamax.mxisd.http.IsAPIv1;
|
||||
import io.kamax.mxisd.storage.crypto.KeyManager;
|
||||
import io.kamax.mxisd.storage.crypto.KeyType;
|
||||
import io.undertow.server.HttpServerExchange;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@@ -31,11 +33,19 @@ public class EphemeralKeyIsValidHandler extends KeyIsValidHandler {
|
||||
|
||||
private transient final Logger log = LoggerFactory.getLogger(EphemeralKeyIsValidHandler.class);
|
||||
|
||||
private KeyManager mgr;
|
||||
|
||||
public EphemeralKeyIsValidHandler(KeyManager mgr) {
|
||||
this.mgr = mgr;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleRequest(HttpServerExchange exchange) {
|
||||
log.warn("Ephemeral key was requested but no ephemeral key are generated, replying not valid");
|
||||
// FIXME process + correctly in query parameter handling
|
||||
String pubKey = getQueryParameter(exchange, "public_key").replace(" ", "+");
|
||||
log.info("Validating ephemeral public key {}", pubKey);
|
||||
|
||||
respondJson(exchange, invalidKey);
|
||||
respondJson(exchange, mgr.isValid(KeyType.Ephemeral, pubKey) ? validKey : invalidKey);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -27,13 +27,14 @@ import io.kamax.mxisd.storage.crypto.GenericKeyIdentifier;
|
||||
import io.kamax.mxisd.storage.crypto.KeyManager;
|
||||
import io.kamax.mxisd.storage.crypto.KeyType;
|
||||
import io.undertow.server.HttpServerExchange;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class KeyGetHandler extends BasicHttpHandler {
|
||||
|
||||
public static final String Key = "key";
|
||||
public static final String Path = IsAPIv1.Base + "/pubkey/{key}";
|
||||
public static final String Path = IsAPIv1.Base + "/pubkey/{" + Key + "}";
|
||||
|
||||
private transient final Logger log = LoggerFactory.getLogger(KeyGetHandler.class);
|
||||
|
||||
@@ -46,7 +47,11 @@ public class KeyGetHandler extends BasicHttpHandler {
|
||||
@Override
|
||||
public void handleRequest(HttpServerExchange exchange) {
|
||||
String key = getQueryParameter(exchange, Key);
|
||||
String[] v = key.split(":", 2);
|
||||
if (StringUtils.isBlank(key)) {
|
||||
throw new IllegalArgumentException("Key ID cannot be empty or blank");
|
||||
}
|
||||
|
||||
String[] v = key.split(":", 2); // Maybe use regex?
|
||||
String keyAlgo = v[0];
|
||||
String keyId = v[1];
|
||||
|
||||
|
||||
@@ -41,7 +41,8 @@ public class RegularKeyIsValidHandler extends KeyIsValidHandler {
|
||||
|
||||
@Override
|
||||
public void handleRequest(HttpServerExchange exchange) {
|
||||
String pubKey = getQueryParameter(exchange, "public_key");
|
||||
// FIXME process + correctly in query parameter handling
|
||||
String pubKey = getQueryParameter(exchange, "public_key").replace(" ", "+");
|
||||
log.info("Validating public key {}", pubKey);
|
||||
|
||||
respondJson(exchange, mgr.isValid(KeyType.Regular, pubKey) ? validKey : invalidKey);
|
||||
|
||||
Reference in New Issue
Block a user