Package org.ejbca.core.protocol.ws.client.gen

Examples of org.ejbca.core.protocol.ws.client.gen.CertificateResponse


        X509Certificate tmpCert = null;
        final Iterator<X509Certificate> i;
        try {
            final PKCS10CertificationRequest pkcs10 = new PKCS10CertificationRequest("SHA1WithRSA", CertTools.stringToBcX509Name("CN=NOUSED"), keyPair.getPublic(), new DERSet(),
                                                                                     keyPair.getPrivate(), this.privateKeyContainerKeyStore.providerName );
            final CertificateResponse certificateResponse = ejbcaWS.pkcs10Request(userData.getUsername(), userData.getPassword(),
                                                                                  new String(Base64.encode(pkcs10.getEncoded())),null,CertificateHelper.RESPONSETYPE_CERTIFICATE);
            i = (Iterator<X509Certificate>)CertificateFactory.getInstance("X.509").generateCertificates(new ByteArrayInputStream(Base64.decode(certificateResponse.getData()))).iterator();
        } catch (Exception e) {
            m_log.error("Certificate generation problem.", e);
            return null;
        }
        while ( i.hasNext() ) {
View Full Code Here


                            user.setPassword(new String(password));
                            user.setStatus(10);
                            ejbcaWS.editUser(user);
                        }

                        final CertificateResponse response =
                                ejbcaWS.pkcs10Request(request.getEndEntity()
                                    .getUsername(),
                                new String(password),
                                new String(request.getRequestBytes()), null,
                                CertificateHelper.RESPONSETYPE_CERTIFICATE);

                        final String base64EncodedData
                                = new String(response.getData());

                        out.println("-----BEGIN CERTIFICATE-----");
                        out.println(base64EncodedData);
                        out.println("-----END CERTIFICATE-----");
                        request.setDone(true);
View Full Code Here

        KeyPair keys = KeyTools.genKeys("1024", AlgorithmConstants.KEYALGORITHM_RSA);
        PKCS10CertificationRequest pkcs10 = new PKCS10CertificationRequest("SHA1WithRSA", CertTools.stringToBcX509Name("CN=NOUSED"), keys.getPublic(),
                new DERSet(), keys.getPrivate());

        CertificateResponse certenv = ejbcaraws.pkcs10Request(CA1_WSTESTUSER1, "foo123", new String(Base64.encode(pkcs10.getEncoded())), null,
                CertificateHelper.RESPONSETYPE_CERTIFICATE);

        assertNotNull(certenv);

        X509Certificate cert = (X509Certificate) CertificateHelper.getCertificate(certenv.getData());

        assertNotNull(cert);

        assertEquals(getDN(CA1_WSTESTUSER1), cert.getSubjectDN().toString());
View Full Code Here

     * Certificate and PKCS#7. If the first one fails an error code will be
     * returned. I the second fails a Exception will be thrown.
     */
    private ErrorCode certreqInternal(UserDataVOWS userdata, String requestdata, int requesttype) throws Exception {
        // Request a certificate via the WS API
        final CertificateResponse certificateResponse;
        try {
            certificateResponse = ejbcaraws.certificateRequest(userdata, requestdata, requesttype, null, CertificateHelper.RESPONSETYPE_CERTIFICATE);
        } catch (EjbcaException_Exception e) {
            final ErrorCode errorCode = e.getFaultInfo().getErrorCode();
            log.info(errorCode.getInternalErrorCode(), e);
            assertNotNull("error code should not be null", errorCode);
            return errorCode;
        }
        // Verify that the response is of the right type
        assertNotNull(certificateResponse);
        assertTrue(certificateResponse.getResponseType().equals(CertificateHelper.RESPONSETYPE_CERTIFICATE));
        // Verify that the certificate in the response has the same Subject DN
        // as in the request.
        final X509Certificate cert = certificateResponse.getCertificate();
        assertNotNull(cert);
        assertTrue(cert.getSubjectDN().toString().equals(userdata.getSubjectDN()));

        // Request a PKCS#7 via the WS API
        final CertificateResponse pkcs7Response = ejbcaraws.certificateRequest(userdata, requestdata, requesttype, null, CertificateHelper.RESPONSETYPE_PKCS7);
        // Verify that the response is of the right type
        assertTrue(pkcs7Response.getResponseType().equals(CertificateHelper.RESPONSETYPE_PKCS7));
        // Verify that the PKCS#7 response contains a certificate
        CMSSignedData cmsSignedData = new CMSSignedData(CertificateHelper.getPKCS7(pkcs7Response.getData()));
        assertNotNull(cmsSignedData);
        CertStore certStore = cmsSignedData.getCertificatesAndCRLs("Collection", "BC");
        assertTrue(certStore.getCertificates(null).size() == 1);
        return null;
    }
View Full Code Here

        user1.setTokenType(UserDataVOWS.TOKEN_TYPE_USERGENERATED);
        user1.setEndEntityProfileName("EMPTY");
        user1.setCertificateProfileName("ENDUSER");
        ejbcaraws.editUser(user1);

        CertificateResponse certenv = ejbcaraws.crmfRequest(CA1_WSTESTUSER1, "foo123", CRMF, null, CertificateHelper.RESPONSETYPE_CERTIFICATE);

        assertNotNull(certenv);

        X509Certificate cert = (X509Certificate) CertificateHelper.getCertificate(certenv.getData());

        assertNotNull(cert);
        log.info(cert.getSubjectDN().toString());
        assertEquals(getDN(CA1_WSTESTUSER1), cert.getSubjectDN().toString());
    }
View Full Code Here

        user1.setTokenType(UserDataVOWS.TOKEN_TYPE_USERGENERATED);
        user1.setEndEntityProfileName("EMPTY");
        user1.setCertificateProfileName("ENDUSER");
        ejbcaraws.editUser(user1);

        CertificateResponse certenv = ejbcaraws.spkacRequest(CA1_WSTESTUSER1, "foo123", SPCAK, null, CertificateHelper.RESPONSETYPE_CERTIFICATE);

        assertNotNull(certenv);

        X509Certificate cert = (X509Certificate) CertificateHelper.getCertificate(certenv.getData());

        assertNotNull(cert);

        assertEquals(getDN(CA1_WSTESTUSER1), cert.getSubjectDN().toString());
    }
View Full Code Here

        KeyPair keys = KeyTools.genKeys("1024", AlgorithmConstants.KEYALGORITHM_RSA);
        PKCS10CertificationRequest pkcs10 = new PKCS10CertificationRequest("SHA1WithRSA", CertTools.stringToBcX509Name("CN=NOUSED"), keys.getPublic(),
                new DERSet(), keys.getPrivate());

        CertificateResponse certenv = ejbcaraws.pkcs10Request(CA1_WSTESTUSER1, "foo123", new String(Base64.encode(pkcs10.getEncoded())), null,
                CertificateHelper.RESPONSETYPE_CERTIFICATE);

        assertNotNull(certenv);
        assertTrue(certenv.getResponseType().equals(CertificateHelper.RESPONSETYPE_CERTIFICATE));
        X509Certificate cert = (X509Certificate) CertificateHelper.getCertificate(certenv.getData());

        assertNotNull(cert);
        assertTrue(cert.getSubjectDN().toString().equals(getDN(CA1_WSTESTUSER1)));

        ejbcaraws.editUser(userdatas.get(0));
        certenv = ejbcaraws
                .pkcs10Request(CA1_WSTESTUSER1, "foo123", new String(Base64.encode(pkcs10.getEncoded())), null, CertificateHelper.RESPONSETYPE_PKCS7);
        assertTrue(certenv.getResponseType().equals(CertificateHelper.RESPONSETYPE_PKCS7));
        CMSSignedData cmsSignedData = new CMSSignedData(CertificateHelper.getPKCS7(certenv.getData()));
        assertTrue(cmsSignedData != null);

        CertStore certStore = cmsSignedData.getCertificatesAndCRLs("Collection", "BC");
        assertTrue(certStore.getCertificates(null).size() == 1);
View Full Code Here

            super(_jobData);
            this.pkcs10 = new PKCS10CertificationRequest("SHA1WithRSA", CertTools.stringToBcX509Name("CN=NOUSED"), keys.getPublic(), new DERSet(), keys.getPrivate());
            this.ejbcaWS = _ejbcaWS;
        }
        public boolean doIt() throws Exception {
            final CertificateResponse certificateResponse = this.ejbcaWS.pkcs10Request(this.jobData.userName, this.jobData.passWord,
                                                                                       new String(Base64.encode(this.pkcs10.getEncoded())),null,CertificateHelper.RESPONSETYPE_CERTIFICATE);
            return checkAndLogCertificateResponse(certificateResponse, this.jobData);
        }
View Full Code Here

            this.user.setPassword(this.jobData.passWord);
            int requestType = CertificateHelper.CERT_REQ_TYPE_PKCS10;
            String responseType = CertificateHelper.RESPONSETYPE_CERTIFICATE;
            String hardTokenSN = null; // not used
            String requestData = new String(Base64.encode(this.pkcs10.getEncoded()));
            final CertificateResponse certificateResponse = this.ejbcaWS.certificateRequest(this.user, requestData, requestType, hardTokenSN, responseType);
            return checkAndLogCertificateResponse(certificateResponse, this.jobData);
        }
View Full Code Here

           

            try{

              //UserDataVOWS userdata, String requestData, int requestType, String hardTokenSN, String responseType)
              CertificateResponse result = getEjbcaRAWS().certificateRequest(userdata,requestdata,requesttype, hardtokensn,CertificateHelper.RESPONSETYPE_CERTIFICATE);
             
              if(result==null){
                getPrintStream().println("No certificate could be generated for user, check server logs for error.");
              }else{
                String filepath = userdata.getUsername();
                if(encoding.equals("DER")){
                  filepath += ".cer";
                }else{
                  filepath += ".pem";
                }
                if(outputPath != null){
                  filepath = outputPath + "/" + filepath;
                }
               
               
                if(encoding.equals("DER")){
                  FileOutputStream fos = new FileOutputStream(filepath);
                  fos.write(CertificateHelper.getCertificate(result.getData()).getEncoded());
                  fos.close();
                }else{
                  FileOutputStream fos = new FileOutputStream(filepath);
                  ArrayList<java.security.cert.Certificate> list = new ArrayList<java.security.cert.Certificate>();
                  list.add(CertificateHelper.getCertificate(result.getData()));
                  fos.write(CertTools.getPEMFromCerts(list));
                  fos.close();                                       
                }
                getPrintStream().println("Certificate generated, written to " + filepath);
              }
View Full Code Here

TOP

Related Classes of org.ejbca.core.protocol.ws.client.gen.CertificateResponse

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.