bcpkix-jdk15on-147

S12PBEInputDecryptorProviderBuilder.1
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.bouncycastle.pkcs.bc;

import java.io.InputStream;
import org.bouncycastle.asn1.pkcs.PKCS12PBEParams;
import org.bouncycastle.asn1.x509.AlgorithmIdentifier;
import org.bouncycastle.crypto.CipherParameters;
import org.bouncycastle.crypto.ExtendedDigest;
import org.bouncycastle.crypto.digests.SHA1Digest;
import org.bouncycastle.crypto.generators.PKCS12ParametersGenerator;
import org.bouncycastle.crypto.io.CipherInputStream;
import org.bouncycastle.crypto.paddings.PaddedBufferedBlockCipher;
import org.bouncycastle.operator.GenericKey;
import org.bouncycastle.operator.InputDecryptor;
import org.bouncycastle.operator.InputDecryptorProvider;

public class BcPKCS12PBEInputDecryptorProviderBuilder
{
  private ExtendedDigest digest;
  
  public BcPKCS12PBEInputDecryptorProviderBuilder()
  {
    this(new SHA1Digest());
  }
  
  public BcPKCS12PBEInputDecryptorProviderBuilder(ExtendedDigest paramExtendedDigest)
  {
    digest = paramExtendedDigest;
  }
  
  public InputDecryptorProvider build(final char[] paramArrayOfChar)
  {
    new InputDecryptorProvider()
    {
      public InputDecryptor get(final AlgorithmIdentifier paramAnonymousAlgorithmIdentifier)
      {
        final PaddedBufferedBlockCipher localPaddedBufferedBlockCipher = PKCS12PBEUtils.getEngine(paramAnonymousAlgorithmIdentifier.getAlgorithm());
        PKCS12PBEParams localPKCS12PBEParams = PKCS12PBEParams.getInstance(paramAnonymousAlgorithmIdentifier.getParameters());
        CipherParameters localCipherParameters = PKCS12PBEUtils.createCipherParameters(paramAnonymousAlgorithmIdentifier.getAlgorithm(), digest, localPaddedBufferedBlockCipher.getBlockSize(), localPKCS12PBEParams, paramArrayOfChar);
        localPaddedBufferedBlockCipher.init(false, localCipherParameters);
        new InputDecryptor()
        {
          public AlgorithmIdentifier getAlgorithmIdentifier()
          {
            return paramAnonymousAlgorithmIdentifier;
          }
          
          public InputStream getInputStream(InputStream paramAnonymous2InputStream)
          {
            return new CipherInputStream(paramAnonymous2InputStream, localPaddedBufferedBlockCipher);
          }
          
          public GenericKey getKey()
          {
            return new GenericKey(PKCS12ParametersGenerator.PKCS12PasswordToBytes(val$password));
          }
        };
      }
    };
  }
}

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

import java.io.OutputStream;
import org.bouncycastle.asn1.pkcs.PKCS12PBEParams;
import org.bouncycastle.asn1.x509.AlgorithmIdentifier;
import org.bouncycastle.crypto.generators.PKCS12ParametersGenerator;
import org.bouncycastle.crypto.io.CipherOutputStream;
import org.bouncycastle.operator.GenericKey;
import org.bouncycastle.operator.OutputEncryptor;

class BcPKCS12PBEOutputEncryptorBuilder$1
  implements OutputEncryptor
{
  BcPKCS12PBEOutputEncryptorBuilder$1(BcPKCS12PBEOutputEncryptorBuilder paramBcPKCS12PBEOutputEncryptorBuilder, PKCS12PBEParams paramPKCS12PBEParams, char[] paramArrayOfChar) {}
  
  public AlgorithmIdentifier getAlgorithmIdentifier()
  {
    return new AlgorithmIdentifier(BcPKCS12PBEOutputEncryptorBuilder.access$000(this$0), val$pbeParams);
  }
  
  public OutputStream getOutputStream(OutputStream paramOutputStream)
  {
    return new CipherOutputStream(paramOutputStream, BcPKCS12PBEOutputEncryptorBuilder.access$100(this$0));
  }
  
  public GenericKey getKey()
  {
    return new GenericKey(PKCS12ParametersGenerator.PKCS12PasswordToBytes(val$password));
  }
}

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

import java.io.OutputStream;
import java.security.SecureRandom;
import org.bouncycastle.asn1.ASN1ObjectIdentifier;
import org.bouncycastle.asn1.pkcs.PKCS12PBEParams;
import org.bouncycastle.asn1.x509.AlgorithmIdentifier;
import org.bouncycastle.crypto.BlockCipher;
import org.bouncycastle.crypto.BufferedBlockCipher;
import org.bouncycastle.crypto.CipherParameters;
import org.bouncycastle.crypto.ExtendedDigest;
import org.bouncycastle.crypto.digests.SHA1Digest;
import org.bouncycastle.crypto.generators.PKCS12ParametersGenerator;
import org.bouncycastle.crypto.io.CipherOutputStream;
import org.bouncycastle.crypto.paddings.PKCS7Padding;
import org.bouncycastle.crypto.paddings.PaddedBufferedBlockCipher;
import org.bouncycastle.operator.GenericKey;
import org.bouncycastle.operator.OutputEncryptor;

public class BcPKCS12PBEOutputEncryptorBuilder
{
  private ExtendedDigest digest;
  private BufferedBlockCipher engine;
  private ASN1ObjectIdentifier algorithm;
  private SecureRandom random;
  
  public BcPKCS12PBEOutputEncryptorBuilder(ASN1ObjectIdentifier paramASN1ObjectIdentifier, BlockCipher paramBlockCipher)
  {
    this(paramASN1ObjectIdentifier, paramBlockCipher, new SHA1Digest());
  }
  
  public BcPKCS12PBEOutputEncryptorBuilder(ASN1ObjectIdentifier paramASN1ObjectIdentifier, BlockCipher paramBlockCipher, ExtendedDigest paramExtendedDigest)
  {
    algorithm = paramASN1ObjectIdentifier;
    engine = new PaddedBufferedBlockCipher(paramBlockCipher, new PKCS7Padding());
    digest = paramExtendedDigest;
  }
  
  public OutputEncryptor build(final char[] paramArrayOfChar)
  {
    if (random == null) {
      random = new SecureRandom();
    }
    byte[] arrayOfByte = new byte[20];
    random.nextBytes(arrayOfByte);
    final PKCS12PBEParams localPKCS12PBEParams = new PKCS12PBEParams(arrayOfByte, 1024);
    CipherParameters localCipherParameters = PKCS12PBEUtils.createCipherParameters(algorithm, digest, engine.getBlockSize(), localPKCS12PBEParams, paramArrayOfChar);
    engine.init(true, localCipherParameters);
    new OutputEncryptor()
    {
      public AlgorithmIdentifier getAlgorithmIdentifier()
      {
        return new AlgorithmIdentifier(algorithm, localPKCS12PBEParams);
      }
      
      public OutputStream getOutputStream(OutputStream paramAnonymousOutputStream)
      {
        return new CipherOutputStream(paramAnonymousOutputStream, engine);
      }
      
      public GenericKey getKey()
      {
        return new GenericKey(PKCS12ParametersGenerator.PKCS12PasswordToBytes(paramArrayOfChar));
      }
    };
  }
}

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

import java.io.OutputStream;
import org.bouncycastle.asn1.ASN1ObjectIdentifier;
import org.bouncycastle.asn1.pkcs.PKCS12PBEParams;
import org.bouncycastle.asn1.x509.AlgorithmIdentifier;
import org.bouncycastle.crypto.generators.PKCS12ParametersGenerator;
import org.bouncycastle.crypto.io.MacOutputStream;
import org.bouncycastle.crypto.macs.HMac;
import org.bouncycastle.operator.GenericKey;
import org.bouncycastle.operator.MacCalculator;

class PKCS12PBEUtils$1
  implements MacCalculator
{
  PKCS12PBEUtils$1(ASN1ObjectIdentifier paramASN1ObjectIdentifier, PKCS12PBEParams paramPKCS12PBEParams, HMac paramHMac, char[] paramArrayOfChar) {}
  
  public AlgorithmIdentifier getAlgorithmIdentifier()
  {
    return new AlgorithmIdentifier(val$digestAlgorithm, val$pbeParams);
  }
  
  public OutputStream getOutputStream()
  {
    return new MacOutputStream(val$hMac);
  }
  
  public byte[] getMac()
  {
    byte[] arrayOfByte = new byte[val$hMac.getMacSize()];
    val$hMac.doFinal(arrayOfByte, 0);
    return arrayOfByte;
  }
  
  public GenericKey getKey()
  {
    return new GenericKey(PKCS12ParametersGenerator.PKCS12PasswordToBytes(val$password));
  }
}

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

import java.io.OutputStream;
import java.math.BigInteger;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import org.bouncycastle.asn1.ASN1ObjectIdentifier;
import org.bouncycastle.asn1.pkcs.PKCS12PBEParams;
import org.bouncycastle.asn1.pkcs.PKCSObjectIdentifiers;
import org.bouncycastle.asn1.x509.AlgorithmIdentifier;
import org.bouncycastle.crypto.BlockCipher;
import org.bouncycastle.crypto.CipherParameters;
import org.bouncycastle.crypto.ExtendedDigest;
import org.bouncycastle.crypto.engines.DESedeEngine;
import org.bouncycastle.crypto.engines.RC2Engine;
import org.bouncycastle.crypto.generators.PKCS12ParametersGenerator;
import org.bouncycastle.crypto.io.MacOutputStream;
import org.bouncycastle.crypto.macs.HMac;
import org.bouncycastle.crypto.modes.CBCBlockCipher;
import org.bouncycastle.crypto.paddings.PKCS7Padding;
import org.bouncycastle.crypto.paddings.PaddedBufferedBlockCipher;
import org.bouncycastle.crypto.params.DESedeParameters;
import org.bouncycastle.crypto.params.KeyParameter;
import org.bouncycastle.crypto.params.ParametersWithIV;
import org.bouncycastle.operator.GenericKey;
import org.bouncycastle.operator.MacCalculator;

class PKCS12PBEUtils
{
  private static Map keySizes = new HashMap();
  private static Set noIvAlgs = new HashSet();
  private static Set desAlgs = new HashSet();
  
  static int getKeySize(ASN1ObjectIdentifier paramASN1ObjectIdentifier)
  {
    return ((Integer)keySizes.get(paramASN1ObjectIdentifier)).intValue();
  }
  
  static boolean hasNoIv(ASN1ObjectIdentifier paramASN1ObjectIdentifier)
  {
    return noIvAlgs.contains(paramASN1ObjectIdentifier);
  }
  
  static boolean isDesAlg(ASN1ObjectIdentifier paramASN1ObjectIdentifier)
  {
    return desAlgs.contains(paramASN1ObjectIdentifier);
  }
  
  static PaddedBufferedBlockCipher getEngine(ASN1ObjectIdentifier paramASN1ObjectIdentifier)
  {
    Object localObject;
    if ((paramASN1ObjectIdentifier.equals(PKCSObjectIdentifiers.pbeWithSHAAnd3_KeyTripleDES_CBC)) || (paramASN1ObjectIdentifier.equals(PKCSObjectIdentifiers.pbeWithSHAAnd2_KeyTripleDES_CBC))) {
      localObject = new DESedeEngine();
    } else if ((paramASN1ObjectIdentifier.equals(PKCSObjectIdentifiers.pbeWithSHAAnd128BitRC2_CBC)) || (paramASN1ObjectIdentifier.equals(PKCSObjectIdentifiers.pbeWithSHAAnd40BitRC2_CBC))) {
      localObject = new RC2Engine();
    } else {
      throw new IllegalStateException("unknown algorithm");
    }
    return new PaddedBufferedBlockCipher(new CBCBlockCipher((BlockCipher)localObject), new PKCS7Padding());
  }
  
  static MacCalculator createMacCalculator(ASN1ObjectIdentifier paramASN1ObjectIdentifier, ExtendedDigest paramExtendedDigest, final PKCS12PBEParams paramPKCS12PBEParams, final char[] paramArrayOfChar)
  {
    PKCS12ParametersGenerator localPKCS12ParametersGenerator = new PKCS12ParametersGenerator(paramExtendedDigest);
    localPKCS12ParametersGenerator.init(PKCS12ParametersGenerator.PKCS12PasswordToBytes(paramArrayOfChar), paramPKCS12PBEParams.getIV(), paramPKCS12PBEParams.getIterations().intValue());
    KeyParameter localKeyParameter = (KeyParameter)localPKCS12ParametersGenerator.generateDerivedMacParameters(paramExtendedDigest.getDigestSize() * 8);
    final HMac localHMac = new HMac(paramExtendedDigest);
    localHMac.init(localKeyParameter);
    new MacCalculator()
    {
      public AlgorithmIdentifier getAlgorithmIdentifier()
      {
        return new AlgorithmIdentifier(val$digestAlgorithm, paramPKCS12PBEParams);
      }
      
      public OutputStream getOutputStream()
      {
        return new MacOutputStream(localHMac);
      }
      
      public byte[] getMac()
      {
        byte[] arrayOfByte = new byte[localHMac.getMacSize()];
        localHMac.doFinal(arrayOfByte, 0);
        return arrayOfByte;
      }
      
      public GenericKey getKey()
      {
        return new GenericKey(PKCS12ParametersGenerator.PKCS12PasswordToBytes(paramArrayOfChar));
      }
    };
  }
  
  static CipherParameters createCipherParameters(ASN1ObjectIdentifier paramASN1ObjectIdentifier, ExtendedDigest paramExtendedDigest, int paramInt, PKCS12PBEParams paramPKCS12PBEParams, char[] paramArrayOfChar)
  {
    PKCS12ParametersGenerator localPKCS12ParametersGenerator = new PKCS12ParametersGenerator(paramExtendedDigest);
    localPKCS12ParametersGenerator.init(PKCS12ParametersGenerator.PKCS12PasswordToBytes(paramArrayOfChar), paramPKCS12PBEParams.getIV(), paramPKCS12PBEParams.getIterations().intValue());
    CipherParameters localCipherParameters;
    if (hasNoIv(paramASN1ObjectIdentifier))
    {
      localCipherParameters = localPKCS12ParametersGenerator.generateDerivedParameters(getKeySize(paramASN1ObjectIdentifier));
    }
    else
    {
      localCipherParameters = localPKCS12ParametersGenerator.generateDerivedParameters(getKeySize(paramASN1ObjectIdentifier), paramInt * 8);
      if (isDesAlg(paramASN1ObjectIdentifier)) {
        DESedeParameters.setOddParity(((KeyParameter)((ParametersWithIV)localCipherParameters).getParameters()).getKey());
      }
    }
    return localCipherParameters;
  }
  
  static
  {
    keySizes.put(PKCSObjectIdentifiers.pbeWithSHAAnd128BitRC4, new Integer(128));
    keySizes.put(PKCSObjectIdentifiers.pbeWithSHAAnd40BitRC4, new Integer(40));
    keySizes.put(PKCSObjectIdentifiers.pbeWithSHAAnd3_KeyTripleDES_CBC, new Integer(192));
    keySizes.put(PKCSObjectIdentifiers.pbeWithSHAAnd2_KeyTripleDES_CBC, new Integer(128));
    keySizes.put(PKCSObjectIdentifiers.pbeWithSHAAnd128BitRC2_CBC, new Integer(128));
    keySizes.put(PKCSObjectIdentifiers.pbeWithSHAAnd40BitRC2_CBC, new Integer(40));
    noIvAlgs.add(PKCSObjectIdentifiers.pbeWithSHAAnd128BitRC4);
    noIvAlgs.add(PKCSObjectIdentifiers.pbeWithSHAAnd40BitRC4);
    desAlgs.add(PKCSObjectIdentifiers.pbeWithSHAAnd3_KeyTripleDES_CBC);
    desAlgs.add(PKCSObjectIdentifiers.pbeWithSHAAnd3_KeyTripleDES_CBC);
  }
}

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

import java.io.IOException;
import java.security.InvalidKeyException;
import java.security.KeyFactory;
import java.security.NoSuchAlgorithmException;
import java.security.NoSuchProviderException;
import java.security.Provider;
import java.security.PublicKey;
import java.security.spec.InvalidKeySpecException;
import java.security.spec.X509EncodedKeySpec;
import java.util.Hashtable;
import org.bouncycastle.asn1.ASN1ObjectIdentifier;
import org.bouncycastle.asn1.pkcs.CertificationRequest;
import org.bouncycastle.asn1.pkcs.PKCSObjectIdentifiers;
import org.bouncycastle.asn1.x509.AlgorithmIdentifier;
import org.bouncycastle.asn1.x509.SubjectPublicKeyInfo;
import org.bouncycastle.asn1.x9.X9ObjectIdentifiers;
import org.bouncycastle.jcajce.DefaultJcaJceHelper;
import org.bouncycastle.jcajce.JcaJceHelper;
import org.bouncycastle.jcajce.NamedJcaJceHelper;
import org.bouncycastle.jcajce.ProviderJcaJceHelper;
import org.bouncycastle.pkcs.PKCS10CertificationRequest;

public class JcaPKCS10CertificationRequest
  extends PKCS10CertificationRequest
{
  private static Hashtable keyAlgorithms = new Hashtable();
  private JcaJceHelper helper = new DefaultJcaJceHelper();
  
  public JcaPKCS10CertificationRequest(CertificationRequest paramCertificationRequest)
  {
    super(paramCertificationRequest);
  }
  
  public JcaPKCS10CertificationRequest(byte[] paramArrayOfByte)
    throws IOException
  {
    super(paramArrayOfByte);
  }
  
  public JcaPKCS10CertificationRequest(PKCS10CertificationRequest paramPKCS10CertificationRequest)
  {
    super(paramPKCS10CertificationRequest.toASN1Structure());
  }
  
  public JcaPKCS10CertificationRequest setProvider(String paramString)
  {
    helper = new NamedJcaJceHelper(paramString);
    return this;
  }
  
  public JcaPKCS10CertificationRequest setProvider(Provider paramProvider)
  {
    helper = new ProviderJcaJceHelper(paramProvider);
    return this;
  }
  
  public PublicKey getPublicKey()
    throws InvalidKeyException, NoSuchAlgorithmException
  {
    try
    {
      SubjectPublicKeyInfo localSubjectPublicKeyInfo = getSubjectPublicKeyInfo();
      X509EncodedKeySpec localX509EncodedKeySpec = new X509EncodedKeySpec(localSubjectPublicKeyInfo.getEncoded());
      KeyFactory localKeyFactory;
      try
      {
        localKeyFactory = helper.createKeyFactory(localSubjectPublicKeyInfo.getAlgorithmId().getAlgorithm().getId());
      }
      catch (NoSuchAlgorithmException localNoSuchAlgorithmException)
      {
        if (keyAlgorithms.get(localSubjectPublicKeyInfo.getAlgorithmId().getAlgorithm()) != null)
        {
          String str = (String)keyAlgorithms.get(localSubjectPublicKeyInfo.getAlgorithmId().getAlgorithm());
          localKeyFactory = helper.createKeyFactory(str);
        }
        else
        {
          throw localNoSuchAlgorithmException;
        }
      }
      return localKeyFactory.generatePublic(localX509EncodedKeySpec);
    }
    catch (InvalidKeySpecException localInvalidKeySpecException)
    {
      throw new InvalidKeyException("error decoding public key");
    }
    catch (IOException localIOException)
    {
      throw new InvalidKeyException("error extracting key encoding");
    }
    catch (NoSuchProviderException localNoSuchProviderException)
    {
      throw new NoSuchAlgorithmException("cannot find provider: " + localNoSuchProviderException.getMessage());
    }
  }
  
  static
  {
    keyAlgorithms.put(PKCSObjectIdentifiers.rsaEncryption, "RSA");
    keyAlgorithms.put(X9ObjectIdentifiers.id_dsa, "DSA");
  }
}

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

import java.security.PublicKey;
import javax.security.auth.x500.X500Principal;
import org.bouncycastle.asn1.x500.X500Name;
import org.bouncycastle.asn1.x509.SubjectPublicKeyInfo;
import org.bouncycastle.pkcs.PKCS10CertificationRequestBuilder;

public class JcaPKCS10CertificationRequestBuilder
  extends PKCS10CertificationRequestBuilder
{
  public JcaPKCS10CertificationRequestBuilder(X500Name paramX500Name, PublicKey paramPublicKey)
  {
    super(paramX500Name, SubjectPublicKeyInfo.getInstance(paramPublicKey.getEncoded()));
  }
  
  public JcaPKCS10CertificationRequestBuilder(X500Principal paramX500Principal, PublicKey paramPublicKey)
  {
    super(X500Name.getInstance(paramX500Principal.getEncoded()), SubjectPublicKeyInfo.getInstance(paramPublicKey.getEncoded()));
  }
}

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

import java.io.IOException;
import java.security.PrivateKey;
import java.security.cert.CertificateEncodingException;
import java.security.cert.X509Certificate;
import org.bouncycastle.asn1.pkcs.PrivateKeyInfo;
import org.bouncycastle.asn1.x509.Certificate;
import org.bouncycastle.operator.OutputEncryptor;
import org.bouncycastle.pkcs.PKCS12SafeBagBuilder;
import org.bouncycastle.pkcs.PKCSIOException;

public class JcaPKCS12SafeBagBuilder
  extends PKCS12SafeBagBuilder
{
  public JcaPKCS12SafeBagBuilder(X509Certificate paramX509Certificate)
    throws IOException
  {
    super(convertCert(paramX509Certificate));
  }
  
  private static Certificate convertCert(X509Certificate paramX509Certificate)
    throws IOException
  {
    try
    {
      return Certificate.getInstance(paramX509Certificate.getEncoded());
    }
    catch (CertificateEncodingException localCertificateEncodingException)
    {
      throw new PKCSIOException("cannot encode certificate: " + localCertificateEncodingException.getMessage(), localCertificateEncodingException);
    }
  }
  
  public JcaPKCS12SafeBagBuilder(PrivateKey paramPrivateKey, OutputEncryptor paramOutputEncryptor)
  {
    super(PrivateKeyInfo.getInstance(paramPrivateKey.getEncoded()), paramOutputEncryptor);
  }
  
  public JcaPKCS12SafeBagBuilder(PrivateKey paramPrivateKey)
  {
    super(PrivateKeyInfo.getInstance(paramPrivateKey.getEncoded()));
  }
}

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

import java.security.PrivateKey;
import org.bouncycastle.asn1.pkcs.PrivateKeyInfo;
import org.bouncycastle.pkcs.PKCS8EncryptedPrivateKeyInfoBuilder;

public class JcaPKCS8EncryptedPrivateKeyInfoBuilder
  extends PKCS8EncryptedPrivateKeyInfoBuilder
{
  public JcaPKCS8EncryptedPrivateKeyInfoBuilder(PrivateKey paramPrivateKey)
  {
    super(PrivateKeyInfo.getInstance(paramPrivateKey.getEncoded()));
  }
}

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

import java.math.BigInteger;
import org.bouncycastle.asn1.DERInteger;
import org.bouncycastle.asn1.tsp.Accuracy;

public class GenTimeAccuracy
{
  private Accuracy accuracy;
  
  public GenTimeAccuracy(Accuracy paramAccuracy)
  {
    accuracy = paramAccuracy;
  }
  
  public int getSeconds()
  {
    return getTimeComponent(accuracy.getSeconds());
  }
  
  public int getMillis()
  {
    return getTimeComponent(accuracy.getMillis());
  }
  
  public int getMicros()
  {
    return getTimeComponent(accuracy.getMicros());
  }
  
  private int getTimeComponent(DERInteger paramDERInteger)
  {
    if (paramDERInteger != null) {
      return paramDERInteger.getValue().intValue();
    }
    return 0;
  }
  
  public String toString()
  {
    return getSeconds() + "." + format(getMillis()) + format(getMicros());
  }
  
  private String format(int paramInt)
  {
    if (paramInt < 10) {
      return "00" + paramInt;
    }
    if (paramInt < 100) {
      return "0" + paramInt;
    }
    return Integer.toString(paramInt);
  }
}

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

import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
import org.bouncycastle.asn1.ASN1ObjectIdentifier;
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;

public abstract interface TSPAlgorithms
{
  public static final ASN1ObjectIdentifier MD5 = PKCSObjectIdentifiers.md5;
  public static final ASN1ObjectIdentifier SHA1 = OIWObjectIdentifiers.idSHA1;
  public static final ASN1ObjectIdentifier SHA224 = NISTObjectIdentifiers.id_sha224;
  public static final ASN1ObjectIdentifier SHA256 = NISTObjectIdentifiers.id_sha256;
  public static final ASN1ObjectIdentifier SHA384 = NISTObjectIdentifiers.id_sha384;
  public static final ASN1ObjectIdentifier SHA512 = NISTObjectIdentifiers.id_sha512;
  public static final ASN1ObjectIdentifier RIPEMD128 = TeleTrusTObjectIdentifiers.ripemd128;
  public static final ASN1ObjectIdentifier RIPEMD160 = TeleTrusTObjectIdentifiers.ripemd160;
  public static final ASN1ObjectIdentifier RIPEMD256 = TeleTrusTObjectIdentifiers.ripemd256;
  public static final ASN1ObjectIdentifier GOST3411 = CryptoProObjectIdentifiers.gostR3411;
  public static final Set ALLOWED = new HashSet(Arrays.asList(new ASN1ObjectIdentifier[] { GOST3411, MD5, SHA1, SHA224, SHA256, SHA384, SHA512, RIPEMD128, RIPEMD160, RIPEMD256 }));
}

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

public class TSPException
  extends Exception
{
  Throwable underlyingException;
  
  public TSPException(String paramString)
  {
    super(paramString);
  }
  
  public TSPException(String paramString, Throwable paramThrowable)
  {
    super(paramString);
    underlyingException = paramThrowable;
  }
  
  public Exception getUnderlyingException()
  {
    return (Exception)underlyingException;
  }
  
  public Throwable getCause()
  {
    return underlyingException;
  }
}

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

import java.io.IOException;

public class TSPIOException
  extends IOException
{
  Throwable underlyingException;
  
  public TSPIOException(String paramString)
  {
    super(paramString);
  }
  
  public TSPIOException(String paramString, Throwable paramThrowable)
  {
    super(paramString);
    underlyingException = paramThrowable;
  }
  
  public Exception getUnderlyingException()
  {
    return (Exception)underlyingException;
  }
  
  public Throwable getCause()
  {
    return underlyingException;
  }
}

/* Location:
 * Qualified Name:     org.bouncycastle.tsp.TSPIOException
 * 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.OutputStream;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.security.Provider;
import java.security.cert.X509Certificate;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.bouncycastle.asn1.ASN1Encodable;
import org.bouncycastle.asn1.ASN1EncodableVector;
import org.bouncycastle.asn1.ASN1InputStream;
import org.bouncycastle.asn1.ASN1ObjectIdentifier;
import org.bouncycastle.asn1.ASN1OctetString;
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.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.Certificate;
import org.bouncycastle.asn1.x509.ExtendedKeyUsage;
import org.bouncycastle.asn1.x509.Extension;
import org.bouncycastle.asn1.x509.Extensions;
import org.bouncycastle.asn1.x509.ExtensionsGenerator;
import org.bouncycastle.asn1.x509.KeyPurposeId;
import org.bouncycastle.asn1.x509.X509Extensions;
import org.bouncycastle.cert.X509CertificateHolder;
import org.bouncycastle.cms.SignerInformation;
import org.bouncycastle.operator.DigestCalculator;
import org.bouncycastle.operator.DigestCalculatorProvider;
import org.bouncycastle.operator.OperatorCreationException;

public class TSPUtil
{
  private static Set EMPTY_SET = Collections.unmodifiableSet(new HashSet());
  private static List EMPTY_LIST = Collections.unmodifiableList(new ArrayList());
  private static final Map digestLengths = new HashMap();
  private static final Map digestNames = new HashMap();
  
  /**
   * @deprecated
   */
  public static Collection getSignatureTimestamps(SignerInformation paramSignerInformation, Provider paramProvider)
    throws TSPValidationException
  {
    ArrayList localArrayList = new ArrayList();
    AttributeTable localAttributeTable = paramSignerInformation.getUnsignedAttributes();
    if (localAttributeTable != null)
    {
      ASN1EncodableVector localASN1EncodableVector = localAttributeTable.getAll(PKCSObjectIdentifiers.id_aa_signatureTimeStampToken);
      for (int i = 0; i < localASN1EncodableVector.size(); i++)
      {
        Attribute localAttribute = (Attribute)localASN1EncodableVector.get(i);
        ASN1Set localASN1Set = localAttribute.getAttrValues();
        for (int j = 0; j < localASN1Set.size(); j++) {
          try
          {
            ContentInfo localContentInfo = ContentInfo.getInstance(localASN1Set.getObjectAt(j));
            TimeStampToken localTimeStampToken = new TimeStampToken(localContentInfo);
            TimeStampTokenInfo localTimeStampTokenInfo = localTimeStampToken.getTimeStampInfo();
            MessageDigest localMessageDigest = createDigestInstance(localTimeStampTokenInfo.getMessageImprintAlgOID().getId(), paramProvider);
            byte[] arrayOfByte = localMessageDigest.digest(paramSignerInformation.getSignature());
            if (!org.bouncycastle.util.Arrays.constantTimeAreEqual(arrayOfByte, localTimeStampTokenInfo.getMessageImprintDigest())) {
              throw new TSPValidationException("Incorrect digest in message imprint");
            }
            localArrayList.add(localTimeStampToken);
          }
          catch (NoSuchAlgorithmException localNoSuchAlgorithmException)
          {
            throw new TSPValidationException("Unknown hash algorithm specified in timestamp");
          }
          catch (Exception localException)
          {
            throw new TSPValidationException("Timestamp could not be parsed");
          }
        }
      }
    }
    return localArrayList;
  }
  
  public static Collection getSignatureTimestamps(SignerInformation paramSignerInformation, DigestCalculatorProvider paramDigestCalculatorProvider)
    throws TSPValidationException
  {
    ArrayList localArrayList = new ArrayList();
    AttributeTable localAttributeTable = paramSignerInformation.getUnsignedAttributes();
    if (localAttributeTable != null)
    {
      ASN1EncodableVector localASN1EncodableVector = localAttributeTable.getAll(PKCSObjectIdentifiers.id_aa_signatureTimeStampToken);
      for (int i = 0; i < localASN1EncodableVector.size(); i++)
      {
        Attribute localAttribute = (Attribute)localASN1EncodableVector.get(i);
        ASN1Set localASN1Set = localAttribute.getAttrValues();
        for (int j = 0; j < localASN1Set.size(); j++) {
          try
          {
            ContentInfo localContentInfo = ContentInfo.getInstance(localASN1Set.getObjectAt(j));
            TimeStampToken localTimeStampToken = new TimeStampToken(localContentInfo);
            TimeStampTokenInfo localTimeStampTokenInfo = localTimeStampToken.getTimeStampInfo();
            DigestCalculator localDigestCalculator = paramDigestCalculatorProvider.get(localTimeStampTokenInfo.getHashAlgorithm());
            OutputStream localOutputStream = localDigestCalculator.getOutputStream();
            localOutputStream.write(paramSignerInformation.getSignature());
            localOutputStream.close();
            byte[] arrayOfByte = localDigestCalculator.getDigest();
            if (!org.bouncycastle.util.Arrays.constantTimeAreEqual(arrayOfByte, localTimeStampTokenInfo.getMessageImprintDigest())) {
              throw new TSPValidationException("Incorrect digest in message imprint");
            }
            localArrayList.add(localTimeStampToken);
          }
          catch (OperatorCreationException localOperatorCreationException)
          {
            throw new TSPValidationException("Unknown hash algorithm specified in timestamp");
          }
          catch (Exception localException)
          {
            throw new TSPValidationException("Timestamp could not be parsed");
          }
        }
      }
    }
    return localArrayList;
  }
  
  public static void validateCertificate(X509Certificate paramX509Certificate)
    throws TSPValidationException
  {
    if (paramX509Certificate.getVersion() != 3) {
      throw new IllegalArgumentException("Certificate must have an ExtendedKeyUsage extension.");
    }
    byte[] arrayOfByte = paramX509Certificate.getExtensionValue(X509Extensions.ExtendedKeyUsage.getId());
    if (arrayOfByte == null) {
      throw new TSPValidationException("Certificate must have an ExtendedKeyUsage extension.");
    }
    if (!paramX509Certificate.getCriticalExtensionOIDs().contains(X509Extensions.ExtendedKeyUsage.getId())) {
      throw new TSPValidationException("Certificate must have an ExtendedKeyUsage extension marked as critical.");
    }
    ASN1InputStream localASN1InputStream = new ASN1InputStream(new ByteArrayInputStream(arrayOfByte));
    try
    {
      localASN1InputStream = new ASN1InputStream(new ByteArrayInputStream(((ASN1OctetString)localASN1InputStream.readObject()).getOctets()));
      ExtendedKeyUsage localExtendedKeyUsage = ExtendedKeyUsage.getInstance(localASN1InputStream.readObject());
      if ((!localExtendedKeyUsage.hasKeyPurposeId(KeyPurposeId.id_kp_timeStamping)) || (localExtendedKeyUsage.size() != 1)) {
        throw new TSPValidationException("ExtendedKeyUsage not solely time stamping.");
      }
    }
    catch (IOException localIOException)
    {
      throw new TSPValidationException("cannot process ExtendedKeyUsage extension");
    }
  }
  
  public static void validateCertificate(X509CertificateHolder paramX509CertificateHolder)
    throws TSPValidationException
  {
    if (paramX509CertificateHolder.toASN1Structure().getVersionNumber() != 3) {
      throw new IllegalArgumentException("Certificate must have an ExtendedKeyUsage extension.");
    }
    Extension localExtension = paramX509CertificateHolder.getExtension(Extension.extendedKeyUsage);
    if (localExtension == null) {
      throw new TSPValidationException("Certificate must have an ExtendedKeyUsage extension.");
    }
    if (!localExtension.isCritical()) {
      throw new TSPValidationException("Certificate must have an ExtendedKeyUsage extension marked as critical.");
    }
    ExtendedKeyUsage localExtendedKeyUsage = ExtendedKeyUsage.getInstance(localExtension.getParsedValue());
    if ((!localExtendedKeyUsage.hasKeyPurposeId(KeyPurposeId.id_kp_timeStamping)) || (localExtendedKeyUsage.size() != 1)) {
      throw new TSPValidationException("ExtendedKeyUsage not solely time stamping.");
    }
  }
  
  static String getDigestAlgName(String paramString)
  {
    String str = (String)digestNames.get(paramString);
    if (str != null) {
      return str;
    }
    return paramString;
  }
  
  static int getDigestLength(String paramString)
    throws TSPException
  {
    Integer localInteger = (Integer)digestLengths.get(paramString);
    if (localInteger != null) {
      return localInteger.intValue();
    }
    throw new TSPException("digest algorithm cannot be found.");
  }
  
  static MessageDigest createDigestInstance(String paramString, Provider paramProvider)
    throws NoSuchAlgorithmException
  {
    String str = getDigestAlgName(paramString);
    if (paramProvider != null) {
      try
      {
        return MessageDigest.getInstance(str, paramProvider);
      }
      catch (NoSuchAlgorithmException localNoSuchAlgorithmException) {}
    }
    return MessageDigest.getInstance(str);
  }
  
  static Set getCriticalExtensionOIDs(X509Extensions paramX509Extensions)
  {
    if (paramX509Extensions == null) {
      return EMPTY_SET;
    }
    return Collections.unmodifiableSet(new HashSet(java.util.Arrays.asList(paramX509Extensions.getCriticalExtensionOIDs())));
  }
  
  static Set getNonCriticalExtensionOIDs(X509Extensions paramX509Extensions)
  {
    if (paramX509Extensions == null) {
      return EMPTY_SET;
    }
    return Collections.unmodifiableSet(new HashSet(java.util.Arrays.asList(paramX509Extensions.getNonCriticalExtensionOIDs())));
  }
  
  static List getExtensionOIDs(Extensions paramExtensions)
  {
    if (paramExtensions == null) {
      return EMPTY_LIST;
    }
    return Collections.unmodifiableList(java.util.Arrays.asList(paramExtensions.getExtensionOIDs()));
  }
  
  static void addExtension(ExtensionsGenerator paramExtensionsGenerator, ASN1ObjectIdentifier paramASN1ObjectIdentifier, boolean paramBoolean, ASN1Encodable paramASN1Encodable)
    throws TSPIOException
  {
    try
    {
      paramExtensionsGenerator.addExtension(paramASN1ObjectIdentifier, paramBoolean, paramASN1Encodable);
    }
    catch (IOException localIOException)
    {
      throw new TSPIOException("cannot encode extension: " + localIOException.getMessage(), localIOException);
    }
  }
  
  static
  {
    digestLengths.put(PKCSObjectIdentifiers.md5.getId(), new Integer(16));
    digestLengths.put(OIWObjectIdentifiers.idSHA1.getId(), new Integer(20));
    digestLengths.put(NISTObjectIdentifiers.id_sha224.getId(), new Integer(28));
    digestLengths.put(NISTObjectIdentifiers.id_sha256.getId(), new Integer(32));
    digestLengths.put(NISTObjectIdentifiers.id_sha384.getId(), new Integer(48));
    digestLengths.put(NISTObjectIdentifiers.id_sha512.getId(), new Integer(64));
    digestLengths.put(TeleTrusTObjectIdentifiers.ripemd128.getId(), new Integer(16));
    digestLengths.put(TeleTrusTObjectIdentifiers.ripemd160.getId(), new Integer(20));
    digestLengths.put(TeleTrusTObjectIdentifiers.ripemd256.getId(), new Integer(32));
    digestLengths.put(CryptoProObjectIdentifiers.gostR3411.getId(), new Integer(32));
    digestNames.put(PKCSObjectIdentifiers.md5.getId(), "MD5");
    digestNames.put(OIWObjectIdentifiers.idSHA1.getId(), "SHA1");
    digestNames.put(NISTObjectIdentifiers.id_sha224.getId(), "SHA224");
    digestNames.put(NISTObjectIdentifiers.id_sha256.getId(), "SHA256");
    digestNames.put(NISTObjectIdentifiers.id_sha384.getId(), "SHA384");
    digestNames.put(NISTObjectIdentifiers.id_sha512.getId(), "SHA512");
    digestNames.put(PKCSObjectIdentifiers.sha1WithRSAEncryption.getId(), "SHA1");
    digestNames.put(PKCSObjectIdentifiers.sha224WithRSAEncryption.getId(), "SHA224");
    digestNames.put(PKCSObjectIdentifiers.sha256WithRSAEncryption.getId(), "SHA256");
    digestNames.put(PKCSObjectIdentifiers.sha384WithRSAEncryption.getId(), "SHA384");
    digestNames.put(PKCSObjectIdentifiers.sha512WithRSAEncryption.getId(), "SHA512");
    digestNames.put(TeleTrusTObjectIdentifiers.ripemd128.getId(), "RIPEMD128");
    digestNames.put(TeleTrusTObjectIdentifiers.ripemd160.getId(), "RIPEMD160");
    digestNames.put(TeleTrusTObjectIdentifiers.ripemd256.getId(), "RIPEMD256");
    digestNames.put(CryptoProObjectIdentifiers.gostR3411.getId(), "GOST3411");
  }
}

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

public class TSPValidationException
  extends TSPException
{
  private int failureCode = -1;
  
  public TSPValidationException(String paramString)
  {
    super(paramString);
  }
  
  public TSPValidationException(String paramString, int paramInt)
  {
    super(paramString);
    failureCode = paramInt;
  }
  
  public int getFailureCode()
  {
    return failureCode;
  }
}

/* Location:
 * Qualified Name:     org.bouncycastle.tsp.TSPValidationException
 * 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 java.security.NoSuchProviderException;
import java.util.Arrays;
import java.util.Collections;
import java.util.Enumeration;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
import org.bouncycastle.asn1.ASN1Boolean;
import org.bouncycastle.asn1.ASN1InputStream;
import org.bouncycastle.asn1.ASN1Integer;
import org.bouncycastle.asn1.ASN1ObjectIdentifier;
import org.bouncycastle.asn1.ASN1OctetString;
import org.bouncycastle.asn1.DERObjectIdentifier;
import org.bouncycastle.asn1.tsp.MessageImprint;
import org.bouncycastle.asn1.tsp.TimeStampReq;
import org.bouncycastle.asn1.x509.AlgorithmIdentifier;
import org.bouncycastle.asn1.x509.Extension;
import org.bouncycastle.asn1.x509.Extensions;

public class TimeStampRequest
{
  private static Set EMPTY_SE
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