implemented EncryptedKeyStore

for this to work, the KeyStorage interface had to be extended

Signed-off-by: Stephan Richter <s.richter@srsoftware.de>
This commit is contained in:
2024-09-29 00:16:56 +02:00
parent 32f773c184
commit 9ea6148583
10 changed files with 141 additions and 44 deletions

View File

@@ -0,0 +1,53 @@
/* © SRSoftware 2024 */
import static de.srsoftware.utils.Strings.uuid;
import de.srsoftware.oidc.api.KeyStorage;
import de.srsoftware.oidc.api.KeyStoreTest;
import de.srsoftware.oidc.datastore.encrypted.EncryptedKeyStore;
import java.io.IOException;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.List;
import org.junit.jupiter.api.BeforeEach;
public class EncryptedKeyStoreTest extends KeyStoreTest {
private class InMemoryKeyStore implements KeyStorage {
private HashMap<String, String> store = new HashMap<>();
@Override
public KeyStorage drop(String keyId) {
store.remove(keyId);
return this;
}
@Override
public List<String> listKeys() {
return List.copyOf(store.keySet());
}
@Override
public String loadJson(String keyId) {
return store.get(keyId);
}
@Override
public KeyStorage store(String keyId, String jsonWebKey) throws IOException {
store.put(keyId, jsonWebKey);
return this;
}
}
private KeyStorage keyStore;
@Override
protected KeyStorage keyStore() {
return keyStore;
}
@BeforeEach
public void setup() throws SQLException {
var backend = new InMemoryKeyStore();
var key = uuid();
var salt = uuid();
keyStore = new EncryptedKeyStore(key, salt, backend);
}
}