Package org.bouncycastle.asn1.x500

Examples of org.bouncycastle.asn1.x500.AttributeTypeAndValue


   * @throws CertificateEncodingException
   */
  public String getUserCertificateOrg()
     throws CertificateEncodingException
  {
    X500Name x500name = new JcaX509CertificateHolder(userCertificate).getSubject();
    RDN org = x500name.getRDNs(BCStyle.O)[0];

    return IETFUtils.valueToString(org.getFirst().getValue());
  }
View Full Code Here


  KeyPair pair = KeyPairGenerator.getInstance("RSA").generateKeyPair();
  TransactionId transId = TransactionId.createTransactionId();
  Nonce recipientNonce = Nonce.nextNonce();
  Nonce senderNonce = recipientNonce;
  X500Name issuer = new X500Name("CN=CA");
  X500Name subject = new X500Name("CN=Client");
  IssuerAndSubject ias = new IssuerAndSubject(issuer, subject);
  BigInteger serial = BigInteger.ONE;
  IssuerAndSerialNumber iasn = new IssuerAndSerialNumber(issuer, serial);
  PKCS10CertificationRequest csr = getCsr(new X500Principal("CN=Client"),
    pair.getPublic(), pair.getPrivate(), "password".toCharArray());
View Full Code Here

  LOGGER.debug("INIT");
    }

    @Override
    public void init() throws ServletException {
  name = new X500Name("CN=Certification Authority");
  pollName = new X500Name("CN=Poll");
  caSerial = BigInteger.TEN;
  try {
      KeyPair keyPair = KeyPairGenerator.getInstance("RSA").genKeyPair();
      priKey = keyPair.getPrivate();
      pubKey = keyPair.getPublic();
View Full Code Here

    @Override
    protected List<X509Certificate> doEnrol(PKCS10CertificationRequest csr,
      TransactionId transId) throws OperationFailureException {
  try {
      X500Name subject = X500Name.getInstance(csr.getSubject());
      LOGGER.debug(subject.toString());
      if (subject.equals(pollName)) {
    return Collections.emptyList();
      }
      String password = getPassword(csr);
      if (!password.equals("password")) {
    LOGGER.debug("Invalid password");
View Full Code Here

  PkiMessageEncoder enc = new PkiMessageEncoder(keyPair.getPrivate(),
    getCertificate(keyPair), envEnc);

  TransactionId transId = TransactionId.createTransactionId();
  Nonce senderNonce = Nonce.nextNonce();
  X500Name name = new X500Name("CN=jscep.org");
  BigInteger serialNumber = BigInteger.ONE;
  IssuerAndSerialNumber iasn = new IssuerAndSerialNumber(name,
    serialNumber);
  GetCert getCert = new GetCert(transId, senderNonce, iasn);
  PkiOperationRequest req = new PkiOperationRequest(enc.encode(getCert));
View Full Code Here

  private String goodIdentifier;
  private String badIdentifier;

  @Before
  public void configureFixtures() throws Exception {
    name = new X500Name("CN=Example");
    pollName = new X500Name("CN=Poll");
    goodSerial = BigInteger.ONE;
    badSerial = BigInteger.ZERO;
    goodIdentifier = null;
    badIdentifier = "bad";
    KeyPair keyPair = KeyPairGenerator.getInstance("RSA").genKeyPair();
View Full Code Here

        signerBuilder = new JcaContentSignerBuilder("MD5withRSA");
      }
 
      // The following variables are used to represent the SCEP client
      KeyPair idPair = KeyPairGenerator.getInstance("RSA").genKeyPair();
      X500Name issuer = new X500Name("CN=entity");
      BigInteger serial = new BigInteger(16, new SecureRandom());
      Calendar cal = Calendar.getInstance();
      cal.add(Calendar.DATE, -1);
      Date notBefore = cal.getTime();
      cal.add(Calendar.DATE, 2);
      Date notAfter = cal.getTime();
      X500Name subject = issuer;
      PublicKey publicKey = idPair.getPublic();
      JcaX509v3CertificateBuilder certBuilder = new JcaX509v3CertificateBuilder(
          issuer, serial, notBefore, notAfter, subject, publicKey);
      X509CertificateHolder idHolder = certBuilder.build(signerBuilder
          .build(idPair.getPrivate()));
      // Convert Bouncy Castle representation of X509Certificate into
      // something usable
      X509Certificate id = (X509Certificate) CertificateFactory.getInstance(
          "X509").generateCertificate(
          new ByteArrayInputStream(idHolder.getEncoded()));
 
      // The following variables are used to represent the entity being
      // enrolled
      X500Name entityName = new X500Name("CN=entity");
      KeyPair entityPair = KeyPairGenerator.getInstance("RSA").genKeyPair();
      SubjectPublicKeyInfo publicKeyInfo = SubjectPublicKeyInfo
          .getInstance(entityPair.getPublic().getEncoded());
      // Generate the certificate signing request
      PKCS10CertificationRequestBuilder csrBuilder = new PKCS10CertificationRequestBuilder(
          entityName, publicKeyInfo);
      // SCEP servers usually require a challenge password
      csrBuilder.addAttribute(
          PKCSObjectIdentifiers.pkcs_9_at_challengePassword,
          new DERPrintableString(new String("password".toCharArray())));
      ContentSigner signer = signerBuilder.build(entityPair.getPrivate());
      PKCS10CertificationRequest csr = csrBuilder.build(signer);
 
      // Send the enrollment request
      EnrollmentResponse response = client
          .enrol(id, idPair.getPrivate(), csr);
      if (response.isFailure()) {
        // Our request was rejected!
        System.out.println("Failed!");
      } else if (response.isPending()) {
        // The server hasn't enrolled us, but we should try again.
        System.out.println("Pending!");
 
        X500Principal entityPrincipal = new X500Principal(
            entityName.getEncoded());
        // We should deal with the response to the poll too. Since this a
        // short-lived
        // test, we conveniently stop processing here. Usually you'd
        // schedule the poll
        // to run at some point in the future.
View Full Code Here

    LOGGER.debug("Retriving CRL from CA");
    // TRANSACTIONAL
    // CRL query
    checkDistributionPoints(profile);

    X500Name name = new X500Name(issuer.getName());
    IssuerAndSerialNumber iasn = new IssuerAndSerialNumber(name, serial);
    Transport transport = createTransport(profile);
    final Transaction t = new NonEnrollmentTransaction(transport,
        getEncoder(identity, key, profile), getDecoder(identity, key,
            profile), iasn, MessageType.GET_CRL);
View Full Code Here

    // Certificate query
    final CertStore store = getCaCertificate(profile);
    CertStoreInspector certs = CertStoreInspector.getInstance(store);
    final X509Certificate ca = certs.getIssuer();

    X500Name name = new X500Name(ca.getIssuerX500Principal().toString());
    IssuerAndSerialNumber iasn = new IssuerAndSerialNumber(name, serial);
    Transport transport = createTransport(profile);
    final Transaction t = new NonEnrollmentTransaction(transport,
        getEncoder(identity, key, profile), getDecoder(identity, key,
            profile), iasn, MessageType.GET_CERT);
View Full Code Here

      throws ClientException, TransactionException {
    LOGGER.debug("Enrolling certificate with CA");

    if (isSelfSigned(identity)) {
      LOGGER.debug("Certificate is self-signed");
      X500Name csrSubject = csr.getSubject();
      X500Name idSubject = X500Utils.toX500Name(identity
          .getSubjectX500Principal());

      if (!csrSubject.equals(idSubject)) {
        LOGGER.error("The self-signed certificate MUST use the same subject name as in the PKCS#10 request.");
      }
View Full Code Here

TOP

Related Classes of org.bouncycastle.asn1.x500.AttributeTypeAndValue

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.