Browse Source
for this to work, the KeyStorage interface had to be extended Signed-off-by: Stephan Richter <s.richter@srsoftware.de>sqlite
Stephan Richter
2 months ago
10 changed files with 141 additions and 44 deletions
@ -0,0 +1,36 @@
@@ -0,0 +1,36 @@
|
||||
/* © SRSoftware 2024 */ |
||||
package de.srsoftware.oidc.datastore.encrypted; |
||||
|
||||
import de.srsoftware.oidc.api.KeyStorage; |
||||
import java.io.IOException; |
||||
import java.util.List; |
||||
|
||||
public class EncryptedKeyStore extends EncryptedConfig implements KeyStorage { |
||||
private final KeyStorage backend; |
||||
|
||||
public EncryptedKeyStore(String key, String salt, KeyStorage backend) { |
||||
super(key, salt); |
||||
this.backend = backend; |
||||
} |
||||
|
||||
@Override |
||||
public KeyStorage drop(String keyId) { |
||||
return backend.drop(keyId); |
||||
} |
||||
|
||||
@Override |
||||
public List<String> listKeys() { |
||||
return backend.listKeys(); |
||||
} |
||||
|
||||
@Override |
||||
public String loadJson(String keyId) throws IOException { |
||||
return decrypt(backend.loadJson(keyId)); |
||||
} |
||||
|
||||
@Override |
||||
public KeyStorage store(String keyId, String jsonWebKey) throws IOException { |
||||
backend.store(keyId, encrypt(jsonWebKey)); |
||||
return this; |
||||
} |
||||
} |
@ -0,0 +1,53 @@
@@ -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); |
||||
} |
||||
} |
Loading…
Reference in new issue