feat: Implement feature to store symmetric passphrases in DB
This commit is contained in:
parent
ac3821c949
commit
2b6473929a
9 changed files with 169 additions and 11 deletions
|
@ -0,0 +1,20 @@
|
|||
package de.mlessmann.certassist.config;
|
||||
|
||||
import org.springframework.context.EnvironmentAware;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.Profile;
|
||||
import org.springframework.core.env.Environment;
|
||||
|
||||
@Configuration
|
||||
@Profile("test")
|
||||
public class TestAppEnvConfig implements EnvironmentAware {
|
||||
|
||||
public static final String TEST_APP_KEY = "5i4Y)Ja0{YCl";
|
||||
|
||||
@Override
|
||||
public void setEnvironment(Environment environment) {
|
||||
if (environment.getProperty("APP_KEY") == null) {
|
||||
System.setProperty("APP_KEY", TEST_APP_KEY);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,29 +1,23 @@
|
|||
package de.mlessmann.certassist.service;
|
||||
|
||||
import de.mlessmann.certassist.openssl.CertificatePasswordProvider;
|
||||
import java.security.SecureRandom;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
@ConditionalOnMissingBean(CertificatePasswordProvider.class)
|
||||
public class InMemoryCertificatePasswordProvider implements CertificatePasswordProvider {
|
||||
|
||||
private final Map<String, String> passwords = new ConcurrentHashMap<>();
|
||||
private static final String CHARACTERS =
|
||||
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*()-_=+[]{}|;:,.<>?";
|
||||
private static final int PASSPHRASE_LENGTH = 16;
|
||||
|
||||
@Override
|
||||
public String generateNewPassword() {
|
||||
SecureRandom random = new SecureRandom();
|
||||
StringBuilder passphrase = new StringBuilder(PASSPHRASE_LENGTH);
|
||||
for (int i = 0; i < PASSPHRASE_LENGTH; i++) {
|
||||
passphrase.append(CHARACTERS.charAt(random.nextInt(CHARACTERS.length())));
|
||||
}
|
||||
return passphrase.toString();
|
||||
return PassphraseService.generateNewPassword(PASSPHRASE_LENGTH);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue