|
From: Marcos F. <mar...@ho...> - 2012-11-08 13:07:12
|
Hi,
I'm getting the following error in this call.
import java.io.ByteArrayInputStream;
import java.util.Enumeration;
import java.util.Random;
import org.ejbca.core.ejb.ra.CertificateRequestSessionRemote;
import org.ejbca.core.model.AlgorithmConstants;
import org.ejbca.core.model.SecConst;
import org.ejbca.core.model.log.Admin;
import org.ejbca.core.model.ra.UserDataVO;
import org.ejbca.util.Base64;
import org.ejbca.util.CertTools;
import org.ejbca.util.NonEjbTestTools;
import java.security.cert.Certificate;
public class TesteCertificado {
private final Admin admin = new Admin(Admin.TYPE_CACOMMANDLINE_USER);
private final Random random = new Random();
private CertificateRequestSessionRemote certificateRequestSession;
/**
* Verify that a soft token can be generated in a single transaction.
*/
public void testSoftTokenRequestRollback() throws Exception {
// First try a successful request and validate the returned KeyStore
String username = "gabrielmendes-" + random.nextInt();
String password = "gabriel";
UserDataVO userdata = new UserDataVO(username, "CN=" + username,
1963139164, null, null, SecConst.USER_ENDUSER,
SecConst.EMPTY_ENDENTITYPROFILE,
SecConst.CERTPROFILE_FIXED_ENDUSER, SecConst.TOKEN_SOFT_JKS,
0, null);
userdata.setPassword(password);
byte[] encodedKeyStore =
certificateRequestSession.processSoftTokenReq(admin, userdata, null, "1024",
AlgorithmConstants.KEYALGORITHM_RSA, true);
// Convert encoded KeyStore to the proper return type
java.security.KeyStore keyStore =
java.security.KeyStore.getInstance("JKS");
keyStore.load(new ByteArrayInputStream(encodedKeyStore),
userdata.getPassword().toCharArray());
Enumeration<String> aliases = keyStore.aliases();
String alias = aliases.nextElement();
Certificate cert = keyStore.getCertificate(alias);
if (CertTools.isSelfSigned(cert)) {
// Ignore the CA cert and get another one
alias = aliases.nextElement();
cert = keyStore.getCertificate(alias);
}
keyStore.getKey(alias, password.toCharArray());
}
/**
* Verify that a soft token can be generated in a single transaction.
*/
public void testCertificateRequestRollback() throws Exception {
// First try a successful request and validate the returned KeyStore
String username = "gabrielmendes-" + random.nextInt();
String password = "gabriel";
UserDataVO userdata = new UserDataVO(username, "CN=" + username,
1963139164, null, null, SecConst.USER_ENDUSER,
SecConst.EMPTY_ENDENTITYPROFILE,
SecConst.CERTPROFILE_FIXED_ENDUSER,
SecConst.TOKEN_SOFT_BROWSERGEN, 0, null);
userdata.setPassword(password);
String pkcs10 = new
String(Base64.encode(NonEjbTestTools.generatePKCS10Req("CN=Ignored",
password)));
byte[] encodedCertificate =
certificateRequestSession.processCertReq(admin, userdata, pkcs10,
SecConst.CERT_REQ_TYPE_PKCS10, null,
SecConst.CERT_RES_TYPE_CERTIFICATE);
CertTools.getCertfromByteArray(encodedCertificate);
}
} }
============================================================================
==================================================
java.lang.NullPointerException
at
TesteCertificado.testSoftTokenRequestRollback(TesteCertificado.java:34)
at test.main(test.java:35)
_____
Nenhum virus encontrado nessa mensagem.
Verificado por AVG - www.avgbrasil.com.br
Versao: 2013.0.2742 / Banco de dados de virus: 2617/5879 - Data de
Lancamento: 11/07/12
|