Package org.apache.clerezza.ssl.keygen

Examples of org.apache.clerezza.ssl.keygen.Certificate


                // a webid is not a good idea, but this will at least be something.
                if (webId != null && webId.length() > 0) cn = webId;
                else cn = "default name (please improve keygen UI code)";
            }

            Certificate cert;
            if ((spkacData == null) || spkacData.isEmpty()) {
                cert = keygen.createFromSpkac(spkacData);

            } else {
                cert = keygen.createFromPEM(pemCsrData);
            }
            cert.setSubjectCommonName(cn);
            cert.addSubjectAlternativeName(webId);
            cert.addDurationInDays("365");
            cert.startEarlier("1"); //always start one hour earlier at least, to avoid clock synchronisation issues
            cert.getSerialisation().writeTo(response);
        } catch (Exception e) {
           throw new ServletException("could not create certificate",e);
        }
    }
View Full Code Here


   * @throws Exception
   */
  public void testSpkac() throws Exception {
    BouncyKeygenService srvc = new BouncyKeygenService();
    srvc.initialize();
    Certificate cert = srvc.createFromSpkac(spkac);
    PubKey spk = cert.getSubjectPublicKey();
    assertNotNull(spk);
    assertTrue(spk instanceof RSAPubKey);
    assertEquals("the expected and real values don't match",
      "c16c47a74f601f081e73df17da1c729f194094df487a24aeed3d424abcb8\r\n" +
        "b8c3c292e8e47294e0d27ee87e11ef91efe4c25bfd4292bf2a8e207104c8\r\n" +
        "9d6bb74a5e6171174fd4abd14eaf957723e9d105134ad96b8b7b9831970e\r\n" +
        "0b9c9716a005572c115af403b4160c62daa929ccaf691a4a2910be969593\r\n" +
        "2236ef39281fcb85\r\n", ((RSAPubKey) spk).getHexModulus());
    assertEquals("int exponent is not correct", "65537", ((RSAPubKey) spk).getIntExponent());
    Date now = new Date();
    cert.addDurationInDays("3");
    cert.setSubjectCommonName("Test");
    cert.addSubjectAlternativeName(WEBID);
    CertSerialisation certByte = cert.getSerialisation();

    //test that the returned certificate contains the correct values...
    Date endDate = cert.getEndDate();
    assertTrue("end date is too early (we added 10 seconds)",
      endDate.getTime() < (now.getTime() + (3 * 24 * 60 * 60 * SECOND) + (10 * SECOND)));
    assertTrue("end date is too late (we removed 10 seconds)",
      endDate.getTime() > (now.getTime() + (3 * 24 * 60 * 60 * SECOND) - (10 * SECOND)));

 
View Full Code Here

   * @throws Exception
   */
  public void testSpkacOneYear() throws Exception {
    BouncyKeygenService srvc = new BouncyKeygenService();
    srvc.initialize();
    Certificate cert = srvc.createFromSpkac(spkac);
    PubKey spk = cert.getSubjectPublicKey();
    assertNotNull(spk);
    assertTrue(spk instanceof RSAPubKey);
    assertEquals("the expected and real values don't match",
      "c16c47a74f601f081e73df17da1c729f194094df487a24aeed3d424abcb8\r\n" +
        "b8c3c292e8e47294e0d27ee87e11ef91efe4c25bfd4292bf2a8e207104c8\r\n" +
        "9d6bb74a5e6171174fd4abd14eaf957723e9d105134ad96b8b7b9831970e\r\n" +
        "0b9c9716a005572c115af403b4160c62daa929ccaf691a4a2910be969593\r\n" +
        "2236ef39281fcb85\r\n", ((RSAPubKey) spk).getHexModulus());
    assertEquals("int exponent is not correct", "65537", ((RSAPubKey) spk).getIntExponent());
    Date now = new Date();

    cert.setSubjectCommonName("Test");
    cert.addSubjectAlternativeName(WEBID);
    cert.startEarlier("2");
    CertSerialisation certByte = cert.getSerialisation();


    //test that the returned certificate contains the correct values...
    Date endDate = cert.getEndDate();
    long end10 = now.getTime() + YEAR + (10 * SECOND);
    assertTrue("end date (" + endDate + ") is too late . It should be before " + new Date(end10) + " - we added 10 seconds .",
      endDate.getTime() < end10);
    end10 = now.getTime() + YEAR - (10 * SECOND);
    assertTrue("end date (" + endDate + ") is too early. It should be after " + new Date(end10) + " - we removed 10 seconds .",
      endDate.getTime() > end10);

    Date startDate = cert.getStartDate();
    long start10 = now.getTime() - (2 * HOUR) - (10 * SECOND);
    assertTrue("start date (" + startDate + ") is too early. It should be after " + new Date(start10) + "- we removed 2 hours and 10 seconds.",
      startDate.getTime() > start10);
    assertTrue("start date (" + startDate + ") is too late It should be after " + new Date(start10) + "- we removed 10 secondes short of 2 hours.",
      startDate.getTime() < (now.getTime() - (2 * HOUR) + (10 * SECOND)));
 
View Full Code Here

TOP

Related Classes of org.apache.clerezza.ssl.keygen.Certificate

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.