bcpkix-jdk15on-147

ovider1, paramProvider2);
  }
  
  public OutputStream open(OutputStream paramOutputStream)
    throws IOException
  {
    return open(paramOutputStream, false);
  }
  
  public OutputStream open(OutputStream paramOutputStream, boolean paramBoolean)
    throws IOException
  {
    return open(CMSObjectIdentifiers.data, paramOutputStream, paramBoolean);
  }
  
  public OutputStream open(OutputStream paramOutputStream1, boolean paramBoolean, OutputStream paramOutputStream2)
    throws IOException
  {
    return open(CMSObjectIdentifiers.data, paramOutputStream1, paramBoolean, paramOutputStream2);
  }
  
  /**
   * @deprecated
   */
  public OutputStream open(OutputStream paramOutputStream, String paramString, boolean paramBoolean)
    throws IOException
  {
    return open(paramOutputStream, paramString, paramBoolean, null);
  }
  
  public OutputStream open(ASN1ObjectIdentifier paramASN1ObjectIdentifier, OutputStream paramOutputStream, boolean paramBoolean)
    throws IOException
  {
    return open(paramASN1ObjectIdentifier, paramOutputStream, paramBoolean, null);
  }
  
  /**
   * @deprecated
   */
  public OutputStream open(OutputStream paramOutputStream1, String paramString, boolean paramBoolean, OutputStream paramOutputStream2)
    throws IOException
  {
    return open(new ASN1ObjectIdentifier(paramString), paramOutputStream1, paramBoolean, paramOutputStream2);
  }
  
  public OutputStream open(ASN1ObjectIdentifier paramASN1ObjectIdentifier, OutputStream paramOutputStream1, boolean paramBoolean, OutputStream paramOutputStream2)
    throws IOException
  {
    BERSequenceGenerator localBERSequenceGenerator1 = new BERSequenceGenerator(paramOutputStream1);
    localBERSequenceGenerator1.addObject(CMSObjectIdentifiers.signedData);
    BERSequenceGenerator localBERSequenceGenerator2 = new BERSequenceGenerator(localBERSequenceGenerator1.getRawOutputStream(), 0, true);
    localBERSequenceGenerator2.addObject(calculateVersion(paramASN1ObjectIdentifier));
    ASN1EncodableVector localASN1EncodableVector = new ASN1EncodableVector();
    Object localObject1 = _signers.iterator();
    while (((Iterator)localObject1).hasNext())
    {
      localObject2 = (SignerInformation)((Iterator)localObject1).next();
      localASN1EncodableVector.add(CMSSignedHelper.INSTANCE.fixAlgID(((SignerInformation)localObject2).getDigestAlgorithmID()));
    }
    localObject1 = signerGens.iterator();
    while (((Iterator)localObject1).hasNext())
    {
      localObject2 = (SignerInfoGenerator)((Iterator)localObject1).next();
      localASN1EncodableVector.add(((SignerInfoGenerator)localObject2).getDigestAlgorithm());
    }
    localBERSequenceGenerator2.getRawOutputStream().write(new DERSet(localASN1EncodableVector).getEncoded());
    localObject1 = new BERSequenceGenerator(localBERSequenceGenerator2.getRawOutputStream());
    ((BERSequenceGenerator)localObject1).addObject(paramASN1ObjectIdentifier);
    Object localObject2 = paramBoolean ? CMSUtils.createBEROctetOutputStream(((BERSequenceGenerator)localObject1).getRawOutputStream(), 0, true, _bufferSize) : null;
    OutputStream localOutputStream1 = CMSUtils.getSafeTeeOutputStream(paramOutputStream2, (OutputStream)localObject2);
    OutputStream localOutputStream2 = CMSUtils.attachSignersToOutputStream(signerGens, localOutputStream1);
    return new CmsSignedDataOutputStream(localOutputStream2, paramASN1ObjectIdentifier, localBERSequenceGenerator1, localBERSequenceGenerator2, (BERSequenceGenerator)localObject1);
  }
  
  void generate(OutputStream paramOutputStream1, String paramString, boolean paramBoolean, OutputStream paramOutputStream2, CMSProcessable paramCMSProcessable)
    throws CMSException, IOException
  {
    OutputStream localOutputStream = open(paramOutputStream1, paramString, paramBoolean, paramOutputStream2);
    if (paramCMSProcessable != null) {
      paramCMSProcessable.write(localOutputStream);
    }
    localOutputStream.close();
  }
  
  private DERInteger calculateVersion(ASN1ObjectIdentifier paramASN1ObjectIdentifier)
  {
    int i = 0;
    int j = 0;
    int k = 0;
    int m = 0;
    Iterator localIterator;
    Object localObject;
    if (certs != null)
    {
      localIterator = certs.iterator();
      while (localIterator.hasNext())
      {
        localObject = localIterator.next();
        if ((localObject instanceof ASN1TaggedObject))
        {
          ASN1TaggedObject localASN1TaggedObject = (ASN1TaggedObject)localObject;
          if (localASN1TaggedObject.getTagNo() == 1) {
            k = 1;
          } else if (localASN1TaggedObject.getTagNo() == 2) {
            m = 1;
          } else if (localASN1TaggedObject.getTagNo() == 3) {
            i = 1;
          }
        }
      }
    }
    if (i != 0) {
      return new DERInteger(5);
    }
    if (crls != null)
    {
      localIterator = crls.iterator();
      while (localIterator.hasNext())
      {
        localObject = localIterator.next();
        if ((localObject instanceof ASN1TaggedObject)) {
          j = 1;
        }
      }
    }
    if (j != 0) {
      return new DERInteger(5);
    }
    if (m != 0) {
      return new DERInteger(4);
    }
    if (k != 0) {
      return new DERInteger(3);
    }
    if (checkForVersion3(_signers)) {
      return new DERInteger(3);
    }
    if (!CMSObjectIdentifiers.data.equals(paramASN1ObjectIdentifier)) {
      return new DERInteger(3);
    }
    return new DERInteger(1);
  }
  
  private boolean checkForVersion3(List paramList)
  {
    Iterator localIterator = paramList.iterator();
    while (localIterator.hasNext())
    {
      SignerInfo localSignerInfo = SignerInfo.getInstance(((SignerInformation)localIterator.next()).toASN1Structure());
      if (localSignerInfo.getVersion().getValue().intValue() == 3) {
        return true;
      }
    }
    return false;
  }
  
  private class CmsSignedDataOutputStream
    extends OutputStream
  {
    private OutputStream _out;
    private ASN1ObjectIdentifier _contentOID;
    private BERSequenceGenerator _sGen;
    private BERSequenceGenerator _sigGen;
    private BERSequenceGenerator _eiGen;
    
    public CmsSignedDataOutputStream(OutputStream paramOutputStream, ASN1ObjectIdentifier paramASN1ObjectIdentifier, BERSequenceGenerator paramBERSequenceGenerator1, BERSequenceGenerator paramBERSequenceGenerator2, BERSequenceGenerator paramBERSequenceGenerator3)
    {
      _out = paramOutputStream;
      _contentOID = paramASN1ObjectIdentifier;
      _sGen = paramBERSequenceGenerator1;
      _sigGen = paramBERSequenceGenerator2;
      _eiGen = paramBERSequenceGenerator3;
    }
    
    public void write(int paramInt)
      throws IOException
    {
      _out.write(paramInt);
    }
    
    public void write(byte[] paramArrayOfByte, int paramInt1, int paramInt2)
      throws IOException
    {
      _out.write(paramArrayOfByte, paramInt1, paramInt2);
    }
    
    public void write(byte[] paramArrayOfByte)
      throws IOException
    {
      _out.write(paramArrayOfByte);
    }
    
    public void close()
      throws IOException
    {
      _out.close();
      _eiGen.close();
      digests.clear();
      if (certs.size() != 0)
      {
        localObject1 = CMSUtils.createBerSetFromList(certs);
        _sigGen.getRawOutputStream().write(new BERTaggedObject(false, 0, (ASN1Encodable)localObject1).getEncoded());
      }
      if (crls.size() != 0)
      {
        localObject1 = CMSUtils.createBerSetFromList(crls);
        _sigGen.getRawOutputStream().write(new BERTaggedObject(false, 1, (ASN1Encodable)localObject1).getEncoded());
      }
      Object localObject1 = new ASN1EncodableVector();
      Iterator localIterator = signerGens.iterator();
      Object localObject2;
      while (localIterator.hasNext())
      {
        localObject2 = (SignerInfoGenerator)localIterator.next();
        try
        {
          ((ASN1EncodableVector)localObject1).add(((SignerInfoGenerator)localObject2).generate(_contentOID));
          byte[] arrayOfByte = ((SignerInfoGenerator)localObject2).getCalculatedDigest();
          digests.put(((SignerInfoGenerator)localObject2).getDigestAlgorithm().getAlgorithm().getId(), arrayOfByte);
        }
        catch (CMSException localCMSException)
        {
          throw new CMSStreamException("exception generating signers: " + localCMSException.getMessage(), localCMSException);
        }
      }
      localIterator = _signers.iterator();
      while (localIterator.hasNext())
      {
        localObject2 = (SignerInformation)localIterator.next();
        ((ASN1EncodableVector)localObject1).add(((SignerInformation)localObject2).toASN1Structure());
      }
      _sigGen.getRawOutputStream().write(new DERSet((ASN1EncodableVector)localObject1).getEncoded());
      _sigGen.close();
      _sGen.close();
    }
  }
}

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

import java.io.IOException;
import java.security.PrivateKey;
import java.security.SecureRandom;
import java.security.cert.CertStore;
import java.security.cert.CertStoreException;
import java.security.interfaces.DSAPrivateKey;
import java.security.interfaces.RSAPrivateKey;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.bouncycastle.asn1.ASN1ObjectIdentifier;
import org.bouncycastle.asn1.ASN1Primitive;
import org.bouncycastle.asn1.ASN1Set;
import org.bouncycastle.asn1.DERObjectIdentifier;
import org.bouncycastle.asn1.DERSet;
import org.bouncycastle.asn1.DERTaggedObject;
import org.bouncycastle.asn1.cms.AttributeTable;
import org.bouncycastle.asn1.cms.CMSObjectIdentifiers;
import org.bouncycastle.asn1.cryptopro.CryptoProObjectIdentifiers;
import org.bouncycastle.asn1.nist.NISTObjectIdentifiers;
import org.bouncycastle.asn1.oiw.OIWObjectIdentifiers;
import org.bouncycastle.asn1.pkcs.PKCSObjectIdentifiers;
import org.bouncycastle.asn1.teletrust.TeleTrusTObjectIdentifiers;
import org.bouncycastle.asn1.x509.AlgorithmIdentifier;
import org.bouncycastle.asn1.x509.AttributeCertificate;
import org.bouncycastle.asn1.x9.X9ObjectIdentifiers;
import org.bouncycastle.jce.interfaces.GOST3410PrivateKey;
import org.bouncycastle.util.Store;
import org.bouncycastle.x509.X509AttributeCertificate;
import org.bouncycastle.x509.X509Store;

public class CMSSignedGenerator
{
  public static final String DATA = CMSObjectIdentifiers.data.getId();
  public static final String DIGEST_SHA1 = OIWObjectIdentifiers.idSHA1.getId();
  public static final String DIGEST_SHA224 = NISTObjectIdentifiers.id_sha224.getId();
  public static final String DIGEST_SHA256 = NISTObjectIdentifiers.id_sha256.getId();
  public static final String DIGEST_SHA384 = NISTObjectIdentifiers.id_sha384.getId();
  public static final String DIGEST_SHA512 = NISTObjectIdentifiers.id_sha512.getId();
  public static final String DIGEST_MD5 = PKCSObjectIdentifiers.md5.getId();
  public static final String DIGEST_GOST3411 = CryptoProObjectIdentifiers.gostR3411.getId();
  public static final String DIGEST_RIPEMD128 = TeleTrusTObjectIdentifiers.ripemd128.getId();
  public static final String DIGEST_RIPEMD160 = TeleTrusTObjectIdentifiers.ripemd160.getId();
  public static final String DIGEST_RIPEMD256 = TeleTrusTObjectIdentifiers.ripemd256.getId();
  public static final String ENCRYPTION_RSA = PKCSObjectIdentifiers.rsaEncryption.getId();
  public static final String ENCRYPTION_DSA = X9ObjectIdentifiers.id_dsa_with_sha1.getId();
  public static final String ENCRYPTION_ECDSA = X9ObjectIdentifiers.ecdsa_with_SHA1.getId();
  public static final String ENCRYPTION_RSA_PSS = PKCSObjectIdentifiers.id_RSASSA_PSS.getId();
  public static final String ENCRYPTION_GOST3410 = CryptoProObjectIdentifiers.gostR3410_94.getId();
  public static final String ENCRYPTION_ECGOST3410 = CryptoProObjectIdentifiers.gostR3410_2001.getId();
  private static final String ENCRYPTION_ECDSA_WITH_SHA1 = X9ObjectIdentifiers.ecdsa_with_SHA1.getId();
  private static final String ENCRYPTION_ECDSA_WITH_SHA224 = X9ObjectIdentifiers.ecdsa_with_SHA224.getId();
  private static final String ENCRYPTION_ECDSA_WITH_SHA256 = X9ObjectIdentifiers.ecdsa_with_SHA256.getId();
  private static final String ENCRYPTION_ECDSA_WITH_SHA384 = X9ObjectIdentifiers.ecdsa_with_SHA384.getId();
  private static final String ENCRYPTION_ECDSA_WITH_SHA512 = X9ObjectIdentifiers.ecdsa_with_SHA512.getId();
  private static final Set NO_PARAMS = new HashSet();
  private static final Map EC_ALGORITHMS = new HashMap();
  protected List certs = new ArrayList();
  protected List crls = new ArrayList();
  protected List _signers = new ArrayList();
  protected List signerGens = new ArrayList();
  protected Map digests = new HashMap();
  protected final SecureRandom rand;
  
  protected CMSSignedGenerator()
  {
    this(new SecureRandom());
  }
  
  protected CMSSignedGenerator(SecureRandom paramSecureRandom)
  {
    rand = paramSecureRandom;
  }
  
  protected String getEncOID(PrivateKey paramPrivateKey, String paramString)
  {
    String str = null;
    if (((paramPrivateKey instanceof RSAPrivateKey)) || ("RSA".equalsIgnoreCase(paramPrivateKey.getAlgorithm())))
    {
      str = ENCRYPTION_RSA;
    }
    else if (((paramPrivateKey instanceof DSAPrivateKey)) || ("DSA".equalsIgnoreCase(paramPrivateKey.getAlgorithm())))
    {
      str = ENCRYPTION_DSA;
      if (!paramString.equals(DIGEST_SHA1)) {
        throw new IllegalArgumentException("can't mix DSA with anything but SHA1");
      }
    }
    else if (("ECDSA".equalsIgnoreCase(paramPrivateKey.getAlgorithm())) || ("EC".equalsIgnoreCase(paramPrivateKey.getAlgorithm())))
    {
      str = (String)EC_ALGORITHMS.get(paramString);
      if (str == null) {
        throw new IllegalArgumentException("can't mix ECDSA with anything but SHA family digests");
      }
    }
    else if (((paramPrivateKey instanceof GOST3410PrivateKey)) || ("GOST3410".equalsIgnoreCase(paramPrivateKey.getAlgorithm())))
    {
      str = ENCRYPTION_GOST3410;
    }
    else if ("ECGOST3410".equalsIgnoreCase(paramPrivateKey.getAlgorithm()))
    {
      str = ENCRYPTION_ECGOST3410;
    }
    return str;
  }
  
  protected Map getBaseParameters(DERObjectIdentifier paramDERObjectIdentifier, AlgorithmIdentifier paramAlgorithmIdentifier, byte[] paramArrayOfByte)
  {
    HashMap localHashMap = new HashMap();
    localHashMap.put("contentType", paramDERObjectIdentifier);
    localHashMap.put("digestAlgID", paramAlgorithmIdentifier);
    localHashMap.put("digest", paramArrayOfByte.clone());
    return localHashMap;
  }
  
  protected ASN1Set getAttributeSet(AttributeTable paramAttributeTable)
  {
    if (paramAttributeTable != null) {
      return new DERSet(paramAttributeTable.toASN1EncodableVector());
    }
    return null;
  }
  
  /**
   * @deprecated
   */
  public void addCertificatesAndCRLs(CertStore paramCertStore)
    throws CertStoreException, CMSException
  {
    certs.addAll(CMSUtils.getCertificatesFromStore(paramCertStore));
    crls.addAll(CMSUtils.getCRLsFromStore(paramCertStore));
  }
  
  public void addCertificates(Store paramStore)
    throws CMSException
  {
    certs.addAll(CMSUtils.getCertificatesFromStore(paramStore));
  }
  
  public void addCRLs(Store paramStore)
    throws CMSException
  {
    crls.addAll(CMSUtils.getCRLsFromStore(paramStore));
  }
  
  public void addAttributeCertificates(Store paramStore)
    throws CMSException
  {
    certs.addAll(CMSUtils.getAttributeCertificatesFromStore(paramStore));
  }
  
  /**
   * @deprecated
   */
  public void addAttributeCertificates(X509Store paramX509Store)
    throws CMSException
  {
    try
    {
      Iterator localIterator = paramX509Store.getMatches(null).iterator();
      while (localIterator.hasNext())
      {
        X509AttributeCertificate localX509AttributeCertificate = (X509AttributeCertificate)localIterator.next();
        certs.add(new DERTaggedObject(false, 2, AttributeCertificate.getInstance(ASN1Primitive.fromByteArray(localX509AttributeCertificate.getEncoded()))));
      }
    }
    catch (IllegalArgumentException localIllegalArgumentException)
    {
      throw new CMSException("error processing attribute certs", localIllegalArgumentException);
    }
    catch (IOException localIOException)
    {
      throw new CMSException("error processing attribute certs", localIOException);
    }
  }
  
  public void addSigners(SignerInformationStore paramSignerInformationStore)
  {
    Iterator localIterator = paramSignerInformationStore.getSigners().iterator();
    while (localIterator.hasNext()) {
      _signers.add(localIterator.next());
    }
  }
  
  public void addSignerInfoGenerator(SignerInfoGenerator paramSignerInfoGenerator)
  {
    signerGens.add(paramSignerInfoGenerator);
  }
  
  public Map getGeneratedDigests()
  {
    return new HashMap(digests);
  }
  
  static
  {
    NO_PARAMS.add(ENCRYPTION_DSA);
    NO_PARAMS.add(ENCRYPTION_ECDSA);
    NO_PARAMS.add(ENCRYPTION_ECDSA_WITH_SHA1);
    NO_PARAMS.add(ENCRYPTION_ECDSA_WITH_SHA224);
    NO_PARAMS.add(ENCRYPTION_ECDSA_WITH_SHA256);
    NO_PARAMS.add(ENCRYPTION_ECDSA_WITH_SHA384);
    NO_PARAMS.add(ENCRYPTION_ECDSA_WITH_SHA512);
    EC_ALGORITHMS.put(DIGEST_SHA1, ENCRYPTION_ECDSA_WITH_SHA1);
    EC_ALGORITHMS.put(DIGEST_SHA224, ENCRYPTION_ECDSA_WITH_SHA224);
    EC_ALGORITHMS.put(DIGEST_SHA256, ENCRYPTION_ECDSA_WITH_SHA256);
    EC_ALGORITHMS.put(DIGEST_SHA384, ENCRYPTION_ECDSA_WITH_SHA384);
    EC_ALGORITHMS.put(DIGEST_SHA512, ENCRYPTION_ECDSA_WITH_SHA512);
  }
}

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

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.security.InvalidAlgorithmParameterException;
import java.security.NoSuchAlgorithmException;
import java.security.Provider;
import java.security.cert.CRLException;
import java.security.cert.CertStore;
import java.security.cert.CertificateException;
import java.security.cert.CertificateFactory;
import java.security.cert.CollectionCertStoreParameters;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.bouncycastle.asn1.ASN1Encodable;
import org.bouncycastle.asn1.ASN1ObjectIdentifier;
import org.bouncycastle.asn1.ASN1Primitive;
import org.bouncycastle.asn1.ASN1Sequence;
import org.bouncycastle.asn1.ASN1Set;
import org.bouncycastle.asn1.ASN1TaggedObject;
import org.bouncycastle.asn1.DERNull;
import org.bouncycastle.asn1.DERObjectIdentifier;
import org.bouncycastle.asn1.cryptopro.CryptoProObjectIdentifiers;
import org.bouncycastle.asn1.eac.EACObjectIdentifiers;
import org.bouncycastle.asn1.nist.NISTObjectIdentifiers;
import org.bouncycastle.asn1.oiw.OIWObjectIdentifiers;
import org.bouncycastle.asn1.pkcs.PKCSObjectIdentifiers;
import org.bouncycastle.asn1.teletrust.TeleTrusTObjectIdentifiers;
import org.bouncycastle.asn1.x509.AlgorithmIdentifier;
import org.bouncycastle.asn1.x509.X509ObjectIdentifiers;
import org.bouncycastle.asn1.x9.X9ObjectIdentifiers;
import org.bouncycastle.x509.NoSuchStoreException;
import org.bouncycastle.x509.X509CollectionStoreParameters;
import org.bouncycastle.x509.X509Store;
import org.bouncycastle.x509.X509V2AttributeCertificate;

class CMSSignedHelper
{
  static final CMSSignedHelper INSTANCE = new CMSSignedHelper();
  private static final Map encryptionAlgs = new HashMap();
  private static final Map digestAlgs = new HashMap();
  private static final Map digestAliases = new HashMap();
  
  private static void addEntries(DERObjectIdentifier paramDERObjectIdentifier, String paramString1, String paramString2)
  {
    digestAlgs.put(paramDERObjectIdentifier.getId(), paramString1);
    encryptionAlgs.put(paramDERObjectIdentifier.getId(), paramString2);
  }
  
  String getDigestAlgName(String paramString)
  {
    String str = (String)digestAlgs.get(paramString);
    if (str != null) {
      return str;
    }
    return paramString;
  }
  
  String getEncryptionAlgName(String paramString)
  {
    String str = (String)encryptionAlgs.get(paramString);
    if (str != null) {
      return str;
    }
    return paramString;
  }
  
  X509Store createAttributeStore(String paramString, Provider paramProvider, ASN1Set paramASN1Set)
    throws NoSuchStoreException, CMSException
  {
    ArrayList localArrayList = new ArrayList();
    if (paramASN1Set != null)
    {
      Enumeration localEnumeration = paramASN1Set.getObjects();
      while (localEnumeration.hasMoreElements()) {
        try
        {
          ASN1Primitive localASN1Primitive = ((ASN1Encodable)localEnumeration.nextElement()).toASN1Primitive();
          if ((localASN1Primitive instanceof ASN1TaggedObject))
          {
            ASN1TaggedObject localASN1TaggedObject = (ASN1TaggedObject)localASN1Primitive;
            if (localASN1TaggedObject.getTagNo() == 2) {
              localArrayList.add(new X509V2AttributeCertificate(ASN1Sequence.getInstance(localASN1TaggedObject, false).getEncoded()));
            }
          }
        }
        catch (IOException localIOException)
        {
          throw new CMSException("can't re-encode attribute certificate!", localIOException);
        }
      }
    }
    try
    {
      return X509Store.getInstance("AttributeCertificate/" + paramString, new X509CollectionStoreParameters(localArrayList), paramProvider);
    }
    catch (IllegalArgumentException localIllegalArgumentException)
    {
      throw new CMSException("can't setup the X509Store", localIllegalArgumentException);
    }
  }
  
  X509Store createCertificateStore(String paramString, Provider paramProvider, ASN1Set paramASN1Set)
    throws NoSuchStoreException, CMSException
  {
    ArrayList localArrayList = new ArrayList();
    if (paramASN1Set != null) {
      addCertsFromSet(localArrayList, paramASN1Set, paramProvider);
    }
    try
    {
      return X509Store.getInstance("Certificate/" + paramString, new X509CollectionStoreParameters(localArrayList), paramProvider);
    }
    catch (IllegalArgumentException localIllegalArgumentException)
    {
      throw new CMSException("can't setup the X509Store", localIllegalArgumentException);
    }
  }
  
  X509Store createCRLsStore(String paramString, Provider paramProvider, ASN1Set paramASN1Set)
    throws NoSuchStoreException, CMSException
  {
    ArrayList localArrayList = new ArrayList();
    if (paramASN1Set != null) {
      addCRLsFromSet(localArrayList, paramASN1Set, paramProvider);
    }
    try
    {
      return X509Store.getInstance("CRL/" + paramString, new X509CollectionStoreParameters(localArrayList), paramProvider);
    }
    catch (IllegalArgumentException localIllegalArgumentException)
    {
      throw new CMSException("can't setup the X509Store", localIllegalArgumentException);
    }
  }
  
  CertStore createCertStore(String paramString, Provider paramProvider, ASN1Set paramASN1Set1, ASN1Set paramASN1Set2)
    throws CMSException, NoSuchAlgorithmException
  {
    ArrayList localArrayList = new ArrayList();
    if (paramASN1Set1 != null) {
      addCertsFromSet(localArrayList, paramASN1Set1, paramProvider);
    }
    if (paramASN1Set2 != null) {
      addCRLsFromSet(localArrayList, paramASN1Set2, paramProvider);
    }
    try
    {
      if (paramProvider != null) {
        return CertStore.getInstance(paramString, new CollectionCertStoreParameters(localArrayList), paramProvider);
      }
      return CertStore.getInstance(paramString, new CollectionCertStoreParameters(localArrayList));
    }
    catch (InvalidAlgorithmParameterException localInvalidAlgorithmParameterException)
    {
      throw new CMSException("can't setup the CertStore", localInvalidAlgorithmParameterException);
    }
  }
  
  private void addCertsFromSet(List paramList, ASN1Set paramASN1Set, Provider paramProvider)
    throws CMSException
  {
    CertificateFactory localCertificateFactory;
    try
    {
      if (paramProvider != null) {
        localCertificateFactory = CertificateFactory.getInstance("X.509", paramProvider);
      } else {
        localCertificateFactory = CertificateFactory.getInstance("X.509");
      }
    }
    catch (CertificateException localCertificateException1)
    {
      throw new CMSException("can't get certificate factory.", localCertificateException1);
    }
    Enumeration localEnumeration = paramASN1Set.getObjects();
    while (localEnumeration.hasMoreElements()) {
      try
      {
        ASN1Primitive localASN1Primitive = ((ASN1Encodable)localEnumeration.nextElement()).toASN1Primitive();
        if ((localASN1Primitive instanceof ASN1Sequence)) {
          paramList.add(localCertificateFactory.generateCertificate(new ByteArrayInputStream(localASN1Primitive.getEncoded())));
        }
      }
      catch (IOException localIOException)
      {
        throw new CMSException("can't re-encode certificate!", localIOException);
      }
      catch (CertificateException localCertificateException2)
      {
        throw new CMSException("can't re-encode certificate!", localCertificateException2);
      }
    }
  }
  
  private void addCRLsFromSet(List paramList, ASN1Set paramASN1Set, Provider paramProvider)
    throws CMSException
  {
    CertificateFactory localCertificateFactory;
    try
    {
      if (paramProvider != null) {
        localCertificateFactory = CertificateFactory.getInstance("X.509", paramProvider);
      } else {
        localCertificateFactory = CertificateFactory.getInstance("X.509");
      }
    }
    catch (CertificateException localCertificateException)
    {
      throw new CMSException("can't get certificate factory.", localCertificateException);
    }
    Enumeration localEnumeration = paramASN1Set.getObjects();
    while (localEnumeration.hasMoreElements()) {
      try
      {
        ASN1Primitive localASN1Primitive = ((ASN1Encodable)localEnumeration.nextElement()).toASN1Primitive();
        paramList.add(localCertificateFactory.generateCRL(new ByteArrayInputStream(localASN1Primitive.getEncoded())));
      }
      catch (IOException localIOException)
      {
        throw new CMSException("can't re-encode CRL!", localIOException);
      }
      catch (CRLException localCRLException)
      {
        throw new CMSException("can't re-encode CRL!", localCRLException);
      }
    }
  }
  
  AlgorithmIdentifier fixAlgID(AlgorithmIdentifier paramAlgorithmIdentifier)
  {
    if (paramAlgorithmIdentifier.getParameters() == null) {
      return new AlgorithmIdentifier(paramAlgorithmIdentifier.getObjectId(), DERNull.INSTANCE);
    }
    return paramAlgorithmIdentifier;
  }
  
  void setSigningEncryptionAlgorithmMapping(DERObjectIdentifier paramDERObjectIdentifier, String paramString)
  {
    encryptionAlgs.put(paramDERObjectIdentifier.getId(), paramString);
  }
  
  void setSigningDigestAlgorithmMapping(DERObjectIdentifier paramDERObjectIdentifier, String paramString)
  {
    digestAlgs.put(paramDERObjectIdentifier.getId(), paramString);
  }
  
  static
  {
    addEntries(NISTObjectIdentifiers.dsa_with_sha224, "SHA224", "DSA");
    addEntries(NISTObjectIdentifiers.dsa_with_sha256, "SHA256", "DSA");
    addEntries(NISTObjectIdentifiers.dsa_with_sha384, "SHA384", "DSA");
    addEntries(NISTObjectIdentifiers.dsa_with_sha512, "SHA512", "DSA");
    addEntries(OIWObjectIdentifiers.dsaWithSHA1, "SHA1", "DSA");
    addEntries(OIWObjectIdentifiers.md4WithRSA, "MD4", "RSA");
    addEntries(OIWObjectIdentifiers.md4WithRSAEncryption, "MD4", "RSA");
    addEntries(OIWObjectIdentifiers.md5WithRSA, "MD5", "RSA");
    addEntries(OIWObjectIdentifiers.sha1WithRSA, "SHA1", "RSA");
    addEntries(PKCSObjectIdentifiers.md2WithRSAEncryption, "MD2", "RSA");
    addEntries(PKCSObjectIdentifiers.md4WithRSAEncryption, "MD4", "RSA");
    addEntries(PKCSObjectIdentifiers.md5WithRSAEncryption, "MD5", "RSA");
    addEntries(PKCSObjectIdentifiers.sha1WithRSAEncryption, "SHA1", "RSA");
    addEntries(PKCSObjectIdentifiers.sha224WithRSAEncryption, "SHA224", "RSA");
    addEntries(PKCSObjectIdentifiers.sha256WithRSAEncryption, "SHA256", "RSA");
    addEntries(PKCSObjectIdentifiers.sha384WithRSAEncryption, "SHA384", "RSA");
    addEntries(PKCSObjectIdentifiers.sha512WithRSAEncryption, "SHA512", "RSA");
    addEntries(X9ObjectIdentifiers.ecdsa_with_SHA1, "SHA1", "ECDSA");
    addEntries(X9ObjectIdentifiers.ecdsa_with_SHA224, "SHA224", "ECDSA");
    addEntries(X9ObjectIdentifiers.ecdsa_with_SHA256, "SHA256", "ECDSA");
    addEntries(X9ObjectIdentifiers.ecdsa_with_SHA384, "SHA384", "ECDSA");
    addEntries(X9ObjectIdentifiers.ecdsa_with_SHA512, "SHA512", "ECDSA");
    addEntries(X9ObjectIdentifiers.id_dsa_with_sha1, "SHA1", "DSA");
    addEntries(EACObjectIdentifiers.id_TA_ECDSA_SHA_1, "SHA1", "ECDSA");
    addEntries(EACObjectIdentifiers.id_TA_ECDSA_SHA_224, "SHA224", "ECDSA");
    addEntries(EACObjectIdentifiers.id_TA_ECDSA_SHA_256, "SHA256", "ECDSA");
    addEntries(EACObjectIdentifiers.id_TA_ECDSA_SHA_384, "SHA384", "ECDSA");
    addEntries(EACObjectIdentifiers.id_TA_ECDSA_SHA_512, "SHA512", "ECDSA");
    addEntries(EACObjectIdentifiers.id_TA_RSA_v1_5_SHA_1, "SHA1", "RSA");
    addEntries(EACObjectIdentifiers.id_TA_RSA_v1_5_SHA_256, "SHA256", "RSA");
    addEntries(EACObjectIdentifiers.id_TA_RSA_PSS_SHA_1, "SHA1", "RSAandMGF1");
    addEntries(EACObjectIdentifiers.id_TA_RSA_PSS_SHA_256, "SHA256", "RSAandMGF1");
    encryptionAlgs.put(X9ObjectIdentifiers.id_dsa.getId(), "DSA");
    encryptionAlgs.put(PKCSObjectIdentifiers.rsaEncryption.getId(), "RSA");
    encryptionAlgs.put(TeleTrusTObjectIdentifiers.teleTrusTRSAsignatureAlgorithm, "RSA");
    encryptionAlgs.put(X509ObjectIdentifiers.id_ea_rsa.getId(), "RSA");
    encryptionAlgs.put(CMSSignedDataGenerator.ENCRYPTION_RSA_PSS, "RSAandMGF1");
    encryptionAlgs.put(CryptoProObjectIdentifiers.gostR3410_94.getId(), "GOST3410");
    encryptionAlgs.put(CryptoProObjectIdentifiers.gostR3410_2001.getId(), "ECGOST3410");
    encryptionAlgs.put("1.3.6.1.4.1.5849.1.6.2", "ECGOST3410");
    encryptionAlgs.put("1.3.6.1.4.1.5849.1.1.5", "GOST3410");
    encryptionAlgs.put(CryptoProObjectIdentifiers.gostR3411_94_with_gostR3410_2001.getId(), "ECGOST3410");
    encryptionAlgs.put(CryptoProObjectIdentifiers.gostR3411_94_with_gostR3410_94.getId(), "GOST3410");
    digestAlgs.put(PKCSObjectIdentifiers.md2.getId(), "MD2");
    digestAlgs.put(PKCSObjectIdentifiers.md4.getId(), "MD4");
    digestAlgs.put(PKCSObjectIdentifiers.md5.getId(), "MD5");
    digestAlgs.put(OIWObjectIdentifiers.idSHA1.getId(), "SHA1");
    digestAlgs.put(NISTObjectIdentifiers.id_sha224.getId(), "SHA224");
    digestAlgs.put(NISTObjectIdentifiers.id_sha256.getId(), "SHA256");
    digestAlgs.put(NISTObjectIdentifiers.id_sha384.getId(), "SHA384");
    digestAlgs.put(NISTObjectIdentifiers.id_sha512.getId(), "SHA512");
    digestAlgs.put(TeleTrusTObjectIdentifiers.ripemd128.getId(), "RIPEMD128");
    digestAlgs.put(TeleTrusTObjectIdentifiers.ripemd160.getId(), "RIPEMD160");
    digestAlgs.put(TeleTrusTObjectIdentifiers.ripemd256.getId(), "RIPEMD256");
    digestAlgs.put(CryptoProObjectIdentifiers.gostR3411.getId(), "GOST3411");
    digestAlgs.put("1.3.6.1.4.1.5849.1.2.1", "GOST3411");
    digestAliases.put("SHA1", new String[] { "SHA-1" });
    digestAliases.put("SHA224", new String[] { "SHA-224" });
    digestAliases.put("SHA256", new String[] { "SHA-256" });
    digestAliases.put("SHA384", new String[] { "SHA-384" });
    digestAliases.put("SHA512", new String[] { "SHA-512" });
  }
}

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

public class CMSSignerDigestMismatchException
  extends CMSException
{
  public CMSSignerDigestMismatchException(String paramString)
  {
    super(paramString);
  }
}

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

import java.io.IOException;

public class CMSStreamException
  extends IOException
{
  private final Throwable underlying;
  
  CMSStreamException(String paramString)
  {
    super(paramString);
    underlying = null;
  }
  
  CMSStreamException(String paramString, Throwable paramThrowable)
  {
    super(paramString);
    underlying = paramThrowable;
  }
  
  public Throwable getCause()
  {
    return underlying;
  }
}

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

import org.bouncycastle.asn1.ASN1ObjectIdentifier;

public abstract interface CMSTypedData
  extends CMSProcessable
{
  public abstract ASN1ObjectIdentifier getContentType();
}

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

import java.io.FilterInputStream;
import java.io.IOException;
import java.io.InputStream;
import org.bouncycastle.util.io.Streams;

class CMSTypedStream$FullReaderStream
  extends FilterInputStream
{
  CMSTypedStream$FullReaderStream(InputStream paramInputStream)
  {
    super(paramInputStream);
  }
  
  public int read(byte[] paramArrayOfByte, int paramInt1, int paramInt2)
    throws IOException
  {
    int i = Streams.readFully(in, paramArrayOfByte, paramInt1, paramInt2);
    return i > 0 ? i : -1;
  }
}

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

import java.io.BufferedInputStream;
import java.io.FilterInputStream;
import java.io.IOException;
import java.io.InputStream;
import org.bouncycastle.asn1.ASN1ObjectIdentifier;
import org.bouncycastle.asn1.pkcs.PKCSObjectIdentifiers;
import org.bouncycastle.util.io.Streams;

public class CMSTypedStream
{
  private static final int BUF_SIZ = 32768;
  private final ASN1ObjectIdentifier _oid;
  private final InputStream _in;
  
  public CMSTypedStream(InputStream paramInputStream)
  {
    this(PKCSObjectIdentifiers.data.getId(), paramInputStream, 32768);
  }
  
  public CMSTypedStream(String paramString, InputStream paramInputStream)
  {
    this(new ASN1ObjectIdentifier(paramString), paramInputStream, 32768);
  }
  
  public CMSTypedStream(String paramString, InputStream paramInputStream, int paramInt)
  {
    this(new ASN1ObjectIdentifier(paramString), paramInputStream, paramInt);
  }
  
  public CMSTypedStream(ASN1ObjectIdentifier paramASN1ObjectIdentifier, InputStream paramInputStream)
  {
    this(paramASN1ObjectIdentifier, paramInputStream, 32768);
  }
  
  public CMSTypedStream(ASN1ObjectIdentifier paramASN1ObjectIdentifier, InputStream paramInputStream, int paramInt)
  {
    _oid = paramASN1ObjectIdentifier;
    _in = new FullReaderStream(new BufferedInputStream(paramInputStream, paramInt));
  }
  
  public ASN1ObjectIdentifier getContentType()
  {
    return _oid;
  }
  
  public InputStream getContentStream()
  {
    return _in;
  }
  
  public void drain()
    throws IOException
  {
    Streams.drain(_in);
    _in.close();
  }
  
  private static class FullReaderStream
    extends FilterInputStream
  {
    FullReaderStream(InputStream paramInputStream)
    {
      super();
    }
    
    public int read(byte[] paramArrayOfByte, int paramInt1, int paramInt2)
      throws IOException
    {
      int i = Streams.readFully(in, paramArrayOfByte, paramInt1, paramInt2);
      return i > 0 ? i : -1;
    }
  }
}

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

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.security.NoSuchProviderException;
import java.security.Provider;
import java.security.Security;
import java.security.cert.CRLException;
import java.security.cert.CertStore;
import java.security.cert.CertStoreException;
import java.security.cert.CertificateEncodingException;
import java.security.cert.X509CRL;
import java.security.cert.X509Certificate;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import org.bouncycastle.asn1.ASN1Encodable;
import org.bouncycastle.asn1.ASN1EncodableVector;
import org.bouncycastle.asn1.ASN1InputStream;
import org.bouncycastle.asn1.ASN1Integer;
import org.bouncycastle.asn1.ASN1Primitive;
import org.bouncycastle.asn1.ASN1Set;
import org.bouncycastle.asn1.BEROctetStringGenerator;
import org.bouncycastle.asn1.BERSet;
import org.bouncycastle.asn1.DERSet;
import org.bouncycastle.asn1.DERTaggedObject;
import org.bouncycastle.asn1.cms.ContentInfo;
import org.bouncycastle.asn1.cms.IssuerAndSerialNumber;
import org.bouncycastle.asn1.x509.CertificateList;
import org.bouncycastle.asn1.x509.TBSCertificateStructure;
import org.bouncycastle.asn1.x509.X509CertificateStructure;
import org.bouncycastle.cert.X509AttributeCertificateHolder;
import org.bouncycastle.cert.X509CRLHolder;
import org.bouncycastle.cert.X509CertificateHolder;
import org.bouncycastle.operator.DigestCalculator;
import org.bouncycastle.util.Store;
import org.bouncycastle.util.io.Streams;
import org.bouncycastle.util.io.TeeInputStream;
import org.bouncycastle.util.io.TeeOutputStream;

class CMSUtils
{
  static ContentInfo readContentInfo(byte[] paramArrayOfByte)
    throws CMSException
  {
    return readContentInfo(new ASN1InputStream(paramArrayOfByte));
  }
  
  static ContentInfo readContentInfo(InputStream paramInputStream)
    throws CMSException
  {
    return readContentInfo(new ASN1InputStream(paramInputStream));
  }
  
  static List getCertificatesFromStore(CertStore paramCertStore)
    throws CertStoreException, CMSException
  {
    ArrayList localArrayList = new ArrayList();
    try
    {
      Iterator localIterator = paramCertStore.getCertificates(null).iterator();
      while (localIterator.hasNext())
      {
        X509Certificate localX509Certificate = (X509Certificate)localIterator.next();
        localArrayList.add(X509CertificateStructure.getInstance(ASN1Primitive.fromByteArray(localX509Certificate.getEncoded())));
      }
      return localArrayList;
    }
    catch (IllegalArgumentException localIllegalArgumentException)
    {
      throw new CMSException("error processing certs", localIllegalArgumentException);
    }
    catch (IOException localIOException)
    {
      throw new CMSException("error processing certs", localIOException);
    }
    catch (CertificateEncodingException localCertificateEncodingException)
    {
      throw new CMSException("error encoding certs", localCertificateEncodingException);
    }
  }
  
  static List getCertificatesFromStore(Store paramStore)
    throws CMSException
  {
    ArrayList localArrayList = new ArrayList();
    try
    {
      Iterator localIterator = paramStore.getMatches(null).iterator();
      while (localIterator.hasNext())
      {
        X509CertificateHolder localX509CertificateHolder = (X509CertificateHolder)localIterator.next();
        localArrayList.add(localX509CertificateHolder.toASN1Structure());
      }
      return localArrayList;
    }
    catch (ClassCastException localClassCastException)
    {
      throw new CMSException("error processing certs", localClassCastException);
    }
  }
  
  static List getAttributeCertificatesFromStore(Store paramStore)
    throws CMSException
  {
    ArrayList localArrayList = new ArrayList();
    try
    {
      Iterator localIterator = paramStore.getMatches(null).iterator();
      while (localIterator.hasNext())
      {
        X509AttributeCertificateHolder localX509AttributeCertificateHolder = (X509AttributeCe
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