Search in sources :

Example 11 with ConfPairs

use of org.xipki.common.ConfPairs in project xipki by xipki.

the class ConfPairsTest method test5.

@Test
public void test5() {
    ConfPairs pairs = new ConfPairs("key-a=value-a\\,");
    String expEncoded = "key-a=value-a\\,";
    Map<String, String> expNameValues = new HashMap<>();
    expNameValues.put("key-a", "value-a,");
    check(pairs, expEncoded, expNameValues);
}
Also used : HashMap(java.util.HashMap) ConfPairs(org.xipki.common.ConfPairs) Test(org.junit.Test)

Example 12 with ConfPairs

use of org.xipki.common.ConfPairs in project xipki by xipki.

the class CaUpdateCmd method getChangeCaEntry.

protected X509ChangeCaEntry getChangeCaEntry() throws Exception {
    X509ChangeCaEntry entry = new X509ChangeCaEntry(new NameId(null, caName));
    if (snBitLen != null) {
        ParamUtil.requireRange("sn-bitlen", snBitLen, 63, 159);
        entry.setSerialNoBitLen(snBitLen);
    }
    if (caStatus != null) {
        entry.setStatus(CaStatus.forName(caStatus));
    }
    if (expirationPeriod != null && expirationPeriod < 0) {
        throw new IllegalCmdParamException("invalid expirationPeriod: " + expirationPeriod);
    } else {
        entry.setExpirationPeriod(expirationPeriod);
    }
    if (keepExpiredCertInDays != null) {
        entry.setKeepExpiredCertInDays(keepExpiredCertInDays);
    }
    if (certFile != null) {
        entry.setCert(X509Util.parseCert(certFile));
    }
    if (signerConf != null) {
        String tmpSignerType = signerType;
        if (tmpSignerType == null) {
            CaEntry caEntry = caManager.getCa(caName);
            if (caEntry == null) {
                throw new IllegalCmdParamException("please specify the signerType");
            }
            tmpSignerType = caEntry.getSignerType();
        }
        signerConf = ShellUtil.canonicalizeSignerConf(tmpSignerType, signerConf, passwordResolver, securityFactory);
        entry.setSignerConf(signerConf);
    }
    if (duplicateKeyS != null) {
        boolean permitted = isEnabled(duplicateKeyS, true, "duplicate-key");
        entry.setDuplicateKeyPermitted(permitted);
    }
    if (duplicateSubjectS != null) {
        boolean permitted = isEnabled(duplicateSubjectS, true, "duplicate-subject");
        entry.setDuplicateSubjectPermitted(permitted);
    }
    if (saveReqS != null) {
        boolean saveReq = isEnabled(saveReqS, true, "save-req");
        entry.setSaveRequest(saveReq);
    }
    if (CollectionUtil.isNonEmpty(permissions)) {
        int intPermission = ShellUtil.getPermission(permissions);
        entry.setPermission(intPermission);
    }
    entry.setCrlUris(getUris(crlUris));
    entry.setDeltaCrlUris(getUris(deltaCrlUris));
    entry.setOcspUris(getUris(ocspUris));
    entry.setCaCertUris(getUris(caCertUris));
    if (validityModeS != null) {
        ValidityMode validityMode = ValidityMode.forName(validityModeS);
        entry.setValidityMode(validityMode);
    }
    if (maxValidity != null) {
        entry.setMaxValidity(CertValidity.getInstance(maxValidity));
    }
    if (crlSignerName != null) {
        entry.setCrlSignerName(crlSignerName);
    }
    if (cmpControlName != null) {
        entry.setCmpControlName(cmpControlName);
    }
    if (responderName != null) {
        entry.setResponderName(responderName);
    }
    if (extraControl != null) {
        entry.setExtraControl(new ConfPairs(extraControl).unmodifiable());
    }
    if (numCrls != null) {
        entry.setNumCrls(numCrls);
    }
    return entry;
}
Also used : X509ChangeCaEntry(org.xipki.ca.server.mgmt.api.x509.X509ChangeCaEntry) CaEntry(org.xipki.ca.server.mgmt.api.CaEntry) ValidityMode(org.xipki.ca.server.mgmt.api.ValidityMode) NameId(org.xipki.ca.api.NameId) IllegalCmdParamException(org.xipki.console.karaf.IllegalCmdParamException) ConfPairs(org.xipki.common.ConfPairs) X509ChangeCaEntry(org.xipki.ca.server.mgmt.api.x509.X509ChangeCaEntry)

Example 13 with ConfPairs

use of org.xipki.common.ConfPairs in project xipki by xipki.

the class CaAddOrGenAction method getCaEntry.

protected X509CaEntry getCaEntry() throws Exception {
    ParamUtil.requireRange("sn-bitlen", snBitLen, 63, 159);
    if (nextCrlNumber < 1) {
        throw new IllegalCmdParamException("invalid CRL number: " + nextCrlNumber);
    }
    if (numCrls < 0) {
        throw new IllegalCmdParamException("invalid numCrls: " + numCrls);
    }
    if (expirationPeriod < 0) {
        throw new IllegalCmdParamException("invalid expirationPeriod: " + expirationPeriod);
    }
    if ("PKCS12".equalsIgnoreCase(signerType) || "JKS".equalsIgnoreCase(signerType)) {
        signerConf = ShellUtil.canonicalizeSignerConf(signerType, signerConf, passwordResolver, securityFactory);
    }
    X509CaUris caUris = new X509CaUris(caCertUris, ocspUris, crlUris, deltaCrlUris);
    X509CaEntry entry = new X509CaEntry(new NameId(null, caName), snBitLen, nextCrlNumber, signerType, signerConf, caUris, numCrls.intValue(), expirationPeriod.intValue());
    entry.setKeepExpiredCertInDays(keepExpiredCertInDays.intValue());
    boolean duplicateKeyPermitted = isEnabled(duplicateKeyS, true, "duplicate-key");
    entry.setDuplicateKeyPermitted(duplicateKeyPermitted);
    boolean duplicateSubjectPermitted = isEnabled(duplicateSubjectS, true, "duplicate-subject");
    entry.setDuplicateSubjectPermitted(duplicateSubjectPermitted);
    boolean saveReq = isEnabled(saveReqS, false, "save-req");
    entry.setSaveRequest(saveReq);
    ValidityMode validityMode = ValidityMode.forName(validityModeS);
    entry.setValidityMode(validityMode);
    CaStatus status = CaStatus.forName(caStatus);
    entry.setStatus(status);
    if (crlSignerName != null) {
        entry.setCrlSignerName(crlSignerName);
    }
    if (responderName != null) {
        entry.setResponderName(responderName);
    }
    CertValidity tmpMaxValidity = CertValidity.getInstance(maxValidity);
    entry.setMaxValidity(tmpMaxValidity);
    entry.setKeepExpiredCertInDays(keepExpiredCertInDays);
    if (cmpControlName != null) {
        entry.setCmpControlName(cmpControlName);
    }
    int intPermission = ShellUtil.getPermission(permissions);
    entry.setPermission(intPermission);
    if (extraControl != null) {
        extraControl = extraControl.trim();
    }
    if (StringUtil.isNotBlank(extraControl)) {
        entry.setExtraControl(new ConfPairs(extraControl).unmodifiable());
    }
    return entry;
}
Also used : X509CaUris(org.xipki.ca.server.mgmt.api.x509.X509CaUris) ValidityMode(org.xipki.ca.server.mgmt.api.ValidityMode) NameId(org.xipki.ca.api.NameId) CertValidity(org.xipki.ca.api.profile.CertValidity) IllegalCmdParamException(org.xipki.console.karaf.IllegalCmdParamException) ConfPairs(org.xipki.common.ConfPairs) CaStatus(org.xipki.ca.server.mgmt.api.CaStatus) X509CaEntry(org.xipki.ca.server.mgmt.api.x509.X509CaEntry)

Example 14 with ConfPairs

use of org.xipki.common.ConfPairs 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);
}
Also used : PasswordResolverException(org.xipki.password.PasswordResolverException) ConfPairs(org.xipki.common.ConfPairs)

Example 15 with ConfPairs

use of org.xipki.common.ConfPairs 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;
        }
    }
}
Also used : PasswordResolverException(org.xipki.password.PasswordResolverException) ConfPairs(org.xipki.common.ConfPairs)

Aggregations

ConfPairs (org.xipki.common.ConfPairs)38 HashMap (java.util.HashMap)8 Test (org.junit.Test)7 X509CaEntry (org.xipki.ca.server.mgmt.api.x509.X509CaEntry)5 IOException (java.io.IOException)4 CertificateException (java.security.cert.CertificateException)4 X509Certificate (java.security.cert.X509Certificate)4 SQLException (java.sql.SQLException)4 NameId (org.xipki.ca.api.NameId)4 CertValidity (org.xipki.ca.api.profile.CertValidity)4 CaMgmtException (org.xipki.ca.server.mgmt.api.CaMgmtException)4 ValidityMode (org.xipki.ca.server.mgmt.api.ValidityMode)4 DataAccessException (org.xipki.datasource.DataAccessException)4 SignerConf (org.xipki.security.SignerConf)4 XiSecurityException (org.xipki.security.exception.XiSecurityException)4 PreparedStatement (java.sql.PreparedStatement)3 OperationException (org.xipki.ca.api.OperationException)3 CaStatus (org.xipki.ca.server.mgmt.api.CaStatus)3 X509CaUris (org.xipki.ca.server.mgmt.api.x509.X509CaUris)3 X509ChangeCaEntry (org.xipki.ca.server.mgmt.api.x509.X509ChangeCaEntry)3