X509Certificate[] chain = new X509Certificate[2];
Certificate[] cachain = getCACertChain(); X509Certificate[] chain = new X509Certificate[cachain.length+1];
    private void createUser(String username, String password, KeyPair rsaKeys)    throws Exception {        cat.debug(">createUser: username=" + username + ", hiddenpwd, keys=" + rsaKeys.toString());        // Send the certificate request to the CA        ISignSession ss = signhome.create();        X509Certificate cert = (X509Certificate)ss.createCertificate(username, password, rsaKeys.getPublic());        // Make a certificate chain from the certificate and the CA-certificate        CertificateFactory cf = CertificateFactory.getInstance("X.509");        X509Certificate[] chain = new X509Certificate[2];        chain[0] = cert;        // CA-certificate        chain[1] = getCACertificate();        if (CertTools.isSelfSigned(chain[1])) {            try {                chain[1].verify(chain[1].getPublicKey());            } catch (GeneralSecurityException se) {                throw new Exception("RootCA certificate does not verify");            }        }        else            throw new Exception("RootCA certificate not self-signed");        // Verify that the user-certificate is signed by our CA        try {            chain[0].verify(chain[1].getPublicKey());        } catch (GeneralSecurityException se) {            throw new Exception("Generated certificate does not verify using CA-certificate.");        }        // Use CommonName as alias in the keystore        String alias = CertTools.getPartFromDN(cert.getSubjectDN().toString(), "CN");        // Store keys and certificates in keystore.        KeyStore p12 = KeyTools.createP12(alias, rsaKeys.getPrivate(), chain[0], chain[1]);        storeKeyStore(p12, username, password);                cat.info("Created P12 for " + username+ ".");        cat.debug(">createUser: username=" + username + ", hiddenpwd, keys=" + rsaKeys.toString());    } // doit