/*************************************************************************
* *
* CESeCore: CE Security Core *
* *
* This software is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Lesser General *
* License as published by the Free Software Foundation; either *
* version 2.1 of the License, or any later version. *
* *
* See terms of license at gnu.org. *
* *
*************************************************************************/
package org.cesecore.keys.validation;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import java.io.File;
import java.security.KeyPair;
import java.security.cert.X509Certificate;
import java.util.LinkedHashMap;
import java.util.List;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.SystemUtils;
import org.apache.log4j.Logger;
import org.cesecore.certificates.util.AlgorithmConstants;
import org.cesecore.internal.UpgradeableDataHashMap;
import org.cesecore.keys.util.KeyTools;
import org.cesecore.util.CertTools;
import org.cesecore.util.CryptoProviderTools;
import org.junit.Before;
import org.junit.Test;
/**
* This class contains whitebox integrations tests for External Command Validators. To determine whether
* an external command was executed as specified we need to place a file on the fileystem in the location
* given by the value mapped to the key EXTERNAL_COMMAND, or if we only care about whether
* the command was invoked, it suffices to ensure the executable does not exist and then check for an
* ExternalProcessException. In ECCV this exception is re-thrown as ValidatorNotApplicableException.
*
* Make scripts executable, if not done with SVN extension!
*
* chmod u+x $EJBCA_HOME/modules/systemtests/resources/platform/unix/*.sh
*
* @version $Id: ExternalCommandCertificateValidatorTest.java 29066 2018-05-30 08:21:35Z andresjakobs $
*/
public class ExternalCommandCertificateValidatorTest {
/** Class logger. */
private static final Logger log = Logger.getLogger(ExternalCommandCertificateValidatorTest.class);
@Before
public void setUp() throws Exception {
log.trace(">setUp()");
CryptoProviderTools.installBCProvider();
log.trace(" data = new LinkedHashMap<>();
final String path = getFilePathFromClasspath("external_process_tools_with_write_to_disk_exit_code_0");
// Check validation of an external call with x.509 RSA public key while IssuancePhase#CERTIFICATE_VALIDATION phase.
data.put(ExternalCommandCertificateValidator.EXTERNAL_COMMAND, path);
data.put(UpgradeableDataHashMap.VERSION, 1f);
validator.setDataMap(data);
validator.validate(null, createCert("C=Test,O=Test,OU=Test,CN=testDisabledWhitelist"), ExternalScriptsWhitelist.permitAll());
}
@Test
public void testAllowedCommand() throws Exception {
final ExternalCommandCertificateValidator validator = new ExternalCommandCertificateValidator();
final LinkedHashMap