Skip to content

Commit

Permalink
Add command pki-server kra-range-generator-update
Browse files Browse the repository at this point in the history
  • Loading branch information
fmarco76 committed Oct 18, 2024
1 parent 4fb546b commit 26e8c1b
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
/**
* @author Marco Fargetta {@literal <[email protected]>}
*/
public class CARangeGeneratorCLI extends CLI{
public class CARangeGeneratorCLI extends CLI {

public CARangeGeneratorCLI(CLI parent) {
super("generator", "CA range generator commands", parent);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public class KeyRepository extends Repository {
public static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(KeyRepository.class);

public static final String PROP_KEY_ID_GENERATOR = "key.id.generator";
public static final String PROP_CERT_ID_RADIX = "key.id.radix";
public static final String PROP_KEY_ID_RADIX = "key.id.radix";
public static final String DEFAULT_KEY_ID_GENERATOR = "legacy";

public static final String PROP_KEY_ID_LENGTH = "key.id.length";
Expand All @@ -66,7 +66,7 @@ public KeyRepository(
super(dbSubsystem, HEX);
DatabaseConfig dbc = dbSubsystem.getDBConfigStore();
try {
this.mRadix = dbc.getInteger(PROP_CERT_ID_RADIX, HEX);
this.mRadix = dbc.getInteger(PROP_KEY_ID_RADIX, HEX);
logger.debug("KeyRepository: number radix {}", this.mRadix);

} catch (EBaseException ex) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,6 @@ public KRARangeCLI(CLI parent) {
super("range", "KRA range management commands", parent);

addModule(new KRARangeUpdateCLI(this));
addModule(new KRARangeGeneratorCLI(this));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//
// Copyright Red Hat, Inc.
//
// SPDX-License-Identifier: GPL-2.0-or-later
//
package org.dogtagpki.server.kra.cli;

import org.dogtagpki.cli.CLI;
/**
* @author Marco Fargetta {@literal <[email protected]>}
*/
public class KRARangeGeneratorCLI extends CLI {
public KRARangeGeneratorCLI(CLI parent) {
super("generator", "kra range generator commands", parent);

addModule(new kraRangeGeneratorUpdateCLI(this));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
//
// Copyright Red Hat, Inc.
//
// SPDX-License-Identifier: GPL-2.0-or-later
//
package org.dogtagpki.server.kra.cli;

import com.netscape.cmscore.apps.DatabaseConfig;
import com.netscape.cmscore.dbs.KeyRepository;
import com.netscape.cmscore.dbs.Repository;
import com.netscape.cmscore.ldapconn.LdapAuthInfo;
import com.netscape.cmscore.ldapconn.LdapConnInfo;
import com.netscape.cmscore.ldapconn.PKISocketFactory;
import org.dogtagpki.cli.CLI;
import org.dogtagpki.server.cli.SubsystemRangeGeneratorUpdateCLI;

/**
*
* @author mfargetta
*/
public class kraRangeGeneratorUpdateCLI extends SubsystemRangeGeneratorUpdateCLI {

public kraRangeGeneratorUpdateCLI(CLI parent) {
super(parent);
}

@Override
protected void updateSerialNumberRangeGenerator(PKISocketFactory socketFactory, LdapConnInfo connInfo,
LdapAuthInfo authInfo, DatabaseConfig dbConfig, String baseDN, Repository.IDGenerator newGenerator, String hostName, String securePort) throws Exception {
String value = dbConfig.getString(
KeyRepository.PROP_KEY_ID_GENERATOR,
KeyRepository.DEFAULT_KEY_ID_GENERATOR);
idGenerator = Repository.IDGenerator.fromString(value);

if (newGenerator == Repository.IDGenerator.RANDOM && idGenerator != Repository.IDGenerator.RANDOM) {
dbConfig.put(KeyRepository.PROP_KEY_ID_GENERATOR, newGenerator.toString());
dbConfig.put(KeyRepository.PROP_KEY_ID_LENGTH, "128");
}
if (newGenerator == Repository.IDGenerator.LEGACY_2 && idGenerator == Repository.IDGenerator.LEGACY) {
dbConfig.put(KeyRepository.PROP_KEY_ID_GENERATOR, newGenerator.toString());
}

super.updateSerialNumberRangeGenerator(socketFactory, connInfo, authInfo, dbConfig, baseDN, newGenerator, hostName, securePort);
}
}

0 comments on commit 26e8c1b

Please sign in to comment.