bcpkix-jdk15on-147

T = Collections.unmodifiableSet(new HashSet());
  private TimeStampReq req;
  private Extensions extensions;
  
  public TimeStampRequest(TimeStampReq paramTimeStampReq)
  {
    req = paramTimeStampReq;
    extensions = paramTimeStampReq.getExtensions();
  }
  
  public TimeStampRequest(byte[] paramArrayOfByte)
    throws IOException
  {
    this(new ByteArrayInputStream(paramArrayOfByte));
  }
  
  public TimeStampRequest(InputStream paramInputStream)
    throws IOException
  {
    try
    {
      req = TimeStampReq.getInstance(new ASN1InputStream(paramInputStream).readObject());
    }
    catch (ClassCastException localClassCastException)
    {
      throw new IOException("malformed request: " + localClassCastException);
    }
    catch (IllegalArgumentException localIllegalArgumentException)
    {
      throw new IOException("malformed request: " + localIllegalArgumentException);
    }
  }
  
  public int getVersion()
  {
    return req.getVersion().getValue().intValue();
  }
  
  public ASN1ObjectIdentifier getMessageImprintAlgOID()
  {
    return req.getMessageImprint().getHashAlgorithm().getAlgorithm();
  }
  
  public byte[] getMessageImprintDigest()
  {
    return req.getMessageImprint().getHashedMessage();
  }
  
  public ASN1ObjectIdentifier getReqPolicy()
  {
    if (req.getReqPolicy() != null) {
      return req.getReqPolicy();
    }
    return null;
  }
  
  public BigInteger getNonce()
  {
    if (req.getNonce() != null) {
      return req.getNonce().getValue();
    }
    return null;
  }
  
  public boolean getCertReq()
  {
    if (req.getCertReq() != null) {
      return req.getCertReq().isTrue();
    }
    return false;
  }
  
  /**
   * @deprecated
   */
  public void validate(Set paramSet1, Set paramSet2, Set paramSet3, String paramString)
    throws TSPException, NoSuchProviderException
  {
    validate(paramSet1, paramSet2, paramSet3);
  }
  
  public void validate(Set paramSet1, Set paramSet2, Set paramSet3)
    throws TSPException
  {
    paramSet1 = convert(paramSet1);
    paramSet2 = convert(paramSet2);
    paramSet3 = convert(paramSet3);
    if (!paramSet1.contains(getMessageImprintAlgOID())) {
      throw new TSPValidationException("request contains unknown algorithm.", 128);
    }
    if ((paramSet2 != null) && (getReqPolicy() != null) && (!paramSet2.contains(getReqPolicy()))) {
      throw new TSPValidationException("request contains unknown policy.", 256);
    }
    if ((getExtensions() != null) && (paramSet3 != null))
    {
      Enumeration localEnumeration = getExtensions().oids();
      while (localEnumeration.hasMoreElements())
      {
        String str = ((DERObjectIdentifier)localEnumeration.nextElement()).getId();
        if (!paramSet3.contains(str)) {
          throw new TSPValidationException("request contains unknown extension.", 8388608);
        }
      }
    }
    int i = TSPUtil.getDigestLength(getMessageImprintAlgOID().getId());
    if (i != getMessageImprintDigest().length) {
      throw new TSPValidationException("imprint digest the wrong length.", 4);
    }
  }
  
  public byte[] getEncoded()
    throws IOException
  {
    return req.getEncoded();
  }
  
  Extensions getExtensions()
  {
    return extensions;
  }
  
  public boolean hasExtensions()
  {
    return extensions != null;
  }
  
  public Extension getExtension(ASN1ObjectIdentifier paramASN1ObjectIdentifier)
  {
    if (extensions != null) {
      return extensions.getExtension(paramASN1ObjectIdentifier);
    }
    return null;
  }
  
  public List getExtensionOIDs()
  {
    return TSPUtil.getExtensionOIDs(extensions);
  }
  
  public byte[] getExtensionValue(String paramString)
  {
    Extensions localExtensions = req.getExtensions();
    if (localExtensions != null)
    {
      Extension localExtension = localExtensions.getExtension(new ASN1ObjectIdentifier(paramString));
      if (localExtension != null) {
        try
        {
          return localExtension.getExtnValue().getEncoded();
        }
        catch (Exception localException)
        {
          throw new RuntimeException("error encoding " + localException.toString());
        }
      }
    }
    return null;
  }
  
  public Set getNonCriticalExtensionOIDs()
  {
    if (extensions == null) {
      return EMPTY_SET;
    }
    return Collections.unmodifiableSet(new HashSet(Arrays.asList(extensions.getNonCriticalExtensionOIDs())));
  }
  
  public Set getCriticalExtensionOIDs()
  {
    if (extensions == null) {
      return EMPTY_SET;
    }
    return Collections.unmodifiableSet(new HashSet(Arrays.asList(extensions.getCriticalExtensionOIDs())));
  }
  
  private Set convert(Set paramSet)
  {
    if (paramSet == null) {
      return paramSet;
    }
    HashSet localHashSet = new HashSet(paramSet.size());
    Iterator localIterator = paramSet.iterator();
    while (localIterator.hasNext())
    {
      Object localObject = localIterator.next();
      if ((localObject instanceof String)) {
        localHashSet.add(new ASN1ObjectIdentifier((String)localObject));
      } else {
        localHashSet.add(localObject);
      }
    }
    return localHashSet;
  }
}

/* Location:
 * Qualified Name:     org.bouncycastle.tsp.TimeStampRequest
 * 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 org.bouncycastle.asn1.ASN1Boolean;
import org.bouncycastle.asn1.ASN1Encodable;
import org.bouncycastle.asn1.ASN1Integer;
import org.bouncycastle.asn1.ASN1ObjectIdentifier;
import org.bouncycastle.asn1.ASN1Primitive;
import org.bouncycastle.asn1.DERNull;
import org.bouncycastle.asn1.tsp.MessageImprint;
import org.bouncycastle.asn1.tsp.TimeStampReq;
import org.bouncycastle.asn1.x509.AlgorithmIdentifier;
import org.bouncycastle.asn1.x509.Extensions;
import org.bouncycastle.asn1.x509.ExtensionsGenerator;

public class TimeStampRequestGenerator
{
  private ASN1ObjectIdentifier reqPolicy;
  private ASN1Boolean certReq;
  private ExtensionsGenerator extGenerator = new ExtensionsGenerator();
  
  /**
   * @deprecated
   */
  public void setReqPolicy(String paramString)
  {
    reqPolicy = new ASN1ObjectIdentifier(paramString);
  }
  
  public void setReqPolicy(ASN1ObjectIdentifier paramASN1ObjectIdentifier)
  {
    reqPolicy = paramASN1ObjectIdentifier;
  }
  
  public void setCertReq(boolean paramBoolean)
  {
    certReq = ASN1Boolean.getInstance(paramBoolean);
  }
  
  /**
   * @deprecated
   */
  public void addExtension(String paramString, boolean paramBoolean, ASN1Encodable paramASN1Encodable)
    throws IOException
  {
    addExtension(paramString, paramBoolean, paramASN1Encodable.toASN1Primitive().getEncoded());
  }
  
  /**
   * @deprecated
   */
  public void addExtension(String paramString, boolean paramBoolean, byte[] paramArrayOfByte)
  {
    extGenerator.addExtension(new ASN1ObjectIdentifier(paramString), paramBoolean, paramArrayOfByte);
  }
  
  public void addExtension(ASN1ObjectIdentifier paramASN1ObjectIdentifier, boolean paramBoolean, ASN1Encodable paramASN1Encodable)
    throws TSPIOException
  {
    TSPUtil.addExtension(extGenerator, paramASN1ObjectIdentifier, paramBoolean, paramASN1Encodable);
  }
  
  public void addExtension(ASN1ObjectIdentifier paramASN1ObjectIdentifier, boolean paramBoolean, byte[] paramArrayOfByte)
  {
    extGenerator.addExtension(paramASN1ObjectIdentifier, paramBoolean, paramArrayOfByte);
  }
  
  /**
   * @deprecated
   */
  public TimeStampRequest generate(String paramString, byte[] paramArrayOfByte)
  {
    return generate(paramString, paramArrayOfByte, null);
  }
  
  /**
   * @deprecated
   */
  public TimeStampRequest generate(String paramString, byte[] paramArrayOfByte, BigInteger paramBigInteger)
  {
    if (paramString == null) {
      throw new IllegalArgumentException("No digest algorithm specified");
    }
    ASN1ObjectIdentifier localASN1ObjectIdentifier = new ASN1ObjectIdentifier(paramString);
    AlgorithmIdentifier localAlgorithmIdentifier = new AlgorithmIdentifier(localASN1ObjectIdentifier, new DERNull());
    MessageImprint localMessageImprint = new MessageImprint(localAlgorithmIdentifier, paramArrayOfByte);
    Extensions localExtensions = null;
    if (!extGenerator.isEmpty()) {
      localExtensions = extGenerator.generate();
    }
    if (paramBigInteger != null) {
      return new TimeStampRequest(new TimeStampReq(localMessageImprint, reqPolicy, new ASN1Integer(paramBigInteger), certReq, localExtensions));
    }
    return new TimeStampRequest(new TimeStampReq(localMessageImprint, reqPolicy, null, certReq, localExtensions));
  }
  
  public TimeStampRequest generate(ASN1ObjectIdentifier paramASN1ObjectIdentifier, byte[] paramArrayOfByte)
  {
    return generate(paramASN1ObjectIdentifier.getId(), paramArrayOfByte);
  }
  
  public TimeStampRequest generate(ASN1ObjectIdentifier paramASN1ObjectIdentifier, byte[] paramArrayOfByte, BigInteger paramBigInteger)
  {
    return generate(paramASN1ObjectIdentifier.getId(), paramArrayOfByte, paramBigInteger);
  }
}

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

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.math.BigInteger;
import org.bouncycastle.asn1.ASN1InputStream;
import org.bouncycastle.asn1.ASN1ObjectIdentifier;
import org.bouncycastle.asn1.DERUTF8String;
import org.bouncycastle.asn1.cmp.PKIFailureInfo;
import org.bouncycastle.asn1.cmp.PKIFreeText;
import org.bouncycastle.asn1.cmp.PKIStatusInfo;
import org.bouncycastle.asn1.cms.Attribute;
import org.bouncycastle.asn1.cms.AttributeTable;
import org.bouncycastle.asn1.pkcs.PKCSObjectIdentifiers;
import org.bouncycastle.asn1.tsp.TimeStampResp;
import org.bouncycastle.util.Arrays;

public class TimeStampResponse
{
  TimeStampResp resp;
  TimeStampToken timeStampToken;
  
  public TimeStampResponse(TimeStampResp paramTimeStampResp)
    throws TSPException, IOException
  {
    resp = paramTimeStampResp;
    if (paramTimeStampResp.getTimeStampToken() != null) {
      timeStampToken = new TimeStampToken(paramTimeStampResp.getTimeStampToken());
    }
  }
  
  public TimeStampResponse(byte[] paramArrayOfByte)
    throws TSPException, IOException
  {
    this(new ByteArrayInputStream(paramArrayOfByte));
  }
  
  public TimeStampResponse(InputStream paramInputStream)
    throws TSPException, IOException
  {
    this(readTimeStampResp(paramInputStream));
  }
  
  private static TimeStampResp readTimeStampResp(InputStream paramInputStream)
    throws IOException, TSPException
  {
    try
    {
      return TimeStampResp.getInstance(new ASN1InputStream(paramInputStream).readObject());
    }
    catch (IllegalArgumentException localIllegalArgumentException)
    {
      throw new TSPException("malformed timestamp response: " + localIllegalArgumentException, localIllegalArgumentException);
    }
    catch (ClassCastException localClassCastException)
    {
      throw new TSPException("malformed timestamp response: " + localClassCastException, localClassCastException);
    }
  }
  
  public int getStatus()
  {
    return resp.getStatus().getStatus().intValue();
  }
  
  public String getStatusString()
  {
    if (resp.getStatus().getStatusString() != null)
    {
      StringBuffer localStringBuffer = new StringBuffer();
      PKIFreeText localPKIFreeText = resp.getStatus().getStatusString();
      for (int i = 0; i != localPKIFreeText.size(); i++) {
        localStringBuffer.append(localPKIFreeText.getStringAt(i).getString());
      }
      return localStringBuffer.toString();
    }
    return null;
  }
  
  public PKIFailureInfo getFailInfo()
  {
    if (resp.getStatus().getFailInfo() != null) {
      return new PKIFailureInfo(resp.getStatus().getFailInfo());
    }
    return null;
  }
  
  public TimeStampToken getTimeStampToken()
  {
    return timeStampToken;
  }
  
  public void validate(TimeStampRequest paramTimeStampRequest)
    throws TSPException
  {
    TimeStampToken localTimeStampToken = getTimeStampToken();
    if (localTimeStampToken != null)
    {
      TimeStampTokenInfo localTimeStampTokenInfo = localTimeStampToken.getTimeStampInfo();
      if ((paramTimeStampRequest.getNonce() != null) && (!paramTimeStampRequest.getNonce().equals(localTimeStampTokenInfo.getNonce()))) {
        throw new TSPValidationException("response contains wrong nonce value.");
      }
      if ((getStatus() != 0) && (getStatus() != 1)) {
        throw new TSPValidationException("time stamp token found in failed request.");
      }
      if (!Arrays.constantTimeAreEqual(paramTimeStampRequest.getMessageImprintDigest(), localTimeStampTokenInfo.getMessageImprintDigest())) {
        throw new TSPValidationException("response for different message imprint digest.");
      }
      if (!localTimeStampTokenInfo.getMessageImprintAlgOID().equals(paramTimeStampRequest.getMessageImprintAlgOID())) {
        throw new TSPValidationException("response for different message imprint algorithm.");
      }
      Attribute localAttribute1 = localTimeStampToken.getSignedAttributes().get(PKCSObjectIdentifiers.id_aa_signingCertificate);
      Attribute localAttribute2 = localTimeStampToken.getSignedAttributes().get(PKCSObjectIdentifiers.id_aa_signingCertificateV2);
      if ((localAttribute1 == null) && (localAttribute2 == null)) {
        throw new TSPValidationException("no signing certificate attribute present.");
      }
      if (((localAttribute1 == null) || (localAttribute2 == null)) || ((paramTimeStampRequest.getReqPolicy() != null) && (!paramTimeStampRequest.getReqPolicy().equals(localTimeStampTokenInfo.getPolicy())))) {
        throw new TSPValidationException("TSA policy wrong for request.");
      }
    }
    else if ((getStatus() == 0) || (getStatus() == 1))
    {
      throw new TSPValidationException("no time stamp token found and one expected.");
    }
  }
  
  public byte[] getEncoded()
    throws IOException
  {
    return resp.getEncoded();
  }
}

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

import org.bouncycastle.asn1.DERBitString;

class TimeStampResponseGenerator$FailInfo
  extends DERBitString
{
  TimeStampResponseGenerator$FailInfo(TimeStampResponseGenerator paramTimeStampResponseGenerator, int paramInt)
  {
    super(getBytes(paramInt), getPadBits(paramInt));
  }
}

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

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.math.BigInteger;
import java.security.NoSuchAlgorithmException;
import java.security.NoSuchProviderException;
import java.util.Date;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;
import org.bouncycastle.asn1.ASN1EncodableVector;
import org.bouncycastle.asn1.ASN1InputStream;
import org.bouncycastle.asn1.ASN1ObjectIdentifier;
import org.bouncycastle.asn1.DERBitString;
import org.bouncycastle.asn1.DERInteger;
import org.bouncycastle.asn1.DERSequence;
import org.bouncycastle.asn1.DERUTF8String;
import org.bouncycastle.asn1.cmp.PKIFreeText;
import org.bouncycastle.asn1.cmp.PKIStatusInfo;
import org.bouncycastle.asn1.cms.ContentInfo;
import org.bouncycastle.asn1.tsp.TimeStampResp;
import org.bouncycastle.cms.CMSSignedData;

public class TimeStampResponseGenerator
{
  int status;
  ASN1EncodableVector statusStrings;
  int failInfo;
  private TimeStampTokenGenerator tokenGenerator;
  private Set acceptedAlgorithms;
  private Set acceptedPolicies;
  private Set acceptedExtensions;
  
  public TimeStampResponseGenerator(TimeStampTokenGenerator paramTimeStampTokenGenerator, Set paramSet)
  {
    this(paramTimeStampTokenGenerator, paramSet, null, null);
  }
  
  public TimeStampResponseGenerator(TimeStampTokenGenerator paramTimeStampTokenGenerator, Set paramSet1, Set paramSet2)
  {
    this(paramTimeStampTokenGenerator, paramSet1, paramSet2, null);
  }
  
  public TimeStampResponseGenerator(TimeStampTokenGenerator paramTimeStampTokenGenerator, Set paramSet1, Set paramSet2, Set paramSet3)
  {
    tokenGenerator = paramTimeStampTokenGenerator;
    acceptedAlgorithms = convert(paramSet1);
    acceptedPolicies = convert(paramSet2);
    acceptedExtensions = convert(paramSet3);
    statusStrings = new ASN1EncodableVector();
  }
  
  private void addStatusString(String paramString)
  {
    statusStrings.add(new DERUTF8String(paramString));
  }
  
  private void setFailInfoField(int paramInt)
  {
    failInfo |= paramInt;
  }
  
  private PKIStatusInfo getPKIStatusInfo()
  {
    ASN1EncodableVector localASN1EncodableVector = new ASN1EncodableVector();
    localASN1EncodableVector.add(new DERInteger(status));
    if (statusStrings.size() > 0) {
      localASN1EncodableVector.add(PKIFreeText.getInstance(new DERSequence(statusStrings)));
    }
    if (failInfo != 0)
    {
      FailInfo localFailInfo = new FailInfo(failInfo);
      localASN1EncodableVector.add(localFailInfo);
    }
    return PKIStatusInfo.getInstance(new DERSequence(localASN1EncodableVector));
  }
  
  /**
   * @deprecated
   */
  public TimeStampResponse generate(TimeStampRequest paramTimeStampRequest, BigInteger paramBigInteger, Date paramDate, String paramString)
    throws NoSuchAlgorithmException, NoSuchProviderException, TSPException
  {
    TimeStampResp localTimeStampResp;
    try
    {
      if (paramDate == null) {
        throw new TSPValidationException("The time source is not available.", 512);
      }
      paramTimeStampRequest.validate(acceptedAlgorithms, acceptedPolicies, acceptedExtensions, paramString);
      status = 0;
      addStatusString("Operation Okay");
      PKIStatusInfo localPKIStatusInfo = getPKIStatusInfo();
      localObject = null;
      try
      {
        ByteArrayInputStream localByteArrayInputStream = new ByteArrayInputStream(tokenGenerator.generate(paramTimeStampRequest, paramBigInteger, paramDate, paramString).toCMSSignedData().getEncoded());
        ASN1InputStream localASN1InputStream = new ASN1InputStream(localByteArrayInputStream);
        localObject = ContentInfo.getInstance(localASN1InputStream.readObject());
      }
      catch (IOException localIOException2)
      {
        throw new TSPException("Timestamp token received cannot be converted to ContentInfo", localIOException2);
      }
      localTimeStampResp = new TimeStampResp(localPKIStatusInfo, (ContentInfo)localObject);
    }
    catch (TSPValidationException localTSPValidationException)
    {
      status = 2;
      setFailInfoField(localTSPValidationException.getFailureCode());
      addStatusString(localTSPValidationException.getMessage());
      Object localObject = getPKIStatusInfo();
      localTimeStampResp = new TimeStampResp((PKIStatusInfo)localObject, null);
    }
    try
    {
      return new TimeStampResponse(localTimeStampResp);
    }
    catch (IOException localIOException1)
    {
      throw new TSPException("created badly formatted response!");
    }
  }
  
  public TimeStampResponse generate(TimeStampRequest paramTimeStampRequest, BigInteger paramBigInteger, Date paramDate)
    throws TSPException
  {
    TimeStampResp localTimeStampResp;
    try
    {
      if (paramDate == null) {
        throw new TSPValidationException("The time source is not available.", 512);
      }
      paramTimeStampRequest.validate(acceptedAlgorithms, acceptedPolicies, acceptedExtensions);
      status = 0;
      addStatusString("Operation Okay");
      PKIStatusInfo localPKIStatusInfo = getPKIStatusInfo();
      localObject = null;
      try
      {
        ByteArrayInputStream localByteArrayInputStream = new ByteArrayInputStream(tokenGenerator.generate(paramTimeStampRequest, paramBigInteger, paramDate).toCMSSignedData().getEncoded());
        ASN1InputStream localASN1InputStream = new ASN1InputStream(localByteArrayInputStream);
        localObject = ContentInfo.getInstance(localASN1InputStream.readObject());
      }
      catch (IOException localIOException2)
      {
        throw new TSPException("Timestamp token received cannot be converted to ContentInfo", localIOException2);
      }
      localTimeStampResp = new TimeStampResp(localPKIStatusInfo, (ContentInfo)localObject);
    }
    catch (TSPValidationException localTSPValidationException)
    {
      status = 2;
      setFailInfoField(localTSPValidationException.getFailureCode());
      addStatusString(localTSPValidationException.getMessage());
      Object localObject = getPKIStatusInfo();
      localTimeStampResp = new TimeStampResp((PKIStatusInfo)localObject, null);
    }
    try
    {
      return new TimeStampResponse(localTimeStampResp);
    }
    catch (IOException localIOException1)
    {
      throw new TSPException("created badly formatted response!");
    }
  }
  
  public TimeStampResponse generateFailResponse(int paramInt1, int paramInt2, String paramString)
    throws TSPException
  {
    status = paramInt1;
    setFailInfoField(paramInt2);
    if (paramString != null) {
      addStatusString(paramString);
    }
    PKIStatusInfo localPKIStatusInfo = getPKIStatusInfo();
    TimeStampResp localTimeStampResp = new TimeStampResp(localPKIStatusInfo, null);
    try
    {
      return new TimeStampResponse(localTimeStampResp);
    }
    catch (IOException localIOException)
    {
      throw new TSPException("created badly formatted response!");
    }
  }
  
  private Set convert(Set paramSet)
  {
    if (paramSet == null) {
      return paramSet;
    }
    HashSet localHashSet = new HashSet(paramSet.size());
    Iterator localIterator = paramSet.iterator();
    while (localIterator.hasNext())
    {
      Object localObject = localIterator.next();
      if ((localObject instanceof String)) {
        localHashSet.add(new ASN1ObjectIdentifier((String)localObject));
      } else {
        localHashSet.add(localObject);
      }
    }
    return localHashSet;
  }
  
  class FailInfo
    extends DERBitString
  {
    FailInfo(int paramInt)
    {
      super(getPadBits(paramInt));
    }
  }
}

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

import org.bouncycastle.asn1.ASN1ObjectIdentifier;
import org.bouncycastle.asn1.ess.ESSCertID;
import org.bouncycastle.asn1.ess.ESSCertIDv2;
import org.bouncycastle.asn1.nist.NISTObjectIdentifiers;
import org.bouncycastle.asn1.oiw.OIWObjectIdentifiers;
import org.bouncycastle.asn1.x509.AlgorithmIdentifier;
import org.bouncycastle.asn1.x509.IssuerSerial;

class TimeStampToken$CertID
{
  private ESSCertID certID;
  private ESSCertIDv2 certIDv2;
  
  TimeStampToken$CertID(TimeStampToken paramTimeStampToken, ESSCertID paramESSCertID)
  {
    certID = paramESSCertID;
    certIDv2 = null;
  }
  
  TimeStampToken$CertID(TimeStampToken paramTimeStampToken, ESSCertIDv2 paramESSCertIDv2)
  {
    certIDv2 = paramESSCertIDv2;
    certID = null;
  }
  
  public String getHashAlgorithmName()
  {
    if (certID != null) {
      return "SHA-1";
    }
    if (NISTObjectIdentifiers.id_sha256.equals(certIDv2.getHashAlgorithm().getAlgorithm())) {
      return "SHA-256";
    }
    return certIDv2.getHashAlgorithm().getAlgorithm().getId();
  }
  
  public AlgorithmIdentifier getHashAlgorithm()
  {
    if (certID != null) {
      return new AlgorithmIdentifier(OIWObjectIdentifiers.idSHA1);
    }
    return certIDv2.getHashAlgorithm();
  }
  
  public byte[] getCertHash()
  {
    if (certID != null) {
      return certID.getCertHash();
    }
    return certIDv2.getCertHash();
  }
  
  public IssuerSerial getIssuerSerial()
  {
    if (certID != null) {
      return certID.getIssuerSerial();
    }
    return certIDv2.getIssuerSerial();
  }
}

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

import java.io.ByteArrayInputStream;
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.cert.CertStore;
import java.security.cert.CertificateEncodingException;
import java.security.cert.CertificateExpiredException;
import java.security.cert.CertificateNotYetValidException;
import java.security.cert.X509Certificate;
import java.util.Collection;
import java.util.Date;
import java.util.Iterator;
import org.bouncycastle.asn1.ASN1InputStream;
import org.bouncycastle.asn1.ASN1Integer;
import org.bouncycastle.asn1.ASN1ObjectIdentifier;
import org.bouncycastle.asn1.ASN1Set;
import org.bouncycastle.asn1.cms.Attribute;
import org.bouncycastle.asn1.cms.AttributeTable;
import org.bouncycastle.asn1.cms.ContentInfo;
import org.bouncycastle.asn1.cms.IssuerAndSerialNumber;
import org.bouncycastle.asn1.ess.ESSCertID;
import org.bouncycastle.asn1.ess.ESSCertIDv2;
import org.bouncycastle.asn1.ess.SigningCertificate;
import org.bouncycastle.asn1.ess.SigningCertificateV2;
import org.bouncycastle.asn1.nist.NISTObjectIdentifiers;
import org.bouncycastle.asn1.oiw.OIWObjectIdentifiers;
import org.bouncycastle.asn1.pkcs.PKCSObjectIdentifiers;
import org.bouncycastle.asn1.tsp.TSTInfo;
import org.bouncycastle.asn1.x500.X500Name;
import org.bouncycastle.asn1.x509.AlgorithmIdentifier;
import org.bouncycastle.asn1.x509.GeneralName;
import org.bouncycastle.asn1.x509.GeneralNames;
import org.bouncycastle.asn1.x509.IssuerSerial;
import org.bouncycastle.asn1.x509.X509Name;
import org.bouncycastle.cert.X509CertificateHolder;
import org.bouncycastle.cms.CMSException;
import org.bouncycastle.cms.CMSProcessable;
import org.bouncycastle.cms.CMSSignedData;
import org.bouncycastle.cms.SignerId;
import org.bouncycastle.cms.SignerInformation;
import org.bouncycastle.cms.SignerInformationStore;
import org.bouncycastle.cms.SignerInformationVerifier;
import org.bouncycastle.jce.PrincipalUtil;
import org.bouncycastle.jce.X509Principal;
import org.bouncycastle.operator.DigestCalculator;
import org.bouncycastle.operator.OperatorCreationException;
import org.bouncycastle.util.Arrays;
import org.bouncycastle.util.Store;

public class TimeStampToken
{
  CMSSignedData tsToken;
  SignerInformation tsaSignerInfo;
  Date genTime;
  TimeStampTokenInfo tstInfo;
  CertID certID;
  
  public TimeStampToken(ContentInfo paramContentInfo)
    throws TSPException, IOException
  {
    this(getSignedData(paramContentInfo));
  }
  
  private static CMSSignedData getSignedData(ContentInfo paramContentInfo)
    throws TSPException
  {
    try
    {
      return new CMSSignedData(paramContentInfo);
    }
    catch (CMSException localCMSException)
    {
      throw new TSPException("TSP parsing error: " + localCMSException.getMessage(), localCMSException.getCause());
    }
  }
  
  public TimeStampToken(CMSSignedData paramCMSSignedData)
    throws TSPException, IOException
  {
    tsToken = paramCMSSignedData;
    if (!tsToken.getSignedContentTypeOID().equals(PKCSObjectIdentifiers.id_ct_TSTInfo.getId())) {
      throw new TSPValidationException("ContentInfo object not for a time stamp.");
    }
    Collection localCollection = tsToken.getSignerInfos().getSigners();
    if (localCollection.size() != 1) {
      throw new IllegalArgumentException("Time-stamp token signed by " + localCollection.size() + " signers, but it must contain just the TSA signature.");
    }
    tsaSignerInfo = ((SignerInformation)localCollection.iterator().next());
    try
    {
      CMSProcessable localCMSProcessable = tsToken.getSignedContent();
      ByteArrayOutputStream localByteArrayOutputStream = new ByteArrayOutputStream();
      localCMSProcessable.write(localByteArrayOutputStream);
      ASN1InputStream localASN1InputStream = new ASN1InputStream(new ByteArrayInputStream(localByteArrayOutputStream.toByteArray()));
      tstInfo = new TimeStampTokenInfo(TSTInfo.getInstance(localASN1InputStream.readObject()));
      Attribute localAttribute = tsaSignerInfo.getSignedAttributes().get(PKCSObjectIdentifiers.id_aa_signingCertificate);
      Object localObject;
      if (localAttribute != null)
      {
        localObject = SigningCertificate.getInstance(localAttribute.getAttrValues().getObjectAt(0));
        certID = new CertID(ESSCertID.getInstance(localObject.getCerts()[0]));
      }
      else
      {
        localAttribute = tsaSignerInfo.getSignedAttributes().get(PKCSObjectIdentifiers.id_aa_signingCertificateV2);
        if (localAttribute == null) {
          throw new TSPValidationException("no signing certificate attribute found, time stamp invalid.");
        }
        localObject = SigningCertificateV2.getInstance(localAttribute.getAttrValues().getObjectAt(0));
        certID = new CertID(ESSCertIDv2.getInstance(localObject.getCerts()[0]));
      }
    }
    catch (CMSException localCMSException)
    {
      throw new TSPException(localCMSException.getMessage(), localCMSException.getUnderlyingException());
    }
  }
  
  public TimeStampTokenInfo getTimeStampInfo()
  {
    return tstInfo;
  }
  
  public SignerId getSID()
  {
    return tsaSignerInfo.getSID();
  }
  
  public AttributeTable getSignedAttributes()
  {
    return tsaSignerInfo.getSignedAttributes();
  }
  
  public AttributeTable getUnsignedAttributes()
  {
    return tsaSignerInfo.getUnsignedAttributes();
  }
  
  /**
   * @deprecated
   */
  public CertStore getCertificatesAndCRLs(String paramString1, String paramString2)
    throws NoSuchAlgorithmException, NoSuchProviderException, CMSException
  {
    return tsToken.getCertificatesAndCRLs(paramString1, paramString2);
  }
  
  public Store getCertificates()
  {
    return tsToken.getCertificates();
  }
  
  public Store getCRLs()
  {
    return tsToken.getCRLs();
  }
  
  public Store getAttributeCertificates()
  {
    return tsToken.getAttributeCertificates();
  }
  
  /**
   * @deprecated
   */
  public void validate(X509Certificate paramX509Certificate, String paramString)
    throws TSPException, TSPValidationException, CertificateExpiredException, CertificateNotYetValidException, NoSuchProviderException
  {
    try
    {
      if (!Arrays.constantTimeAreEqual(certID.getCertHash(), MessageDigest.getInstance(certID.getHashAlgorithmName()).digest(paramX509Certificate.getEncoded()))) {
        throw new TSPValidationException("certificate hash does not match certID hash.");
      }
      if (certID.getIssuerSerial() != null)
      {
        if (!certID.getIssuerSerial().getSerial().getValue().equals(paramX509Certificate.getSerialNumber())) {
          throw new TSPValidationException("certificate serial number does not match certID for signature.");
        }
        GeneralName[] arrayOfGeneralName = certID.getIssuerSerial().getIssuer().getNames();
        X509Principal localX509Principal = PrincipalUtil.getIssuerX509Principal(paramX509Certificate);
        int i = 0;
        for (int j = 0; j != arrayOfGeneralName.length; j++) {
          if ((arrayOfGeneralName[j].getTagNo() == 4) && (new X509Principal(X509Name.getInstance(arrayOfGeneralName[j].getName())).equals(localX509Principal)))
          {
            i = 1;
            break;
          }
        }
        if (i == 0) {
          throw new TSPValidationException("certificate name does not match certID for signature. ");
        }
      }
      TSPUtil.validateCertificate(paramX509Certificate);
      paramX509Certificate.checkValidity(tstInfo.getGenTime());
      if (!tsaSignerInfo.verify(paramX509Certificate, paramString)) {
        throw new TSPValidationException("signature not created by certificate.");
      }
    }
    catch (CMSException localCMSException)
    {
      if (localCMSException.getUnderlyingException() != null) {
        throw new TSPException(localCMSException.getMessage(), localCMSException.getUnderlyingException());
      }
      throw new TSPException("CMS exception: " + localCMSException, localCMSException);
    }
    catch (NoSuchAlgorithmException localNoSuchAlgorithmException)
    {
      throw new TSPException("cannot find algorithm: " + localNoSuchAlgorithmException, localNoSuchAlgorithmException);
    }
    catch (CertificateEncodingException localCertificateEncodingException)
    {
      throw new TSPException("problem processing certificate: " + localCertificateEncodingException, localCertificateEncodingException);
    }
  }
  
  public void validate(SignerInformationVerifier paramSignerInformationVerifier)
    throws TSPException, TSPValidationException
  {
    if (!paramSignerInformationVerifier.hasAssociatedCertificate()) {
      throw new IllegalArgumentException("verifier provider needs an associated certificate");
    }
    try
    {
      X509CertificateHolder localX509CertificateHolder = paramSignerInformationVerifier.getAssociatedCertificate();
      DigestCalculator localDigestCalculator = paramSignerInformationVerifier.getDigestCalculator(certID.getHashAlgorithm());
      OutputStream localOutputStream = localDigestCalculator.getOutputStream();
      localOutputStream.write(localX509CertificateHolder.getEncoded());
      localOutputStream.close();
      if (!Arrays.constantTimeAreEqual(certID.getCertHash(), localDigestCalculator.getDigest())) {
        throw new TSPValidationException("certificate hash does not match certID hash.");
      }
      if (certID.getIssuerSerial() != null)
      {
        IssuerAndSerialNumber localIssuerAndSerialNumber = new IssuerAndSerialNumber(localX509CertificateHolder.toASN1Structure());
        if (!certID.getIssuerSerial().getSerial().equals(localIssuerAndSerialNumber.getSerialNumber())) {
          throw new TSPValidationException("certificate serial number does not match certID for signature.");
        }
        GeneralName[] arrayOfGeneralName = certID.getIssuerSerial().getIssuer().getNames();
        int i = 0;
        for (int j = 0; j != arrayOfGeneralName.length; j++) {
          if ((arrayOfGeneralName[j].getTagNo() == 4) && (X500Name.getInstance(arrayOfGeneralName[j].getName()).equals(X500Name.getInstance(localIssuerAndSerialNumber.getName()))))
          {
            i = 1;
            break;
          }
        }
        if (i == 0) {
          throw new TSPValidationException("certificate name does not match certID for signature. ");
        }
      }
      TSPUtil.validateCertificate(localX509CertificateHolder);
      if (!localX509CertificateHolder.isValidOn(tstInfo.getGenTime())) {
        throw new TSPValidationException("certificate not valid when time stamp created.");
      }
      if (!tsaSignerInfo.verify(paramSignerInformationVerifier)) {
        throw new TSPValidationException("signature not created by certificate.");
      }
    }
    catch (CMSException localCMSException)
    {
      if (localCMSException.getUnderlyingException() != null) {
        throw new TSPException(localCMSException.getMessage(), localCMSException.getUnderlyingException());
      }
      throw new TSPException("CMS exception: " + localCMSException, localCMSException);
    }
    catch (IOException localIOException)
    {
      throw new TSPException("problem processing certificate: " + localIOException, localIOException);
    }
    catch (OperatorCreationException localOperatorCreationException)
    {
      throw new TSPException("unable to create digest: " + localOperatorCreationException.getMessage(), localOperatorCreationException);
    }
  }
  
  public boolean isSignatureValid(SignerInformationVerifier paramSignerInformationVerifier)
    throws TSPException
  {
    try
    {
      return tsaSignerInfo.verify(paramSignerInformationVerifier);
    }
    catch (CMSException localCMSException)
    {
      if (localCMSException.getUnderlyingException() != null) {
        throw new TSPException(localCMSException.getMessage(), localCMSException.getUnderlyingException());
      }
      throw new TSPException("CMS exception: " + localCMSException, localCMSException);
    }
  }
  
  public CMSSignedData toCMSSignedData()
  {
    return tsToken;
  }
  
  public byte[] getEncoded()
    throws IOException
  {
    return tsToken.getEncoded();
  }
  
  private class CertID
  {
    private ESSCertID certID;
    private ESSCertIDv2 certIDv2;
    
    CertID(ESSCertID paramESSCertID)
    {
      certID = paramESSCertID;
      certIDv2 = null;
    }
    
    CertID(ESSCertIDv2 paramESSCertIDv2)
    {
      certIDv2 = paramESSCertIDv2;
      certID = null;
    }
    
    public String getHashAlgorithmName()
    {
      if (certID != null) {
        return "SHA-1";
      }
      if (NISTObjectIdentifiers.id_sha256.equals(certIDv2.getHashAlgorithm().getAlgorithm())) {
        return "SHA-256";
      }
      return certIDv2.getHashAlgorithm().getAlgorithm().getId();
    }
    
    public AlgorithmIdentifier getHashAlgorithm()
    {
      if (certID != null) {
        return new AlgorithmIdentifier(OIWObjectIdentifiers.idSHA1);
      }
      return certIDv2.getHashAlgorithm();
    }
    
    public byte[] getCertHash()
    {
      if (certID != null) {
        return certID.getCertHash();
      }
      return certIDv2.getCertHash();
    }
    
    public IssuerSerial getIssuerSerial()
    {
      if (certID != null) {
        return certID.getIssuerSerial();
      }
      return certIDv2.getIssuerSerial();
    }
  }
}

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

import java.util.Map;
import org.bouncycastle.asn1.cms.AttributeTable;
import org.bouncycastle.asn1.ess.ESSCertID;
import org.bouncycastle.asn1.ess.SigningCertificate;
import org.bouncycastle.asn1.pkcs.PKCSObjectIdentifiers;
import org.bouncycastle.cms.CMSAttributeTableGenerationException;
import org.bouncycastle.cms.CMSAttributeTableGenerator;
import org.bouncycastle.cms.SignerInfoGenerator;

class TimeStampTokenGenerator$1
  implements CMSAttributeTableGenerator
{
  TimeStampTokenGenerator$1(TimeStampTokenGenerator paramTimeStampTokenGenerator, SignerInfoGenerator paramSignerInfoGenerator, ESSCertID paramESSCertID) {}
  
  public AttributeTable getAttributes(Map paramMap)
    throws CMSAttributeTableGenerationException
  {
    AttributeTable localAttributeTable = val$signerInfoGen.getSignedAttributeTableGenerator().getAttributes(paramMap);
    return localAttributeTable.add(PKCSObjectIdentifiers.id_aa_signingCertificate, new SigningCertificate(val$essCertid));
  }
}

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

import java.io.ByteArrayOutputStream;
import java.io.OutputStream;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import org.bouncycastle.asn1.DERNull;
import org.bouncycastle.asn1.oiw.OIWObjectIdentifiers;
import org.bouncycastle.asn1.x509.AlgorithmIdentifier;
import org.bouncycastle.operator.DigestCalculator;

class TimeStampTokenGenerator$2
  implements 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());
    }
  }
}

/* Location:
 * Qualified Nam
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