Compare commits
4
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
bc9b4c2e6f | ||
|
|
6f6243688d | ||
|
|
425b65e6b2 | ||
|
|
649fd5407c |
@@ -4,6 +4,8 @@ import java.time.LocalDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
@@ -47,6 +49,9 @@ public class JobResult {
|
||||
*/
|
||||
private final List<String> notes = new CopyOnWriteArrayList<>();
|
||||
|
||||
/** Key/value metadata that survives the write-through into the shared job store. */
|
||||
private final Map<String, String> metadata = new ConcurrentHashMap<>();
|
||||
|
||||
/**
|
||||
* Create a new JobResult with the given job ID
|
||||
*
|
||||
@@ -161,4 +166,16 @@ public class JobResult {
|
||||
public List<String> getNotes() {
|
||||
return Collections.unmodifiableList(notes);
|
||||
}
|
||||
|
||||
/** Attach a metadata value, e.g. a policy id so cluster peers can identify a policy run. */
|
||||
public void putMetadata(String key, String value) {
|
||||
if (key != null && value != null) {
|
||||
this.metadata.put(key, value);
|
||||
}
|
||||
}
|
||||
|
||||
/** An unmodifiable view of this job's metadata. */
|
||||
public Map<String, String> getMetadata() {
|
||||
return Collections.unmodifiableMap(metadata);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -230,6 +230,18 @@ public class TaskManager {
|
||||
return false;
|
||||
}
|
||||
|
||||
/** Attach metadata to a job and write it through to the shared store for cluster peers. */
|
||||
public boolean putMetadata(String jobId, String key, String value) {
|
||||
JobResult jobResult = jobResults.get(jobId);
|
||||
if (jobResult != null) {
|
||||
jobResult.putMetadata(key, value);
|
||||
writeThrough(jobId, jobResult);
|
||||
return true;
|
||||
}
|
||||
log.warn("Attempted to set metadata on non-existent job ID: {}", jobId);
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get statistics about all jobs in the system
|
||||
*
|
||||
@@ -378,7 +390,7 @@ public class TaskManager {
|
||||
fileIds.add(rf.getFileId());
|
||||
}
|
||||
}
|
||||
Map<String, String> meta = new HashMap<>();
|
||||
Map<String, String> meta = new HashMap<>(result.getMetadata());
|
||||
if (result.getNotes() != null && !result.getNotes().isEmpty()) {
|
||||
meta.put("notesCount", Integer.toString(result.getNotes().size()));
|
||||
}
|
||||
|
||||
@@ -96,7 +96,8 @@ spring.main.allow-bean-definition-overriding=true
|
||||
# spring-data-redis is on the classpath only for the optional Valkey backplane (which wires its own
|
||||
# factory); exclude Spring Boot's stock Redis auto-config so a default install doesn't create a dead
|
||||
# localhost:6379 factory that flips /actuator/health to DOWN.
|
||||
spring.autoconfigure.exclude=org.springframework.boot.data.redis.autoconfigure.DataRedisAutoConfiguration,org.springframework.boot.data.redis.autoconfigure.DataRedisReactiveAutoConfiguration
|
||||
# Also exclude the repositories auto-config: in cluster mode it needs a redisTemplate bean we don't define.
|
||||
spring.autoconfigure.exclude=org.springframework.boot.data.redis.autoconfigure.DataRedisAutoConfiguration,org.springframework.boot.data.redis.autoconfigure.DataRedisReactiveAutoConfiguration,org.springframework.boot.data.redis.autoconfigure.DataRedisRepositoriesAutoConfiguration
|
||||
|
||||
# Set up a consistent temporary directory location
|
||||
java.io.tmpdir=${stirling.tempfiles.directory:${java.io.tmpdir}/stirling-pdf}
|
||||
|
||||
+12
-1
@@ -44,10 +44,13 @@ public class CredentialEncryption {
|
||||
private static volatile SecretKey key;
|
||||
|
||||
private final String configuredKey;
|
||||
private final boolean clusterEnabled;
|
||||
|
||||
public CredentialEncryption(
|
||||
@Value("${stirling.security.credentialEncryptionKey:}") String configuredKey) {
|
||||
@Value("${stirling.security.credentialEncryptionKey:}") String configuredKey,
|
||||
@Value("${cluster.enabled:false}") boolean clusterEnabled) {
|
||||
this.configuredKey = configuredKey;
|
||||
this.clusterEnabled = clusterEnabled;
|
||||
}
|
||||
|
||||
@PostConstruct
|
||||
@@ -64,6 +67,14 @@ public class CredentialEncryption {
|
||||
if (configured != null && !configured.isBlank()) {
|
||||
return new SecretKeySpec(Base64.getDecoder().decode(configured.trim()), ALGORITHM);
|
||||
}
|
||||
// Cluster nodes must share this key, so fail fast rather than generate a node-local one.
|
||||
if (clusterEnabled) {
|
||||
throw new IllegalStateException(
|
||||
"cluster.enabled=true requires a shared credential encryption key. Set"
|
||||
+ " STIRLING_CREDENTIAL_ENCRYPTION_KEY (or"
|
||||
+ " stirling.security.credentialEncryptionKey) to the same value on every"
|
||||
+ " node.");
|
||||
}
|
||||
return loadOrCreateKeyFile();
|
||||
}
|
||||
|
||||
|
||||
+35
-6
@@ -6,6 +6,7 @@ import java.util.Comparator;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnBooleanProperty;
|
||||
import org.springframework.core.io.FileSystemResource;
|
||||
@@ -40,6 +41,8 @@ import jakarta.validation.Valid;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import stirling.software.common.cluster.JobStore;
|
||||
import stirling.software.common.cluster.JobStoreEntry;
|
||||
import stirling.software.common.model.ApplicationProperties;
|
||||
import stirling.software.common.model.job.JobResponse;
|
||||
import stirling.software.common.service.JobOwnershipService;
|
||||
@@ -104,6 +107,8 @@ public class PolicyController {
|
||||
private final ApplicationProperties applicationProperties;
|
||||
private final TempFileManager tempFileManager;
|
||||
private final JobOwnershipService jobOwnershipService;
|
||||
// Shared job store: lets the run endpoints see runs that executed on other nodes.
|
||||
private final JobStore jobStore;
|
||||
|
||||
@PostMapping(value = "/run", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
|
||||
@Operation(
|
||||
@@ -174,10 +179,19 @@ public class PolicyController {
|
||||
description = "Returns the current status, step cursor, and output files of a run.")
|
||||
public ResponseEntity<PolicyRunView> status(@PathVariable String runId) {
|
||||
PolicyRun run = runRegistry.get(runId);
|
||||
if (run == null) {
|
||||
return ResponseEntity.notFound().build();
|
||||
if (run != null) {
|
||||
return ResponseEntity.ok(PolicyRunView.of(run));
|
||||
}
|
||||
return ResponseEntity.ok(PolicyRunView.of(run));
|
||||
// Not local: read the run's shared projection so any node can serve its status.
|
||||
if (ownedByCurrentUser(runId)) {
|
||||
Optional<JobStoreEntry> entry = jobStore.get(runId);
|
||||
if (entry.isPresent()
|
||||
&& entry.get().resultMeta() != null
|
||||
&& entry.get().resultMeta().containsKey("policyId")) {
|
||||
return ResponseEntity.ok(PolicyRunView.ofEntry(entry.get()));
|
||||
}
|
||||
}
|
||||
return ResponseEntity.notFound().build();
|
||||
}
|
||||
|
||||
@GetMapping("/runs")
|
||||
@@ -190,11 +204,26 @@ public class PolicyController {
|
||||
+ " collected, rather than orphaned on the backend. Ad-hoc runs (no"
|
||||
+ " policy id) are excluded.")
|
||||
public List<PolicyRunView> listRuns() {
|
||||
return runRegistry.all().stream()
|
||||
// Local runs first (they carry live step state); keyed by runId to dedupe shared entries.
|
||||
Map<String, PolicyRunView> byRunId = new LinkedHashMap<>();
|
||||
runRegistry.all().stream()
|
||||
.filter(run -> run.getPolicyId() != null)
|
||||
.filter(run -> ownedByCurrentUser(run.getRunId()))
|
||||
.map(PolicyRunView::of)
|
||||
.toList();
|
||||
.forEach(run -> byRunId.put(run.getRunId(), PolicyRunView.of(run)));
|
||||
// Then runs from other nodes, read from the shared job store.
|
||||
for (JobStoreEntry entry : jobStore.all()) {
|
||||
if (byRunId.containsKey(entry.jobId())) {
|
||||
continue;
|
||||
}
|
||||
Map<String, String> meta = entry.resultMeta();
|
||||
if (meta == null || !meta.containsKey("policyId")) {
|
||||
continue; // ad-hoc job, not a stored-policy run
|
||||
}
|
||||
if (ownedByCurrentUser(entry.jobId())) {
|
||||
byRunId.put(entry.jobId(), PolicyRunView.ofEntry(entry));
|
||||
}
|
||||
}
|
||||
return List.copyOf(byRunId.values());
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+4
@@ -136,6 +136,10 @@ public class PolicyEngine {
|
||||
// ownership check passes. No-op when security is off.
|
||||
String runId = jobOwnershipService.createScopedJobKey(UUID.randomUUID().toString());
|
||||
taskManager.createTask(runId);
|
||||
// Tag the shared job entry with the policy id so peers can list it as a policy run.
|
||||
if (policyId != null) {
|
||||
taskManager.putMetadata(runId, "policyId", policyId);
|
||||
}
|
||||
PolicyRun run = new PolicyRun(runId, policyId, definition);
|
||||
registry.register(run);
|
||||
CompletableFuture<PolicyRun> completion = new CompletableFuture<>();
|
||||
|
||||
+31
@@ -1,7 +1,9 @@
|
||||
package stirling.software.proprietary.policy.model;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import stirling.software.common.cluster.JobStoreEntry;
|
||||
import stirling.software.common.model.job.ResultFile;
|
||||
|
||||
/**
|
||||
@@ -34,4 +36,33 @@ public record PolicyRunView(
|
||||
run.getOutputs(),
|
||||
run.getCreatedAt().toEpochMilli());
|
||||
}
|
||||
|
||||
/** Cross-node view from a shared job-store entry; step cursor is node-local so it reads 0. */
|
||||
public static PolicyRunView ofEntry(JobStoreEntry entry) {
|
||||
Map<String, String> meta = entry.resultMeta() == null ? Map.of() : entry.resultMeta();
|
||||
PolicyRunStatus status =
|
||||
switch (entry.state()) {
|
||||
case COMPLETE -> PolicyRunStatus.COMPLETED;
|
||||
case FAILED -> PolicyRunStatus.FAILED;
|
||||
case RUNNING, PENDING -> PolicyRunStatus.RUNNING;
|
||||
};
|
||||
List<ResultFile> outputs =
|
||||
entry.fileIds() == null
|
||||
? List.of()
|
||||
: entry.fileIds().stream()
|
||||
.map(id -> ResultFile.builder().fileId(id).build())
|
||||
.toList();
|
||||
long createdAt = entry.createdAt() == null ? 0L : entry.createdAt().toEpochMilli();
|
||||
return new PolicyRunView(
|
||||
entry.jobId(),
|
||||
meta.get("policyId"),
|
||||
status,
|
||||
0,
|
||||
0,
|
||||
entry.error(),
|
||||
null,
|
||||
null,
|
||||
outputs,
|
||||
createdAt);
|
||||
}
|
||||
}
|
||||
|
||||
+52
@@ -0,0 +1,52 @@
|
||||
package stirling.software.proprietary.security.model;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
import org.hibernate.annotations.CreationTimestamp;
|
||||
|
||||
import jakarta.persistence.Column;
|
||||
import jakarta.persistence.Convert;
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.Id;
|
||||
import jakarta.persistence.Table;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
|
||||
import stirling.software.proprietary.integration.crypto.EncryptedStringConverter;
|
||||
|
||||
/** A JWT signing keypair in the shared DB; the private key is encrypted at rest. */
|
||||
@Entity
|
||||
@Table(name = "jwt_signing_keys")
|
||||
@NoArgsConstructor
|
||||
@Getter
|
||||
@Setter
|
||||
public class JwtSigningKeyEntity implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Id
|
||||
@Column(name = "key_id", length = 128)
|
||||
private String keyId;
|
||||
|
||||
// Base64 X.509 public key (non-secret).
|
||||
@Column(name = "verifying_key", columnDefinition = "text", nullable = false)
|
||||
private String verifyingKey;
|
||||
|
||||
// Base64 PKCS#8 private key, encrypted at rest.
|
||||
@Convert(converter = EncryptedStringConverter.class)
|
||||
@Column(name = "signing_key", columnDefinition = "text", nullable = false)
|
||||
private String signingKey;
|
||||
|
||||
@CreationTimestamp
|
||||
@Column(name = "created_at", updatable = false)
|
||||
private LocalDateTime createdAt;
|
||||
|
||||
public JwtSigningKeyEntity(String keyId, String verifyingKey, String signingKey) {
|
||||
this.keyId = keyId;
|
||||
this.verifyingKey = verifyingKey;
|
||||
this.signingKey = signingKey;
|
||||
}
|
||||
}
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
package stirling.software.proprietary.security.repository;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import stirling.software.proprietary.security.model.JwtSigningKeyEntity;
|
||||
|
||||
/** Shared-DB store of JWT signing keys - the source of truth every cluster node reads from. */
|
||||
@Repository
|
||||
public interface JwtSigningKeyRepository extends JpaRepository<JwtSigningKeyEntity, String> {
|
||||
|
||||
/** Newest first, so the most recently created key is the active signing key. */
|
||||
List<JwtSigningKeyEntity> findAllByOrderByCreatedAtDesc();
|
||||
|
||||
/**
|
||||
* The current active signing key: the single newest row. Used for cheap cluster convergence.
|
||||
*/
|
||||
Optional<JwtSigningKeyEntity> findFirstByOrderByCreatedAtDesc();
|
||||
|
||||
/** Keys created before the cutoff, eligible for rotation cleanup. */
|
||||
List<JwtSigningKeyEntity> findByCreatedAtBefore(LocalDateTime cutoff);
|
||||
}
|
||||
+34
-1
@@ -3,8 +3,10 @@ package stirling.software.proprietary.security.service;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.time.Duration;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -17,6 +19,8 @@ import jakarta.annotation.PostConstruct;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import stirling.software.common.cluster.DistributedLock;
|
||||
import stirling.software.common.cluster.DistributedLock.LockHandle;
|
||||
import stirling.software.common.configuration.InstallationPathConfig;
|
||||
import stirling.software.common.model.ApplicationProperties;
|
||||
import stirling.software.proprietary.security.model.JwtVerificationKey;
|
||||
@@ -26,15 +30,23 @@ import stirling.software.proprietary.security.model.JwtVerificationKey;
|
||||
@ConditionalOnBooleanProperty("v2")
|
||||
public class KeyPairCleanupService {
|
||||
|
||||
// Cluster-wide single-writer: keys live in the shared DB, so only one node may prune + rotate
|
||||
// per cycle. Otherwise every node runs this and they race to delete each other's keys.
|
||||
private static final String CLEANUP_LOCK = "jwt-key-cleanup";
|
||||
private static final Duration LOCK_LEASE = Duration.ofMinutes(5);
|
||||
|
||||
private final KeyPersistenceService keyPersistenceService;
|
||||
private final ApplicationProperties.Security.Jwt jwtProperties;
|
||||
private final DistributedLock distributedLock;
|
||||
|
||||
@Autowired
|
||||
public KeyPairCleanupService(
|
||||
KeyPersistenceService keyPersistenceService,
|
||||
ApplicationProperties applicationProperties) {
|
||||
ApplicationProperties applicationProperties,
|
||||
DistributedLock distributedLock) {
|
||||
this.keyPersistenceService = keyPersistenceService;
|
||||
this.jwtProperties = applicationProperties.getSecurity().getJwt();
|
||||
this.distributedLock = distributedLock;
|
||||
}
|
||||
|
||||
@Transactional
|
||||
@@ -44,7 +56,28 @@ public class KeyPairCleanupService {
|
||||
if (!jwtProperties.isEnableKeyCleanup() || !keyPersistenceService.isKeystoreEnabled()) {
|
||||
return;
|
||||
}
|
||||
// A lock-backend error must never fail this @PostConstruct/scheduled run: degrade to
|
||||
// "skip this cycle" so a transient Valkey blip can't stop a node from booting.
|
||||
Optional<LockHandle> lock;
|
||||
try {
|
||||
lock = distributedLock.tryAcquire(CLEANUP_LOCK, LOCK_LEASE);
|
||||
} catch (RuntimeException e) {
|
||||
log.warn(
|
||||
"Could not acquire the JWT key-cleanup lock ({}); skipping this cycle",
|
||||
e.getMessage());
|
||||
return;
|
||||
}
|
||||
// No lock means another node is already pruning; skip until the next tick.
|
||||
if (lock.isEmpty()) {
|
||||
log.debug("Another node holds the JWT key-cleanup lock; skipping this cycle");
|
||||
return;
|
||||
}
|
||||
try (LockHandle held = lock.get()) {
|
||||
runCleanup();
|
||||
}
|
||||
}
|
||||
|
||||
private void runCleanup() {
|
||||
LocalDateTime cutoffDate =
|
||||
LocalDateTime.now().minusDays(jwtProperties.getKeyRetentionDays());
|
||||
|
||||
|
||||
+172
-257
@@ -18,15 +18,17 @@ import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.Base64;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.cache.Cache;
|
||||
import org.springframework.cache.CacheManager;
|
||||
import org.springframework.cache.annotation.CacheEvict;
|
||||
import org.springframework.cache.caffeine.CaffeineCache;
|
||||
import org.springframework.context.annotation.DependsOn;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import jakarta.annotation.PostConstruct;
|
||||
|
||||
@@ -34,27 +36,39 @@ import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import stirling.software.common.configuration.InstallationPathConfig;
|
||||
import stirling.software.common.model.ApplicationProperties;
|
||||
import stirling.software.proprietary.security.model.JwtSigningKeyEntity;
|
||||
import stirling.software.proprietary.security.model.JwtVerificationKey;
|
||||
import stirling.software.proprietary.security.repository.JwtSigningKeyRepository;
|
||||
|
||||
/** Persists JWT signing keys in the shared DB so all nodes sign/verify with the same key. */
|
||||
@Slf4j
|
||||
@Service
|
||||
// CredentialEncryption must init first: startup persists an encrypted private key.
|
||||
@DependsOn("credentialEncryption")
|
||||
public class KeyPersistenceService implements KeyPersistenceServiceInterface {
|
||||
|
||||
public static final String KEY_SUFFIX = ".key";
|
||||
public static final String PUB_KEY_SUFFIX = ".pub";
|
||||
|
||||
private final ApplicationProperties.Security.Jwt jwtProperties;
|
||||
private final CacheManager cacheManager;
|
||||
private final Cache verifyingKeyCache;
|
||||
private final JwtSigningKeyRepository keyRepository;
|
||||
private final boolean clusterEnabled;
|
||||
|
||||
// kid -> KeyPair; safe to cache since key material is immutable.
|
||||
private final Map<String, KeyPair> keyPairCache = new ConcurrentHashMap<>();
|
||||
|
||||
private volatile JwtVerificationKey activeKey;
|
||||
|
||||
@Autowired
|
||||
public KeyPersistenceService(
|
||||
ApplicationProperties applicationProperties, CacheManager cacheManager) {
|
||||
ApplicationProperties applicationProperties,
|
||||
CacheManager cacheManager,
|
||||
JwtSigningKeyRepository keyRepository,
|
||||
@Value("${cluster.enabled:false}") boolean clusterEnabled) {
|
||||
this.jwtProperties = applicationProperties.getSecurity().getJwt();
|
||||
this.cacheManager = cacheManager;
|
||||
this.verifyingKeyCache = cacheManager.getCache("verifyingKeys");
|
||||
this.keyRepository = keyRepository;
|
||||
this.clusterEnabled = clusterEnabled;
|
||||
}
|
||||
|
||||
@PostConstruct
|
||||
@@ -63,138 +77,86 @@ public class KeyPersistenceService implements KeyPersistenceServiceInterface {
|
||||
log.info("JWT keystore is disabled - keys will be generated in memory");
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
ensurePrivateKeyDirectoryExists();
|
||||
loadExistingKeysFromDisk();
|
||||
importLegacyDiskKeysIfPresent();
|
||||
loadKeysFromDb();
|
||||
} catch (Exception e) {
|
||||
log.error("Failed to initialize keystore, using in-memory generation", e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Load all existing JWT keys from disk into memory on startup.
|
||||
*
|
||||
* <p>This ensures tokens signed with previous keys remain valid after server restart. If no
|
||||
* keys exist on disk, generates a new keypair.
|
||||
*/
|
||||
private void loadExistingKeysFromDisk() {
|
||||
try {
|
||||
Path keyDirectory = Path.of(InstallationPathConfig.getPrivateKeyPath());
|
||||
|
||||
if (!Files.exists(keyDirectory)) {
|
||||
log.info("No existing keys found, generating new keypair");
|
||||
generateAndStoreKeypair();
|
||||
return;
|
||||
}
|
||||
|
||||
List<Path> keyFiles;
|
||||
try (var stream = Files.list(keyDirectory)) {
|
||||
keyFiles =
|
||||
stream.filter(path -> path.toString().endsWith(KEY_SUFFIX))
|
||||
.sorted(
|
||||
(a, b) ->
|
||||
b.getFileName().compareTo(a.getFileName())) // Most
|
||||
// recent
|
||||
// first
|
||||
.toList();
|
||||
}
|
||||
|
||||
if (keyFiles.isEmpty()) {
|
||||
log.info("No existing keys found in directory, generating new keypair");
|
||||
generateAndStoreKeypair();
|
||||
return;
|
||||
}
|
||||
|
||||
log.info("Loading {} existing JWT keys from disk", keyFiles.size());
|
||||
int loadedCount = 0;
|
||||
|
||||
for (Path keyFile : keyFiles) {
|
||||
try {
|
||||
String keyId = keyFile.getFileName().toString().replace(KEY_SUFFIX, "");
|
||||
|
||||
// Load private key first
|
||||
PrivateKey privateKey = loadPrivateKey(keyId);
|
||||
|
||||
// Try to load public key, or generate it from private key if missing
|
||||
// (migration)
|
||||
String encodedPublicKey;
|
||||
try {
|
||||
encodedPublicKey = loadPublicKey(keyId);
|
||||
} catch (IOException e) {
|
||||
// Public key file doesn't exist - generate it from private key (migration)
|
||||
log.info("Migrating legacy key: generating public key file for {}", keyId);
|
||||
KeyPair keyPair = reconstructKeyPair(privateKey);
|
||||
|
||||
// Save the public key file
|
||||
Path publicKeyFile = keyDirectory.resolve(keyId + PUB_KEY_SUFFIX);
|
||||
encodedPublicKey = encodePublicKey(keyPair.getPublic());
|
||||
Files.writeString(publicKeyFile, encodedPublicKey);
|
||||
publicKeyFile.toFile().setReadable(true, true);
|
||||
publicKeyFile.toFile().setWritable(true, true);
|
||||
publicKeyFile.toFile().setExecutable(false, false);
|
||||
|
||||
log.info("Successfully migrated key: {}", keyId);
|
||||
}
|
||||
|
||||
// Create verification key and add to cache
|
||||
JwtVerificationKey verifyingKey =
|
||||
new JwtVerificationKey(keyId, encodedPublicKey);
|
||||
verifyingKeyCache.put(keyId, verifyingKey);
|
||||
loadedCount++;
|
||||
|
||||
// Set the most recent key as active (first in sorted list)
|
||||
if (activeKey == null) {
|
||||
activeKey = verifyingKey;
|
||||
log.info("Set active JWT signing key: {}", keyId);
|
||||
} else {
|
||||
log.debug(
|
||||
"Loaded historical JWT key: {} (created: {})",
|
||||
keyId,
|
||||
verifyingKey.getCreatedAt());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.warn(
|
||||
"Failed to load key: {}, skipping. Error: {}",
|
||||
keyFile.getFileName(),
|
||||
e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
if (loadedCount == 0) {
|
||||
log.warn("No valid keys could be loaded from disk, generating new keypair");
|
||||
generateAndStoreKeypair();
|
||||
} else {
|
||||
log.info(
|
||||
"Successfully loaded {} JWT keys, active key: {}",
|
||||
loadedCount,
|
||||
activeKey.getKeyId());
|
||||
}
|
||||
|
||||
} catch (IOException e) {
|
||||
log.error("Failed to load keys from disk, generating new keypair", e);
|
||||
log.error("Failed to initialize keystore, generating a fresh keypair", e);
|
||||
generateAndStoreKeypair();
|
||||
}
|
||||
}
|
||||
|
||||
@Transactional
|
||||
private JwtVerificationKey generateAndStoreKeypair() {
|
||||
JwtVerificationKey verifyingKey = null;
|
||||
/**
|
||||
* Cluster convergence: adopt the newest signing key in the shared DB as this node's active key.
|
||||
* Runs on every node so a key a peer just minted becomes the shared active signer within one
|
||||
* interval, keeping cluster rotation equivalent to single-node. Cluster-only: a single node
|
||||
* always holds its own newest key, so this is skipped entirely off-cluster.
|
||||
*/
|
||||
@Scheduled(fixedDelayString = "${stirling.security.jwt.activeKeyReloadMs:300000}")
|
||||
public void reloadActiveKeyFromDb() {
|
||||
if (!clusterEnabled || !isKeystoreEnabled()) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
Optional<JwtSigningKeyEntity> newestOpt =
|
||||
keyRepository.findFirstByOrderByCreatedAtDesc();
|
||||
if (newestOpt.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
JwtSigningKeyEntity newest = newestOpt.get();
|
||||
JwtVerificationKey current = activeKey;
|
||||
if (current != null && newest.getKeyId().equals(current.getKeyId())) {
|
||||
return;
|
||||
}
|
||||
JwtVerificationKey adopted =
|
||||
new JwtVerificationKey(newest.getKeyId(), newest.getVerifyingKey());
|
||||
verifyingKeyCache.put(newest.getKeyId(), adopted);
|
||||
activeKey = adopted;
|
||||
log.info(
|
||||
"Adopted newest JWT signing key {} from the shared DB as active",
|
||||
newest.getKeyId());
|
||||
} catch (Exception e) {
|
||||
log.warn("Could not reload active JWT key from the shared DB: {}", e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/** Load every signing key from the shared DB into the caches; most recent becomes active. */
|
||||
private void loadKeysFromDb() {
|
||||
List<JwtSigningKeyEntity> keys = keyRepository.findAllByOrderByCreatedAtDesc();
|
||||
if (keys.isEmpty()) {
|
||||
log.info("No JWT keys in the database, generating a new keypair");
|
||||
generateAndStoreKeypair();
|
||||
return;
|
||||
}
|
||||
for (JwtSigningKeyEntity key : keys) {
|
||||
verifyingKeyCache.put(
|
||||
key.getKeyId(), new JwtVerificationKey(key.getKeyId(), key.getVerifyingKey()));
|
||||
}
|
||||
activeKey = new JwtVerificationKey(keys.get(0).getKeyId(), keys.get(0).getVerifyingKey());
|
||||
log.info("Loaded {} JWT key(s) from DB, active key: {}", keys.size(), activeKey.getKeyId());
|
||||
}
|
||||
|
||||
private JwtVerificationKey generateAndStoreKeypair() {
|
||||
try {
|
||||
KeyPair keyPair = generateRSAKeypair();
|
||||
String keyId = generateKeyId();
|
||||
String verifyingKey = encodePublicKey(keyPair.getPublic());
|
||||
String signingKey =
|
||||
Base64.getEncoder().encodeToString(keyPair.getPrivate().getEncoded());
|
||||
|
||||
storeKeyPair(keyId, keyPair);
|
||||
verifyingKey = new JwtVerificationKey(keyId, encodePublicKey(keyPair.getPublic()));
|
||||
verifyingKeyCache.put(keyId, verifyingKey);
|
||||
activeKey = verifyingKey;
|
||||
// Converter encrypts the private key at rest with the shared credential-encryption key.
|
||||
keyRepository.save(new JwtSigningKeyEntity(keyId, verifyingKey, signingKey));
|
||||
|
||||
keyPairCache.put(keyId, keyPair);
|
||||
JwtVerificationKey verificationKey = new JwtVerificationKey(keyId, verifyingKey);
|
||||
verifyingKeyCache.put(keyId, verificationKey);
|
||||
activeKey = verificationKey;
|
||||
log.info("Generated and stored new JWT keypair: {}", keyId);
|
||||
} catch (IOException e) {
|
||||
return verificationKey;
|
||||
} catch (RuntimeException e) {
|
||||
log.error("Failed to generate and store keypair", e);
|
||||
return null;
|
||||
}
|
||||
|
||||
return verifyingKey;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -207,25 +169,29 @@ public class KeyPersistenceService implements KeyPersistenceServiceInterface {
|
||||
|
||||
@Override
|
||||
public Optional<KeyPair> getKeyPair(String keyId) {
|
||||
if (!isKeystoreEnabled()) {
|
||||
if (!isKeystoreEnabled() || keyId == null) {
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
KeyPair cached = keyPairCache.get(keyId);
|
||||
if (cached != null) {
|
||||
return Optional.of(cached);
|
||||
}
|
||||
Optional<JwtSigningKeyEntity> entityOpt = keyRepository.findById(keyId);
|
||||
if (entityOpt.isEmpty()) {
|
||||
log.warn("No signing key found in DB for keyId: {}", keyId);
|
||||
return Optional.empty();
|
||||
}
|
||||
JwtSigningKeyEntity entity = entityOpt.get();
|
||||
try {
|
||||
JwtVerificationKey verifyingKey =
|
||||
verifyingKeyCache.get(keyId, JwtVerificationKey.class);
|
||||
|
||||
if (verifyingKey == null) {
|
||||
log.warn("No signing key found in database for keyId: {}", keyId);
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
PrivateKey privateKey = loadPrivateKey(keyId);
|
||||
PublicKey publicKey = decodePublicKey(verifyingKey.getVerifyingKey());
|
||||
|
||||
return Optional.of(new KeyPair(publicKey, privateKey));
|
||||
} catch (Exception e) {
|
||||
log.error("Failed to load keypair for keyId: {}", keyId, e);
|
||||
KeyPair keyPair =
|
||||
new KeyPair(
|
||||
decodePublicKey(entity.getVerifyingKey()),
|
||||
decodePrivateKey(entity.getSigningKey()));
|
||||
keyPairCache.put(keyId, keyPair);
|
||||
verifyingKeyCache.put(keyId, new JwtVerificationKey(keyId, entity.getVerifyingKey()));
|
||||
return Optional.of(keyPair);
|
||||
} catch (NoSuchAlgorithmException | InvalidKeySpecException e) {
|
||||
log.error("Failed to decode keypair for keyId: {}", keyId, e);
|
||||
return Optional.empty();
|
||||
}
|
||||
}
|
||||
@@ -241,44 +207,69 @@ public class KeyPersistenceService implements KeyPersistenceServiceInterface {
|
||||
}
|
||||
|
||||
@Override
|
||||
@CacheEvict(
|
||||
value = {"verifyingKeys"},
|
||||
key = "#keyId",
|
||||
condition = "#root.target.isKeystoreEnabled()")
|
||||
public void removeKey(String keyId) {
|
||||
keyRepository.deleteById(keyId);
|
||||
verifyingKeyCache.evict(keyId);
|
||||
keyPairCache.remove(keyId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<JwtVerificationKey> getKeysEligibleForCleanup(LocalDateTime cutoffDate) {
|
||||
CaffeineCache caffeineCache = (CaffeineCache) verifyingKeyCache;
|
||||
com.github.benmanes.caffeine.cache.Cache<Object, Object> nativeCache =
|
||||
caffeineCache.getNativeCache();
|
||||
|
||||
log.debug(
|
||||
"Cache size: {}, Checking {} keys for cleanup",
|
||||
nativeCache.estimatedSize(),
|
||||
nativeCache.asMap().size());
|
||||
|
||||
return nativeCache.asMap().values().stream()
|
||||
.filter(value -> value instanceof JwtVerificationKey)
|
||||
.map(value -> (JwtVerificationKey) value)
|
||||
.filter(
|
||||
key -> {
|
||||
boolean eligible = key.getCreatedAt().isBefore(cutoffDate);
|
||||
log.debug(
|
||||
"Key {} created at {}, eligible for cleanup: {}",
|
||||
key.getKeyId(),
|
||||
key.getCreatedAt(),
|
||||
eligible);
|
||||
return eligible;
|
||||
})
|
||||
return keyRepository.findByCreatedAtBefore(cutoffDate).stream()
|
||||
.map(e -> new JwtVerificationKey(e.getKeyId(), e.getVerifyingKey()))
|
||||
.toList();
|
||||
}
|
||||
|
||||
/** Import any pre-existing on-disk keys into the DB once, so upgrades keep sessions valid. */
|
||||
private void importLegacyDiskKeysIfPresent() {
|
||||
if (keyRepository.count() > 0) {
|
||||
return;
|
||||
}
|
||||
Path keyDirectory = Path.of(InstallationPathConfig.getPrivateKeyPath());
|
||||
if (!Files.exists(keyDirectory)) {
|
||||
return;
|
||||
}
|
||||
List<Path> keyFiles;
|
||||
try (var stream = Files.list(keyDirectory)) {
|
||||
keyFiles = stream.filter(p -> p.toString().endsWith(KEY_SUFFIX)).toList();
|
||||
} catch (IOException e) {
|
||||
log.warn("Could not list legacy key directory {}: {}", keyDirectory, e.getMessage());
|
||||
return;
|
||||
}
|
||||
int imported = 0;
|
||||
for (Path keyFile : keyFiles) {
|
||||
String keyId = keyFile.getFileName().toString().replace(KEY_SUFFIX, "");
|
||||
try {
|
||||
PrivateKey privateKey = loadPrivateKey(keyId);
|
||||
String verifyingKey = resolveLegacyPublicKey(keyId, privateKey);
|
||||
String signingKey = Base64.getEncoder().encodeToString(privateKey.getEncoded());
|
||||
keyRepository.save(new JwtSigningKeyEntity(keyId, verifyingKey, signingKey));
|
||||
imported++;
|
||||
} catch (Exception e) {
|
||||
log.warn("Skipping legacy key {}: {}", keyId, e.getMessage());
|
||||
}
|
||||
}
|
||||
if (imported > 0) {
|
||||
log.info("Imported {} legacy JWT key(s) from disk into the shared DB", imported);
|
||||
}
|
||||
}
|
||||
|
||||
private String resolveLegacyPublicKey(String keyId, PrivateKey privateKey)
|
||||
throws NoSuchAlgorithmException, InvalidKeySpecException {
|
||||
try {
|
||||
return loadPublicKey(keyId);
|
||||
} catch (IOException e) {
|
||||
// No .pub file: derive the public key from the RSA private key.
|
||||
return encodePublicKey(reconstructKeyPair(privateKey).getPublic());
|
||||
}
|
||||
}
|
||||
|
||||
// UUID suffix so two nodes booting the same second don't collide on keyId.
|
||||
private String generateKeyId() {
|
||||
return "jwt-key-"
|
||||
+ LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd-HHmmss"));
|
||||
+ LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd-HHmmss"))
|
||||
+ "-"
|
||||
+ UUID.randomUUID().toString().substring(0, 8);
|
||||
}
|
||||
|
||||
private KeyPair generateRSAKeypair() {
|
||||
@@ -291,125 +282,49 @@ public class KeyPersistenceService implements KeyPersistenceServiceInterface {
|
||||
}
|
||||
}
|
||||
|
||||
private void ensurePrivateKeyDirectoryExists() throws IOException {
|
||||
Path keyPath = Path.of(InstallationPathConfig.getPrivateKeyPath());
|
||||
|
||||
if (!Files.exists(keyPath)) {
|
||||
Files.createDirectories(keyPath);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Store both private and public keys to disk.
|
||||
*
|
||||
* <p>Private key stored as: keyId.key
|
||||
*
|
||||
* <p>Public key stored as: keyId.pub
|
||||
*/
|
||||
private void storeKeyPair(String keyId, KeyPair keyPair) throws IOException {
|
||||
Path keyDirectory = Path.of(InstallationPathConfig.getPrivateKeyPath());
|
||||
|
||||
// Store private key
|
||||
Path privateKeyFile = keyDirectory.resolve(keyId + KEY_SUFFIX);
|
||||
String encodedPrivateKey =
|
||||
Base64.getEncoder().encodeToString(keyPair.getPrivate().getEncoded());
|
||||
Files.writeString(privateKeyFile, encodedPrivateKey);
|
||||
|
||||
// Set read/write to only the owner (security)
|
||||
privateKeyFile.toFile().setReadable(true, true);
|
||||
privateKeyFile.toFile().setWritable(true, true);
|
||||
privateKeyFile.toFile().setExecutable(false, false);
|
||||
|
||||
// Store public key
|
||||
Path publicKeyFile = keyDirectory.resolve(keyId + PUB_KEY_SUFFIX);
|
||||
String encodedPublicKey =
|
||||
Base64.getEncoder().encodeToString(keyPair.getPublic().getEncoded());
|
||||
Files.writeString(publicKeyFile, encodedPublicKey);
|
||||
|
||||
// Public key can be more permissive but still restrict to owner
|
||||
publicKeyFile.toFile().setReadable(true, true);
|
||||
publicKeyFile.toFile().setWritable(true, true);
|
||||
publicKeyFile.toFile().setExecutable(false, false);
|
||||
|
||||
log.debug(
|
||||
"Stored keypair to disk: {} (private: {}, public: {})",
|
||||
keyId,
|
||||
privateKeyFile.getFileName(),
|
||||
publicKeyFile.getFileName());
|
||||
}
|
||||
|
||||
private PrivateKey loadPrivateKey(String keyId)
|
||||
throws IOException, NoSuchAlgorithmException, InvalidKeySpecException {
|
||||
Path keyFile =
|
||||
Path.of(InstallationPathConfig.getPrivateKeyPath()).resolve(keyId + KEY_SUFFIX);
|
||||
|
||||
if (!Files.exists(keyFile)) {
|
||||
throw new IOException("Private key not found: " + keyFile);
|
||||
}
|
||||
|
||||
String encodedKey = Files.readString(keyFile);
|
||||
byte[] keyBytes = Base64.getDecoder().decode(encodedKey);
|
||||
PKCS8EncodedKeySpec keySpec = new PKCS8EncodedKeySpec(keyBytes);
|
||||
KeyFactory keyFactory = KeyFactory.getInstance("RSA");
|
||||
|
||||
return keyFactory.generatePrivate(keySpec);
|
||||
return decodePrivateKey(Files.readString(keyFile));
|
||||
}
|
||||
|
||||
/**
|
||||
* Load public key from disk.
|
||||
*
|
||||
* @param keyId the key identifier
|
||||
* @return Base64-encoded public key string
|
||||
* @throws IOException if the public key file is not found
|
||||
*/
|
||||
private String loadPublicKey(String keyId) throws IOException {
|
||||
Path publicKeyFile =
|
||||
Path.of(InstallationPathConfig.getPrivateKeyPath()).resolve(keyId + PUB_KEY_SUFFIX);
|
||||
|
||||
if (!Files.exists(publicKeyFile)) {
|
||||
throw new IOException("Public key not found: " + publicKeyFile);
|
||||
}
|
||||
|
||||
return Files.readString(publicKeyFile).trim();
|
||||
}
|
||||
|
||||
/**
|
||||
* Reconstruct a KeyPair from a PrivateKey.
|
||||
*
|
||||
* <p>For RSA keys, derives the public key from the private key.
|
||||
*
|
||||
* @param privateKey the RSA private key
|
||||
* @return reconstructed KeyPair
|
||||
* @throws NoSuchAlgorithmException if RSA algorithm is not available
|
||||
* @throws InvalidKeySpecException if the key specification is invalid
|
||||
*/
|
||||
private KeyPair reconstructKeyPair(PrivateKey privateKey)
|
||||
throws NoSuchAlgorithmException, InvalidKeySpecException {
|
||||
// For RSA, we can derive the public key from the private key
|
||||
KeyFactory keyFactory = KeyFactory.getInstance("RSA");
|
||||
|
||||
// Get the private key spec
|
||||
RSAPrivateCrtKey rsaPrivateKey = (RSAPrivateCrtKey) privateKey;
|
||||
|
||||
// Create public key spec from private key parameters
|
||||
RSAPublicKeySpec publicKeySpec =
|
||||
new RSAPublicKeySpec(rsaPrivateKey.getModulus(), rsaPrivateKey.getPublicExponent());
|
||||
|
||||
// Generate public key
|
||||
PublicKey publicKey = keyFactory.generatePublic(publicKeySpec);
|
||||
|
||||
return new KeyPair(publicKey, privateKey);
|
||||
return new KeyPair(keyFactory.generatePublic(publicKeySpec), privateKey);
|
||||
}
|
||||
|
||||
private String encodePublicKey(PublicKey publicKey) {
|
||||
return Base64.getEncoder().encodeToString(publicKey.getEncoded());
|
||||
}
|
||||
|
||||
@Override
|
||||
public PublicKey decodePublicKey(String encodedKey)
|
||||
throws NoSuchAlgorithmException, InvalidKeySpecException {
|
||||
byte[] keyBytes = Base64.getDecoder().decode(encodedKey);
|
||||
X509EncodedKeySpec keySpec = new X509EncodedKeySpec(keyBytes);
|
||||
KeyFactory keyFactory = KeyFactory.getInstance("RSA");
|
||||
return keyFactory.generatePublic(keySpec);
|
||||
X509EncodedKeySpec keySpec = new X509EncodedKeySpec(Base64.getDecoder().decode(encodedKey));
|
||||
return KeyFactory.getInstance("RSA").generatePublic(keySpec);
|
||||
}
|
||||
|
||||
private PrivateKey decodePrivateKey(String encodedKey)
|
||||
throws NoSuchAlgorithmException, InvalidKeySpecException {
|
||||
PKCS8EncodedKeySpec keySpec =
|
||||
new PKCS8EncodedKeySpec(Base64.getDecoder().decode(encodedKey));
|
||||
return KeyFactory.getInstance("RSA").generatePrivate(keySpec);
|
||||
}
|
||||
}
|
||||
|
||||
+7
-1
@@ -27,6 +27,8 @@ import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.server.ResponseStatusException;
|
||||
import org.springframework.web.servlet.mvc.method.annotation.SseEmitter;
|
||||
|
||||
import stirling.software.common.cluster.JobStore;
|
||||
import stirling.software.common.cluster.inprocess.InProcessJobStore;
|
||||
import stirling.software.common.model.ApplicationProperties;
|
||||
import stirling.software.common.model.job.JobResponse;
|
||||
import stirling.software.common.service.JobOwnershipService;
|
||||
@@ -78,6 +80,7 @@ class PolicyControllerTest {
|
||||
@Mock private JobOwnershipService jobOwnershipService;
|
||||
|
||||
private ApplicationProperties applicationProperties;
|
||||
private final JobStore jobStore = new InProcessJobStore();
|
||||
private PolicyController controller;
|
||||
|
||||
private final java.util.List<stirling.software.proprietary.policy.trigger.PolicyTrigger>
|
||||
@@ -106,7 +109,8 @@ class PolicyControllerTest {
|
||||
policyTriggers,
|
||||
applicationProperties,
|
||||
tempFileManager,
|
||||
jobOwnershipService);
|
||||
jobOwnershipService,
|
||||
jobStore);
|
||||
}
|
||||
|
||||
private static stirling.software.proprietary.policy.trigger.PolicyTrigger trigger(
|
||||
@@ -264,6 +268,8 @@ class PolicyControllerTest {
|
||||
@DisplayName("returns 404 when run is unknown")
|
||||
void notFound() {
|
||||
when(runRegistry.get("missing")).thenReturn(null);
|
||||
when(jobOwnershipService.extractJobId("missing")).thenReturn("missing");
|
||||
when(jobOwnershipService.createScopedJobKey("missing")).thenReturn("missing");
|
||||
|
||||
ResponseEntity<PolicyRunView> response = controller.status("missing");
|
||||
|
||||
|
||||
+102
@@ -0,0 +1,102 @@
|
||||
package stirling.software.proprietary.security.service;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.Mockito.lenient;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
|
||||
import stirling.software.common.cluster.DistributedLock;
|
||||
import stirling.software.common.cluster.DistributedLock.LockHandle;
|
||||
import stirling.software.common.model.ApplicationProperties;
|
||||
import stirling.software.proprietary.security.model.JwtVerificationKey;
|
||||
|
||||
/** Cluster safety: pruning JWT keys is single-writer, gated on the shared cleanup lock. */
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
class KeyPairCleanupServiceTest {
|
||||
|
||||
@Mock private KeyPersistenceService keyPersistenceService;
|
||||
@Mock private ApplicationProperties applicationProperties;
|
||||
@Mock private ApplicationProperties.Security security;
|
||||
@Mock private ApplicationProperties.Security.Jwt jwtProperties;
|
||||
@Mock private DistributedLock distributedLock;
|
||||
@Mock private LockHandle lockHandle;
|
||||
|
||||
private KeyPairCleanupService cleanupService;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
lenient().when(applicationProperties.getSecurity()).thenReturn(security);
|
||||
lenient().when(security.getJwt()).thenReturn(jwtProperties);
|
||||
lenient().when(jwtProperties.isEnableKeyCleanup()).thenReturn(true);
|
||||
lenient().when(keyPersistenceService.isKeystoreEnabled()).thenReturn(true);
|
||||
cleanupService =
|
||||
new KeyPairCleanupService(
|
||||
keyPersistenceService, applicationProperties, distributedLock);
|
||||
}
|
||||
|
||||
@Test
|
||||
void skipsPruningWhenAnotherNodeHoldsTheLock() {
|
||||
when(distributedLock.tryAcquire(any(), any())).thenReturn(Optional.empty());
|
||||
|
||||
cleanupService.cleanup();
|
||||
|
||||
// No node-local pruning happened; the lock holder owns this cycle.
|
||||
verify(keyPersistenceService, never()).getKeysEligibleForCleanup(any());
|
||||
verify(keyPersistenceService, never()).refreshActiveKeyPair();
|
||||
}
|
||||
|
||||
@Test
|
||||
void prunesAndRotatesWhenLockAcquiredThenReleasesIt() {
|
||||
when(distributedLock.tryAcquire(any(), any())).thenReturn(Optional.of(lockHandle));
|
||||
when(keyPersistenceService.getKeysEligibleForCleanup(any()))
|
||||
.thenReturn(List.of(new JwtVerificationKey("old-key", "cHVi")));
|
||||
|
||||
cleanupService.cleanup();
|
||||
|
||||
verify(keyPersistenceService).removeKey("old-key");
|
||||
verify(keyPersistenceService).refreshActiveKeyPair();
|
||||
verify(lockHandle).close();
|
||||
}
|
||||
|
||||
@Test
|
||||
void releasesTheLockEvenWhenNoKeysAreEligible() {
|
||||
when(distributedLock.tryAcquire(any(), any())).thenReturn(Optional.of(lockHandle));
|
||||
when(keyPersistenceService.getKeysEligibleForCleanup(any())).thenReturn(List.of());
|
||||
|
||||
cleanupService.cleanup();
|
||||
|
||||
verify(keyPersistenceService, never()).refreshActiveKeyPair();
|
||||
verify(lockHandle).close();
|
||||
}
|
||||
|
||||
@Test
|
||||
void skipsPruningWhenTheLockBackendErrors() {
|
||||
// A Valkey blip at boot must not fail startup: tryAcquire throwing degrades to skip.
|
||||
when(distributedLock.tryAcquire(any(), any()))
|
||||
.thenThrow(new RuntimeException("valkey unreachable"));
|
||||
|
||||
cleanupService.cleanup();
|
||||
|
||||
verify(keyPersistenceService, never()).getKeysEligibleForCleanup(any());
|
||||
verify(keyPersistenceService, never()).refreshActiveKeyPair();
|
||||
}
|
||||
|
||||
@Test
|
||||
void doesNothingWhenCleanupDisabled() {
|
||||
when(jwtProperties.isEnableKeyCleanup()).thenReturn(false);
|
||||
|
||||
cleanupService.cleanup();
|
||||
|
||||
verify(distributedLock, never()).tryAcquire(any(), any());
|
||||
}
|
||||
}
|
||||
+93
-144
@@ -4,45 +4,41 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.Mockito.lenient;
|
||||
import static org.mockito.Mockito.mockStatic;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.security.KeyPair;
|
||||
import java.security.KeyPairGenerator;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.util.Base64;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.junit.jupiter.api.io.TempDir;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.ValueSource;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockedStatic;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
import org.springframework.cache.CacheManager;
|
||||
import org.springframework.cache.concurrent.ConcurrentMapCacheManager;
|
||||
|
||||
import stirling.software.common.configuration.InstallationPathConfig;
|
||||
import stirling.software.common.model.ApplicationProperties;
|
||||
import stirling.software.proprietary.security.model.JwtSigningKeyEntity;
|
||||
import stirling.software.proprietary.security.model.JwtVerificationKey;
|
||||
import stirling.software.proprietary.security.repository.JwtSigningKeyRepository;
|
||||
|
||||
/** DB-backed keystore: a key present only in the shared DB still resolves (the cross-node case). */
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
class KeyPersistenceServiceInterfaceTest {
|
||||
|
||||
@Mock private ApplicationProperties applicationProperties;
|
||||
|
||||
@Mock private ApplicationProperties.Security security;
|
||||
|
||||
@Mock private ApplicationProperties.Security.Jwt jwtConfig;
|
||||
|
||||
@TempDir Path tempDir;
|
||||
@Mock private JwtSigningKeyRepository keyRepository;
|
||||
|
||||
private KeyPersistenceService keyPersistenceService;
|
||||
private KeyPair testKeyPair;
|
||||
@@ -58,175 +54,128 @@ class KeyPersistenceServiceInterfaceTest {
|
||||
|
||||
lenient().when(applicationProperties.getSecurity()).thenReturn(security);
|
||||
lenient().when(security.getJwt()).thenReturn(jwtConfig);
|
||||
lenient().when(jwtConfig.isEnableKeystore()).thenReturn(true); // Default value
|
||||
lenient().when(jwtConfig.isEnableKeystore()).thenReturn(true);
|
||||
lenient().when(keyRepository.save(any())).thenAnswer(inv -> inv.getArgument(0));
|
||||
// clusterEnabled=true so the convergence-reload path is exercised.
|
||||
keyPersistenceService =
|
||||
new KeyPersistenceService(applicationProperties, cacheManager, keyRepository, true);
|
||||
}
|
||||
|
||||
private JwtSigningKeyEntity entityFrom(String keyId) {
|
||||
return new JwtSigningKeyEntity(
|
||||
keyId,
|
||||
Base64.getEncoder().encodeToString(testKeyPair.getPublic().getEncoded()),
|
||||
Base64.getEncoder().encodeToString(testKeyPair.getPrivate().getEncoded()));
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@ValueSource(booleans = {true, false})
|
||||
void testKeystoreEnabled(boolean keystoreEnabled) {
|
||||
when(jwtConfig.isEnableKeystore()).thenReturn(keystoreEnabled);
|
||||
|
||||
try (MockedStatic<InstallationPathConfig> mockedStatic =
|
||||
mockStatic(InstallationPathConfig.class)) {
|
||||
mockedStatic
|
||||
.when(InstallationPathConfig::getPrivateKeyPath)
|
||||
.thenReturn(tempDir.toString());
|
||||
keyPersistenceService = new KeyPersistenceService(applicationProperties, cacheManager);
|
||||
|
||||
assertEquals(keystoreEnabled, keyPersistenceService.isKeystoreEnabled());
|
||||
}
|
||||
assertEquals(keystoreEnabled, keyPersistenceService.isKeystoreEnabled());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testGetActiveKeypairWhenNoActiveKeyExists() {
|
||||
try (MockedStatic<InstallationPathConfig> mockedStatic =
|
||||
mockStatic(InstallationPathConfig.class)) {
|
||||
mockedStatic
|
||||
.when(InstallationPathConfig::getPrivateKeyPath)
|
||||
.thenReturn(tempDir.toString());
|
||||
keyPersistenceService = new KeyPersistenceService(applicationProperties, cacheManager);
|
||||
keyPersistenceService.initializeKeystore();
|
||||
void generatesAndPersistsAKeyWhenNoneIsActive() {
|
||||
// getActiveKey with no active key mints one and persists it - no disk involved.
|
||||
JwtVerificationKey active = keyPersistenceService.getActiveKey();
|
||||
|
||||
JwtVerificationKey result = keyPersistenceService.getActiveKey();
|
||||
|
||||
assertNotNull(result);
|
||||
assertNotNull(result.getKeyId());
|
||||
assertNotNull(result.getVerifyingKey());
|
||||
}
|
||||
assertNotNull(active);
|
||||
assertNotNull(active.getKeyId());
|
||||
assertNotNull(active.getVerifyingKey());
|
||||
verify(keyRepository).save(any(JwtSigningKeyEntity.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testGetActiveKeyPairWithExistingKey() throws Exception {
|
||||
String keyId = "test-key-2024-01-01-120000";
|
||||
String publicKeyBase64 =
|
||||
Base64.getEncoder().encodeToString(testKeyPair.getPublic().getEncoded());
|
||||
String privateKeyBase64 =
|
||||
Base64.getEncoder().encodeToString(testKeyPair.getPrivate().getEncoded());
|
||||
void loadsTheMostRecentExistingKeyAsActive() {
|
||||
when(keyRepository.count()).thenReturn(1L);
|
||||
when(keyRepository.findAllByOrderByCreatedAtDesc())
|
||||
.thenReturn(List.of(entityFrom("jwt-key-2026-07-13-000000-abcd1234")));
|
||||
|
||||
JwtVerificationKey existingKey = new JwtVerificationKey(keyId, publicKeyBase64);
|
||||
keyPersistenceService.initializeKeystore();
|
||||
JwtVerificationKey active = keyPersistenceService.getActiveKey();
|
||||
|
||||
Path keyFile = tempDir.resolve(keyId + ".key");
|
||||
Files.writeString(keyFile, privateKeyBase64);
|
||||
|
||||
try (MockedStatic<InstallationPathConfig> mockedStatic =
|
||||
mockStatic(InstallationPathConfig.class)) {
|
||||
mockedStatic
|
||||
.when(InstallationPathConfig::getPrivateKeyPath)
|
||||
.thenReturn(tempDir.toString());
|
||||
keyPersistenceService = new KeyPersistenceService(applicationProperties, cacheManager);
|
||||
keyPersistenceService.initializeKeystore();
|
||||
|
||||
JwtVerificationKey result = keyPersistenceService.getActiveKey();
|
||||
|
||||
assertNotNull(result);
|
||||
assertNotNull(result.getKeyId());
|
||||
}
|
||||
assertEquals("jwt-key-2026-07-13-000000-abcd1234", active.getKeyId());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testGetKeyPair() throws Exception {
|
||||
String keyId = "test-key-123";
|
||||
String publicKeyBase64 =
|
||||
Base64.getEncoder().encodeToString(testKeyPair.getPublic().getEncoded());
|
||||
String privateKeyBase64 =
|
||||
Base64.getEncoder().encodeToString(testKeyPair.getPrivate().getEncoded());
|
||||
void getKeyPairResolvesAKeyPresentOnlyInTheSharedDb() {
|
||||
// Never initialised locally: the key lives only in the DB, as if another node minted it.
|
||||
String keyId = "jwt-key-from-another-node";
|
||||
when(keyRepository.findById(keyId)).thenReturn(Optional.of(entityFrom(keyId)));
|
||||
|
||||
JwtVerificationKey signingKey = new JwtVerificationKey(keyId, publicKeyBase64);
|
||||
Optional<KeyPair> result = keyPersistenceService.getKeyPair(keyId);
|
||||
|
||||
Path keyFile = tempDir.resolve(keyId + ".key");
|
||||
Files.writeString(keyFile, privateKeyBase64);
|
||||
|
||||
try (MockedStatic<InstallationPathConfig> mockedStatic =
|
||||
mockStatic(InstallationPathConfig.class)) {
|
||||
mockedStatic
|
||||
.when(InstallationPathConfig::getPrivateKeyPath)
|
||||
.thenReturn(tempDir.toString());
|
||||
keyPersistenceService = new KeyPersistenceService(applicationProperties, cacheManager);
|
||||
|
||||
keyPersistenceService
|
||||
.getClass()
|
||||
.getDeclaredField("verifyingKeyCache")
|
||||
.setAccessible(true);
|
||||
var cache = cacheManager.getCache("verifyingKeys");
|
||||
cache.put(keyId, signingKey);
|
||||
|
||||
Optional<KeyPair> result = keyPersistenceService.getKeyPair(keyId);
|
||||
|
||||
assertTrue(result.isPresent());
|
||||
assertNotNull(result.get().getPublic());
|
||||
assertNotNull(result.get().getPrivate());
|
||||
}
|
||||
assertTrue(result.isPresent());
|
||||
assertNotNull(result.get().getPublic());
|
||||
assertNotNull(result.get().getPrivate());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testGetKeyPairNotFound() {
|
||||
String keyId = "non-existent-key";
|
||||
|
||||
try (MockedStatic<InstallationPathConfig> mockedStatic =
|
||||
mockStatic(InstallationPathConfig.class)) {
|
||||
mockedStatic
|
||||
.when(InstallationPathConfig::getPrivateKeyPath)
|
||||
.thenReturn(tempDir.toString());
|
||||
keyPersistenceService = new KeyPersistenceService(applicationProperties, cacheManager);
|
||||
|
||||
Optional<KeyPair> result = keyPersistenceService.getKeyPair(keyId);
|
||||
|
||||
assertFalse(result.isPresent());
|
||||
}
|
||||
void getKeyPairIsEmptyWhenTheKeyIsUnknown() {
|
||||
when(keyRepository.findById("nope")).thenReturn(Optional.empty());
|
||||
assertFalse(keyPersistenceService.getKeyPair("nope").isPresent());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testGetKeyPairWhenKeystoreDisabled() {
|
||||
void getKeyPairIsEmptyWhenKeystoreDisabled() {
|
||||
when(jwtConfig.isEnableKeystore()).thenReturn(false);
|
||||
|
||||
try (MockedStatic<InstallationPathConfig> mockedStatic =
|
||||
mockStatic(InstallationPathConfig.class)) {
|
||||
mockedStatic
|
||||
.when(InstallationPathConfig::getPrivateKeyPath)
|
||||
.thenReturn(tempDir.toString());
|
||||
keyPersistenceService = new KeyPersistenceService(applicationProperties, cacheManager);
|
||||
|
||||
Optional<KeyPair> result = keyPersistenceService.getKeyPair("any-key");
|
||||
|
||||
assertFalse(result.isPresent());
|
||||
}
|
||||
assertFalse(keyPersistenceService.getKeyPair("any-key").isPresent());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testInitializeKeystoreCreatesDirectory() throws IOException {
|
||||
try (MockedStatic<InstallationPathConfig> mockedStatic =
|
||||
mockStatic(InstallationPathConfig.class)) {
|
||||
mockedStatic
|
||||
.when(InstallationPathConfig::getPrivateKeyPath)
|
||||
.thenReturn(tempDir.toString());
|
||||
keyPersistenceService = new KeyPersistenceService(applicationProperties, cacheManager);
|
||||
keyPersistenceService.initializeKeystore();
|
||||
void eligibleForCleanupIsSourcedFromTheDb() {
|
||||
when(keyRepository.findByCreatedAtBefore(any())).thenReturn(List.of(entityFrom("old-key")));
|
||||
|
||||
assertTrue(Files.exists(tempDir));
|
||||
assertTrue(Files.isDirectory(tempDir));
|
||||
}
|
||||
List<JwtVerificationKey> stale =
|
||||
keyPersistenceService.getKeysEligibleForCleanup(java.time.LocalDateTime.now());
|
||||
|
||||
assertEquals(1, stale.size());
|
||||
assertEquals("old-key", stale.get(0).getKeyId());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testLoadExistingKeypairWithMissingPrivateKeyFile() throws Exception {
|
||||
String keyId = "test-key-missing-file";
|
||||
String publicKeyBase64 =
|
||||
Base64.getEncoder().encodeToString(testKeyPair.getPublic().getEncoded());
|
||||
void reloadAdoptsTheNewestKeyAPeerMinted() {
|
||||
// Boot with our own key active, then a peer mints a newer one in the shared DB.
|
||||
when(keyRepository.count()).thenReturn(1L);
|
||||
when(keyRepository.findAllByOrderByCreatedAtDesc())
|
||||
.thenReturn(List.of(entityFrom("jwt-key-local-old")));
|
||||
keyPersistenceService.initializeKeystore();
|
||||
assertEquals("jwt-key-local-old", keyPersistenceService.getActiveKey().getKeyId());
|
||||
|
||||
JwtVerificationKey existingKey = new JwtVerificationKey(keyId, publicKeyBase64);
|
||||
when(keyRepository.findFirstByOrderByCreatedAtDesc())
|
||||
.thenReturn(Optional.of(entityFrom("jwt-key-peer-new")));
|
||||
|
||||
try (MockedStatic<InstallationPathConfig> mockedStatic =
|
||||
mockStatic(InstallationPathConfig.class)) {
|
||||
mockedStatic
|
||||
.when(InstallationPathConfig::getPrivateKeyPath)
|
||||
.thenReturn(tempDir.toString());
|
||||
keyPersistenceService = new KeyPersistenceService(applicationProperties, cacheManager);
|
||||
keyPersistenceService.initializeKeystore();
|
||||
keyPersistenceService.reloadActiveKeyFromDb();
|
||||
|
||||
JwtVerificationKey result = keyPersistenceService.getActiveKey();
|
||||
assertNotNull(result);
|
||||
assertNotNull(result.getKeyId());
|
||||
assertNotNull(result.getVerifyingKey());
|
||||
}
|
||||
// Converged: this node now signs with the peer's newer key.
|
||||
assertEquals("jwt-key-peer-new", keyPersistenceService.getActiveKey().getKeyId());
|
||||
}
|
||||
|
||||
@Test
|
||||
void reloadDoesNothingOffCluster() {
|
||||
KeyPersistenceService singleNode =
|
||||
new KeyPersistenceService(
|
||||
applicationProperties, cacheManager, keyRepository, false);
|
||||
|
||||
singleNode.reloadActiveKeyFromDb();
|
||||
|
||||
// Off-cluster the DB is never consulted for convergence.
|
||||
verify(keyRepository, org.mockito.Mockito.never()).findFirstByOrderByCreatedAtDesc();
|
||||
}
|
||||
|
||||
@Test
|
||||
void reloadIsANoOpWhenAlreadyHoldingTheNewestKey() {
|
||||
when(keyRepository.count()).thenReturn(1L);
|
||||
when(keyRepository.findAllByOrderByCreatedAtDesc())
|
||||
.thenReturn(List.of(entityFrom("jwt-key-current")));
|
||||
keyPersistenceService.initializeKeystore();
|
||||
|
||||
when(keyRepository.findFirstByOrderByCreatedAtDesc())
|
||||
.thenReturn(Optional.of(entityFrom("jwt-key-current")));
|
||||
|
||||
keyPersistenceService.reloadActiveKeyFromDb();
|
||||
|
||||
assertEquals("jwt-key-current", keyPersistenceService.getActiveKey().getKeyId());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,7 +11,6 @@ editor/public/vendor/
|
||||
editor/public/mockServiceWorker.js
|
||||
# Auto-generated OG/social-preview metadata (scripts/generate-og-metadata.mjs); regenerated verbatim.
|
||||
editor/public/og-metadata.json
|
||||
editor/public/og-metadata.saas.json
|
||||
editor/src/core/data/ogImageMap.json
|
||||
editor/public/pdfjs*/
|
||||
editor/public/js/thirdParty/
|
||||
|
||||
@@ -1,679 +0,0 @@
|
||||
{
|
||||
"default": {
|
||||
"image": "/og_images/saas/app.png",
|
||||
"title": "Stirling - Edit any PDF. Govern every PDF.",
|
||||
"ogTitle": "Edit any PDF. Govern every PDF.",
|
||||
"description": "The free, open-source PDF Editor, plus a Processor that governs every PDF your organization touches. 1¢ per PDF."
|
||||
},
|
||||
"byTool": {
|
||||
"certSign": {
|
||||
"image": "/og_images/certSign.png",
|
||||
"title": "Certificate Sign - Stirling PDF",
|
||||
"description": "Sign PDF documents using digital certificates"
|
||||
},
|
||||
"sign": {
|
||||
"image": "/og_images/sign.png",
|
||||
"title": "Sign - Stirling PDF",
|
||||
"description": "Adds signature to PDF by drawing, text or image"
|
||||
},
|
||||
"sharedSign": {
|
||||
"image": "/og_images/home.png",
|
||||
"title": "Shared Signing - Stirling PDF",
|
||||
"description": "Request signatures from others and track signing sessions"
|
||||
},
|
||||
"addText": {
|
||||
"image": "/og_images/add-text.png",
|
||||
"title": "Add Text - Stirling PDF",
|
||||
"description": "Add custom text anywhere in your PDF"
|
||||
},
|
||||
"addPassword": {
|
||||
"image": "/og_images/add-password.png",
|
||||
"title": "Add Password - Stirling PDF",
|
||||
"description": "Add password protection and restrictions to PDF files"
|
||||
},
|
||||
"removePassword": {
|
||||
"image": "/og_images/remove-password.png",
|
||||
"title": "Remove Password - Stirling PDF",
|
||||
"description": "Remove password protection from PDF documents"
|
||||
},
|
||||
"removePages": {
|
||||
"image": "/og_images/remove.png",
|
||||
"title": "Remove Pages - Stirling PDF",
|
||||
"description": "Remove specific pages from a PDF document"
|
||||
},
|
||||
"removeBlanks": {
|
||||
"image": "/og_images/remove-blank-pages.png",
|
||||
"title": "Remove Blank Pages - Stirling PDF",
|
||||
"description": "Remove blank pages from PDF documents"
|
||||
},
|
||||
"removeAnnotations": {
|
||||
"image": "/og_images/remove-annotations.png",
|
||||
"title": "Remove Annotations - Stirling PDF",
|
||||
"description": "Remove annotations and comments from PDF documents"
|
||||
},
|
||||
"removeImage": {
|
||||
"image": "/og_images/remove-image.png",
|
||||
"title": "Remove Images - Stirling PDF",
|
||||
"description": "Remove all images from a PDF document"
|
||||
},
|
||||
"changePermissions": {
|
||||
"image": "/og_images/change-permissions.png",
|
||||
"title": "Change Permissions - Stirling PDF",
|
||||
"description": "Change document restrictions and permissions"
|
||||
},
|
||||
"watermark": {
|
||||
"image": "/og_images/add-watermark.png",
|
||||
"title": "Add Watermark - Stirling PDF",
|
||||
"description": "Add a custom watermark to your PDF document."
|
||||
},
|
||||
"sanitize": {
|
||||
"image": "/og_images/sanitize.png",
|
||||
"title": "Sanitize - Stirling PDF",
|
||||
"description": "Remove potentially harmful elements from PDF files"
|
||||
},
|
||||
"split": {
|
||||
"image": "/og_images/split.png",
|
||||
"title": "Split - Stirling PDF",
|
||||
"description": "Split PDFs into multiple documents"
|
||||
},
|
||||
"merge": {
|
||||
"image": "/og_images/mergePdfs.png",
|
||||
"title": "Merge - Stirling PDF",
|
||||
"description": "Merge multiple PDFs into a single document"
|
||||
},
|
||||
"convert": {
|
||||
"image": "/og_images/convert.png",
|
||||
"title": "Convert - Stirling PDF",
|
||||
"description": "Convert files to and from PDF format"
|
||||
},
|
||||
"ocr": {
|
||||
"image": "/og_images/ocr.png",
|
||||
"title": "OCR - Stirling PDF",
|
||||
"description": "Extract text from scanned PDFs using Optical Character Recognition"
|
||||
},
|
||||
"addImage": {
|
||||
"image": "/og_images/add-image.png",
|
||||
"title": "Add Image - Stirling PDF",
|
||||
"description": "Add images anywhere in your PDF"
|
||||
},
|
||||
"rotate": {
|
||||
"image": "/og_images/rotate.png",
|
||||
"title": "Rotate - Stirling PDF",
|
||||
"description": "Easily rotate your PDFs."
|
||||
},
|
||||
"annotate": {
|
||||
"image": "/og_images/annotate.png",
|
||||
"title": "Annotate - Stirling PDF",
|
||||
"description": "Highlight, draw, add notes, and shapes directly in the viewer"
|
||||
},
|
||||
"scannerImageSplit": {
|
||||
"image": "/og_images/detect-split-scanned-photos.png",
|
||||
"title": "Detect & Split Scanned Photos - Stirling PDF",
|
||||
"description": "Detect and split scanned photos into separate pages"
|
||||
},
|
||||
"editTableOfContents": {
|
||||
"image": "/og_images/edit-table-of-contents.png",
|
||||
"title": "Edit Table of Contents - Stirling PDF",
|
||||
"description": "Add or edit bookmarks and table of contents in PDF documents"
|
||||
},
|
||||
"scannerEffect": {
|
||||
"image": "/og_images/scanner-effect.png",
|
||||
"title": "Scanner Effect - Stirling PDF",
|
||||
"description": "Create a PDF that looks like it was scanned"
|
||||
},
|
||||
"autoRename": {
|
||||
"image": "/og_images/auto-rename-pdf-file.png",
|
||||
"title": "Auto Rename PDF File - Stirling PDF",
|
||||
"description": "Automatically rename PDF files based on their content"
|
||||
},
|
||||
"pageLayout": {
|
||||
"image": "/og_images/multi-page-layout.png",
|
||||
"title": "Multi-Page Layout - Stirling PDF",
|
||||
"description": "Merge multiple pages of a PDF document into a single page"
|
||||
},
|
||||
"scalePages": {
|
||||
"image": "/og_images/adjust-page-size-scale.png",
|
||||
"title": "Adjust page size/scale - Stirling PDF",
|
||||
"description": "Change the size/scale of a page and/or its contents."
|
||||
},
|
||||
"adjustContrast": {
|
||||
"image": "/og_images/adjust-colors-contrast.png",
|
||||
"title": "Adjust Colors/Contrast - Stirling PDF",
|
||||
"description": "Adjust colors and contrast of PDF documents"
|
||||
},
|
||||
"crop": {
|
||||
"image": "/og_images/cropPdf.png",
|
||||
"title": "Crop PDF - Stirling PDF",
|
||||
"description": "Crop a PDF to reduce its size (maintains text!)"
|
||||
},
|
||||
"pdfToSinglePage": {
|
||||
"image": "/og_images/single-large-page.png",
|
||||
"title": "PDF to Single Large Page - Stirling PDF",
|
||||
"description": "Merges all PDF pages into one large single page"
|
||||
},
|
||||
"repair": {
|
||||
"image": "/og_images/repair.png",
|
||||
"title": "Repair - Stirling PDF",
|
||||
"description": "Repair corrupted or damaged PDF files"
|
||||
},
|
||||
"compare": {
|
||||
"image": "/og_images/compare.png",
|
||||
"title": "Compare - Stirling PDF",
|
||||
"description": "Compare two PDF documents and highlight differences"
|
||||
},
|
||||
"addPageNumbers": {
|
||||
"image": "/og_images/add-page-numbers.png",
|
||||
"title": "Add Page Numbers - Stirling PDF",
|
||||
"description": "Add Page numbers throughout a document in a set location"
|
||||
},
|
||||
"redact": {
|
||||
"image": "/og_images/redact.png",
|
||||
"title": "Redact - Stirling PDF",
|
||||
"description": "Permanently remove sensitive information from PDF documents"
|
||||
},
|
||||
"flatten": {
|
||||
"image": "/og_images/flatten.png",
|
||||
"title": "Flatten - Stirling PDF",
|
||||
"description": "Remove all interactive elements and forms from a PDF"
|
||||
},
|
||||
"removeCertSign": {
|
||||
"image": "/og_images/remove-certificate-sign.png",
|
||||
"title": "Remove Certificate Sign - Stirling PDF",
|
||||
"description": "Remove digital signature from PDF documents"
|
||||
},
|
||||
"unlockPDFForms": {
|
||||
"image": "/og_images/unlock-pdf-forms.png",
|
||||
"title": "Unlock PDF Forms - Stirling PDF",
|
||||
"description": "Remove read-only property of form fields in a PDF document."
|
||||
},
|
||||
"compress": {
|
||||
"image": "/og_images/compress.png",
|
||||
"title": "Compress - Stirling PDF",
|
||||
"description": "Compress PDFs to reduce their file size."
|
||||
},
|
||||
"extractPages": {
|
||||
"image": "/og_images/extract-pages.png",
|
||||
"title": "Extract Pages - Stirling PDF",
|
||||
"description": "Extract specific pages from a PDF document"
|
||||
},
|
||||
"reorganizePages": {
|
||||
"image": "/og_images/reorganize-pages.png",
|
||||
"title": "Reorganize Pages - Stirling PDF",
|
||||
"description": "Rearrange, duplicate, or delete PDF pages with visual drag-and-drop control."
|
||||
},
|
||||
"extractImages": {
|
||||
"image": "/og_images/extract-images.png",
|
||||
"title": "Extract Images - Stirling PDF",
|
||||
"description": "Extract images from PDF documents"
|
||||
},
|
||||
"addStamp": {
|
||||
"image": "/og_images/add-stamp.png",
|
||||
"title": "Add Stamp to PDF - Stirling PDF",
|
||||
"description": "Add text or add image stamps at set locations"
|
||||
},
|
||||
"addAttachments": {
|
||||
"image": "/og_images/add-attachments.png",
|
||||
"title": "Add Attachments - Stirling PDF",
|
||||
"description": "Add or remove embedded files (attachments) to/from a PDF"
|
||||
},
|
||||
"changeMetadata": {
|
||||
"image": "/og_images/change-metadata.png",
|
||||
"title": "Change Metadata - Stirling PDF",
|
||||
"description": "Change/Remove/Add metadata from a PDF document"
|
||||
},
|
||||
"overlayPdfs": {
|
||||
"image": "/og_images/overlay-pdfs.png",
|
||||
"title": "Overlay Pdfs - Stirling PDF",
|
||||
"description": "The Free Adobe Acrobat alternative (10M+ Downloads)"
|
||||
},
|
||||
"getPdfInfo": {
|
||||
"image": "/og_images/get-all-info-on-pdf.png",
|
||||
"title": "Get ALL Info on PDF - Stirling PDF",
|
||||
"description": "Grabs any and all information possible on PDFs"
|
||||
},
|
||||
"validateSignature": {
|
||||
"image": "/og_images/validate-pdf-signature.png",
|
||||
"title": "Validate PDF Signature - Stirling PDF",
|
||||
"description": "Verify digital signatures and certificates in PDF documents"
|
||||
},
|
||||
"timestampPdf": {
|
||||
"image": "/og_images/timestamp-pdf.png",
|
||||
"title": "Timestamp PDF - Stirling PDF",
|
||||
"description": "Add an RFC 3161 document timestamp to prove when your PDF existed"
|
||||
},
|
||||
"replaceColor": {
|
||||
"image": "/og_images/replace-and-invert-color.png",
|
||||
"title": "Replace & Invert Color - Stirling PDF",
|
||||
"description": "Replace or invert colors in PDF documents"
|
||||
},
|
||||
"showJS": {
|
||||
"image": "/og_images/show-javascript.png",
|
||||
"title": "Show JavaScript - Stirling PDF",
|
||||
"description": "Extract and display JavaScript code from PDF documents"
|
||||
},
|
||||
"bookletImposition": {
|
||||
"image": "/og_images/booklet-imposition.png",
|
||||
"title": "Booklet Imposition - Stirling PDF",
|
||||
"description": "Create booklets with proper page ordering and multi-page layout for printing and binding"
|
||||
},
|
||||
"pdfTextEditor": {
|
||||
"image": "/og_images/pdf-text-editor.png",
|
||||
"title": "PDF Text Editor - Stirling PDF",
|
||||
"description": "Review and edit text and images in PDFs with grouped text editing and PDF regeneration"
|
||||
},
|
||||
"formFill": {
|
||||
"image": "/og_images/form-fill.png",
|
||||
"title": "Fill Form - Stirling PDF",
|
||||
"description": "Fill PDF form fields interactively with a visual editor"
|
||||
},
|
||||
"multiTool": {
|
||||
"image": "/og_images/multi-tool.png",
|
||||
"title": "Multi-Tool - Stirling PDF",
|
||||
"description": "Use multiple tools on a single PDF document"
|
||||
},
|
||||
"read": {
|
||||
"image": "/og_images/read.png",
|
||||
"title": "Read - Stirling PDF",
|
||||
"description": "View and annotate PDFs. Highlight text, draw, or insert comments for review and collaboration."
|
||||
},
|
||||
"automate": {
|
||||
"image": "/og_images/automate.png",
|
||||
"title": "Automate - Stirling PDF",
|
||||
"description": "Build multi-step workflows by chaining together PDF actions. Ideal for recurring tasks."
|
||||
},
|
||||
"devApi": {
|
||||
"image": "/og_images/dev-api.png",
|
||||
"title": "API - Stirling PDF",
|
||||
"description": "Link to API documentation"
|
||||
},
|
||||
"devFolderScanning": {
|
||||
"image": "/og_images/dev-folder-scanning.png",
|
||||
"title": "Automated Folder Scanning - Stirling PDF",
|
||||
"description": "Link to automated folder scanning guide"
|
||||
},
|
||||
"devSsoGuide": {
|
||||
"image": "/og_images/dev-sso-guide.png",
|
||||
"title": "SSO Guide - Stirling PDF",
|
||||
"description": "Link to SSO guide"
|
||||
},
|
||||
"devAirgapped": {
|
||||
"image": "/og_images/dev-airgapped.png",
|
||||
"title": "Air-gapped Setup - Stirling PDF",
|
||||
"description": "Link to air-gapped setup guide"
|
||||
},
|
||||
"/login": {
|
||||
"image": "/og_images/home.png",
|
||||
"title": "Sign In - Stirling PDF",
|
||||
"description": "The Free Adobe Acrobat alternative (10M+ Downloads)"
|
||||
},
|
||||
"/signup": {
|
||||
"image": "/og_images/home.png",
|
||||
"title": "Sign Up - Stirling PDF",
|
||||
"description": "The Free Adobe Acrobat alternative (10M+ Downloads)"
|
||||
},
|
||||
"/mobile-scanner": {
|
||||
"image": "/og_images/home.png",
|
||||
"title": "Mobile Scanner - Stirling PDF",
|
||||
"description": "The Free Adobe Acrobat alternative (10M+ Downloads)"
|
||||
},
|
||||
"/files": {
|
||||
"image": "/og_images/home.png",
|
||||
"title": "Files - Stirling PDF",
|
||||
"description": "The Free Adobe Acrobat alternative (10M+ Downloads)"
|
||||
},
|
||||
"/settings": {
|
||||
"image": "/og_images/home.png",
|
||||
"title": "Settings - Stirling PDF",
|
||||
"description": "The Free Adobe Acrobat alternative (10M+ Downloads)"
|
||||
},
|
||||
"/settings/preferences": {
|
||||
"image": "/og_images/home.png",
|
||||
"title": "Preferences Settings - Stirling PDF",
|
||||
"description": "The Free Adobe Acrobat alternative (10M+ Downloads)"
|
||||
},
|
||||
"/settings/notifications": {
|
||||
"image": "/og_images/home.png",
|
||||
"title": "Notifications Settings - Stirling PDF",
|
||||
"description": "The Free Adobe Acrobat alternative (10M+ Downloads)"
|
||||
},
|
||||
"/settings/connections": {
|
||||
"image": "/og_images/home.png",
|
||||
"title": "Connections Settings - Stirling PDF",
|
||||
"description": "The Free Adobe Acrobat alternative (10M+ Downloads)"
|
||||
},
|
||||
"/settings/account": {
|
||||
"image": "/og_images/home.png",
|
||||
"title": "Account Settings - Stirling PDF",
|
||||
"description": "The Free Adobe Acrobat alternative (10M+ Downloads)"
|
||||
},
|
||||
"/settings/general": {
|
||||
"image": "/og_images/home.png",
|
||||
"title": "General Settings - Stirling PDF",
|
||||
"description": "The Free Adobe Acrobat alternative (10M+ Downloads)"
|
||||
},
|
||||
"/settings/people": {
|
||||
"image": "/og_images/home.png",
|
||||
"title": "People Settings - Stirling PDF",
|
||||
"description": "The Free Adobe Acrobat alternative (10M+ Downloads)"
|
||||
},
|
||||
"/settings/teams": {
|
||||
"image": "/og_images/home.png",
|
||||
"title": "Teams Settings - Stirling PDF",
|
||||
"description": "The Free Adobe Acrobat alternative (10M+ Downloads)"
|
||||
},
|
||||
"/settings/security": {
|
||||
"image": "/og_images/home.png",
|
||||
"title": "Security Settings - Stirling PDF",
|
||||
"description": "The Free Adobe Acrobat alternative (10M+ Downloads)"
|
||||
},
|
||||
"/settings/identity": {
|
||||
"image": "/og_images/home.png",
|
||||
"title": "Identity Settings - Stirling PDF",
|
||||
"description": "The Free Adobe Acrobat alternative (10M+ Downloads)"
|
||||
},
|
||||
"/settings/plan": {
|
||||
"image": "/og_images/home.png",
|
||||
"title": "Plan Settings - Stirling PDF",
|
||||
"description": "The Free Adobe Acrobat alternative (10M+ Downloads)"
|
||||
},
|
||||
"/settings/payments": {
|
||||
"image": "/og_images/home.png",
|
||||
"title": "Payments Settings - Stirling PDF",
|
||||
"description": "The Free Adobe Acrobat alternative (10M+ Downloads)"
|
||||
},
|
||||
"/settings/requests": {
|
||||
"image": "/og_images/home.png",
|
||||
"title": "Requests Settings - Stirling PDF",
|
||||
"description": "The Free Adobe Acrobat alternative (10M+ Downloads)"
|
||||
},
|
||||
"/settings/developer": {
|
||||
"image": "/og_images/home.png",
|
||||
"title": "Developer Settings - Stirling PDF",
|
||||
"description": "The Free Adobe Acrobat alternative (10M+ Downloads)"
|
||||
},
|
||||
"/settings/api-keys": {
|
||||
"image": "/og_images/home.png",
|
||||
"title": "Api Keys Settings - Stirling PDF",
|
||||
"description": "The Free Adobe Acrobat alternative (10M+ Downloads)"
|
||||
},
|
||||
"/settings/hotkeys": {
|
||||
"image": "/og_images/home.png",
|
||||
"title": "Hotkeys Settings - Stirling PDF",
|
||||
"description": "The Free Adobe Acrobat alternative (10M+ Downloads)"
|
||||
},
|
||||
"/settings/adminGeneral": {
|
||||
"image": "/og_images/home.png",
|
||||
"title": "Admin General Settings - Stirling PDF",
|
||||
"description": "The Free Adobe Acrobat alternative (10M+ Downloads)"
|
||||
},
|
||||
"/settings/adminSecurity": {
|
||||
"image": "/og_images/home.png",
|
||||
"title": "Admin Security Settings - Stirling PDF",
|
||||
"description": "The Free Adobe Acrobat alternative (10M+ Downloads)"
|
||||
},
|
||||
"/settings/adminConnections": {
|
||||
"image": "/og_images/home.png",
|
||||
"title": "Admin Connections Settings - Stirling PDF",
|
||||
"description": "The Free Adobe Acrobat alternative (10M+ Downloads)"
|
||||
},
|
||||
"/settings/adminPrivacy": {
|
||||
"image": "/og_images/home.png",
|
||||
"title": "Admin Privacy Settings - Stirling PDF",
|
||||
"description": "The Free Adobe Acrobat alternative (10M+ Downloads)"
|
||||
},
|
||||
"/settings/adminDatabase": {
|
||||
"image": "/og_images/home.png",
|
||||
"title": "Admin Database Settings - Stirling PDF",
|
||||
"description": "The Free Adobe Acrobat alternative (10M+ Downloads)"
|
||||
},
|
||||
"/settings/adminAdvanced": {
|
||||
"image": "/og_images/home.png",
|
||||
"title": "Admin Advanced Settings - Stirling PDF",
|
||||
"description": "The Free Adobe Acrobat alternative (10M+ Downloads)"
|
||||
},
|
||||
"/settings/adminLegal": {
|
||||
"image": "/og_images/home.png",
|
||||
"title": "Admin Legal Settings - Stirling PDF",
|
||||
"description": "The Free Adobe Acrobat alternative (10M+ Downloads)"
|
||||
},
|
||||
"/settings/adminPremium": {
|
||||
"image": "/og_images/home.png",
|
||||
"title": "Admin Premium Settings - Stirling PDF",
|
||||
"description": "The Free Adobe Acrobat alternative (10M+ Downloads)"
|
||||
},
|
||||
"/settings/adminFeatures": {
|
||||
"image": "/og_images/home.png",
|
||||
"title": "Admin Features Settings - Stirling PDF",
|
||||
"description": "The Free Adobe Acrobat alternative (10M+ Downloads)"
|
||||
},
|
||||
"/settings/adminPlan": {
|
||||
"image": "/og_images/home.png",
|
||||
"title": "Admin Plan Settings - Stirling PDF",
|
||||
"description": "The Free Adobe Acrobat alternative (10M+ Downloads)"
|
||||
},
|
||||
"/settings/adminAudit": {
|
||||
"image": "/og_images/home.png",
|
||||
"title": "Admin Audit Settings - Stirling PDF",
|
||||
"description": "The Free Adobe Acrobat alternative (10M+ Downloads)"
|
||||
},
|
||||
"/settings/adminUsage": {
|
||||
"image": "/og_images/home.png",
|
||||
"title": "Admin Usage Settings - Stirling PDF",
|
||||
"description": "The Free Adobe Acrobat alternative (10M+ Downloads)"
|
||||
},
|
||||
"/settings/adminEndpoints": {
|
||||
"image": "/og_images/home.png",
|
||||
"title": "Admin Endpoints Settings - Stirling PDF",
|
||||
"description": "The Free Adobe Acrobat alternative (10M+ Downloads)"
|
||||
},
|
||||
"/settings/adminStorageSharing": {
|
||||
"image": "/og_images/home.png",
|
||||
"title": "Admin Storage Sharing Settings - Stirling PDF",
|
||||
"description": "The Free Adobe Acrobat alternative (10M+ Downloads)"
|
||||
},
|
||||
"/settings/adminMcp": {
|
||||
"image": "/og_images/home.png",
|
||||
"title": "Admin Mcp Settings - Stirling PDF",
|
||||
"description": "The Free Adobe Acrobat alternative (10M+ Downloads)"
|
||||
},
|
||||
"/settings/help": {
|
||||
"image": "/og_images/home.png",
|
||||
"title": "Help Settings - Stirling PDF",
|
||||
"description": "The Free Adobe Acrobat alternative (10M+ Downloads)"
|
||||
},
|
||||
"/settings/legal": {
|
||||
"image": "/og_images/home.png",
|
||||
"title": "Legal Settings - Stirling PDF",
|
||||
"description": "The Free Adobe Acrobat alternative (10M+ Downloads)"
|
||||
},
|
||||
"/settings/backendThirdPartyLicenses": {
|
||||
"image": "/og_images/home.png",
|
||||
"title": "Backend Third Party Licenses Settings - Stirling PDF",
|
||||
"description": "The Free Adobe Acrobat alternative (10M+ Downloads)"
|
||||
},
|
||||
"/settings/frontendThirdPartyLicenses": {
|
||||
"image": "/og_images/home.png",
|
||||
"title": "Frontend Third Party Licenses Settings - Stirling PDF",
|
||||
"description": "The Free Adobe Acrobat alternative (10M+ Downloads)"
|
||||
},
|
||||
"/settings/payg": {
|
||||
"image": "/og_images/home.png",
|
||||
"title": "Payg Settings - Stirling PDF",
|
||||
"description": "The Free Adobe Acrobat alternative (10M+ Downloads)"
|
||||
},
|
||||
"/settings/account-link": {
|
||||
"image": "/og_images/home.png",
|
||||
"title": "Account Link Settings - Stirling PDF",
|
||||
"description": "The Free Adobe Acrobat alternative (10M+ Downloads)"
|
||||
},
|
||||
"/processor": {
|
||||
"image": "/og_images/saas/app-processor.png",
|
||||
"title": "Stirling Processor - Govern every PDF your organization touches",
|
||||
"ogTitle": "Govern every PDF your organization touches",
|
||||
"description": "Redaction, retention, and encryption policies enforced everywhere PDFs enter your org. Distribute the free Editor anywhere. 1¢ per PDF."
|
||||
},
|
||||
"/editor": {
|
||||
"image": "/og_images/saas/app-editor.png",
|
||||
"title": "Stirling - The world's most secure PDF editor",
|
||||
"ogTitle": "The world's most secure PDF editor",
|
||||
"description": "Edit, sign, redact, and convert PDFs in your browser. Free forever, open source, and self-hostable."
|
||||
}
|
||||
},
|
||||
"byPath": {
|
||||
"/cert-sign": "certSign",
|
||||
"/sign": "sign",
|
||||
"/shared-sign": "sharedSign",
|
||||
"/add-text": "addText",
|
||||
"/add-password": "addPassword",
|
||||
"/remove-password": "removePassword",
|
||||
"/remove-pages": "removePages",
|
||||
"/remove-blanks": "removeBlanks",
|
||||
"/remove-annotations": "removeAnnotations",
|
||||
"/remove-image": "removeImage",
|
||||
"/change-permissions": "changePermissions",
|
||||
"/watermark": "watermark",
|
||||
"/sanitize": "sanitize",
|
||||
"/split": "split",
|
||||
"/merge": "merge",
|
||||
"/convert": "convert",
|
||||
"/ocr": "ocr",
|
||||
"/add-image": "addImage",
|
||||
"/rotate": "rotate",
|
||||
"/annotate": "annotate",
|
||||
"/scanner-image-split": "scannerImageSplit",
|
||||
"/edit-table-of-contents": "editTableOfContents",
|
||||
"/scanner-effect": "scannerEffect",
|
||||
"/auto-rename": "autoRename",
|
||||
"/page-layout": "pageLayout",
|
||||
"/scale-pages": "scalePages",
|
||||
"/adjust-contrast": "adjustContrast",
|
||||
"/crop": "crop",
|
||||
"/pdf-to-single-page": "pdfToSinglePage",
|
||||
"/repair": "repair",
|
||||
"/compare": "compare",
|
||||
"/add-page-numbers": "addPageNumbers",
|
||||
"/redact": "redact",
|
||||
"/flatten": "flatten",
|
||||
"/remove-cert-sign": "removeCertSign",
|
||||
"/unlock-p-d-f-forms": "unlockPDFForms",
|
||||
"/compress": "compress",
|
||||
"/extract-pages": "extractPages",
|
||||
"/reorganize-pages": "reorganizePages",
|
||||
"/extract-images": "extractImages",
|
||||
"/add-stamp": "addStamp",
|
||||
"/add-attachments": "addAttachments",
|
||||
"/change-metadata": "changeMetadata",
|
||||
"/overlay-pdfs": "overlayPdfs",
|
||||
"/get-pdf-info": "getPdfInfo",
|
||||
"/validate-signature": "validateSignature",
|
||||
"/timestamp-pdf": "timestampPdf",
|
||||
"/replace-color": "replaceColor",
|
||||
"/show-j-s": "showJS",
|
||||
"/booklet-imposition": "bookletImposition",
|
||||
"/pdf-text-editor": "pdfTextEditor",
|
||||
"/form-fill": "formFill",
|
||||
"/multi-tool": "multiTool",
|
||||
"/read": "read",
|
||||
"/automate": "automate",
|
||||
"/dev-api": "devApi",
|
||||
"/dev-folder-scanning": "devFolderScanning",
|
||||
"/dev-sso-guide": "devSsoGuide",
|
||||
"/dev-airgapped": "devAirgapped",
|
||||
"/split-pdfs": "split",
|
||||
"/merge-pdfs": "merge",
|
||||
"/compress-pdf": "compress",
|
||||
"/rotate-pdf": "rotate",
|
||||
"/convert-pdf": "convert",
|
||||
"/file-to-pdf": "convert",
|
||||
"/eml-to-pdf": "convert",
|
||||
"/html-to-pdf": "convert",
|
||||
"/markdown-to-pdf": "convert",
|
||||
"/pdf-to-csv": "convert",
|
||||
"/pdf-to-xlsx": "convert",
|
||||
"/pdf-to-img": "convert",
|
||||
"/pdf-to-markdown": "convert",
|
||||
"/pdf-to-pdfa": "convert",
|
||||
"/pdf-to-word": "convert",
|
||||
"/pdf-to-xml": "convert",
|
||||
"/cbr-to-pdf": "convert",
|
||||
"/pdf-to-cbr": "convert",
|
||||
"/cbz-to-pdf": "convert",
|
||||
"/pdf-to-cbz": "convert",
|
||||
"/manage-signatures": "certSign",
|
||||
"/remove-certificate-sign": "removeCertSign",
|
||||
"/unlock-pdf-forms": "unlockPDFForms",
|
||||
"/sanitize-pdf": "sanitize",
|
||||
"/ocr-pdf": "ocr",
|
||||
"/add-watermark": "watermark",
|
||||
"/single-large-page": "pdfToSinglePage",
|
||||
"/auto-split-pdf": "split",
|
||||
"/auto-size-split-pdf": "split",
|
||||
"/annotations": "annotate",
|
||||
"/fake-scan": "scannerEffect",
|
||||
"/replace-color-pdf": "replaceColor",
|
||||
"/show-js": "showJS",
|
||||
"/pdf-organizer": "reorganizePages",
|
||||
"/multi-page-layout": "pageLayout",
|
||||
"/extract-page": "extractPages",
|
||||
"/img-to-pdf": "convert",
|
||||
"/pdf-to-presentation": "convert",
|
||||
"/pdf-to-text": "convert",
|
||||
"/pdf-to-html": "convert",
|
||||
"/auto-redact": "redact",
|
||||
"/stamp": "addStamp",
|
||||
"/view-pdf": "read",
|
||||
"/get-info-on-pdf": "getPdfInfo",
|
||||
"/remove-image-pdf": "removeImage",
|
||||
"/replace-and-invert-color-pdf": "replaceColor",
|
||||
"/pipeline": "automate",
|
||||
"/extract-image-scans": "scannerImageSplit",
|
||||
"/show-javascript": "showJS",
|
||||
"/split-by-size-or-count": "split",
|
||||
"/overlay-pdf": "overlayPdfs",
|
||||
"/split-pdf-by-sections": "split",
|
||||
"/split-pdf-by-chapters": "split",
|
||||
"/login": "/login",
|
||||
"/signup": "/signup",
|
||||
"/mobile-scanner": "/mobile-scanner",
|
||||
"/files": "/files",
|
||||
"/settings": "/settings",
|
||||
"/settings/preferences": "/settings/preferences",
|
||||
"/settings/notifications": "/settings/notifications",
|
||||
"/settings/connections": "/settings/connections",
|
||||
"/settings/account": "/settings/account",
|
||||
"/settings/general": "/settings/general",
|
||||
"/settings/people": "/settings/people",
|
||||
"/settings/teams": "/settings/teams",
|
||||
"/settings/security": "/settings/security",
|
||||
"/settings/identity": "/settings/identity",
|
||||
"/settings/plan": "/settings/plan",
|
||||
"/settings/payments": "/settings/payments",
|
||||
"/settings/requests": "/settings/requests",
|
||||
"/settings/developer": "/settings/developer",
|
||||
"/settings/api-keys": "/settings/api-keys",
|
||||
"/settings/hotkeys": "/settings/hotkeys",
|
||||
"/settings/adminGeneral": "/settings/adminGeneral",
|
||||
"/settings/adminSecurity": "/settings/adminSecurity",
|
||||
"/settings/adminConnections": "/settings/adminConnections",
|
||||
"/settings/adminPrivacy": "/settings/adminPrivacy",
|
||||
"/settings/adminDatabase": "/settings/adminDatabase",
|
||||
"/settings/adminAdvanced": "/settings/adminAdvanced",
|
||||
"/settings/adminLegal": "/settings/adminLegal",
|
||||
"/settings/adminPremium": "/settings/adminPremium",
|
||||
"/settings/adminFeatures": "/settings/adminFeatures",
|
||||
"/settings/adminPlan": "/settings/adminPlan",
|
||||
"/settings/adminAudit": "/settings/adminAudit",
|
||||
"/settings/adminUsage": "/settings/adminUsage",
|
||||
"/settings/adminEndpoints": "/settings/adminEndpoints",
|
||||
"/settings/adminStorageSharing": "/settings/adminStorageSharing",
|
||||
"/settings/adminMcp": "/settings/adminMcp",
|
||||
"/settings/help": "/settings/help",
|
||||
"/settings/legal": "/settings/legal",
|
||||
"/settings/backendThirdPartyLicenses": "/settings/backendThirdPartyLicenses",
|
||||
"/settings/frontendThirdPartyLicenses": "/settings/frontendThirdPartyLicenses",
|
||||
"/settings/payg": "/settings/payg",
|
||||
"/settings/account-link": "/settings/account-link",
|
||||
"/processor": "/processor",
|
||||
"/editor": "/editor"
|
||||
}
|
||||
}
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 119 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 125 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 118 KiB |
@@ -4,8 +4,7 @@
|
||||
//
|
||||
// Outputs:
|
||||
// src/core/data/ogImageMap.json - { toolId: imageBasename } (imported by the client)
|
||||
// public/og-metadata.json - { default, byTool, byPath } (prerender input, all flavors)
|
||||
// public/og-metadata.saas.json - same shape, SaaS marketing copy/art (prerender input, --mode saas)
|
||||
// public/og-metadata.json - { default, byTool, byPath } (read by the backend at startup)
|
||||
//
|
||||
// Run: `node scripts/generate-og-metadata.mjs` (writes files)
|
||||
// `node scripts/generate-og-metadata.mjs --check` (CI drift guard: fails if stale)
|
||||
@@ -27,35 +26,6 @@ const SITE_TITLE = "Stirling PDF";
|
||||
const SITE_DESC = "The Free Adobe Acrobat alternative (10M+ Downloads)";
|
||||
const DEFAULT_IMAGE_BASENAME = "home";
|
||||
|
||||
// SaaS (stirling.com) link-preview cards. Only the SaaS build (`--mode saas`)
|
||||
// uses og-metadata.saas.json; every other flavour keeps the tool-registry copy
|
||||
// above. `ogTitle` is the punchy social headline; `title` is the SEO <title>.
|
||||
// `home` overrides the site default (served at `/app`); the rest are extra
|
||||
// marketing landing routes prerendered so their links unfurl with bespoke art.
|
||||
const SAAS_DEFAULT = {
|
||||
image: "/og_images/saas/app.png",
|
||||
title: "Stirling - Edit any PDF. Govern every PDF.",
|
||||
ogTitle: "Edit any PDF. Govern every PDF.",
|
||||
description:
|
||||
"The free, open-source PDF Editor, plus a Processor that governs every PDF your organization touches. 1¢ per PDF.",
|
||||
};
|
||||
const SAAS_ROUTE_OVERRIDES = {
|
||||
"/processor": {
|
||||
image: "/og_images/saas/app-processor.png",
|
||||
title: "Stirling Processor - Govern every PDF your organization touches",
|
||||
ogTitle: "Govern every PDF your organization touches",
|
||||
description:
|
||||
"Redaction, retention, and encryption policies enforced everywhere PDFs enter your org. Distribute the free Editor anywhere. 1¢ per PDF.",
|
||||
},
|
||||
"/editor": {
|
||||
image: "/og_images/saas/app-editor.png",
|
||||
title: "Stirling - The world's most secure PDF editor",
|
||||
ogTitle: "The world's most secure PDF editor",
|
||||
description:
|
||||
"Edit, sign, redact, and convert PDFs in your browser. Free forever, open source, and self-hostable.",
|
||||
},
|
||||
};
|
||||
|
||||
// Tools whose art exists under a legacy v1 filename that does not match the
|
||||
// tool id or any current URL slug. Verified against public/og_images contents.
|
||||
const LEGACY_IMAGE_OVERRIDES = {
|
||||
@@ -208,33 +178,10 @@ const manifest = {
|
||||
byPath,
|
||||
};
|
||||
|
||||
// SaaS manifest: same tool pages as above, but the home default and two extra
|
||||
// marketing routes carry the stirling.com cards. Keeps all per-tool OG intact.
|
||||
const saasManifest = {
|
||||
default: SAAS_DEFAULT,
|
||||
byTool: { ...byTool },
|
||||
byPath: { ...byPath },
|
||||
};
|
||||
for (const [routePath, entry] of Object.entries(SAAS_ROUTE_OVERRIDES)) {
|
||||
saasManifest.byTool[routePath] = entry;
|
||||
saasManifest.byPath[routePath] = routePath;
|
||||
}
|
||||
// SaaS card art lives in the saas/ subdir (outside the root images scan), so
|
||||
// check the files on disk directly.
|
||||
const missingSaasImages = [SAAS_DEFAULT, ...Object.values(SAAS_ROUTE_OVERRIDES)]
|
||||
.map((e) => e.image)
|
||||
.filter((img) => !fs.existsSync(path.join(ROOT, "public" + img)));
|
||||
if (missingSaasImages.length)
|
||||
console.warn(
|
||||
`\nWARNING: SaaS OG cards reference missing images: ${missingSaasImages.join(", ")}`,
|
||||
);
|
||||
|
||||
const mapJson = JSON.stringify(ogImageMap, null, 2) + "\n";
|
||||
const manifestJson = JSON.stringify(manifest, null, 2) + "\n";
|
||||
const saasManifestJson = JSON.stringify(saasManifest, null, 2) + "\n";
|
||||
const mapPath = "src/core/data/ogImageMap.json";
|
||||
const manifestPath = "public/og-metadata.json";
|
||||
const saasManifestPath = "public/og-metadata.saas.json";
|
||||
|
||||
const check = process.argv.includes("--check");
|
||||
if (check) {
|
||||
@@ -246,11 +193,6 @@ if (check) {
|
||||
read(manifestPath) !== manifestJson
|
||||
)
|
||||
stale.push(manifestPath);
|
||||
if (
|
||||
!fs.existsSync(path.join(ROOT, saasManifestPath)) ||
|
||||
read(saasManifestPath) !== saasManifestJson
|
||||
)
|
||||
stale.push(saasManifestPath);
|
||||
if (stale.length) {
|
||||
console.error(
|
||||
"OG metadata is stale. Run `node scripts/generate-og-metadata.mjs`:\n " +
|
||||
@@ -262,13 +204,9 @@ if (check) {
|
||||
} else {
|
||||
fs.writeFileSync(path.join(ROOT, mapPath), mapJson);
|
||||
fs.writeFileSync(path.join(ROOT, manifestPath), manifestJson);
|
||||
fs.writeFileSync(path.join(ROOT, saasManifestPath), saasManifestJson);
|
||||
console.log(
|
||||
`Wrote ${mapPath} (${Object.keys(ogImageMap).length} tools with art)`,
|
||||
);
|
||||
console.log(
|
||||
`Wrote ${saasManifestPath} (${Object.keys(saasManifest.byPath).length} paths, SaaS)`,
|
||||
);
|
||||
console.log(`Wrote ${manifestPath} (${Object.keys(byPath).length} paths)`);
|
||||
}
|
||||
|
||||
|
||||
@@ -4,8 +4,6 @@ export interface OgEntry {
|
||||
image: string;
|
||||
title: string;
|
||||
description: string;
|
||||
/** Punchier social-card title; falls back to `title` for the <title> tag. */
|
||||
ogTitle?: string;
|
||||
}
|
||||
|
||||
export interface OgInjectOptions {
|
||||
|
||||
@@ -15,13 +15,12 @@ export const escapeHtml = (value) =>
|
||||
const absolute = (urlPath, ogBase) => (ogBase ? ogBase + urlPath : urlPath);
|
||||
|
||||
/**
|
||||
* Build the OG/Twitter <meta> block for one route. `ogTitle` lets the social
|
||||
* card show a punchier headline than the (SEO) <title>; falls back to `title`.
|
||||
* @param {{image:string,title:string,description:string,ogTitle?:string}} entry
|
||||
* Build the OG/Twitter <meta> block for one route.
|
||||
* @param {{image:string,title:string,description:string}} entry
|
||||
* @param {{ogBase?:string, pageUrlPath?:string|null}} opts
|
||||
*/
|
||||
export function buildOgTags(entry, { ogBase = "", pageUrlPath = null } = {}) {
|
||||
const title = escapeHtml(entry.ogTitle ?? entry.title);
|
||||
const title = escapeHtml(entry.title);
|
||||
const description = escapeHtml(entry.description);
|
||||
const imageUrl = absolute(entry.image, ogBase);
|
||||
const image = escapeHtml(imageUrl);
|
||||
|
||||
@@ -102,28 +102,6 @@ describe("injectOg (build-time prerender)", () => {
|
||||
);
|
||||
expect(tags).toContain("A "B" & <C>");
|
||||
});
|
||||
|
||||
it("uses ogTitle for the social card but title for the <title> tag", () => {
|
||||
const out = injectOg(
|
||||
TEMPLATE,
|
||||
{
|
||||
image: "/og_images/saas/app.png",
|
||||
title: "Stirling - Edit any PDF. Govern every PDF.",
|
||||
ogTitle: "Edit any PDF. Govern every PDF.",
|
||||
description: "d",
|
||||
},
|
||||
{},
|
||||
);
|
||||
expect(out).toContain(
|
||||
"<title>Stirling - Edit any PDF. Govern every PDF.</title>",
|
||||
);
|
||||
expect(out).toContain(
|
||||
'<meta property="og:title" content="Edit any PDF. Govern every PDF." />',
|
||||
);
|
||||
expect(out).toContain(
|
||||
'<meta name="twitter:title" content="Edit any PDF. Govern every PDF." />',
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe("prerenderOg (flat + nested route files)", () => {
|
||||
|
||||
@@ -83,7 +83,7 @@ export default function Login() {
|
||||
"app.description",
|
||||
"The Free Adobe Acrobat alternative (10M+ Downloads)",
|
||||
),
|
||||
ogImage: `${baseUrl}/og_images/saas/app.png`,
|
||||
ogImage: `${baseUrl}/og_images/home.png`,
|
||||
ogUrl: `${window.location.origin}${window.location.pathname}`,
|
||||
});
|
||||
|
||||
|
||||
@@ -108,7 +108,7 @@ export default function Signup() {
|
||||
"app.description",
|
||||
"The Free Adobe Acrobat alternative (10M+ Downloads)",
|
||||
),
|
||||
ogImage: `${baseUrl}/og_images/saas/app.png`,
|
||||
ogImage: `${baseUrl}/og_images/home.png`,
|
||||
ogUrl: `${window.location.origin}${window.location.pathname}`,
|
||||
});
|
||||
|
||||
|
||||
@@ -88,12 +88,7 @@ function compressStaticCopyPlugin(): PluginOption {
|
||||
// Pages). Otherwise URLs stay root-relative, which still resolves against whatever
|
||||
// origin serves the page (correct for self-hosted Docker). Logic lives in
|
||||
// scripts/og-prerender.mjs so it can be unit-tested without a full build.
|
||||
function prerenderOgPlugin(isSaas: boolean): PluginOption {
|
||||
// SaaS (stirling.com) prerenders the marketing cards from a dedicated
|
||||
// manifest; every other flavour uses the tool-registry manifest.
|
||||
const manifestFile = isSaas
|
||||
? "public/og-metadata.saas.json"
|
||||
: "public/og-metadata.json";
|
||||
function prerenderOgPlugin(): PluginOption {
|
||||
return {
|
||||
name: "prerender-og",
|
||||
apply: "build" as const,
|
||||
@@ -110,11 +105,14 @@ function prerenderOgPlugin(isSaas: boolean): PluginOption {
|
||||
let manifest;
|
||||
try {
|
||||
manifest = JSON.parse(
|
||||
await fs.readFile(path.resolve(__dirname, manifestFile), "utf8"),
|
||||
await fs.readFile(
|
||||
path.resolve(__dirname, "public/og-metadata.json"),
|
||||
"utf8",
|
||||
),
|
||||
);
|
||||
} catch {
|
||||
console.warn(
|
||||
`[prerender-og] ${manifestFile} missing; skipping OG prerender. ` +
|
||||
"[prerender-og] public/og-metadata.json missing; skipping OG prerender. " +
|
||||
"Run `node scripts/generate-og-metadata.mjs`.",
|
||||
);
|
||||
return;
|
||||
@@ -332,7 +330,7 @@ export default defineConfig(async ({ mode, command }) => {
|
||||
],
|
||||
}),
|
||||
compressStaticCopyPlugin(),
|
||||
prerenderOgPlugin(effectiveMode === "saas"),
|
||||
prerenderOgPlugin(),
|
||||
],
|
||||
server: {
|
||||
host: true,
|
||||
|
||||
Reference in New Issue
Block a user