Skip to content

Commit 0a19ab0

Browse files
author
Stueypoo
committed
Reverting the code to just include the -cacert option.
1 parent 991f982 commit 0a19ab0

File tree

2 files changed

+0
-115
lines changed

2 files changed

+0
-115
lines changed

modules/ejbca-ejb-cli/src/org/ejbca/ui/cli/ca/CaImportCertDirCommand.java

Lines changed: 0 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
import org.cesecore.util.EjbRemoteHelper;
3636
import org.ejbca.core.ejb.ra.raadmin.EndEntityProfileSessionRemote;
3737
import org.ejbca.core.model.authorization.AccessRulesConstants;
38-
import org.ejbca.ui.cli.ca.CertificateImporter.Result;
3938
import org.ejbca.ui.cli.infrastructure.command.CommandResult;
4039
import org.ejbca.ui.cli.infrastructure.parameter.Parameter;
4140
import org.ejbca.ui.cli.infrastructure.parameter.ParameterContainer;
@@ -57,8 +56,6 @@ public class CaImportCertDirCommand extends BaseCaAdminCommand {
5756
private static final Logger log = Logger.getLogger(CaImportCertDirCommand.class);
5857

5958
public static final String DATE_FORMAT = "yyyy.MM.dd-HH:mm";
60-
public static final String DATE_FORMAT_WINSAFE = "yyyy.MM.dd-HH.mm"; // The colon character (:) will cause issued within Windows filenames, so use a period instead.
61-
6259
private static final String USERNAME_FILTER_KEY = "--filter";
6360
private static final String CA_NAME_KEY = "--caname";
6461
private static final String ACTIVE_KEY = "-a";
@@ -70,7 +67,6 @@ public class CaImportCertDirCommand extends BaseCaAdminCommand {
7067
private static final String REVOCATION_TIME = "--revocation-time";
7168
private static final String THREAD_COUNT = "--threads";
7269
private static final String CACERT = "--cacert";
73-
private static final String REVOKEDETAILS = "--revoke-details-in-filename";
7470

7571
private static final String ACTIVE = "ACTIVE";
7672
private static final String REVOKED = "REVOKED";
@@ -99,10 +95,6 @@ public class CaImportCertDirCommand extends BaseCaAdminCommand {
9995
"Number of threads used during the import. Default is 1 thread."));
10096
registerParameter(new Parameter(CACERT, "CA Certificate File", MandatoryMode.OPTIONAL, StandaloneMode.FORBID, ParameterMode.ARGUMENT,
10197
"Specify an alternate CA certificate file (in PEM). Use this option when importing certificates that were issued by the previous CA certificate. Please note that the supplied certificate is not verified."));
102-
registerParameter(new Parameter(REVOKEDETAILS, "Revocation Details", MandatoryMode.OPTIONAL, StandaloneMode.FORBID, ParameterMode.FLAG,
103-
"Revocation details are to be derived from the filename of the certificate. The filename must end with '!<REASON>!<INVALIDITY_TIME>'. The REASON can be the value or label as described in RFC5280 section 5.3.1. "
104-
+ "INVALIDITY_TIME is formatted as '"+DATE_FORMAT_WINSAFE+"' and assumed to be the local timezone. Note: Filename extensions (ie., '.crt. or '.pem') are not supported. Please also note that any file without "
105-
+ "revocation details will not be imported."));
10698
}
10799

108100
@Override
@@ -248,59 +240,6 @@ public CommandResult execute(final ParameterContainer parameters) {
248240

249241

250242
for (final File file : files) {
251-
252-
// Check if revocation details are to be derived from the filename. Only do this if status is REVOKED
253-
if ( (status == CertificateConstants.CERT_REVOKED) && parameters.containsKey(REVOKEDETAILS)) {
254-
// Find the revocation details from the filename. The details are separated with an exclamation (!) character.
255-
final String[] sa = file.getName().split("!");
256-
if (sa.length <3) {
257-
log.error("ERROR: The revocation details are not found in filename '"+file.getName()+"'. Ignoring this file.");
258-
results.add( Result.GENERAL_IMPORT_ERROR);
259-
continue;
260-
} else {
261-
// Process the REASON from 2nd last string in array
262-
String sRevCode = sa[ sa.length-2 ].toUpperCase();
263-
// Check if using a code value
264-
try {
265-
final int iRevCode = Integer.parseInt(sRevCode);
266-
revocationReason = RevocationReasons.getFromDatabaseValue(iRevCode);
267-
if(revocationReason == null) {
268-
log.error("ERROR: '" + iRevCode + "' is not a valid revocation reason code. Ignoring this file '"+file.getName()+"'.");
269-
results.add( Result.GENERAL_IMPORT_ERROR);
270-
continue;
271-
}
272-
273-
} catch (NumberFormatException e) {
274-
// Not an integer, must be the full text
275-
// Correct the string value to suit RevocationReason
276-
if ( sRevCode.equals("KEYCOMPROMISE")) sRevCode = "KEY_COMPROMISE";
277-
if ( sRevCode.equals("CACOMPROMISE")) sRevCode = "CA_COMPROMISE";
278-
if ( sRevCode.equals("AFFILIATIONCHANGED")) sRevCode = "AFFILIATION_CHANGED";
279-
if ( sRevCode.equals("CESSATIONOFOPERATION")) sRevCode = "CESSATION_OF_OPERATION";
280-
if ( sRevCode.equals("CERTIFICATEHOLD")) sRevCode = "CERTIFICATE_HOLD";
281-
if ( sRevCode.equals("PRIVILEGESWITHDRAWN")) sRevCode = "PRIVILEGES_WITHDRAWN";
282-
if ( sRevCode.equals("AACOMPROMISE")) sRevCode = "AA_COMPROMISE";
283-
284-
revocationReason = RevocationReasons.getFromCliValue(sRevCode.toUpperCase());
285-
if(revocationReason == null) {
286-
log.error("ERROR: '" + sRevCode + "' is not a valid revocation reason. Ignoring this file '"+file.getName()+"'.");
287-
results.add( Result.GENERAL_IMPORT_ERROR);
288-
continue;
289-
}
290-
}
291-
292-
// Process the TIME from last string in array
293-
final String sRevTime = sa[ sa.length-1 ];
294-
try {
295-
revocationTime = new SimpleDateFormat(DATE_FORMAT_WINSAFE).parse( sRevTime);
296-
} catch (ParseException e) {
297-
log.error("ERROR: '" + sRevTime + "' was not a valid revocation time. Use this time format '"+DATE_FORMAT_WINSAFE+"'. Ignoring this file '"+file.getName()+"'.");
298-
results.add( Result.GENERAL_IMPORT_ERROR);
299-
continue;
300-
}
301-
}
302-
}
303-
304243
futures.add(executorService.submit(new CertificateImporter()
305244
.setAuthenticationToken(getAuthenticationToken())
306245
.setCaCertificate(cacert)

modules/systemtests/src-test/org/ejbca/ui/cli/ca/CaImportCertDirCommandSystemTest.java

Lines changed: 0 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -194,60 +194,6 @@ public void testImportRevokedWithReasonAndTime() throws AuthorizationDeniedExcep
194194
certificateStatus.revocationDate);
195195
}
196196

197-
@Test
198-
public void testImportRevokedWithReasonAndTimeInFilennameReasonCode() throws AuthorizationDeniedException, ParseException {
199-
// Rename the certificate file
200-
File newFile = new File(tempDirectory, "test!cert!6!2022.07.08-15.49");
201-
certificateFile.renameTo(newFile);
202-
String[] args = new String[] { "DN", CA_NAME, "REVOKED", tempDirectory.getAbsolutePath(), "--eeprofile", "EMPTY", "--certprofile", "ENDUSER",
203-
"--revoke-details-in-filename" };
204-
assertEquals(CommandResult.SUCCESS, command.execute(args));
205-
EndEntityInformation endEntityInformation = endEntityAccessSession.findUser(authenticationToken, CERTIFICATE_DN);
206-
assertNotNull("Certificate was not imported.", endEntityInformation);
207-
assertEquals("Certificate was imported with incorrect status", EndEntityConstants.STATUS_GENERATED, endEntityInformation.getStatus());
208-
CertificateStatus certificateStatus = certificateStoreSession.getStatus(CA_DN, certificateSerialNumber);
209-
assertEquals("Certificate revocation reason was incorrectly imported.", RevocationReasons.CERTIFICATEHOLD.getDatabaseValue(),
210-
certificateStatus.revocationReason);
211-
assertEquals("Certificate revocation date was incorrectly imported.", new SimpleDateFormat(CaImportCertDirCommand.DATE_FORMAT_WINSAFE).parse("2022.07.08-15.49"),
212-
certificateStatus.revocationDate);
213-
}
214-
215-
@Test
216-
public void testImportRevokedWithReasonAndTimeInFilennameReasonText() throws AuthorizationDeniedException, ParseException {
217-
// Rename the certificate file
218-
File newFile = new File(tempDirectory, "!affiliationChanged!2023.08.21-05.26");
219-
certificateFile.renameTo(newFile);
220-
String[] args = new String[] { "DN", CA_NAME, "REVOKED", tempDirectory.getAbsolutePath(), "--eeprofile", "EMPTY", "--certprofile", "ENDUSER",
221-
"--revoke-details-in-filename" };
222-
assertEquals(CommandResult.SUCCESS, command.execute(args));
223-
EndEntityInformation endEntityInformation = endEntityAccessSession.findUser(authenticationToken, CERTIFICATE_DN);
224-
assertNotNull("Certificate was not imported.", endEntityInformation);
225-
assertEquals("Certificate was imported with incorrect status", EndEntityConstants.STATUS_GENERATED, endEntityInformation.getStatus());
226-
CertificateStatus certificateStatus = certificateStoreSession.getStatus(CA_DN, certificateSerialNumber);
227-
assertEquals("Certificate revocation reason was incorrectly imported.", RevocationReasons.AFFILIATIONCHANGED.getDatabaseValue(),
228-
certificateStatus.revocationReason);
229-
assertEquals("Certificate revocation date was incorrectly imported.", new SimpleDateFormat(CaImportCertDirCommand.DATE_FORMAT_WINSAFE).parse("2023.08.21-05.26"),
230-
certificateStatus.revocationDate);
231-
}
232-
233-
@Test
234-
public void testImportRevokedWithReasonAndTimeInFilennameReasonTextWithUnderscores() throws AuthorizationDeniedException, ParseException {
235-
// Rename the certificate file
236-
File newFile = new File(tempDirectory, "test!CESSATION_OF_OPERATION!2021.02.28-0.01");
237-
certificateFile.renameTo(newFile);
238-
String[] args = new String[] { "DN", CA_NAME, "REVOKED", tempDirectory.getAbsolutePath(), "--eeprofile", "EMPTY", "--certprofile", "ENDUSER",
239-
"--revoke-details-in-filename" };
240-
assertEquals(CommandResult.SUCCESS, command.execute(args));
241-
EndEntityInformation endEntityInformation = endEntityAccessSession.findUser(authenticationToken, CERTIFICATE_DN);
242-
assertNotNull("Certificate was not imported.", endEntityInformation);
243-
assertEquals("Certificate was imported with incorrect status", EndEntityConstants.STATUS_GENERATED, endEntityInformation.getStatus());
244-
CertificateStatus certificateStatus = certificateStoreSession.getStatus(CA_DN, certificateSerialNumber);
245-
assertEquals("Certificate revocation reason was incorrectly imported.", RevocationReasons.CESSATIONOFOPERATION.getDatabaseValue(),
246-
certificateStatus.revocationReason);
247-
assertEquals("Certificate revocation date was incorrectly imported.", new SimpleDateFormat(CaImportCertDirCommand.DATE_FORMAT_WINSAFE).parse("2021.02.28-0.01"),
248-
certificateStatus.revocationDate);
249-
}
250-
251197
@Test
252198
public void testImportFromAnotherCA() throws Exception {
253199
// Import a certificate from another CA. One way to do this is to save the current CA cert, re-create the CA, then import EE cert.

0 commit comments

Comments
 (0)