A B C D E F G H I J K L M N O P Q R S T U V W X Y Z

package org.bouncycastle.jce

Code Examples of org.bouncycastle.jce.PKCS10CertificationRequest

A class for verifying and creating PKCS10 Certification requests. CertificationRequest ::= SEQUENCE { certificationRequestInfo CertificationRequestInfo, signatureAlgorithm AlgorithmIdentifier{{ SignatureAlgorithms }}, signature BIT STRING } CertificationRequestInfo ::= SEQUENCE { version INTEGER { v...

View Full Code of org.bouncycastle.jce.PKCS10CertificationRequest


		 keyPair = KeyTools.genKeys("512", null, "RSA");
	 }

	 public void test01Pkcs10RequestMessage() throws InvalidKeyException, NoSuchAlgorithmException, NoSuchProviderException, SignatureException {
		 X509Name dn = new X509Name("CN=Test,OU=foo");
		 PKCS10CertificationRequest basicpkcs10 = new PKCS10CertificationRequest("SHA1WithRSA", dn, 
				 keyPair.getPublic(), new DERSet(), keyPair.getPrivate());

		 PKCS10RequestMessage msg = new PKCS10RequestMessage(basicpkcs10);
		 String username = msg.getUsername();
		 assertEquals("Test", username);

		 dn = new X509Name("C=SE, O=Foo, CN=Test Testsson");
		 basicpkcs10 = new PKCS10CertificationRequest("SHA1WithRSA", dn, 
				 keyPair.getPublic(), new DERSet(), keyPair.getPrivate());

		 msg = new PKCS10RequestMessage(basicpkcs10);
		 username = msg.getUsername();
		 assertEquals("Test", username);

		 // oid for unstructuredName, will be handles specially by EJBCA
		 dn = new X509Name("CN=Test + 1.2.840.113549.1.9.2=AttrValue1");
		 basicpkcs10 = new PKCS10CertificationRequest("SHA1WithRSA", dn, 
				 keyPair.getPublic(), new DERSet(), keyPair.getPrivate());

		 msg = new PKCS10RequestMessage(basicpkcs10);
		 username = msg.getUsername();
		 assertEquals("Test", username);

		 dn = new X509Name("CN=Test + 1.2.840.113549.1.9.2=AttrValue1 AttrValue2");
		 basicpkcs10 = new PKCS10CertificationRequest("SHA1WithRSA", dn, 
				 keyPair.getPublic(), new DERSet(), keyPair.getPrivate());

		 msg = new PKCS10RequestMessage(basicpkcs10);
		 username = msg.getUsername();
		 assertEquals("Test", username);

		 dn = new X509Name("CN=Test+1.2.840.113549.1.9.2=AttrValue1");
		 basicpkcs10 = new PKCS10CertificationRequest("SHA1WithRSA", dn, 
				 keyPair.getPublic(), new DERSet(), keyPair.getPrivate());

		 msg = new PKCS10RequestMessage(basicpkcs10);
		 username = msg.getUsername();
		 assertEquals("Test", username);

		 dn = new X509Name("CN=Test+1.2.840.113549.1.9.2=AttrValue1 AttrValue2");
		 basicpkcs10 = new PKCS10CertificationRequest("SHA1WithRSA", dn, 
				 keyPair.getPublic(), new DERSet(), keyPair.getPrivate());

		 msg = new PKCS10RequestMessage(basicpkcs10);
		 username = msg.getUsername();
		 assertEquals("Test", username);

		 // Completely unknown oid
		 dn = new X509Name("CN=Test + 1.2.840.113549.1.9.3=AttrValue1");
		 basicpkcs10 = new PKCS10CertificationRequest("SHA1WithRSA", dn, 
				 keyPair.getPublic(), new DERSet(), keyPair.getPrivate());

		 msg = new PKCS10RequestMessage(basicpkcs10);
		 username = msg.getUsername();
		 assertEquals("Test", username);

		 dn = new X509Name("CN=Test + 1.2.840.113549.1.9.3=AttrValue1 AttrValue2");
		 basicpkcs10 = new PKCS10CertificationRequest("SHA1WithRSA", dn, 
				 keyPair.getPublic(), new DERSet(), keyPair.getPrivate());

		 msg = new PKCS10RequestMessage(basicpkcs10);
		 username = msg.getUsername();
		 assertEquals("Test", username);

		 dn = new X509Name("CN=Test+1.2.840.113549.1.9.3=AttrValue1");
		 basicpkcs10 = new PKCS10CertificationRequest("SHA1WithRSA", dn, 
				 keyPair.getPublic(), new DERSet(), keyPair.getPrivate());

		 msg = new PKCS10RequestMessage(basicpkcs10);
		 username = msg.getUsername();
		 assertEquals("Test", username);

		 dn = new X509Name("CN=Test+1.2.840.113549.1.9.3=AttrValue1 AttrValue2");
		 basicpkcs10 = new PKCS10CertificationRequest("SHA1WithRSA", dn, 
				 keyPair.getPublic(), new DERSet(), keyPair.getPrivate());

		 msg = new PKCS10RequestMessage(basicpkcs10);
		 username = msg.getUsername();
		 assertEquals("Test", username);

		 dn = new X509Name("1.2.840.113549.1.9.3=AttrValue1 AttrValue2+CN=Test");
		 basicpkcs10 = new PKCS10CertificationRequest("SHA1WithRSA", dn, 
				 keyPair.getPublic(), new DERSet(), keyPair.getPrivate());

		 msg = new PKCS10RequestMessage(basicpkcs10);
		 username = msg.getUsername();
		 assertEquals("Test", username);

		 dn = new X509Name("1.2.840.113549.1.9.3=AttrValue1 AttrValue2+CN=Test+O=abc");
		 basicpkcs10 = new PKCS10CertificationRequest("SHA1WithRSA", dn, 
				 keyPair.getPublic(), new DERSet(), keyPair.getPrivate());

		 msg = new PKCS10RequestMessage(basicpkcs10);
		 username = msg.getUsername();
		 assertEquals("Test", username);

		 dn = new X509Name("1.2.840.113549.1.9.3=AttrValue1\\+\\= AttrValue2+CN=Test+O=abc");	// very strange, but should still be valid 
		 basicpkcs10 = new PKCS10CertificationRequest("SHA1WithRSA", dn, 
				 keyPair.getPublic(), new DERSet(), keyPair.getPrivate());

		 msg = new PKCS10RequestMessage(basicpkcs10);
		 username = msg.getUsername();
		 assertEquals("Test", username);

View Full Code Here


		log.trace("<test18DNSpaceTrimming()");
	}

	@SuppressWarnings("unchecked")
    public void test19getAltNameStringFromExtension() throws Exception {
		PKCS10CertificationRequest p10 = new PKCS10CertificationRequest(
				p10ReqWithAltNames);
		CertificationRequestInfo info = p10.getCertificationRequestInfo();
		ASN1Set set = info.getAttributes();
		// The set of attributes contains a sequence of with type oid
		// PKCSObjectIdentifiers.pkcs_9_at_extensionRequest
		Enumeration<Object> en = set.getObjects();
		boolean found = false;
		while (en.hasMoreElements()) {
			ASN1Sequence seq = ASN1Sequence.getInstance(en.nextElement());
			DERObjectIdentifier oid = (DERObjectIdentifier) seq.getObjectAt(0);
			if (oid.equals(PKCSObjectIdentifiers.pkcs_9_at_extensionRequest)) {
				// The object at position 1 is a SET of x509extensions
				DERSet s = (DERSet) seq.getObjectAt(1);
				X509Extensions exts = X509Extensions.getInstance(s
						.getObjectAt(0));
				X509Extension ext = exts
						.getExtension(X509Extensions.SubjectAlternativeName);
				if (ext != null) {
					found = true;
					String altNames = CertTools
							.getAltNameStringFromExtension(ext);
					assertEquals(
							"dNSName=ort3-kru.net.polisen.se, iPAddress=10.252.255.237",
							altNames);
				}
			}
		}
		assertTrue(found);

		p10 = new PKCS10CertificationRequest(p10ReqWithAltNames2);
		info = p10.getCertificationRequestInfo();
		set = info.getAttributes();
		// The set of attributes contains a sequence of with type oid
		// PKCSObjectIdentifiers.pkcs_9_at_extensionRequest
		
		en = set.getObjects();

View Full Code Here



    protected void makeCertRequest(String dn, KeyPair rsaKeys, String reqfile) throws NoSuchAlgorithmException, IOException, NoSuchProviderException,
            InvalidKeyException, SignatureException {
        getLogger().trace(">makeCertRequest: dn='" + dn + "', reqfile='" + reqfile + "'.");

        PKCS10CertificationRequest req = new PKCS10CertificationRequest("SHA1WithRSA", CertTools.stringToBcX509Name(dn), rsaKeys.getPublic(), new DERSet(),
                rsaKeys.getPrivate());

        /*
         * We don't use these unnecessary attributes DERConstructedSequence kName
         * = new DERConstructedSequence(); DERConstructedSet kSeq = new
         * DERConstructedSet();
         * kName.addObject(PKCSObjectIdentifiers.pkcs_9_at_emailAddress);
         * kSeq.addObject(new DERIA5String("foo@bar.se"));
         * kName.addObject(kSeq); req.setAttributes(kName);
         */
        ByteArrayOutputStream bOut = new ByteArrayOutputStream();
        DEROutputStream dOut = new DEROutputStream(bOut);
        dOut.writeObject(req);
        dOut.close();

        PKCS10CertificationRequest req2 = new PKCS10CertificationRequest(bOut.toByteArray());
        boolean verify = req2.verify();
        getLogger().info("Verify returned " + verify);

        if (verify == false) {
            getLogger().info("Aborting!");
            return;

View Full Code Here


    public void test03TestBCPKCS10() throws Exception {
        log.trace(">test03TestBCPKCS10()");
        userAdminSession.setUserStatus(admin, "foo", UserDataConstants.STATUS_NEW);
        log.debug("Reset status of 'foo' to NEW");
        // Create certificate request
        PKCS10CertificationRequest req = new PKCS10CertificationRequest("SHA1WithRSA", CertTools.stringToBcX509Name("C=SE, O=AnaTom, CN=foo"), rsakeys
                .getPublic(), new DERSet(), rsakeys.getPrivate());
        ByteArrayOutputStream bOut = new ByteArrayOutputStream();
        DEROutputStream dOut = new DEROutputStream(bOut);
        dOut.writeObject(req);
        dOut.close();

        PKCS10CertificationRequest req2 = new PKCS10CertificationRequest(bOut.toByteArray());
        boolean verify = req2.verify();
        log.debug("Verify returned " + verify);
        assertTrue(verify);
        log.debug("CertificationRequest generated successfully.");
        byte[] bcp10 = bOut.toByteArray();
        PKCS10RequestMessage p10 = new PKCS10RequestMessage(bcp10);

View Full Code Here


        tokenUser1.setStatus(UserDataVOWS.STATUS_NEW);
        tokenUser1.setTokenType(UserDataVOWS.TOKEN_TYPE_USERGENERATED);
        tokenUser1.setEndEntityProfileName("EMPTY");
        tokenUser1.setCertificateProfileName("ENDUSER");
        KeyPair basickeys = KeyTools.genKeys("1024", AlgorithmConstants.KEYALGORITHM_RSA);
        PKCS10CertificationRequest basicpkcs10 = new PKCS10CertificationRequest("SHA1WithRSA", CertTools.stringToBcX509Name("CN=NOTUSED"), basickeys
                .getPublic(), new DERSet(), basickeys.getPrivate());
        ArrayList<TokenCertificateRequestWS> requests = new ArrayList<TokenCertificateRequestWS>();
        TokenCertificateRequestWS tokenCertReqWS = new TokenCertificateRequestWS();
        tokenCertReqWS.setCAName(caName);
        tokenCertReqWS.setCertificateProfileName("WSTESTPROFILE");
        tokenCertReqWS.setValidityIdDays("1");
        tokenCertReqWS.setPkcs10Data(basicpkcs10.getDEREncoded());
        tokenCertReqWS.setType(HardTokenConstants.REQUESTTYPE_PKCS10_REQUEST);
        requests.add(tokenCertReqWS);
        tokenCertReqWS = new TokenCertificateRequestWS();
        tokenCertReqWS.setCAName(caName);
        tokenCertReqWS.setCertificateProfileName("ENDUSER");

View Full Code Here

TOP

View Full Code of org.bouncycastle.jce.PKCS10CertificationRequest

A B C D E F G H I J K L M N O P Q R S T U V W X Y Z

TOP