|
From: ejbca-support <ejb...@pr...> - 2012-11-09 07:39:02
|
Marcos,
Since the stacktrace indicates that the null-pointer exception is in your code rather
than in EJBCA I think you should continue debugging it. Since you have all the source
to UserDtataVO etc. it should be possible.
Cheers,
Anders
tech support
On 2012-11-08 14:06, Marcos Fontana wrote:
> *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_)
>
|