Bugfix: keysave should work now on docker and device
LocationBasedServices/sumoc-backend/pipeline/head This commit looks good
LocationBasedServices/sumoc-backend/pipeline/head This commit looks good
This commit is contained in:
@@ -20,15 +20,14 @@ public class RSAKeyProperties {
|
||||
private final RSAPrivateKey privateKey;
|
||||
|
||||
public RSAKeyProperties(
|
||||
@Value("${RSA_PUBLIC_KEY_PATH:./keys/jwt-public.pem}") String publicKeyPath,
|
||||
@Value("${RSA_PRIVATE_KEY_PATH:./keys/jwt-private.pem}") String privateKeyPath
|
||||
@Value("${security.rsa.public-key-path}") String publicKeyPath,
|
||||
@Value("${security.rsa.private-key-path}") String privateKeyPath
|
||||
) {
|
||||
try {
|
||||
Path pubPath = Paths.get(publicKeyPath);
|
||||
Path privPath = Paths.get(privateKeyPath);
|
||||
|
||||
if (pubPath.getParent() != null) Files.createDirectories(pubPath.getParent());
|
||||
if (privPath.getParent() != null) Files.createDirectories(privPath.getParent());
|
||||
Files.createDirectories(pubPath.getParent());
|
||||
|
||||
if (Files.exists(pubPath) && Files.exists(privPath)) {
|
||||
this.publicKey = readPublicKey(pubPath);
|
||||
@@ -36,21 +35,23 @@ public class RSAKeyProperties {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!Files.isWritable(pubPath.getParent())) {
|
||||
throw new IllegalStateException("Key directory not writable: " + pubPath.getParent());
|
||||
}
|
||||
|
||||
KeyPair pair = KeyGeneratorUtility.generateRsaKey();
|
||||
RSAPublicKey pub = (RSAPublicKey) pair.getPublic();
|
||||
RSAPrivateKey priv = (RSAPrivateKey) pair.getPrivate();
|
||||
this.publicKey = (RSAPublicKey) pair.getPublic();
|
||||
this.privateKey = (RSAPrivateKey) pair.getPrivate();
|
||||
|
||||
writePublicKey(pubPath, pub);
|
||||
writePrivateKey(privPath, priv);
|
||||
|
||||
this.publicKey = pub;
|
||||
this.privateKey = priv;
|
||||
writePublicKey(pubPath, this.publicKey);
|
||||
writePrivateKey(privPath, this.privateKey);
|
||||
|
||||
} catch (Exception e) {
|
||||
throw new IllegalStateException("Failed to load or generate RSA keys", e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public RSAPublicKey getPublicKey() { return publicKey; }
|
||||
public RSAPrivateKey getPrivateKey() { return privateKey; }
|
||||
|
||||
@@ -91,6 +92,6 @@ public class RSAKeyProperties {
|
||||
"-----END " + type + "-----\n";
|
||||
Path tmp = Paths.get(path.toString() + ".tmp");
|
||||
Files.writeString(tmp, pem, StandardCharsets.UTF_8, StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING);
|
||||
Files.move(tmp, path, StandardCopyOption.REPLACE_EXISTING, StandardCopyOption.ATOMIC_MOVE);
|
||||
Files.move(tmp, path, StandardCopyOption.REPLACE_EXISTING);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@ import lombok.Setter;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
@Entity
|
||||
@Table(name = "users")
|
||||
|
||||
Reference in New Issue
Block a user