use of org.xipki.password.PasswordResolverException in project xipki by xipki.
the class CaManagerImpl method init.
private void init() throws CaMgmtException {
if (securityFactory == null) {
throw new IllegalStateException("securityFactory is not set");
}
if (datasourceFactory == null) {
throw new IllegalStateException("datasourceFactory is not set");
}
if (x509CertProfileFactoryRegister == null) {
throw new IllegalStateException("x509CertProfileFactoryRegister is not set");
}
if (x509CertPublisherFactoryRegister == null) {
throw new IllegalStateException("x509CertPublisherFactoryRegister is not set");
}
if (caConfFile == null) {
throw new IllegalStateException("caConfFile is not set");
}
Properties caConfProps = new Properties();
try {
caConfProps.load(new FileInputStream(IoUtil.expandFilepath(caConfFile)));
} catch (IOException ex) {
throw new CaMgmtException("could not parse CA configuration" + caConfFile, ex);
}
String caModeStr = caConfProps.getProperty("ca.mode");
if (caModeStr != null) {
if ("slave".equalsIgnoreCase(caModeStr)) {
masterMode = false;
} else if ("master".equalsIgnoreCase(caModeStr)) {
masterMode = true;
} else {
throw new CaMgmtException(concat("invalid ca.mode '", caModeStr, "'"));
}
} else {
masterMode = true;
}
int shardId;
String shardIdStr = caConfProps.getProperty("ca.shardId");
if (StringUtil.isBlank(shardIdStr)) {
throw new CaMgmtException("ca.shardId is not set");
}
LOG.info("ca.shardId: {}", shardIdStr);
try {
shardId = Integer.parseInt(shardIdStr);
} catch (NumberFormatException ex) {
throw new CaMgmtException(concat("invalid ca.shardId '", shardIdStr, "'"));
}
if (shardId < 0 || shardId > 127) {
throw new CaMgmtException("ca.shardId is not in [0, 127]");
}
if (this.datasources == null) {
this.datasources = new ConcurrentHashMap<>();
for (Object objKey : caConfProps.keySet()) {
String key = (String) objKey;
if (!StringUtil.startsWithIgnoreCase(key, "datasource.")) {
continue;
}
String datasourceFile = caConfProps.getProperty(key);
try {
String datasourceName = key.substring("datasource.".length());
DataSourceWrapper datasource = datasourceFactory.createDataSourceForFile(datasourceName, datasourceFile, securityFactory.getPasswordResolver());
Connection conn = datasource.getConnection();
datasource.returnConnection(conn);
this.datasources.put(datasourceName, datasource);
} catch (DataAccessException | PasswordResolverException | IOException | RuntimeException ex) {
throw new CaMgmtException(concat(ex.getClass().getName(), " while parsing datasource ", datasourceFile, ": ", ex.getMessage()), ex);
}
}
this.datasource = this.datasources.get("ca");
}
if (this.datasource == null) {
throw new CaMgmtException("no datasource named 'ca' configured");
}
this.queryExecutor = new CaManagerQueryExecutor(this.datasource);
initEnvironmentParamters();
String envEpoch = envParameterResolver.getParameter(ENV_EPOCH);
if (masterMode) {
lockCa(true);
if (envEpoch == null) {
final long day = 24L * 60 * 60 * 1000;
envEpoch = queryExecutor.setEpoch(new Date(System.currentTimeMillis() - day));
LOG.info("set environment {} to {}", ENV_EPOCH, envEpoch);
}
queryExecutor.addRequestorIfNeeded(RequestorInfo.NAME_BY_CA);
queryExecutor.addRequestorIfNeeded(RequestorInfo.NAME_BY_USER);
} else {
if (envEpoch == null) {
throw new CaMgmtException("The CA system must be started first with ca.mode = master");
}
}
LOG.info("use EPOCH: {}", envEpoch);
long epoch = DateUtil.parseUtcTimeyyyyMMdd(envEpoch).getTime();
UniqueIdGenerator idGen = new UniqueIdGenerator(epoch, shardId);
try {
this.certstore = new CertificateStore(datasource, idGen);
} catch (DataAccessException ex) {
throw new CaMgmtException(ex.getMessage(), ex);
}
initCaAliases();
initCertprofiles();
initPublishers();
initCmpControls();
initRequestors();
initResponders();
initCrlSigners();
initCas();
initSceps();
}
use of org.xipki.password.PasswordResolverException in project xipki by xipki.
the class DataSourceFactory method createDataSource.
public DataSourceWrapper createDataSource(String name, InputStream conf, PasswordResolver passwordResolver) throws PasswordResolverException, IOException {
ParamUtil.requireNonNull("conf", conf);
Properties config = new Properties();
try {
config.load(conf);
} finally {
try {
conf.close();
} catch (Exception ex) {
LOG.error("could not close stream: {}", ex.getMessage());
}
}
return createDataSource(name, config, passwordResolver);
}
use of org.xipki.password.PasswordResolverException in project xipki by xipki.
the class FilePasswordCallback method init.
// method getPassword
@Override
public void init(String conf) throws PasswordResolverException {
ParamUtil.requireNonBlank("conf", conf);
ConfPairs pairs = new ConfPairs(conf);
passwordFile = pairs.value("file");
if (StringUtil.isBlank(passwordFile)) {
throw new PasswordResolverException("invalid configuration " + conf + ", no file is specified");
}
passwordFile = IoUtil.expandFilepath(passwordFile);
}
use of org.xipki.password.PasswordResolverException in project xipki by xipki.
the class FilePasswordCallback method getPassword.
@Override
public char[] getPassword(String prompt, String testToken) throws PasswordResolverException {
if (passwordFile == null) {
throw new PasswordResolverException("please initialize me first");
}
String passwordHint = null;
BufferedReader reader = null;
try {
reader = new BufferedReader(new FileReader(IoUtil.expandFilepath(passwordFile)));
String line;
while ((line = reader.readLine()) != null) {
line = line.trim();
if (StringUtil.isNotBlank(line) && !line.startsWith("#")) {
passwordHint = line;
break;
}
}
} catch (IOException ex) {
throw new PasswordResolverException("could not read file " + passwordFile, ex);
} finally {
if (reader != null) {
try {
reader.close();
} catch (IOException ex) {
LOG.error("could not close reader: {}", ex.getMessage());
}
}
}
if (passwordHint == null) {
throw new PasswordResolverException("no password is specified in file " + passwordFile);
}
if (StringUtil.startsWithIgnoreCase(passwordHint, OBFPasswordService.OBFUSCATE)) {
return OBFPasswordService.deobfuscate(passwordHint).toCharArray();
} else {
return passwordHint.toCharArray();
}
}
use of org.xipki.password.PasswordResolverException in project xipki by xipki.
the class GuiPasswordCallback method init.
@Override
public void init(String conf) throws PasswordResolverException {
if (StringUtil.isBlank(conf)) {
quorum = 1;
return;
}
ConfPairs pairs = new ConfPairs(conf);
String str = pairs.value("quorum");
quorum = Integer.valueOf(str);
if (quorum < 1 || quorum > 10) {
throw new PasswordResolverException("quorum " + quorum + " is not in [1,10]");
}
str = pairs.value("tries");
if (StringUtil.isNotBlank(str)) {
int intValue = Integer.parseInt(str);
if (intValue > 0) {
this.tries = intValue;
}
}
}
Aggregations