bcpkix-jdk15on-147

m paramInputStream)
  {
    if ((operator instanceof InputDecryptor)) {
      return ((InputDecryptor)operator).getInputStream(paramInputStream);
    }
    return new TeeInputStream(paramInputStream, ((MacCalculator)operator).getOutputStream());
  }
  
  public boolean isMacBased()
  {
    return operator instanceof MacCalculator;
  }
  
  public byte[] getMac()
  {
    return ((MacCalculator)operator).getMac();
  }
}

/* Location:
 * Qualified Name:     org.bouncycastle.cms.RecipientOperator
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.bouncycastle.cms;

import java.math.BigInteger;
import org.bouncycastle.asn1.x500.X500Name;
import org.bouncycastle.cert.selector.X509CertificateHolderSelector;
import org.bouncycastle.util.Selector;

public class SignerId
  implements Selector
{
  private X509CertificateHolderSelector baseSelector;
  
  private SignerId(X509CertificateHolderSelector paramX509CertificateHolderSelector)
  {
    baseSelector = paramX509CertificateHolderSelector;
  }
  
  public SignerId(byte[] paramArrayOfByte)
  {
    this(null, null, paramArrayOfByte);
  }
  
  public SignerId(X500Name paramX500Name, BigInteger paramBigInteger)
  {
    this(paramX500Name, paramBigInteger, null);
  }
  
  public SignerId(X500Name paramX500Name, BigInteger paramBigInteger, byte[] paramArrayOfByte)
  {
    this(new X509CertificateHolderSelector(paramX500Name, paramBigInteger, paramArrayOfByte));
  }
  
  public X500Name getIssuer()
  {
    return baseSelector.getIssuer();
  }
  
  public BigInteger getSerialNumber()
  {
    return baseSelector.getSerialNumber();
  }
  
  public byte[] getSubjectKeyIdentifier()
  {
    return baseSelector.getSubjectKeyIdentifier();
  }
  
  public int hashCode()
  {
    return baseSelector.hashCode();
  }
  
  public boolean equals(Object paramObject)
  {
    if (!(paramObject instanceof SignerId)) {
      return false;
    }
    SignerId localSignerId = (SignerId)paramObject;
    return baseSelector.equals(baseSelector);
  }
  
  public boolean match(Object paramObject)
  {
    if ((paramObject instanceof SignerInformation)) {
      return ((SignerInformation)paramObject).getSID().equals(this);
    }
    return baseSelector.match(paramObject);
  }
  
  public Object clone()
  {
    return new SignerId(baseSelector);
  }
}

/* Location:
 * Qualified Name:     org.bouncycastle.cms.SignerId
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.bouncycastle.cms;

import java.io.IOException;
import java.io.OutputStream;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import org.bouncycastle.asn1.ASN1ObjectIdentifier;
import org.bouncycastle.asn1.ASN1Set;
import org.bouncycastle.asn1.DERObjectIdentifier;
import org.bouncycastle.asn1.DEROctetString;
import org.bouncycastle.asn1.DERSet;
import org.bouncycastle.asn1.cms.AttributeTable;
import org.bouncycastle.asn1.cms.SignerIdentifier;
import org.bouncycastle.asn1.cms.SignerInfo;
import org.bouncycastle.asn1.x509.AlgorithmIdentifier;
import org.bouncycastle.cert.X509CertificateHolder;
import org.bouncycastle.operator.ContentSigner;
import org.bouncycastle.operator.DefaultDigestAlgorithmIdentifierFinder;
import org.bouncycastle.operator.DigestAlgorithmIdentifierFinder;
import org.bouncycastle.operator.DigestCalculator;
import org.bouncycastle.operator.DigestCalculatorProvider;
import org.bouncycastle.operator.OperatorCreationException;
import org.bouncycastle.util.io.TeeOutputStream;

public class SignerInfoGenerator
{
  private final SignerIdentifier signerIdentifier;
  private final CMSAttributeTableGenerator sAttrGen;
  private final CMSAttributeTableGenerator unsAttrGen;
  private final ContentSigner signer;
  private final DigestCalculator digester;
  private final DigestAlgorithmIdentifierFinder digAlgFinder = new DefaultDigestAlgorithmIdentifierFinder();
  private final CMSSignatureEncryptionAlgorithmFinder sigEncAlgFinder;
  private byte[] calculatedDigest = null;
  private X509CertificateHolder certHolder;
  
  SignerInfoGenerator(SignerIdentifier paramSignerIdentifier, ContentSigner paramContentSigner, DigestCalculatorProvider paramDigestCalculatorProvider, CMSSignatureEncryptionAlgorithmFinder paramCMSSignatureEncryptionAlgorithmFinder)
    throws OperatorCreationException
  {
    this(paramSignerIdentifier, paramContentSigner, paramDigestCalculatorProvider, paramCMSSignatureEncryptionAlgorithmFinder, false);
  }
  
  SignerInfoGenerator(SignerIdentifier paramSignerIdentifier, ContentSigner paramContentSigner, DigestCalculatorProvider paramDigestCalculatorProvider, CMSSignatureEncryptionAlgorithmFinder paramCMSSignatureEncryptionAlgorithmFinder, boolean paramBoolean)
    throws OperatorCreationException
  {
    signerIdentifier = paramSignerIdentifier;
    signer = paramContentSigner;
    if (paramDigestCalculatorProvider != null) {
      digester = paramDigestCalculatorProvider.get(digAlgFinder.find(paramContentSigner.getAlgorithmIdentifier()));
    } else {
      digester = null;
    }
    if (paramBoolean)
    {
      sAttrGen = null;
      unsAttrGen = null;
    }
    else
    {
      sAttrGen = new DefaultSignedAttributeTableGenerator();
      unsAttrGen = null;
    }
    sigEncAlgFinder = paramCMSSignatureEncryptionAlgorithmFinder;
  }
  
  public SignerInfoGenerator(SignerInfoGenerator paramSignerInfoGenerator, CMSAttributeTableGenerator paramCMSAttributeTableGenerator1, CMSAttributeTableGenerator paramCMSAttributeTableGenerator2)
  {
    signerIdentifier = signerIdentifier;
    signer = signer;
    digester = digester;
    sigEncAlgFinder = sigEncAlgFinder;
    sAttrGen = paramCMSAttributeTableGenerator1;
    unsAttrGen = paramCMSAttributeTableGenerator2;
  }
  
  SignerInfoGenerator(SignerIdentifier paramSignerIdentifier, ContentSigner paramContentSigner, DigestCalculatorProvider paramDigestCalculatorProvider, CMSSignatureEncryptionAlgorithmFinder paramCMSSignatureEncryptionAlgorithmFinder, CMSAttributeTableGenerator paramCMSAttributeTableGenerator1, CMSAttributeTableGenerator paramCMSAttributeTableGenerator2)
    throws OperatorCreationException
  {
    signerIdentifier = paramSignerIdentifier;
    signer = paramContentSigner;
    if (paramDigestCalculatorProvider != null) {
      digester = paramDigestCalculatorProvider.get(digAlgFinder.find(paramContentSigner.getAlgorithmIdentifier()));
    } else {
      digester = null;
    }
    sAttrGen = paramCMSAttributeTableGenerator1;
    unsAttrGen = paramCMSAttributeTableGenerator2;
    sigEncAlgFinder = paramCMSSignatureEncryptionAlgorithmFinder;
  }
  
  public boolean hasAssociatedCertificate()
  {
    return certHolder != null;
  }
  
  public X509CertificateHolder getAssociatedCertificate()
  {
    return certHolder;
  }
  
  public AlgorithmIdentifier getDigestAlgorithm()
  {
    if (digester != null) {
      return digester.getAlgorithmIdentifier();
    }
    return digAlgFinder.find(signer.getAlgorithmIdentifier());
  }
  
  public OutputStream getCalculatingOutputStream()
  {
    if (digester != null)
    {
      if (sAttrGen == null) {
        return new TeeOutputStream(digester.getOutputStream(), signer.getOutputStream());
      }
      return digester.getOutputStream();
    }
    return signer.getOutputStream();
  }
  
  public SignerInfo generate(ASN1ObjectIdentifier paramASN1ObjectIdentifier)
    throws CMSException
  {
    try
    {
      ASN1Set localASN1Set = null;
      AlgorithmIdentifier localAlgorithmIdentifier = null;
      if (sAttrGen != null)
      {
        localAlgorithmIdentifier = digester.getAlgorithmIdentifier();
        calculatedDigest = digester.getDigest();
        localObject1 = getBaseParameters(paramASN1ObjectIdentifier, digester.getAlgorithmIdentifier(), calculatedDigest);
        localObject2 = sAttrGen.getAttributes(Collections.unmodifiableMap((Map)localObject1));
        localASN1Set = getAttributeSet((AttributeTable)localObject2);
        localObject3 = signer.getOutputStream();
        ((OutputStream)localObject3).write(localASN1Set.getEncoded("DER"));
        ((OutputStream)localObject3).close();
      }
      else if (digester != null)
      {
        localAlgorithmIdentifier = digester.getAlgorithmIdentifier();
        calculatedDigest = digester.getDigest();
      }
      else
      {
        localAlgorithmIdentifier = digAlgFinder.find(signer.getAlgorithmIdentifier());
        calculatedDigest = null;
      }
      Object localObject1 = signer.getSignature();
      Object localObject2 = null;
      if (unsAttrGen != null)
      {
        localObject3 = getBaseParameters(paramASN1ObjectIdentifier, localAlgorithmIdentifier, calculatedDigest);
        ((Map)localObject3).put("encryptedDigest", ((byte[])localObject1).clone());
        AttributeTable localAttributeTable = unsAttrGen.getAttributes(Collections.unmodifiableMap((Map)localObject3));
        localObject2 = getAttributeSet(localAttributeTable);
      }
      Object localObject3 = sigEncAlgFinder.findEncryptionAlgorithm(signer.getAlgorithmIdentifier());
      return new SignerInfo(signerIdentifier, localAlgorithmIdentifier, localASN1Set, (AlgorithmIdentifier)localObject3, new DEROctetString((byte[])localObject1), (ASN1Set)localObject2);
    }
    catch (IOException localIOException)
    {
      throw new CMSException("encoding error.", localIOException);
    }
  }
  
  void setAssociatedCertificate(X509CertificateHolder paramX509CertificateHolder)
  {
    certHolder = paramX509CertificateHolder;
  }
  
  private ASN1Set getAttributeSet(AttributeTable paramAttributeTable)
  {
    if (paramAttributeTable != null) {
      return new DERSet(paramAttributeTable.toASN1EncodableVector());
    }
    return null;
  }
  
  private Map getBaseParameters(DERObjectIdentifier paramDERObjectIdentifier, AlgorithmIdentifier paramAlgorithmIdentifier, byte[] paramArrayOfByte)
  {
    HashMap localHashMap = new HashMap();
    if (paramDERObjectIdentifier != null) {
      localHashMap.put("contentType", paramDERObjectIdentifier);
    }
    localHashMap.put("digestAlgID", paramAlgorithmIdentifier);
    localHashMap.put("digest", paramArrayOfByte.clone());
    return localHashMap;
  }
  
  public byte[] getCalculatedDigest()
  {
    if (calculatedDigest != null) {
      return (byte[])calculatedDigest.clone();
    }
    return null;
  }
  
  public CMSAttributeTableGenerator getSignedAttributeTableGenerator()
  {
    return sAttrGen;
  }
  
  public CMSAttributeTableGenerator getUnsignedAttributeTableGenerator()
  {
    return unsAttrGen;
  }
}

/* Location:
 * Qualified Name:     org.bouncycastle.cms.SignerInfoGenerator
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.bouncycastle.cms;

import org.bouncycastle.asn1.DEROctetString;
import org.bouncycastle.asn1.cms.IssuerAndSerialNumber;
import org.bouncycastle.asn1.cms.SignerIdentifier;
import org.bouncycastle.cert.X509CertificateHolder;
import org.bouncycastle.operator.ContentSigner;
import org.bouncycastle.operator.DigestCalculatorProvider;
import org.bouncycastle.operator.OperatorCreationException;

public class SignerInfoGeneratorBuilder
{
  private DigestCalculatorProvider digestProvider;
  private boolean directSignature;
  private CMSAttributeTableGenerator signedGen;
  private CMSAttributeTableGenerator unsignedGen;
  private CMSSignatureEncryptionAlgorithmFinder sigEncAlgFinder;
  
  public SignerInfoGeneratorBuilder(DigestCalculatorProvider paramDigestCalculatorProvider)
  {
    this(paramDigestCalculatorProvider, new DefaultCMSSignatureEncryptionAlgorithmFinder());
  }
  
  public SignerInfoGeneratorBuilder(DigestCalculatorProvider paramDigestCalculatorProvider, CMSSignatureEncryptionAlgorithmFinder paramCMSSignatureEncryptionAlgorithmFinder)
  {
    digestProvider = paramDigestCalculatorProvider;
    sigEncAlgFinder = paramCMSSignatureEncryptionAlgorithmFinder;
  }
  
  public SignerInfoGeneratorBuilder setDirectSignature(boolean paramBoolean)
  {
    directSignature = paramBoolean;
    return this;
  }
  
  public SignerInfoGeneratorBuilder setSignedAttributeGenerator(CMSAttributeTableGenerator paramCMSAttributeTableGenerator)
  {
    signedGen = paramCMSAttributeTableGenerator;
    return this;
  }
  
  public SignerInfoGeneratorBuilder setUnsignedAttributeGenerator(CMSAttributeTableGenerator paramCMSAttributeTableGenerator)
  {
    unsignedGen = paramCMSAttributeTableGenerator;
    return this;
  }
  
  public SignerInfoGenerator build(ContentSigner paramContentSigner, X509CertificateHolder paramX509CertificateHolder)
    throws OperatorCreationException
  {
    SignerIdentifier localSignerIdentifier = new SignerIdentifier(new IssuerAndSerialNumber(paramX509CertificateHolder.toASN1Structure()));
    SignerInfoGenerator localSignerInfoGenerator = createGenerator(paramContentSigner, localSignerIdentifier);
    localSignerInfoGenerator.setAssociatedCertificate(paramX509CertificateHolder);
    return localSignerInfoGenerator;
  }
  
  public SignerInfoGenerator build(ContentSigner paramContentSigner, byte[] paramArrayOfByte)
    throws OperatorCreationException
  {
    SignerIdentifier localSignerIdentifier = new SignerIdentifier(new DEROctetString(paramArrayOfByte));
    return createGenerator(paramContentSigner, localSignerIdentifier);
  }
  
  private SignerInfoGenerator createGenerator(ContentSigner paramContentSigner, SignerIdentifier paramSignerIdentifier)
    throws OperatorCreationException
  {
    if (directSignature) {
      return new SignerInfoGenerator(paramSignerIdentifier, paramContentSigner, digestProvider, sigEncAlgFinder, true);
    }
    if ((signedGen != null) || (unsignedGen != null))
    {
      if (signedGen == null) {
        signedGen = new DefaultSignedAttributeTableGenerator();
      }
      return new SignerInfoGenerator(paramSignerIdentifier, paramContentSigner, digestProvider, sigEncAlgFinder, signedGen, unsignedGen);
    }
    return new SignerInfoGenerator(paramSignerIdentifier, paramContentSigner, digestProvider, sigEncAlgFinder);
  }
}

/* Location:
 * Qualified Name:     org.bouncycastle.cms.SignerInfoGeneratorBuilder
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.bouncycastle.cms;

import java.io.IOException;
import java.io.OutputStream;
import java.math.BigInteger;
import java.security.NoSuchAlgorithmException;
import java.security.NoSuchProviderException;
import java.security.Provider;
import java.security.PublicKey;
import java.security.cert.CertificateExpiredException;
import java.security.cert.CertificateNotYetValidException;
import java.security.cert.X509Certificate;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Enumeration;
import java.util.Iterator;
import java.util.List;
import org.bouncycastle.asn1.ASN1Encodable;
import org.bouncycastle.asn1.ASN1EncodableVector;
import org.bouncycastle.asn1.ASN1Integer;
import org.bouncycastle.asn1.ASN1ObjectIdentifier;
import org.bouncycastle.asn1.ASN1OctetString;
import org.bouncycastle.asn1.ASN1Primitive;
import org.bouncycastle.asn1.ASN1Set;
import org.bouncycastle.asn1.DERObjectIdentifier;
import org.bouncycastle.asn1.DERSet;
import org.bouncycastle.asn1.cms.Attribute;
import org.bouncycastle.asn1.cms.AttributeTable;
import org.bouncycastle.asn1.cms.CMSAttributes;
import org.bouncycastle.asn1.cms.IssuerAndSerialNumber;
import org.bouncycastle.asn1.cms.SignerIdentifier;
import org.bouncycastle.asn1.cms.SignerInfo;
import org.bouncycastle.asn1.cms.Time;
import org.bouncycastle.asn1.x509.AlgorithmIdentifier;
import org.bouncycastle.asn1.x509.DigestInfo;
import org.bouncycastle.cert.X509CertificateHolder;
import org.bouncycastle.cms.jcajce.JcaSignerInfoVerifierBuilder;
import org.bouncycastle.cms.jcajce.JcaSimpleSignerInfoVerifierBuilder;
import org.bouncycastle.operator.ContentVerifier;
import org.bouncycastle.operator.DigestCalculator;
import org.bouncycastle.operator.OperatorCreationException;
import org.bouncycastle.operator.RawContentVerifier;
import org.bouncycastle.operator.jcajce.JcaDigestCalculatorProviderBuilder;
import org.bouncycastle.util.Arrays;

public class SignerInformation
{
  private SignerId sid;
  private SignerInfo info;
  private AlgorithmIdentifier digestAlgorithm;
  private AlgorithmIdentifier encryptionAlgorithm;
  private final ASN1Set signedAttributeSet;
  private final ASN1Set unsignedAttributeSet;
  private CMSProcessable content;
  private byte[] signature;
  private ASN1ObjectIdentifier contentType;
  private byte[] resultDigest;
  private AttributeTable signedAttributeValues;
  private AttributeTable unsignedAttributeValues;
  private boolean isCounterSignature;
  
  SignerInformation(SignerInfo paramSignerInfo, ASN1ObjectIdentifier paramASN1ObjectIdentifier, CMSProcessable paramCMSProcessable, byte[] paramArrayOfByte)
  {
    info = paramSignerInfo;
    contentType = paramASN1ObjectIdentifier;
    isCounterSignature = (paramASN1ObjectIdentifier == null);
    SignerIdentifier localSignerIdentifier = paramSignerInfo.getSID();
    Object localObject;
    if (localSignerIdentifier.isTagged())
    {
      localObject = ASN1OctetString.getInstance(localSignerIdentifier.getId());
      sid = new SignerId(((ASN1OctetString)localObject).getOctets());
    }
    else
    {
      localObject = IssuerAndSerialNumber.getInstance(localSignerIdentifier.getId());
      sid = new SignerId(((IssuerAndSerialNumber)localObject).getName(), ((IssuerAndSerialNumber)localObject).getSerialNumber().getValue());
    }
    digestAlgorithm = paramSignerInfo.getDigestAlgorithm();
    signedAttributeSet = paramSignerInfo.getAuthenticatedAttributes();
    unsignedAttributeSet = paramSignerInfo.getUnauthenticatedAttributes();
    encryptionAlgorithm = paramSignerInfo.getDigestEncryptionAlgorithm();
    signature = paramSignerInfo.getEncryptedDigest().getOctets();
    content = paramCMSProcessable;
    resultDigest = paramArrayOfByte;
  }
  
  public boolean isCounterSignature()
  {
    return isCounterSignature;
  }
  
  public ASN1ObjectIdentifier getContentType()
  {
    return contentType;
  }
  
  private byte[] encodeObj(ASN1Encodable paramASN1Encodable)
    throws IOException
  {
    if (paramASN1Encodable != null) {
      return paramASN1Encodable.toASN1Primitive().getEncoded();
    }
    return null;
  }
  
  public SignerId getSID()
  {
    return sid;
  }
  
  public int getVersion()
  {
    return info.getVersion().getValue().intValue();
  }
  
  public AlgorithmIdentifier getDigestAlgorithmID()
  {
    return digestAlgorithm;
  }
  
  public String getDigestAlgOID()
  {
    return digestAlgorithm.getObjectId().getId();
  }
  
  public byte[] getDigestAlgParams()
  {
    try
    {
      return encodeObj(digestAlgorithm.getParameters());
    }
    catch (Exception localException)
    {
      throw new RuntimeException("exception getting digest parameters " + localException);
    }
  }
  
  public byte[] getContentDigest()
  {
    if (resultDigest == null) {
      throw new IllegalStateException("method can only be called after verify.");
    }
    return (byte[])resultDigest.clone();
  }
  
  public String getEncryptionAlgOID()
  {
    return encryptionAlgorithm.getObjectId().getId();
  }
  
  public byte[] getEncryptionAlgParams()
  {
    try
    {
      return encodeObj(encryptionAlgorithm.getParameters());
    }
    catch (Exception localException)
    {
      throw new RuntimeException("exception getting encryption parameters " + localException);
    }
  }
  
  public AttributeTable getSignedAttributes()
  {
    if ((signedAttributeSet != null) && (signedAttributeValues == null)) {
      signedAttributeValues = new AttributeTable(signedAttributeSet);
    }
    return signedAttributeValues;
  }
  
  public AttributeTable getUnsignedAttributes()
  {
    if ((unsignedAttributeSet != null) && (unsignedAttributeValues == null)) {
      unsignedAttributeValues = new AttributeTable(unsignedAttributeSet);
    }
    return unsignedAttributeValues;
  }
  
  public byte[] getSignature()
  {
    return (byte[])signature.clone();
  }
  
  public SignerInformationStore getCounterSignatures()
  {
    AttributeTable localAttributeTable = getUnsignedAttributes();
    if (localAttributeTable == null) {
      return new SignerInformationStore(new ArrayList(0));
    }
    ArrayList localArrayList = new ArrayList();
    ASN1EncodableVector localASN1EncodableVector = localAttributeTable.getAll(CMSAttributes.counterSignature);
    for (int i = 0; i < localASN1EncodableVector.size(); i++)
    {
      Attribute localAttribute = (Attribute)localASN1EncodableVector.get(i);
      ASN1Set localASN1Set = localAttribute.getAttrValues();
      if (localASN1Set.size() < 1) {}
      Enumeration localEnumeration = localASN1Set.getObjects();
      while (localEnumeration.hasMoreElements())
      {
        SignerInfo localSignerInfo = SignerInfo.getInstance(localEnumeration.nextElement());
        localArrayList.add(new SignerInformation(localSignerInfo, null, new CMSProcessableByteArray(getSignature()), null));
      }
    }
    return new SignerInformationStore(localArrayList);
  }
  
  public byte[] getEncodedSignedAttributes()
    throws IOException
  {
    if (signedAttributeSet != null) {
      return signedAttributeSet.getEncoded();
    }
    return null;
  }
  
  /**
   * @deprecated
   */
  private boolean doVerify(PublicKey paramPublicKey, Provider paramProvider)
    throws CMSException, NoSuchAlgorithmException
  {
    try
    {
      SignerInformationVerifier localSignerInformationVerifier;
      if (paramProvider != null)
      {
        if (!paramProvider.getName().equalsIgnoreCase("BC")) {
          localSignerInformationVerifier = new JcaSignerInfoVerifierBuilder(new JcaDigestCalculatorProviderBuilder().build()).setProvider(paramProvider).build(paramPublicKey);
        } else {
          localSignerInformationVerifier = new JcaSimpleSignerInfoVerifierBuilder().setProvider(paramProvider).build(paramPublicKey);
        }
      }
      else {
        localSignerInformationVerifier = new JcaSimpleSignerInfoVerifierBuilder().build(paramPublicKey);
      }
      return doVerify(localSignerInformationVerifier);
    }
    catch (OperatorCreationException localOperatorCreationException)
    {
      throw new CMSException("unable to create verifier: " + localOperatorCreationException.getMessage(), localOperatorCreationException);
    }
  }
  
  private boolean doVerify(SignerInformationVerifier paramSignerInformationVerifier)
    throws CMSException
  {
    String str = CMSSignedHelper.INSTANCE.getEncryptionAlgName(getEncryptionAlgOID());
    try
    {
      if (resultDigest == null)
      {
        DigestCalculator localDigestCalculator = paramSignerInformationVerifier.getDigestCalculator(getDigestAlgorithmID());
        if (content != null)
        {
          localObject2 = localDigestCalculator.getOutputStream();
          content.write((OutputStream)localObject2);
          ((OutputStream)localObject2).close();
        }
        else if (signedAttributeSet == null)
        {
          throw new CMSException("data not encapsulated in signature - use detached constructor.");
        }
        resultDigest = localDigestCalculator.getDigest();
      }
    }
    catch (IOException localIOException1)
    {
      throw new CMSException("can't process mime object to create signature.", localIOException1);
    }
    catch (OperatorCreationException localOperatorCreationException1)
    {
      throw new CMSException("can't create digest calculator: " + localOperatorCreationException1.getMessage(), localOperatorCreationException1);
    }
    Object localObject1 = getSingleValuedSignedAttribute(CMSAttributes.contentType, "content-type");
    if (localObject1 == null)
    {
      if ((!isCounterSignature) && (signedAttributeSet != null)) {
        throw new CMSException("The content-type attribute type MUST be present whenever signed attributes are present in signed-data");
      }
    }
    else
    {
      if (isCounterSignature) {
        throw new CMSException("[For counter signatures,] the signedAttributes field MUST NOT contain a content-type attribute");
      }
      if (!(localObject1 instanceof DERObjectIdentifier)) {
        throw new CMSException("content-type attribute value not of ASN.1 type 'OBJECT IDENTIFIER'");
      }
      localObject2 = (DERObjectIdentifier)localObject1;
      if (!((DERObjectIdentifier)localObject2).equals(contentType)) {
        throw new CMSException("content-type attribute value does not match eContentType");
      }
    }
    localObject1 = getSingleValuedSignedAttribute(CMSAttributes.messageDigest, "message-digest");
    if (localObject1 == null)
    {
      if (signedAttributeSet != null) {
        throw new CMSException("the message-digest signed attribute type MUST be present when there are any signed attributes present");
      }
    }
    else
    {
      if (!(localObject1 instanceof ASN1OctetString)) {
        throw new CMSException("message-digest attribute value not of ASN.1 type 'OCTET STRING'");
      }
      localObject2 = (ASN1OctetString)localObject1;
      if (!Arrays.constantTimeAreEqual(resultDigest, ((ASN1OctetString)localObject2).getOctets())) {
        throw new CMSSignerDigestMismatchException("message-digest attribute value does not match calculated value");
      }
    }
    localObject1 = getSignedAttributes();
    if ((localObject1 != null) && (((AttributeTable)localObject1).getAll(CMSAttributes.counterSignature).size() > 0)) {
      throw new CMSException("A countersignature attribute MUST NOT be a signed attribute");
    }
    Object localObject2 = getUnsignedAttributes();
    Object localObject3;
    if (localObject2 != null)
    {
      localObject3 = ((AttributeTable)localObject2).getAll(CMSAttributes.counterSignature);
      for (int i = 0; i < ((ASN1EncodableVector)localObject3).size(); i++)
      {
        Attribute localAttribute = (Attribute)((ASN1EncodableVector)localObject3).get(i);
        if (localAttribute.getAttrValues().size() < 1) {
          throw new CMSException("A countersignature attribute MUST contain at least one AttributeValue");
        }
      }
    }
    try
    {
      localObject1 = paramSignerInformationVerifier.getContentVerifier(encryptionAlgorithm, info.getDigestAlgorithm());
      localObject2 = ((ContentVerifier)localObject1).getOutputStream();
      if (signedAttributeSet == null)
      {
        if (resultDigest != null)
        {
          if ((localObject1 instanceof RawContentVerifier))
          {
            localObject3 = (RawContentVerifier)localObject1;
            if (str.equals("RSA"))
            {
              DigestInfo localDigestInfo = new DigestInfo(digestAlgorithm, resultDigest);
              return ((RawContentVerifier)localObject3).verify(localDigestInfo.getEncoded("DER"), getSignature());
            }
            return ((RawContentVerifier)localObject3).verify(resultDigest, getSignature());
          }
          throw new CMSException("verifier unable to process raw signature");
        }
        if (content != null) {
          content.write((OutputStream)localObject2);
        }
      }
      else
      {
        ((OutputStream)localObject2).write(getEncodedSignedAttributes());
      }
      ((OutputStream)localObject2).close();
      return ((ContentVerifier)localObject1).verify(getSignature());
    }
    catch (IOException localIOException2)
    {
      throw new CMSException("can't process mime object to create signature.", localIOException2);
    }
    catch (OperatorCreationException localOperatorCreationException2)
    {
      throw new CMSException("can't create content verifier: " + localOperatorCreationException2.getMessage(), localOperatorCreationException2);
    }
  }
  
  /**
   * @deprecated
   */
  public boolean verify(PublicKey paramPublicKey, String paramString)
    throws NoSuchAlgorithmException, NoSuchProviderException, CMSException
  {
    return verify(paramPublicKey, CMSUtils.getProvider(paramString));
  }
  
  /**
   * @deprecated
   */
  public boolean verify(PublicKey paramPublicKey, Provider paramProvider)
    throws NoSuchAlgorithmException, NoSuchProviderException, CMSException
  {
    getSigningTime();
    return doVerify(paramPublicKey, paramProvider);
  }
  
  /**
   * @deprecated
   */
  public boolean verify(X509Certificate paramX509Certificate, String paramString)
    throws NoSuchAlgorithmException, NoSuchProviderException, CertificateExpiredException, CertificateNotYetValidException, CMSException
  {
    return verify(paramX509Certificate, CMSUtils.getProvider(paramString));
  }
  
  /**
   * @deprecated
   */
  public boolean verify(X509Certificate paramX509Certificate, Provider paramProvider)
    throws NoSuchAlgorithmException, CertificateExpiredException, CertificateNotYetValidException, CMSException
  {
    Time localTime = getSigningTime();
    if (localTime != null) {
      paramX509Certificate.checkValidity(localTime.getDate());
    }
    return doVerify(paramX509Certificate.getPublicKey(), paramProvider);
  }
  
  public boolean verify(SignerInformationVerifier paramSignerInformationVerifier)
    throws CMSException
  {
    Time localTime = getSigningTime();
    if ((paramSignerInformationVerifier.hasAssociatedCertificate()) && (localTime != null))
    {
      X509CertificateHolder localX509CertificateHolder = paramSignerInformationVerifier.getAssociatedCertificate();
      if (!localX509CertificateHolder.isValidOn(localTime.getDate())) {
        throw new CMSVerifierCertificateNotValidException("verifier not valid at signingTime");
      }
    }
    return doVerify(paramSignerInformationVerifier);
  }
  
  /**
   * @deprecated
   */
  public SignerInfo toSignerInfo()
  {
    return info;
  }
  
  public SignerInfo toASN1Structure()
  {
    return info;
  }
  
  private ASN1Primitive getSingleValuedSignedAttribute(ASN1ObjectIdentifier paramASN1ObjectIdentifier, String paramString)
    throws CMSException
  {
    AttributeTable localAttributeTable1 = getUnsignedAttributes();
    if ((localAttributeTable1 != null) && (localAttributeTable1.getAll(paramASN1ObjectIdentifier).size() > 0)) {
      throw new CMSException("The " + paramString + " attribute MUST NOT be an unsigned attribute");
    }
    AttributeTable localAttributeTable2 = getSignedAttributes();
    if (localAttributeTable2 == null) {
      return null;
    }
    ASN1EncodableVector localASN1EncodableVector = localAttributeTable2.getAll(paramASN1ObjectIdentifier);
    switch (localASN1EncodableVector.size())
    {
    case 0: 
      return null;
    case 1: 
      Attribute localAttribute = (Attribute)localASN1EncodableVector.get(0);
      ASN1Set localASN1Set = localAttribute.getAttrValues();
      if (localASN1Set.size() != 1) {
        throw new CMSException("A " + paramString + " attribute MUST have a single attribute value");
      }
      return localASN1Set.getObjectAt(0).toASN1Primitive();
    }
    throw new CMSException("The SignedAttributes in a signerInfo MUST NOT include multiple instances of the " + paramString + " attribute");
  }
  
  private Time getSigningTime()
    throws CMSException
  {
    ASN1Primitive localASN1Primitive = getSingleValuedSignedAttribute(CMSAttributes.signingTime, "signing-time");
    if (localASN1Primitive == null) {
      return null;
    }
    try
    {
      return Time.getInstance(localASN1Primitive);
    }
    catch (IllegalArgumentException localIllegalArgumentException)
    {
      throw new CMSException("signing-time attribute value not a valid 'Time' structure");
    }
  }
  
  public static SignerInformation replaceUnsignedAttributes(SignerInformation paramSignerInformation, AttributeTable paramAttributeTable)
  {
    SignerInfo localSignerInfo = info;
    DERSet localDERSet = null;
    if (paramAttributeTable != null) {
      localDERSet = new DERSet(paramAttributeTable.toASN1EncodableVector());
    }
    return new SignerInformation(new SignerInfo(localSignerInfo.getSID(), localSignerInfo.getDigestAlgorithm(), localSignerInfo.getAuthenticatedAttributes(), localSignerInfo.getDigestEncryptionAlgorithm(), localSignerInfo.getEncryptedDigest(), localDERSet), contentType, content, null);
  }
  
  public static SignerInformation addCounterSigners(SignerInformation paramSignerInformation, SignerInformationStore paramSignerInformationStore)
  {
    SignerInfo localSignerInfo = info;
    AttributeTable localAttributeTable = paramSignerInformation.getUnsignedAttributes();
    ASN1EncodableVector localASN1EncodableVector1;
    if (localAttributeTable != null) {
      localASN1EncodableVector1 = localAttributeTable.toASN1EncodableVector();
    } else {
      localASN1EncodableVector1 = new ASN1EncodableVector();
    }
    ASN1EncodableVector localASN1EncodableVector2 = new ASN1EncodableVector();
    Iterator localIterator = paramSignerInformationStore.getSigners().iterator();
    while (localIterator.hasNext()) {
      localASN1EncodableVector2.add(((SignerInformation)localIterator.next()).toSignerInfo());
    }
    localASN1EncodableVector1.add(new Attribute(CMSAttributes.counterSignature, new DERSet(localASN1EncodableVector2)));
    return new SignerInformation(new SignerInfo(localSignerInfo.getSID(), localSignerInfo.getDigestAlgorithm(), localSignerInfo.getAuthenticatedAttributes(), localSignerInfo.getDigestEncryptionAlgorithm(), localSignerInfo.getEncryptedDigest(), new DERSet(localASN1EncodableVector1)), contentType, content, null);
  }
}

/* Location:
 * Qualified Name:     org.bouncycastle.cms.SignerInformation
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.bouncycastle.cms;

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

public class SignerInformationStore
{
  private ArrayList all = new ArrayList();
  private Map table = new HashMap();
  
  public SignerInformationStore(Collection paramCollection)
  {
    Iterator localIterator = paramCollection.iterator();
    while (localIterator.hasNext())
    {
      SignerInformation localSignerInformation = (SignerInformation)localIterator.next();
      SignerId localSignerId = localSignerInformation.getSID();
      ArrayList localArrayList = (ArrayList)table.get(localSignerId);
      if (localArrayList == null)
      {
        localArrayList = new ArrayList(1);
        table.put(localSignerId, localArrayList);
      }
      localArrayList.add(localSignerInformation);
    }
    all = new ArrayList(paramCollection);
  }
  
  public SignerInformation get(SignerId paramSignerId)
  {
    Collection localCollection = getSigners(paramSignerId);
    return localCollection.size() == 0 ? null : (SignerInformation)localCollection.iterator().next();
  }
  
  public int size()
  {
    return all.size();
  }
  
  public Collection getSigners()
  {
    return new ArrayList(all);
  }
  
  public Collection getSigners(SignerId paramSignerId)
  {
    if ((paramSignerId.getIssuer() != null) && (paramSignerId.getSubjectKeyIdentifier() != null))
    {
      localArrayList = new ArrayList();
      Collection localCollection1 = getSigners(new SignerId(paramSignerId.getIssuer(), paramSignerId.getSerialNumber()));
      if (localCollection1 != null) {
        localArrayList.addAll(localCollection1);
      }
      Collection localCollection2 = getSigners(new SignerId(paramSignerId.getSubjectKeyIdentifier()));
      if (localCollection2 != null) {
        localArrayList.addAll(localCollection2);
      }
      return localArrayList;
    }
    ArrayList localArrayList = (ArrayList)table.get(paramSignerId);
    return localArrayList == null ? new ArrayList() : new ArrayList(localArrayList);
  }
}

/* Location:
 * Qualified Name:     org.bouncycastle.cms.SignerInformationStore
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.bouncycastle.cms;

import org.bouncycastle.asn1.x509.AlgorithmIdentifier;
import org.bouncycastle.cert.X509CertificateHolder;
import org.bouncycastle.operator.ContentVerifier;
import org.bouncycastle.operator.ContentVerifierProvider;
import org.bouncycastle.operator.DigestCalculator;
import org.bouncycastle.operator.DigestCalculatorProvider;
import org.bouncycastle.operator.OperatorCreationException;
import org.bouncycastle.operator.SignatureAlgorithmIdentifierFinder;

public class SignerInformationVerifier
{
  private ContentVerifierProvider verifierProvider;
  private DigestCalculatorProvider digestProvider;
  private SignatureAlgorithmIdentifierFinder sigAlgorithmFinder;
  private CMSSignatureAlgorithmNameGenerator sigNameGenerator;
  
  public SignerInformationVerifier(CMSSignatureAlgorithmNameGenerator paramCMSSignatureAlgorithmNameGenerator, SignatureAlgorithmIdentifierFinder paramSignatureAlgorithmIdentifierFinder, ContentVerifierProvider paramContentVerifierProvider, DigestCalculatorProvider paramDigestCalculatorProvider)
  {
    sigNameGenerator = paramCMSSignatureAlgorithmNameGenerator;
    sigAlgorithmFinder = paramSignatureAlgorithmIdentifierFinder;
    verifierProvider = paramContentVerifierProvider;
    digestProvider = paramDigestCalculatorProvider;
  }
  
  public boolean hasAssociatedCertificate()
  {
    return verifierProvider.hasAssociatedCertificate();
  }
  
  public X509CertificateHolder getAssociatedCertificate()
  {
    return verifierProvider.getAssociatedCertificate();
  }
  
  public ContentVerifier getContentVerifier(AlgorithmIdentifier paramAlgorithmIdentifier1, AlgorithmIdentifier paramAlgorithmIdentifier2)
    throws OperatorCreationException
  {
    String str = sigNameGenerator.getSignatureName(paramAlgorithmIdentifier2, paramAlgorithmIdentifier1);
    return verifierProvider.get(sigAlgorithmFinder.find(str));
  }
  
  public DigestCalculator getDigestCalculator(AlgorithmIdentifier paramAlgorithmIdentifier)
    throws OperatorCreationException
  {
    return digestProvider.get(paramAlgorithmIdentifier);
  }
}

/* Location:
 * Qualified Name:     org.bouncycastle.cms.SignerInformationVerifier
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.bouncycastle.cms;

import java.util.Map;
import org.bouncycastle.asn1.cms.AttributeTable;

public class SimpleAttributeTableGenerator
  implements CMSAttributeTableGenerator
{
  private final AttributeTable attributes;
  
  public SimpleAttributeTableGenerator(AttributeTable paramAttributeTable)
  {
    attributes = paramAttributeTable;
  }
  
  public AttributeTable getAttributes(Map paramMap)
  {
    return attributes;
  }
}

/* Location:
 * Qualified Name:     org.bouncycastle.cms.SimpleAttributeTableGenerator
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.bouncycastle.cms.bc;

import org.bouncycastle.asn1.cms.IssuerAndSerialNumber;
import org.bouncycastle.cert.X509CertificateHolder;
import org.bouncycastle.cms.KeyTransRecipientInfoGenerator;
import org.bouncycastle.operator.bc.BcAsymmetricKeyWrapper;

public abstract class BcKeyTransRecipientInfoGenerator
  extends KeyTransRecipientInfoGenerator
{
  public BcKeyTransRecipientInfoGenerator(X509CertificateHolder paramX509CertificateHolder, BcAsymmetricKeyWrapper paramBcAsymmetricKeyWrapper)
  {
    super(new IssuerAndSerialNumber(paramX509CertificateHolder.toASN1Structure()), paramBcAsymmetricKeyWrapper);
  }
  
  public BcKeyTransRecipientInfoGenerator(byte[] paramArrayOfByte, BcAsymmetricKeyWrapper paramBcAsymmetricKeyWrapper)
  {
    super(paramArrayOfByte, paramBcAsymmetricKeyWrapper);
  }
}

/* Location:
 * Qualified Name:     org.bouncycastle.cms.bc.BcKeyTransRecipientInfoGenerator
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.bouncycastle.cms.bc;

import java.io.IOException;
import org.bouncycastle.asn1.x509.AlgorithmIdentifier;
import org.bouncycastle.asn1.x509.SubjectPublicKeyInfo;
import org.bouncycastle.cert.X509CertificateHolder;
import org.bouncycastle.crypto.params.AsymmetricKeyParameter;
import org.bouncycastle.opera
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31

Further reading...

For more information on Java 1.5 Tiger, you may find Java 1.5 Tiger, A developer's Notebook by D. Flanagan and B. McLaughlin from O'Reilly of interest.

New!JAR listings


Copyright 2006-2019. Infinite Loop Ltd