Examples of CMSProcessable


Examples of org.bouncycastle.cms.CMSProcessable

        userCertificate = convert(cert);
    }

    if(originalData != null)
    {
      CMSProcessable signedContent = s.getSignedContent();
      signedContent.write(originalData);
    }

    return verified;
  }
View Full Code Here

Examples of org.bouncycastle.cms.CMSProcessable

    InputStream is = new FileInputStream(p7m);
    OutputStream os = new FileOutputStream(output);
    try
    {
      CMSSignedData sdp = new CMSSignedData(is);
      CMSProcessable cmsp = sdp.getSignedContent();
      os.write((byte[])cmsp.getContent());
    }
    finally
    {
      is.close();
      os.close();
View Full Code Here

Examples of org.bouncycastle.cms.CMSProcessable

  public CMSSignedData encode(PkiMessage<?> message)
      throws MessageEncodingException {
    LOGGER.debug("Encoding pkiMessage");
    LOGGER.debug("Encoding message: {}", message);

    CMSProcessable content = getContent(message);
    LOGGER.debug(
        "Signing pkiMessage using key belonging to [issuer={}; serial={}]",
        signerId.getIssuerDN(), signerId.getSerialNumber());
    try {
      CMSSignedDataGenerator generator = new CMSSignedDataGenerator();
View Full Code Here

Examples of org.bouncycastle.cms.CMSProcessable

    }
  }

  private CMSProcessable getContent(PkiMessage<?> message)
      throws MessageEncodingException {
    CMSProcessable signable;

    boolean hasMessageData = true;
    if (message instanceof CertRep) {
      CertRep response = (CertRep) message;
      if (response.getPkiStatus() != PkiStatus.SUCCESS) {
View Full Code Here

Examples of org.bouncycastle.cms.CMSProcessable

      throws MessageDecodingException {
  LOGGER.debug("Decoding pkiMessage");
  validate(pkiMessage);

  // The signed content is always an octet string
  CMSProcessable signedContent = pkiMessage.getSignedContent();

  SignerInformationStore signerStore = pkiMessage.getSignerInfos();
  SignerInformation signerInfo = signerStore.get(new JcaSignerId(signer));
  if (signerInfo == null) {
      throw new MessageDecodingException("Could not for signerInfo for "
        + signer.getIssuerDN());
  }

  LOGGER.debug("pkiMessage digest algorithm: {}",
    signerInfo.getDigestAlgorithmID().getAlgorithm());
  LOGGER.debug("pkiMessage encryption algorithm: {}",
    signerInfo.getEncryptionAlgOID());

  Store store = pkiMessage.getCertificates();
  Collection<?> certColl;
  try {
      certColl = store.getMatches(signerInfo.getSID());
  } catch (StoreException e) {
      throw new MessageDecodingException(e);
  }
  if (certColl.size() > 0) {
      X509CertificateHolder cert = (X509CertificateHolder) certColl
        .iterator().next();
      LOGGER.debug(
        "Verifying pkiMessage using key belonging to [issuer={}; serial={}]",
        cert.getIssuer(), cert.getSerialNumber());
      SignerInformationVerifier verifier;
      try {
    verifier = new JcaSimpleSignerInfoVerifierBuilder().build(cert);
    signerInfo.verify(verifier);

    LOGGER.debug("pkiMessage verified.");
      } catch (Exception e) {
    throw new MessageDecodingException(e);
      }
  } else {
      LOGGER.warn("Unable to verify message because the signedData contained no certificates.");
  }

  Hashtable<DERObjectIdentifier, Attribute> attrTable = signerInfo
    .getSignedAttributes().toHashtable();

  if (LOGGER.isDebugEnabled()) {
      LOGGER.debug("pkiMessage has {} signed attributes:", signerInfo
        .getSignedAttributes().size());
      for (DERObjectIdentifier oid : attrTable.keySet()) {
    LOGGER.debug("  {}: {}", oid.getId(), attrTable.get(oid)
      .getAttrValues());
      }
  }

  MessageType messageType = toMessageType(attrTable
    .get(toOid(MESSAGE_TYPE)));
  Nonce senderNonce = toNonce(attrTable.get(toOid(SENDER_NONCE)));
  TransactionId transId = toTransactionId(attrTable.get(toOid(TRANS_ID)));

  if (messageType == MessageType.CERT_REP) {
      PkiStatus pkiStatus = toPkiStatus(attrTable.get(toOid(PKI_STATUS)));
      Nonce recipientNonce = toNonce(attrTable
        .get(toOid(RECIPIENT_NONCE)));

      if (pkiStatus == PkiStatus.FAILURE) {
    FailInfo failInfo = toFailInfo(attrTable.get(toOid(FAIL_INFO)));
    LOGGER.debug("Finished decoding pkiMessage");
    return new CertRep(transId, senderNonce, recipientNonce,
      failInfo);
      } else if (pkiStatus == PkiStatus.PENDING) {
    LOGGER.debug("Finished decoding pkiMessage");
    return new CertRep(transId, senderNonce, recipientNonce);
      } else {
    final CMSEnvelopedData ed = getEnvelopedData(signedContent
      .getContent());
    final byte[] envelopedContent = decoder.decode(ed);
    CMSSignedData messageData;
    try {
        messageData = new CMSSignedData(envelopedContent);
    } catch (CMSException e) {
        throw new MessageDecodingException(e);
    }
    LOGGER.debug("Finished decoding pkiMessage");
    return new CertRep(transId, senderNonce, recipientNonce,
      messageData);
      }
  } else {
      CMSEnvelopedData ed = getEnvelopedData(signedContent.getContent());
      byte[] decoded = decoder.decode(ed);
      if (messageType == MessageType.GET_CERT) {
    IssuerAndSerialNumber messageData = IssuerAndSerialNumber
      .getInstance(decoded);
    LOGGER.debug("Finished decoding pkiMessage");
View Full Code Here

Examples of org.bouncycastle.cms.CMSProcessable

  }

  public byte[] getContent(final byte[] data) {
    try {
      CMSSignedData signedData = new CMSSignedData(data);
      CMSProcessable processable = signedData.getSignedContent();
      return this.getContent(processable);
    } catch (Exception e) {
      throw new SignerException(e);
    }
  }
View Full Code Here

Examples of org.bouncycastle.cms.CMSProcessable

      bodyHeaders.add("Content-Type",  out.getMediaType().toString());
      writer.writeTo(out.getEntity(), out.getType(), out.getGenericType(), null, out.getMediaType(), bodyHeaders, bodyOs);
      CMSSignedDataGenerator signGen = new CMSSignedDataGenerator();
      signGen.addSigner(out.getPrivateKey(), (X509Certificate)out.getCertificate(), CMSSignedDataGenerator.DIGEST_SHA1);
      //signGen.addCertificatesAndCRLs(certs);
      CMSProcessable content = new CMSProcessableByteArray(bodyOs.toByteArray());

      CMSSignedData signedData = signGen.generate(content, true, "BC");
      return signedData.getEncoded();
   }
View Full Code Here

Examples of org.bouncycastle.cms.CMSProcessable

   private static byte[] p7s(PrivateKey priv, X509Certificate storecert, CertStore certs, byte[] contentbytes) throws CertStoreException, CMSException, NoSuchAlgorithmException, NoSuchProviderException, IOException
   {
      CMSSignedDataGenerator signGen = new CMSSignedDataGenerator();
      signGen.addSigner(priv, (X509Certificate)storecert, CMSSignedDataGenerator.DIGEST_SHA512);
      //signGen.addCertificatesAndCRLs(certs);
      CMSProcessable content = new CMSProcessableByteArray(contentbytes);

      CMSSignedData signedData = signGen.generate(content, true, "BC");
      return signedData.getEncoded();
   }
View Full Code Here

Examples of org.bouncycastle.cms.CMSProcessable

            }
          }
        }
      }
      if (verified) {
        CMSProcessable signedContent = signedData.getSignedContent();
        byte[] content = (byte[]) signedContent.getContent();
        verified = Arrays.equals(data, content);
      }
      return verified;
    } catch (Exception e) {
      throw new SignerException(e);
View Full Code Here

Examples of org.bouncycastle.cms.CMSProcessable

    {
        super(getInputStream(message));

        this.message = message;

        CMSProcessable  cont = this.getSignedContent();

        if (cont != null)
        {
            byte[]  contBytes = (byte[])cont.getContent();
   
            this.content = SMIMEUtil.toMimeBodyPart(contBytes);
        }
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.