bcpkix-jdk15on-147

e:     org.bouncycastle.tsp.TimeStampTokenGenerator.2
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.bouncycastle.tsp;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.math.BigInteger;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.security.NoSuchProviderException;
import java.security.PrivateKey;
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.security.interfaces.DSAPrivateKey;
import java.security.interfaces.RSAPrivateKey;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import org.bouncycastle.asn1.ASN1Boolean;
import org.bouncycastle.asn1.ASN1GeneralizedTime;
import org.bouncycastle.asn1.ASN1Integer;
import org.bouncycastle.asn1.ASN1ObjectIdentifier;
import org.bouncycastle.asn1.DERNull;
import org.bouncycastle.asn1.DERSet;
import org.bouncycastle.asn1.cms.Attribute;
import org.bouncycastle.asn1.cms.AttributeTable;
import org.bouncycastle.asn1.ess.ESSCertID;
import org.bouncycastle.asn1.ess.SigningCertificate;
import org.bouncycastle.asn1.oiw.OIWObjectIdentifiers;
import org.bouncycastle.asn1.pkcs.PKCSObjectIdentifiers;
import org.bouncycastle.asn1.tsp.Accuracy;
import org.bouncycastle.asn1.tsp.MessageImprint;
import org.bouncycastle.asn1.tsp.TSTInfo;
import org.bouncycastle.asn1.x509.AlgorithmIdentifier;
import org.bouncycastle.asn1.x509.GeneralName;
import org.bouncycastle.cert.X509CertificateHolder;
import org.bouncycastle.cert.jcajce.JcaX509CRLHolder;
import org.bouncycastle.cert.jcajce.JcaX509CertificateHolder;
import org.bouncycastle.cms.CMSAttributeTableGenerationException;
import org.bouncycastle.cms.CMSAttributeTableGenerator;
import org.bouncycastle.cms.CMSException;
import org.bouncycastle.cms.CMSProcessableByteArray;
import org.bouncycastle.cms.CMSSignedData;
import org.bouncycastle.cms.CMSSignedDataGenerator;
import org.bouncycastle.cms.CMSSignedGenerator;
import org.bouncycastle.cms.DefaultSignedAttributeTableGenerator;
import org.bouncycastle.cms.SignerInfoGenerator;
import org.bouncycastle.cms.SimpleAttributeTableGenerator;
import org.bouncycastle.cms.jcajce.JcaSignerInfoGeneratorBuilder;
import org.bouncycastle.jce.interfaces.GOST3410PrivateKey;
import org.bouncycastle.operator.DigestCalculator;
import org.bouncycastle.operator.OperatorCreationException;
import org.bouncycastle.operator.jcajce.JcaContentSignerBuilder;
import org.bouncycastle.operator.jcajce.JcaDigestCalculatorProviderBuilder;
import org.bouncycastle.util.CollectionStore;
import org.bouncycastle.util.Store;

public class TimeStampTokenGenerator
{
  int accuracySeconds = -1;
  int accuracyMillis = -1;
  int accuracyMicros = -1;
  boolean ordering = false;
  GeneralName tsa = null;
  private ASN1ObjectIdentifier tsaPolicyOID;
  PrivateKey key;
  X509Certificate cert;
  String digestOID;
  AttributeTable signedAttr;
  AttributeTable unsignedAttr;
  private List certs = new ArrayList();
  private List crls = new ArrayList();
  private List attrCerts = new ArrayList();
  private SignerInfoGenerator signerInfoGen;
  
  public TimeStampTokenGenerator(DigestCalculator paramDigestCalculator, final SignerInfoGenerator paramSignerInfoGenerator, ASN1ObjectIdentifier paramASN1ObjectIdentifier)
    throws IllegalArgumentException, TSPException
  {
    signerInfoGen = paramSignerInfoGenerator;
    tsaPolicyOID = paramASN1ObjectIdentifier;
    if (!paramDigestCalculator.getAlgorithmIdentifier().getAlgorithm().equals(OIWObjectIdentifiers.idSHA1)) {
      throw new IllegalArgumentException("Digest calculator must be for SHA-1");
    }
    if (!paramSignerInfoGenerator.hasAssociatedCertificate()) {
      throw new IllegalArgumentException("SignerInfoGenerator must have an associated certificate");
    }
    TSPUtil.validateCertificate(paramSignerInfoGenerator.getAssociatedCertificate());
    try
    {
      OutputStream localOutputStream = paramDigestCalculator.getOutputStream();
      localOutputStream.write(paramSignerInfoGenerator.getAssociatedCertificate().getEncoded());
      localOutputStream.close();
      final ESSCertID localESSCertID = new ESSCertID(paramDigestCalculator.getDigest());
      signerInfoGen = new SignerInfoGenerator(paramSignerInfoGenerator, new CMSAttributeTableGenerator()
      {
        public AttributeTable getAttributes(Map paramAnonymousMap)
          throws CMSAttributeTableGenerationException
        {
          AttributeTable localAttributeTable = paramSignerInfoGenerator.getSignedAttributeTableGenerator().getAttributes(paramAnonymousMap);
          return localAttributeTable.add(PKCSObjectIdentifiers.id_aa_signingCertificate, new SigningCertificate(localESSCertID));
        }
      }, paramSignerInfoGenerator.getUnsignedAttributeTableGenerator());
    }
    catch (IOException localIOException)
    {
      throw new TSPException("Exception processing certificate.", localIOException);
    }
  }
  
  /**
   * @deprecated
   */
  public TimeStampTokenGenerator(SignerInfoGenerator paramSignerInfoGenerator, ASN1ObjectIdentifier paramASN1ObjectIdentifier)
    throws IllegalArgumentException, TSPException
  {
    this(new DigestCalculator()
    {
      private ByteArrayOutputStream bOut = new ByteArrayOutputStream();
      
      public AlgorithmIdentifier getAlgorithmIdentifier()
      {
        return new AlgorithmIdentifier(OIWObjectIdentifiers.idSHA1, DERNull.INSTANCE);
      }
      
      public OutputStream getOutputStream()
      {
        return bOut;
      }
      
      public byte[] getDigest()
      {
        try
        {
          return MessageDigest.getInstance("SHA-1").digest(bOut.toByteArray());
        }
        catch (NoSuchAlgorithmException localNoSuchAlgorithmException)
        {
          throw new IllegalStateException("cannot find sha-1: " + localNoSuchAlgorithmException.getMessage());
        }
      }
    }, paramSignerInfoGenerator, paramASN1ObjectIdentifier);
  }
  
  /**
   * @deprecated
   */
  public TimeStampTokenGenerator(PrivateKey paramPrivateKey, X509Certificate paramX509Certificate, String paramString1, String paramString2)
    throws IllegalArgumentException, TSPException
  {
    this(paramPrivateKey, paramX509Certificate, paramString1, paramString2, null, null);
  }
  
  /**
   * @deprecated
   */
  public TimeStampTokenGenerator(PrivateKey paramPrivateKey, X509Certificate paramX509Certificate, ASN1ObjectIdentifier paramASN1ObjectIdentifier, String paramString)
    throws IllegalArgumentException, TSPException
  {
    this(paramPrivateKey, paramX509Certificate, paramASN1ObjectIdentifier.getId(), paramString, null, null);
  }
  
  /**
   * @deprecated
   */
  public TimeStampTokenGenerator(PrivateKey paramPrivateKey, X509Certificate paramX509Certificate, String paramString1, String paramString2, AttributeTable paramAttributeTable1, AttributeTable paramAttributeTable2)
    throws IllegalArgumentException, TSPException
  {
    key = paramPrivateKey;
    cert = paramX509Certificate;
    digestOID = paramString1;
    tsaPolicyOID = new ASN1ObjectIdentifier(paramString2);
    unsignedAttr = paramAttributeTable2;
    Hashtable localHashtable = null;
    if (paramAttributeTable1 != null) {
      localHashtable = paramAttributeTable1.toHashtable();
    } else {
      localHashtable = new Hashtable();
    }
    TSPUtil.validateCertificate(paramX509Certificate);
    try
    {
      ESSCertID localESSCertID = new ESSCertID(MessageDigest.getInstance("SHA-1").digest(paramX509Certificate.getEncoded()));
      localHashtable.put(PKCSObjectIdentifiers.id_aa_signingCertificate, new Attribute(PKCSObjectIdentifiers.id_aa_signingCertificate, new DERSet(new SigningCertificate(localESSCertID))));
    }
    catch (NoSuchAlgorithmException localNoSuchAlgorithmException)
    {
      throw new TSPException("Can't find a SHA-1 implementation.", localNoSuchAlgorithmException);
    }
    catch (CertificateEncodingException localCertificateEncodingException)
    {
      throw new TSPException("Exception processing certificate.", localCertificateEncodingException);
    }
    signedAttr = new AttributeTable(localHashtable);
  }
  
  /**
   * @deprecated
   */
  public void setCertificatesAndCRLs(CertStore paramCertStore)
    throws CertStoreException, TSPException
  {
    Collection localCollection = paramCertStore.getCertificates(null);
    Iterator localIterator = localCollection.iterator();
    while (localIterator.hasNext()) {
      try
      {
        certs.add(new JcaX509CertificateHolder((X509Certificate)localIterator.next()));
      }
      catch (CertificateEncodingException localCertificateEncodingException)
      {
        throw new TSPException("cannot encode certificate: " + localCertificateEncodingException.getMessage(), localCertificateEncodingException);
      }
    }
    localCollection = paramCertStore.getCRLs(null);
    localIterator = localCollection.iterator();
    while (localIterator.hasNext()) {
      try
      {
        crls.add(new JcaX509CRLHolder((X509CRL)localIterator.next()));
      }
      catch (CRLException localCRLException)
      {
        throw new TSPException("cannot encode CRL: " + localCRLException.getMessage(), localCRLException);
      }
    }
  }
  
  public void addCertificates(Store paramStore)
  {
    certs.addAll(paramStore.getMatches(null));
  }
  
  public void addCRLs(Store paramStore)
  {
    crls.addAll(paramStore.getMatches(null));
  }
  
  public void addAttributeCertificates(Store paramStore)
  {
    attrCerts.addAll(paramStore.getMatches(null));
  }
  
  public void setAccuracySeconds(int paramInt)
  {
    accuracySeconds = paramInt;
  }
  
  public void setAccuracyMillis(int paramInt)
  {
    accuracyMillis = paramInt;
  }
  
  public void setAccuracyMicros(int paramInt)
  {
    accuracyMicros = paramInt;
  }
  
  public void setOrdering(boolean paramBoolean)
  {
    ordering = paramBoolean;
  }
  
  public void setTSA(GeneralName paramGeneralName)
  {
    tsa = paramGeneralName;
  }
  
  public TimeStampToken generate(TimeStampRequest paramTimeStampRequest, BigInteger paramBigInteger, Date paramDate, String paramString)
    throws NoSuchAlgorithmException, NoSuchProviderException, TSPException
  {
    if (signerInfoGen == null) {
      try
      {
        JcaSignerInfoGeneratorBuilder localJcaSignerInfoGeneratorBuilder = new JcaSignerInfoGeneratorBuilder(new JcaDigestCalculatorProviderBuilder().setProvider(paramString).build());
        localJcaSignerInfoGeneratorBuilder.setSignedAttributeGenerator(new DefaultSignedAttributeTableGenerator(signedAttr));
        if (unsignedAttr != null) {
          localJcaSignerInfoGeneratorBuilder.setUnsignedAttributeGenerator(new SimpleAttributeTableGenerator(unsignedAttr));
        }
        signerInfoGen = localJcaSignerInfoGeneratorBuilder.build(new JcaContentSignerBuilder(getSigAlgorithm(key, digestOID)).setProvider(paramString).build(key), cert);
      }
      catch (OperatorCreationException localOperatorCreationException)
      {
        throw new TSPException("Error generating signing operator", localOperatorCreationException);
      }
      catch (CertificateEncodingException localCertificateEncodingException)
      {
        throw new TSPException("Error encoding certificate", localCertificateEncodingException);
      }
    }
    return generate(paramTimeStampRequest, paramBigInteger, paramDate);
  }
  
  public TimeStampToken generate(TimeStampRequest paramTimeStampRequest, BigInteger paramBigInteger, Date paramDate)
    throws TSPException
  {
    if (signerInfoGen == null) {
      throw new IllegalStateException("can only use this method with SignerInfoGenerator constructor");
    }
    ASN1ObjectIdentifier localASN1ObjectIdentifier = paramTimeStampRequest.getMessageImprintAlgOID();
    AlgorithmIdentifier localAlgorithmIdentifier = new AlgorithmIdentifier(localASN1ObjectIdentifier, new DERNull());
    MessageImprint localMessageImprint = new MessageImprint(localAlgorithmIdentifier, paramTimeStampRequest.getMessageImprintDigest());
    Accuracy localAccuracy = null;
    if ((accuracySeconds > 0) || (accuracyMillis > 0) || (accuracyMicros > 0))
    {
      localObject1 = null;
      if (accuracySeconds > 0) {
        localObject1 = new ASN1Integer(accuracySeconds);
      }
      localASN1Integer = null;
      if (accuracyMillis > 0) {
        localASN1Integer = new ASN1Integer(accuracyMillis);
      }
      localObject2 = null;
      if (accuracyMicros > 0) {
        localObject2 = new ASN1Integer(accuracyMicros);
      }
      localAccuracy = new Accuracy((ASN1Integer)localObject1, localASN1Integer, (ASN1Integer)localObject2);
    }
    Object localObject1 = null;
    if (ordering) {
      localObject1 = new ASN1Boolean(ordering);
    }
    ASN1Integer localASN1Integer = null;
    if (paramTimeStampRequest.getNonce() != null) {
      localASN1Integer = new ASN1Integer(paramTimeStampRequest.getNonce());
    }
    Object localObject2 = tsaPolicyOID;
    if (paramTimeStampRequest.getReqPolicy() != null) {
      localObject2 = paramTimeStampRequest.getReqPolicy();
    }
    TSTInfo localTSTInfo = new TSTInfo((ASN1ObjectIdentifier)localObject2, localMessageImprint, new ASN1Integer(paramBigInteger), new ASN1GeneralizedTime(paramDate), localAccuracy, (ASN1Boolean)localObject1, localASN1Integer, tsa, paramTimeStampRequest.getExtensions());
    try
    {
      CMSSignedDataGenerator localCMSSignedDataGenerator = new CMSSignedDataGenerator();
      if (paramTimeStampRequest.getCertReq())
      {
        localCMSSignedDataGenerator.addCertificates(new CollectionStore(certs));
        localCMSSignedDataGenerator.addCRLs(new CollectionStore(crls));
        localCMSSignedDataGenerator.addAttributeCertificates(new CollectionStore(attrCerts));
      }
      else
      {
        localCMSSignedDataGenerator.addCRLs(new CollectionStore(crls));
      }
      localCMSSignedDataGenerator.addSignerInfoGenerator(signerInfoGen);
      byte[] arrayOfByte = localTSTInfo.getEncoded("DER");
      CMSSignedData localCMSSignedData = localCMSSignedDataGenerator.generate(new CMSProcessableByteArray(PKCSObjectIdentifiers.id_ct_TSTInfo, arrayOfByte), true);
      return new TimeStampToken(localCMSSignedData);
    }
    catch (CMSException localCMSException)
    {
      throw new TSPException("Error generating time-stamp token", localCMSException);
    }
    catch (IOException localIOException)
    {
      throw new TSPException("Exception encoding info", localIOException);
    }
  }
  
  private String getSigAlgorithm(PrivateKey paramPrivateKey, String paramString)
  {
    String str = null;
    if (((paramPrivateKey instanceof RSAPrivateKey)) || ("RSA".equalsIgnoreCase(paramPrivateKey.getAlgorithm()))) {
      str = "RSA";
    } else if (((paramPrivateKey instanceof DSAPrivateKey)) || ("DSA".equalsIgnoreCase(paramPrivateKey.getAlgorithm()))) {
      str = "DSA";
    } else if (("ECDSA".equalsIgnoreCase(paramPrivateKey.getAlgorithm())) || ("EC".equalsIgnoreCase(paramPrivateKey.getAlgorithm()))) {
      str = "ECDSA";
    } else if (((paramPrivateKey instanceof GOST3410PrivateKey)) || ("GOST3410".equalsIgnoreCase(paramPrivateKey.getAlgorithm()))) {
      str = "GOST3410";
    } else if ("ECGOST3410".equalsIgnoreCase(paramPrivateKey.getAlgorithm())) {
      str = CMSSignedGenerator.ENCRYPTION_ECGOST3410;
    }
    return TSPUtil.getDigestAlgName(paramString) + "with" + str;
  }
}

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

import java.io.IOException;
import java.math.BigInteger;
import java.text.ParseException;
import java.util.Date;
import org.bouncycastle.asn1.ASN1Boolean;
import org.bouncycastle.asn1.ASN1GeneralizedTime;
import org.bouncycastle.asn1.ASN1Integer;
import org.bouncycastle.asn1.ASN1ObjectIdentifier;
import org.bouncycastle.asn1.tsp.Accuracy;
import org.bouncycastle.asn1.tsp.MessageImprint;
import org.bouncycastle.asn1.tsp.TSTInfo;
import org.bouncycastle.asn1.x509.AlgorithmIdentifier;
import org.bouncycastle.asn1.x509.GeneralName;

public class TimeStampTokenInfo
{
  TSTInfo tstInfo;
  Date genTime;
  
  TimeStampTokenInfo(TSTInfo paramTSTInfo)
    throws TSPException, IOException
  {
    tstInfo = paramTSTInfo;
    try
    {
      genTime = paramTSTInfo.getGenTime().getDate();
    }
    catch (ParseException localParseException)
    {
      throw new TSPException("unable to parse genTime field");
    }
  }
  
  public boolean isOrdered()
  {
    return tstInfo.getOrdering().isTrue();
  }
  
  public Accuracy getAccuracy()
  {
    return tstInfo.getAccuracy();
  }
  
  public Date getGenTime()
  {
    return genTime;
  }
  
  public GenTimeAccuracy getGenTimeAccuracy()
  {
    if (getAccuracy() != null) {
      return new GenTimeAccuracy(getAccuracy());
    }
    return null;
  }
  
  public ASN1ObjectIdentifier getPolicy()
  {
    return tstInfo.getPolicy();
  }
  
  public BigInteger getSerialNumber()
  {
    return tstInfo.getSerialNumber().getValue();
  }
  
  public GeneralName getTsa()
  {
    return tstInfo.getTsa();
  }
  
  public BigInteger getNonce()
  {
    if (tstInfo.getNonce() != null) {
      return tstInfo.getNonce().getValue();
    }
    return null;
  }
  
  public AlgorithmIdentifier getHashAlgorithm()
  {
    return tstInfo.getMessageImprint().getHashAlgorithm();
  }
  
  public ASN1ObjectIdentifier getMessageImprintAlgOID()
  {
    return tstInfo.getMessageImprint().getHashAlgorithm().getAlgorithm();
  }
  
  public byte[] getMessageImprintDigest()
  {
    return tstInfo.getMessageImprint().getHashedMessage();
  }
  
  public byte[] getEncoded()
    throws IOException
  {
    return tstInfo.getEncoded();
  }
  
  /**
   * @deprecated
   */
  public TSTInfo toTSTInfo()
  {
    return tstInfo;
  }
  
  public TSTInfo toASN1Structure()
  {
    return tstInfo;
  }
}

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

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URI;
import java.net.URISyntaxException;
import org.bouncycastle.asn1.ASN1InputStream;
import org.bouncycastle.asn1.ASN1ObjectIdentifier;
import org.bouncycastle.asn1.ASN1OctetString;
import org.bouncycastle.asn1.DERIA5String;
import org.bouncycastle.asn1.cms.AttributeTable;
import org.bouncycastle.asn1.cms.CMSObjectIdentifiers;
import org.bouncycastle.asn1.cms.ContentInfo;
import org.bouncycastle.asn1.cms.Evidence;
import org.bouncycastle.asn1.cms.TimeStampAndCRL;
import org.bouncycastle.asn1.cms.TimeStampTokenEvidence;
import org.bouncycastle.asn1.cms.TimeStampedData;
import org.bouncycastle.cms.CMSException;
import org.bouncycastle.cms.CMSSignedData;
import org.bouncycastle.operator.DigestCalculator;
import org.bouncycastle.operator.DigestCalculatorProvider;
import org.bouncycastle.operator.OperatorCreationException;
import org.bouncycastle.tsp.TimeStampToken;

public class CMSTimeStampedData
{
  private TimeStampedData timeStampedData;
  private ContentInfo contentInfo;
  private TimeStampDataUtil util;
  
  public CMSTimeStampedData(ContentInfo paramContentInfo)
  {
    initialize(paramContentInfo);
  }
  
  public CMSTimeStampedData(InputStream paramInputStream)
    throws IOException
  {
    try
    {
      initialize(ContentInfo.getInstance(new ASN1InputStream(paramInputStream).readObject()));
    }
    catch (ClassCastException localClassCastException)
    {
      throw new IOException("Malformed content: " + localClassCastException);
    }
    catch (IllegalArgumentException localIllegalArgumentException)
    {
      throw new IOException("Malformed content: " + localIllegalArgumentException);
    }
  }
  
  public CMSTimeStampedData(byte[] paramArrayOfByte)
    throws IOException
  {
    this(new ByteArrayInputStream(paramArrayOfByte));
  }
  
  private void initialize(ContentInfo paramContentInfo)
  {
    contentInfo = paramContentInfo;
    if (CMSObjectIdentifiers.timestampedData.equals(paramContentInfo.getContentType())) {
      timeStampedData = TimeStampedData.getInstance(paramContentInfo.getContent());
    } else {
      throw new IllegalArgumentException("Malformed content - type must be " + CMSObjectIdentifiers.timestampedData.getId());
    }
    util = new TimeStampDataUtil(timeStampedData);
  }
  
  public byte[] calculateNextHash(DigestCalculator paramDigestCalculator)
    throws CMSException
  {
    return util.calculateNextHash(paramDigestCalculator);
  }
  
  public CMSTimeStampedData addTimeStamp(TimeStampToken paramTimeStampToken)
    throws CMSException
  {
    TimeStampAndCRL[] arrayOfTimeStampAndCRL1 = util.getTimeStamps();
    TimeStampAndCRL[] arrayOfTimeStampAndCRL2 = new TimeStampAndCRL[arrayOfTimeStampAndCRL1.length + 1];
    System.arraycopy(arrayOfTimeStampAndCRL1, 0, arrayOfTimeStampAndCRL2, 0, arrayOfTimeStampAndCRL1.length);
    arrayOfTimeStampAndCRL2[arrayOfTimeStampAndCRL1.length] = new TimeStampAndCRL(paramTimeStampToken.toCMSSignedData().getContentInfo());
    return new CMSTimeStampedData(new ContentInfo(CMSObjectIdentifiers.timestampedData, new TimeStampedData(timeStampedData.getDataUri(), timeStampedData.getMetaData(), timeStampedData.getContent(), new Evidence(new TimeStampTokenEvidence(arrayOfTimeStampAndCRL2)))));
  }
  
  public byte[] getContent()
  {
    if (timeStampedData.getContent() != null) {
      return timeStampedData.getContent().getOctets();
    }
    return null;
  }
  
  public URI getDataUri()
    throws URISyntaxException
  {
    DERIA5String localDERIA5String = timeStampedData.getDataUri();
    if (localDERIA5String != null) {
      return new URI(localDERIA5String.getString());
    }
    return null;
  }
  
  public String getFileName()
  {
    return util.getFileName();
  }
  
  public String getMediaType()
  {
    return util.getMediaType();
  }
  
  public AttributeTable getOtherMetaData()
  {
    return util.getOtherMetaData();
  }
  
  public TimeStampToken[] getTimeStampTokens()
    throws CMSException
  {
    return util.getTimeStampTokens();
  }
  
  public void initialiseMessageImprintDigestCalculator(DigestCalculator paramDigestCalculator)
    throws CMSException
  {
    util.initialiseMessageImprintDigestCalculator(paramDigestCalculator);
  }
  
  public DigestCalculator getMessageImprintDigestCalculator(DigestCalculatorProvider paramDigestCalculatorProvider)
    throws OperatorCreationException
  {
    return util.getMessageImprintDigestCalculator(paramDigestCalculatorProvider);
  }
  
  public void validate(DigestCalculatorProvider paramDigestCalculatorProvider, byte[] paramArrayOfByte)
    throws ImprintDigestInvalidException, CMSException
  {
    util.validate(paramDigestCalculatorProvider, paramArrayOfByte);
  }
  
  public void validate(DigestCalculatorProvider paramDigestCalculatorProvider, byte[] paramArrayOfByte, TimeStampToken paramTimeStampToken)
    throws ImprintDigestInvalidException, CMSException
  {
    util.validate(paramDigestCalculatorProvider, paramArrayOfByte, paramTimeStampToken);
  }
  
  public byte[] getEncoded()
    throws IOException
  {
    return contentInfo.getEncoded();
  }
}

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

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URI;
import org.bouncycastle.asn1.BEROctetString;
import org.bouncycastle.asn1.DERIA5String;
import org.bouncycastle.asn1.cms.CMSObjectIdentifiers;
import org.bouncycastle.asn1.cms.ContentInfo;
import org.bouncycastle.asn1.cms.Evidence;
import org.bouncycastle.asn1.cms.TimeStampAndCRL;
import org.bouncycastle.asn1.cms.TimeStampTokenEvidence;
import org.bouncycastle.asn1.cms.TimeStampedData;
import org.bouncycastle.cms.CMSException;
import org.bouncycastle.cms.CMSSignedData;
import org.bouncycastle.tsp.TimeStampToken;
import org.bouncycastle.util.io.Streams;

public class CMSTimeStampedDataGenerator
  extends CMSTimeStampedGenerator
{
  public CMSTimeStampedData generate(TimeStampToken paramTimeStampToken)
    throws CMSException
  {
    return generate(paramTimeStampToken, (InputStream)null);
  }
  
  public CMSTimeStampedData generate(TimeStampToken paramTimeStampToken, byte[] paramArrayOfByte)
    throws CMSException
  {
    return generate(paramTimeStampToken, new ByteArrayInputStream(paramArrayOfByte));
  }
  
  public CMSTimeStampedData generate(TimeStampToken paramTimeStampToken, InputStream paramInputStream)
    throws CMSException
  {
    ByteArrayOutputStream localByteArrayOutputStream = new ByteArrayOutputStream();
    if (paramInputStream != null) {
      try
      {
        Streams.pipeAll(paramInputStream, localByteArrayOutputStream);
      }
      catch (IOException localIOException)
      {
        throw new CMSException("exception encapsulating content: " + localIOException.getMessage(), localIOException);
      }
    }
    BEROctetString localBEROctetString = null;
    if (localByteArrayOutputStream.size() != 0) {
      localBEROctetString = new BEROctetString(localByteArrayOutputStream.toByteArray());
    }
    TimeStampAndCRL localTimeStampAndCRL = new TimeStampAndCRL(paramTimeStampToken.toCMSSignedData().toASN1Structure());
    DERIA5String localDERIA5String = null;
    if (dataUri != null) {
      localDERIA5String = new DERIA5String(dataUri.toString());
    }
    return new CMSTimeStampedData(new ContentInfo(CMSObjectIdentifiers.timestampedData, new TimeStampedData(localDERIA5String, metaData, localBEROctetString, new Evidence(new TimeStampTokenEvidence(localTimeStampAndCRL)))));
  }
}

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

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URI;
import java.net.URISyntaxException;
import org.bouncycastle.asn1.ASN1ObjectIdentifier;
import org.bouncycastle.asn1.ASN1OctetStringParser;
import org.bouncycastle.asn1.DERIA5String;
import org.bouncycastle.asn1.cms.AttributeTable;
import org.bouncycastle.asn1.cms.CMSObjectIdentifiers;
import org.bouncycastle.asn1.cms.ContentInfoParser;
import org.bouncycastle.asn1.cms.TimeStampedDataParser;
import org.bouncycastle.cms.CMSContentInfoParser;
import org.bouncycastle.cms.CMSException;
import org.bouncycastle.operator.DigestCalculator;
import org.bouncycastle.operator.DigestCalculatorProvider;
import org.bouncycastle.operator.OperatorCreationException;
import org.bouncycastle.tsp.TimeStampToken;
import org.bouncycastle.util.io.Streams;

public class CMSTimeStampedDataParser
  extends CMSContentInfoParser
{
  private TimeStampedDataParser timeStampedData;
  private TimeStampDataUtil util;
  
  public CMSTimeStampedDataParser(InputStream paramInputStream)
    throws CMSException
  {
    super(paramInputStream);
    initialize(_contentInfo);
  }
  
  public CMSTimeStampedDataParser(byte[] paramArrayOfByte)
    throws CMSException
  {
    this(new ByteArrayInputStream(paramArrayOfByte));
  }
  
  private void initialize(ContentInfoParser paramContentInfoParser)
    throws CMSException
  {
    try
    {
      if (CMSObjectIdentifiers.timestampedData.equals(paramContentInfoParser.getContentType())) {
        timeStampedData = TimeStampedDataParser.getInstance(paramContentInfoParser.getContent(16));
      } else {
        throw new IllegalArgumentException("Malformed content - type must be " + CMSObjectIdentifiers.timestampedData.getId());
      }
    }
    catch (IOException localIOException)
    {
      throw new CMSException("parsing exception: " + localIOException.getMessage(), localIOException);
    }
  }
  
  public byte[] calculateNextHash(DigestCalculator paramDigestCalculator)
    throws CMSException
  {
    return util.calculateNextHash(paramDigestCalculator);
  }
  
  public InputStream getContent()
  {
    if (timeStampedData.getContent() != null) {
      return timeStampedData.getContent().getOctetStream();
    }
    return null;
  }
  
  public URI getDataUri()
    throws URISyntaxException
  {
    DERIA5String localDERIA5String = timeStampedData.getDataUri();
    if (localDERIA5String != null) {
      return new URI(localDERIA5String.getString());
    }
    return null;
  }
  
  public String getFileName()
  {
    return util.getFileName();
  }
  
  public String getMediaType()
  {
    return util.getMediaType();
  }
  
  public AttributeTable getOtherMetaData()
  {
    return util.getOtherMetaData();
  }
  
  public void initialiseMessageImprintDigestCalculator(DigestCalculator paramDigestCalculator)
    throws CMSException
  {
    util.initialiseMessageImprintDigestCalculator(paramDigestCalculator);
  }
  
  public DigestCalculator getMessageImprintDigestCalculator(DigestCalculatorProvider paramDigestCalculatorProvider)
    throws OperatorCreationException
  {
    try
    {
      parseTimeStamps();
    }
    catch (CMSException localCMSException)
    {
      throw new OperatorCreationException("unable to extract algorithm ID: " + localCMSException.getMessage(), localCMSException);
    }
    return util.getMessageImprintDigestCalculator(paramDigestCalculatorProvider);
  }
  
  public TimeStampToken[] getTimeStampTokens()
    throws CMSException
  {
    parseTimeStamps();
    return util.getTimeStampTokens();
  }
  
  public void validate(DigestCalculatorProvider paramDigestCalculatorProvider, byte[] paramArrayOfByte)
    throws ImprintDigestInvalidException, CMSException
  {
    parseTimeStamps();
    util.validate(paramDigestCalculatorProvider, paramArrayOfByte);
  }
  
  public void validate(DigestCalculatorProvider paramDigestCalculatorProvider, byte[] paramArrayOfByte, TimeStampToken paramTimeStampToken)
    throws ImprintDigestInvalidException, CMSException
  {
    parseTimeStamps();
    util.validate(paramDigestCalculatorProvider, paramArrayOfByte, paramTimeStampToken);
  }
  
  private void parseTimeStamps()
    throws CMSException
  {
    try
    {
      if (util == null)
      {
        InputStream localInputStream = getContent();
        if (localInputStream != null) {
          Streams.drain(localInputStream);
        }
        util = new TimeStampDataUtil(timeStampedData);
      }
    }
    catch (IOException localIOException)
    {
      throw new CMSException("unable to parse evidence block: " + localIOException.getMessage(), localIOException);
    }
  }
}

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

import java.net.URI;
import org.bouncycastle.asn1.DERBoolean;
import org.bouncycastle.asn1.DERIA5String;
import org.bouncycastle.asn1.DERUTF8String;
import org.bouncycastle.asn1.cms.Attributes;
import org.bouncycastle.asn1.cms.MetaData;
import org.bouncycastle.cms.CMSException;
import org.bouncycastle.operator.DigestCalculator;

public class CMSTimeStampedGenerator
{
  protected MetaData metaData;
  protected URI dataUri;
  
  public void setDataUri(URI paramURI)
  {
    dataUri = paramURI;
  }
  
  public void setMetaData(boolean paramBoolean, String paramString1, String paramString2)
  {
    setMetaData(paramBoolean, paramString1, paramString2, null);
  }
  
  public void setMetaData(boolean paramBoolean, String paramString1, String paramString2, Attributes paramAttributes)
  {
    DERUTF8String localDERUTF8String = null;
    if (paramString1 != null) {
      localDERUTF8String = new DERUTF8String(paramString1);
    }
    DERIA5String localDERIA5String = null;
    if (paramString2 != null) {
      localDERIA5String = new DERIA5String(paramString2);
    }
    setMetaData(paramBoolean, localDERUTF8String, localDERIA5String, paramAttributes);
  }
  
  private void setMetaData(boolean paramBoolean, DERUTF8String paramDERUTF8String, DERIA5String paramDERIA5String, Attributes paramAttributes)
  {
    metaData = new MetaData(new DERBoolean(paramBoolean), paramDERUTF8String, paramDERIA5String, paramAttributes);
  }
  
  public void initialiseMessageImprintDigestCalculator(DigestCalculator paramDigestCalculator)
    throws CMSException
  {
    MetaDataUtil localMetaDataUtil = new MetaDataUtil(metaData);
    localMetaDataUtil.initialiseMessageImprintDigestCalculator(paramDigestCalculator);
  }
}

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

import org.bouncycastle.tsp.TimeStampToken;

public class ImprintDigestInvalidException
  extends Exception
{
  private TimeStampToken token;
  
  public ImprintDigestInvalidException(String paramString, TimeStampToken paramTimeStampToken)
  {
    super(paramString);
    token = paramTimeStampToken;
  }
  
  public TimeStampToken getTimeStampToken()
  {
    return token;
  }
}

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

import java.io.IOException;
import java.io.OutputStream;
import org.bouncycastle.asn1.ASN1String;
import org.bouncycastle.asn1.cms.Attributes;
import org.bouncycastle.asn1.cms.MetaData;
import org.bouncycastle.cms.CMSException;
import org.bouncycastle.operator.DigestCalculator;

class MetaDataUtil
{
  private final MetaData metaData;
  
  MetaDataUtil(MetaData paramMetaData)
  {
    metaData = paramMetaData;
  }
  
  void initialiseMessageImprintDigestCalculator(DigestCalculator paramDigestCalculator)
    throws CMSException
  {
    if ((metaData != null) && (metaData.isHashProtected())) {
      try
      {
        paramDigestCalculator.getOutputStream().write(metaData.getEncoded("DER"));
      }
      catch (IOException localIOException)
      {
        throw new CMSException("unable to initialise calculator from metaData: " + localIOException.getMessage(), localIOException);
      }
    }
  }
  
  String getFileName()
  {
    if (metaData != null) {
      return convertString(metaData.getFileName());
    }
    return null;
  }
  
  String getMediaType()
  {
    if (metaData != null) {
      return convertString(metaData.getMediaType());
    }
    return null;
  }
  
  Attributes getOtherMetaData()
  {
    if (metaData != null) {
      return metaData.getOtherMetaData();
    }
    return null;
  }
  
  private String convertString(ASN1String paramASN1String)
  {
    if (paramASN1String != null) {
      return paramASN1String.toString();
    }
    return null;
  }
}

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

import java.io.IOException;
import java.io.OutputStream;
import org.bouncycastle.asn1.ASN1ObjectIdentifier;
import org.bouncycastle.asn1.cms.AttributeTable;
import org.bouncycastle.asn1.cms.ContentInfo;
import org.bouncycastle.asn1.cms.Evidence;
import org.bouncycastle.asn1.cms.TimeStampAndCRL;
import org.bouncycastle.asn1.cms.TimeStampTokenEvidence;
import org.bouncycastle.asn1.cms.TimeStampedData;
import org.bouncycastle.asn1.cms.TimeStampedDataParser;
import org.bouncycastle.asn1.x509.AlgorithmIdentifier;
import org.bouncycastle.cms.CMSException;
import org.bouncycastle.operator.DigestCalculator;
import org.bouncycastle.operator.DigestCalculatorProvider;
import org.bouncycastle.operator.OperatorCreationException;
import org.bouncycastle.tsp.TSPException;
import org.bouncycastle.tsp.TimeStampToken;
import org.bouncycastle.tsp.TimeStampTokenInfo;
import org.bouncycastle.util.Arrays;

class TimeStampDataUtil
{
  private final TimeStampAndCRL[] timeStamps;
  private final MetaDataUtil metaDataUtil;
  
  TimeStampDataUtil(TimeStampedData paramTimeStampedData)
  {
    metaDataUtil = new MetaDataUtil(paramTimeStampedData.getMetaData());
    Evidence localEvidence = paramTimeStampedData.getTemporalEvidence();
    timeStamps = localEvidence.getTstEvidence().toTimeStampAndCRLArray();
  }
  
  TimeStampDataUtil(TimeStampedDataParser paramTimeStampedDataParser)
    throws IOException
  {
    metaDataUtil = new MetaDataUtil(paramTimeStampedDataParser.getMetaData());
    Evidence localEvidence = paramTimeStampedDataParser.getTemporalEvidence();
    timeStamps = localEvidence.getTstEvidence().toTimeStampAndCRLArray();
  }
  
  TimeStampToken getTimeStampToken(TimeStampAndCRL paramTimeStampAndCRL)
    throws CMSException
  {
    ContentInfo localContentInfo = paramTimeStampAndCRL.getTimeStampToken();
    try
    {
      TimeStampToken localTimeStampToken = new TimeStampToken(localContentInfo);
      return localTimeStampToken;
    }
    catch (IOException localIOException)
    {
      throw new CMSException("unable to parse token data: " + localIOException.getMessage(), localIOException);
    }
    catch (TSPException localTSPException)
    {
      if ((localTSPException.getCause() instanceof CMSException)) {
        throw ((CMSException)localTSPException.getCause());
      }
      throw new CMSException("token data invalid: " + localTSPException.getMessage(), localTSPException);
    }
    catch (IllegalArgumentException localIllegalArgumentException)
    {
      throw new CMSException("token data invalid: " + localIllegalArgumentException.getMessage(), localIllegalArgumentException);
    }
  }
  
  void initialiseMessageImprintDigestCalculator(DigestCalculator paramDigestCalculator)
    throws CMSException
  {
    metaDataUtil.initialiseMessageImprintDigestCalculator(paramDigestCalculator);
  }
  
  DigestCalculator getMessageImprintDigestCalculator(DigestCalculatorProvider paramDigestCalculatorProvider)
    throws OperatorCreationException
  {
    try
    {
      TimeStampToken localTimeStampToken = getTimeStampToken(timeStamps[0]);
      TimeStampTokenInfo localTimeStampTokenInfo = localTimeStampToken.getTimeStampInfo();
      ASN1ObjectIdentifier localASN1ObjectIdentifier = localTimeStampTokenInfo.getMessageImprintAlgOID();
      DigestCalculator localDigestCalculator = paramDigestCalculatorProvider.get(new AlgorithmIdentifier(localASN1ObjectIdentifier));
      initialiseMessageImprintDigestCalculator(localDigestCalculator);
      return localDigestCalculator;
    }
    catch (CMSException localCMSException)
    {
      throw new OperatorCreationException("unable to extract algorithm ID: " + localCMSException.getMessage(), localCMSException);
    }
  }
  
  TimeStampToken[] getTimeStampTokens()
    throws CMSException
  {
    TimeStampToken[] arrayOfTimeStampToken = new TimeStampToken[timeStamps.length];
    for (int i = 0; i < timeStamps.length; i++) {
      arrayOfTimeStampToken[i] = getTimeStampToken(timeStamps[i]);
    }
    return arrayOfTimeStampToken;
  }
  
  TimeStampAndCRL[] getTimeStamps()
  {
    return timeStamps;
  }
  
  byte[] calculateNextHash(DigestCalculator paramDigestCalculator)
    throws CMSException
  {
    TimeStampAndCRL localTimeStampAndCRL = timeStamps[(timeStamps.length - 1)];
    OutputStream localOutputStream = paramDigestCalculator.getOutputStream();
    try
    {
      localOutputStream.write(localTimeStampAndCRL.getEncoded("DER"));
      localOutputStream.close();
      return paramDigestCalculator.getDigest();
    }
    catch (IOException localIOException)
    {
      throw new CMSException("exception calculating
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-2017. Infinite Loop Ltd