bcpkix-jdk15on-147

egalArgumentException localIllegalArgumentException)
    {
      throw new EACIOException("malformed data: " + localIllegalArgumentException.getMessage(), localIllegalArgumentException);
    }
    catch (ASN1ParsingException localASN1ParsingException)
    {
      if ((localASN1ParsingException.getCause() instanceof IOException)) {
        throw ((IOException)localASN1ParsingException.getCause());
      }
      throw new EACIOException("malformed data: " + localASN1ParsingException.getMessage(), localASN1ParsingException);
    }
  }
  
  public EACCertificateRequestHolder(byte[] paramArrayOfByte)
    throws IOException
  {
    this(parseBytes(paramArrayOfByte));
  }
  
  public EACCertificateRequestHolder(CVCertificateRequest paramCVCertificateRequest)
  {
    request = paramCVCertificateRequest;
  }
  
  public CVCertificateRequest toASN1Structure()
  {
    return request;
  }
  
  public PublicKeyDataObject getPublicKeyDataObject()
  {
    return request.getPublicKey();
  }
  
  public boolean isInnerSignatureValid(EACSignatureVerifier paramEACSignatureVerifier)
    throws EACException
  {
    try
    {
      OutputStream localOutputStream = paramEACSignatureVerifier.getOutputStream();
      localOutputStream.write(request.getCertificateBody().getEncoded("DER"));
      localOutputStream.close();
      return paramEACSignatureVerifier.verify(request.getInnerSignature());
    }
    catch (Exception localException)
    {
      throw new EACException("unable to process signature: " + localException.getMessage(), localException);
    }
  }
}

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

public class EACException
  extends Exception
{
  private Throwable cause;
  
  public EACException(String paramString, Throwable paramThrowable)
  {
    super(paramString);
    cause = paramThrowable;
  }
  
  public EACException(String paramString)
  {
    super(paramString);
  }
  
  public Throwable getCause()
  {
    return cause;
  }
}

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

import java.io.IOException;

public class EACIOException
  extends IOException
{
  private Throwable cause;
  
  public EACIOException(String paramString, Throwable paramThrowable)
  {
    super(paramString);
    cause = paramThrowable;
  }
  
  public EACIOException(String paramString)
  {
    super(paramString);
  }
  
  public Throwable getCause()
  {
    return cause;
  }
}

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

import java.security.KeyFactory;
import java.security.NoSuchAlgorithmException;

class DefaultEACHelper
  implements EACHelper
{
  public KeyFactory createKeyFactory(String paramString)
    throws NoSuchAlgorithmException
  {
    return KeyFactory.getInstance(paramString);
  }
}

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

import java.security.KeyFactory;
import java.security.NoSuchAlgorithmException;
import java.security.NoSuchProviderException;

abstract interface EACHelper
{
  public abstract KeyFactory createKeyFactory(String paramString)
    throws NoSuchProviderException, NoSuchAlgorithmException;
}

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

import java.math.BigInteger;
import java.security.KeyFactory;
import java.security.NoSuchAlgorithmException;
import java.security.NoSuchProviderException;
import java.security.Provider;
import java.security.PublicKey;
import java.security.interfaces.ECPublicKey;
import java.security.spec.ECField;
import java.security.spec.ECFieldFp;
import java.security.spec.EllipticCurve;
import java.security.spec.InvalidKeySpecException;
import java.security.spec.RSAPublicKeySpec;
import org.bouncycastle.asn1.ASN1ObjectIdentifier;
import org.bouncycastle.asn1.eac.EACObjectIdentifiers;
import org.bouncycastle.asn1.eac.ECDSAPublicKey;
import org.bouncycastle.asn1.eac.PublicKeyDataObject;
import org.bouncycastle.eac.EACException;
import org.bouncycastle.jce.spec.ECPublicKeySpec;
import org.bouncycastle.math.ec.ECCurve;
import org.bouncycastle.math.ec.ECCurve.Fp;

public class JcaPublicKeyConverter
{
  private EACHelper helper = new DefaultEACHelper();
  
  public JcaPublicKeyConverter setProvider(String paramString)
  {
    helper = new NamedEACHelper(paramString);
    return this;
  }
  
  public JcaPublicKeyConverter setProvider(Provider paramProvider)
  {
    helper = new ProviderEACHelper(paramProvider);
    return this;
  }
  
  public PublicKey getKey(PublicKeyDataObject paramPublicKeyDataObject)
    throws EACException, InvalidKeySpecException
  {
    if (paramPublicKeyDataObject.getUsage().on(EACObjectIdentifiers.id_TA_ECDSA)) {
      return getECPublicKeyPublicKey((ECDSAPublicKey)paramPublicKeyDataObject);
    }
    org.bouncycastle.asn1.eac.RSAPublicKey localRSAPublicKey = (org.bouncycastle.asn1.eac.RSAPublicKey)paramPublicKeyDataObject;
    RSAPublicKeySpec localRSAPublicKeySpec = new RSAPublicKeySpec(localRSAPublicKey.getModulus(), localRSAPublicKey.getPublicExponent());
    try
    {
      KeyFactory localKeyFactory = helper.createKeyFactory("RSA");
      return localKeyFactory.generatePublic(localRSAPublicKeySpec);
    }
    catch (NoSuchProviderException localNoSuchProviderException)
    {
      throw new EACException("cannot find provider: " + localNoSuchProviderException.getMessage(), localNoSuchProviderException);
    }
    catch (NoSuchAlgorithmException localNoSuchAlgorithmException)
    {
      throw new EACException("cannot find algorithm ECDSA: " + localNoSuchAlgorithmException.getMessage(), localNoSuchAlgorithmException);
    }
  }
  
  private PublicKey getECPublicKeyPublicKey(ECDSAPublicKey paramECDSAPublicKey)
    throws EACException, InvalidKeySpecException
  {
    org.bouncycastle.jce.spec.ECParameterSpec localECParameterSpec = getParams(paramECDSAPublicKey);
    ECCurve localECCurve = localECParameterSpec.getCurve();
    org.bouncycastle.math.ec.ECPoint localECPoint = localECCurve.decodePoint(paramECDSAPublicKey.getPublicPointY());
    ECPublicKeySpec localECPublicKeySpec = new ECPublicKeySpec(localECPoint, localECParameterSpec);
    KeyFactory localKeyFactory;
    try
    {
      localKeyFactory = helper.createKeyFactory("ECDSA");
    }
    catch (NoSuchProviderException localNoSuchProviderException)
    {
      throw new EACException("cannot find provider: " + localNoSuchProviderException.getMessage(), localNoSuchProviderException);
    }
    catch (NoSuchAlgorithmException localNoSuchAlgorithmException)
    {
      throw new EACException("cannot find algorithm ECDSA: " + localNoSuchAlgorithmException.getMessage(), localNoSuchAlgorithmException);
    }
    return localKeyFactory.generatePublic(localECPublicKeySpec);
  }
  
  private org.bouncycastle.jce.spec.ECParameterSpec getParams(ECDSAPublicKey paramECDSAPublicKey)
  {
    if (!paramECDSAPublicKey.hasParameters()) {
      throw new IllegalArgumentException("Public key does not contains EC Params");
    }
    BigInteger localBigInteger1 = paramECDSAPublicKey.getPrimeModulusP();
    ECCurve.Fp localFp = new ECCurve.Fp(localBigInteger1, paramECDSAPublicKey.getFirstCoefA(), paramECDSAPublicKey.getSecondCoefB());
    org.bouncycastle.math.ec.ECPoint localECPoint = localFp.decodePoint(paramECDSAPublicKey.getBasePointG());
    BigInteger localBigInteger2 = paramECDSAPublicKey.getOrderOfBasePointR();
    BigInteger localBigInteger3 = paramECDSAPublicKey.getCofactorF();
    org.bouncycastle.jce.spec.ECParameterSpec localECParameterSpec = new org.bouncycastle.jce.spec.ECParameterSpec(localFp, localECPoint, localBigInteger2, localBigInteger3);
    return localECParameterSpec;
  }
  
  public PublicKeyDataObject getPublicKeyDataObject(ASN1ObjectIdentifier paramASN1ObjectIdentifier, PublicKey paramPublicKey)
  {
    if ((paramPublicKey instanceof java.security.interfaces.RSAPublicKey))
    {
      localObject = (java.security.interfaces.RSAPublicKey)paramPublicKey;
      return new org.bouncycastle.asn1.eac.RSAPublicKey(paramASN1ObjectIdentifier, ((java.security.interfaces.RSAPublicKey)localObject).getModulus(), ((java.security.interfaces.RSAPublicKey)localObject).getPublicExponent());
    }
    Object localObject = (ECPublicKey)paramPublicKey;
    java.security.spec.ECParameterSpec localECParameterSpec = ((ECPublicKey)localObject).getParams();
    return new ECDSAPublicKey(paramASN1ObjectIdentifier, ((ECFieldFp)localECParameterSpec.getCurve().getField()).getP(), localECParameterSpec.getCurve().getA(), localECParameterSpec.getCurve().getB(), convertPoint(convertCurve(localECParameterSpec.getCurve()), localECParameterSpec.getGenerator(), false).getEncoded(), localECParameterSpec.getOrder(), convertPoint(convertCurve(localECParameterSpec.getCurve()), ((ECPublicKey)localObject).getW(), false).getEncoded(), localECParameterSpec.getCofactor());
  }
  
  private static org.bouncycastle.math.ec.ECPoint convertPoint(ECCurve paramECCurve, java.security.spec.ECPoint paramECPoint, boolean paramBoolean)
  {
    return paramECCurve.createPoint(paramECPoint.getAffineX(), paramECPoint.getAffineY(), paramBoolean);
  }
  
  private static ECCurve convertCurve(EllipticCurve paramEllipticCurve)
  {
    ECField localECField = paramEllipticCurve.getField();
    BigInteger localBigInteger1 = paramEllipticCurve.getA();
    BigInteger localBigInteger2 = paramEllipticCurve.getB();
    if ((localECField instanceof ECFieldFp)) {
      return new ECCurve.Fp(((ECFieldFp)localECField).getP(), localBigInteger1, localBigInteger2);
    }
    throw new IllegalStateException("not implemented yet!!!");
  }
}

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

import java.security.KeyFactory;
import java.security.NoSuchAlgorithmException;
import java.security.NoSuchProviderException;

class NamedEACHelper
  implements EACHelper
{
  private final String providerName;
  
  NamedEACHelper(String paramString)
  {
    providerName = paramString;
  }
  
  public KeyFactory createKeyFactory(String paramString)
    throws NoSuchProviderException, NoSuchAlgorithmException
  {
    return KeyFactory.getInstance(paramString, providerName);
  }
}

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

import java.security.KeyFactory;
import java.security.NoSuchAlgorithmException;
import java.security.Provider;

class ProviderEACHelper
  implements EACHelper
{
  private final Provider provider;
  
  ProviderEACHelper(Provider paramProvider)
  {
    provider = paramProvider;
  }
  
  public KeyFactory createKeyFactory(String paramString)
    throws NoSuchAlgorithmException
  {
    return KeyFactory.getInstance(paramString, provider);
  }
}

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

import java.io.OutputStream;
import org.bouncycastle.asn1.ASN1ObjectIdentifier;

public abstract interface EACSignatureVerifier
{
  public abstract ASN1ObjectIdentifier getUsageIdentifier();
  
  public abstract OutputStream getOutputStream();
  
  public abstract boolean verify(byte[] paramArrayOfByte);
}

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

import java.io.OutputStream;
import org.bouncycastle.asn1.ASN1ObjectIdentifier;

public abstract interface EACSigner
{
  public abstract ASN1ObjectIdentifier getUsageIdentifier();
  
  public abstract OutputStream getOutputStream();
  
  public abstract byte[] getSignature();
}

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

import java.security.NoSuchAlgorithmException;
import java.security.Signature;

class DefaultEACHelper
  extends EACHelper
{
  protected Signature createSignature(String paramString)
    throws NoSuchAlgorithmException
  {
    return Signature.getInstance(paramString);
  }
}

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

import java.security.NoSuchAlgorithmException;
import java.security.NoSuchProviderException;
import java.security.Signature;
import java.util.Hashtable;
import org.bouncycastle.asn1.ASN1ObjectIdentifier;
import org.bouncycastle.asn1.eac.EACObjectIdentifiers;

abstract class EACHelper
{
  private static final Hashtable sigNames = new Hashtable();
  
  public Signature getSignature(ASN1ObjectIdentifier paramASN1ObjectIdentifier)
    throws NoSuchProviderException, NoSuchAlgorithmException
  {
    return createSignature((String)sigNames.get(paramASN1ObjectIdentifier));
  }
  
  protected abstract Signature createSignature(String paramString)
    throws NoSuchProviderException, NoSuchAlgorithmException;
  
  static
  {
    sigNames.put(EACObjectIdentifiers.id_TA_RSA_v1_5_SHA_1, "SHA1withRSA");
    sigNames.put(EACObjectIdentifiers.id_TA_RSA_v1_5_SHA_256, "SHA256withRSA");
    sigNames.put(EACObjectIdentifiers.id_TA_RSA_PSS_SHA_1, "SHA1withRSAandMGF1");
    sigNames.put(EACObjectIdentifiers.id_TA_RSA_PSS_SHA_256, "SHA256withRSAandMGF1");
    sigNames.put(EACObjectIdentifiers.id_TA_RSA_v1_5_SHA_512, "SHA512withRSA");
    sigNames.put(EACObjectIdentifiers.id_TA_RSA_PSS_SHA_512, "SHA512withRSAandMGF1");
    sigNames.put(EACObjectIdentifiers.id_TA_ECDSA_SHA_1, "SHA1withECDSA");
    sigNames.put(EACObjectIdentifiers.id_TA_ECDSA_SHA_224, "SHA224withECDSA");
    sigNames.put(EACObjectIdentifiers.id_TA_ECDSA_SHA_256, "SHA256withECDSA");
    sigNames.put(EACObjectIdentifiers.id_TA_ECDSA_SHA_384, "SHA384withECDSA");
    sigNames.put(EACObjectIdentifiers.id_TA_ECDSA_SHA_512, "SHA512withECDSA");
  }
}

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

class EACUtil {}

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

import java.io.OutputStream;
import java.security.SignatureException;
import org.bouncycastle.asn1.ASN1ObjectIdentifier;
import org.bouncycastle.asn1.eac.EACObjectIdentifiers;
import org.bouncycastle.eac.operator.EACSignatureVerifier;
import org.bouncycastle.operator.RuntimeOperatorException;

class JcaEACSignatureVerifierBuilder$1
  implements EACSignatureVerifier
{
  JcaEACSignatureVerifierBuilder$1(JcaEACSignatureVerifierBuilder paramJcaEACSignatureVerifierBuilder, ASN1ObjectIdentifier paramASN1ObjectIdentifier, JcaEACSignatureVerifierBuilder.SignatureOutputStream paramSignatureOutputStream) {}
  
  public ASN1ObjectIdentifier getUsageIdentifier()
  {
    return val$usageOid;
  }
  
  public OutputStream getOutputStream()
  {
    return val$sigStream;
  }
  
  public boolean verify(byte[] paramArrayOfByte)
  {
    try
    {
      if (val$usageOid.on(EACObjectIdentifiers.id_TA_ECDSA)) {
        try
        {
          byte[] arrayOfByte = JcaEACSignatureVerifierBuilder.access$000(paramArrayOfByte);
          return val$sigStream.verify(arrayOfByte);
        }
        catch (Exception localException)
        {
          return false;
        }
      }
      return val$sigStream.verify(paramArrayOfByte);
    }
    catch (SignatureException localSignatureException)
    {
      throw new RuntimeOperatorException("exception obtaining signature: " + localSignatureException.getMessage(), localSignatureException);
    }
  }
}

/* Location:
 * Qualified Name:     org.bouncycastle.eac.operator.jcajce.JcaEACSignatureVerifierBuilder.1
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.bouncycastle.eac.operator.jcajce;

import java.io.IOException;
import java.io.OutputStream;
import java.security.Signature;
import java.security.SignatureException;
import org.bouncycastle.operator.OperatorStreamException;

class JcaEACSignatureVerifierBuilder$SignatureOutputStream
  extends OutputStream
{
  private Signature sig;
  
  JcaEACSignatureVerifierBuilder$SignatureOutputStream(JcaEACSignatureVerifierBuilder paramJcaEACSignatureVerifierBuilder, Signature paramSignature)
  {
    sig = paramSignature;
  }
  
  public void write(byte[] paramArrayOfByte, int paramInt1, int paramInt2)
    throws IOException
  {
    try
    {
      sig.update(paramArrayOfByte, paramInt1, paramInt2);
    }
    catch (SignatureException localSignatureException)
    {
      throw new OperatorStreamException("exception in content signer: " + localSignatureException.getMessage(), localSignatureException);
    }
  }
  
  public void write(byte[] paramArrayOfByte)
    throws IOException
  {
    try
    {
      sig.update(paramArrayOfByte);
    }
    catch (SignatureException localSignatureException)
    {
      throw new OperatorStreamException("exception in content signer: " + localSignatureException.getMessage(), localSignatureException);
    }
  }
  
  public void write(int paramInt)
    throws IOException
  {
    try
    {
      sig.update((byte)paramInt);
    }
    catch (SignatureException localSignatureException)
    {
      throw new OperatorStreamException("exception in content signer: " + localSignatureException.getMessage(), localSignatureException);
    }
  }
  
  boolean verify(byte[] paramArrayOfByte)
    throws SignatureException
  {
    return sig.verify(paramArrayOfByte);
  }
}

/* Location:
 * Qualified Name:     org.bouncycastle.eac.operator.jcajce.JcaEACSignatureVerifierBuilder.SignatureOutputStream
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.bouncycastle.eac.operator.jcajce;

import java.io.IOException;
import java.io.OutputStream;
import java.math.BigInteger;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.security.NoSuchProviderException;
import java.security.Provider;
import java.security.PublicKey;
import java.security.Signature;
import java.security.SignatureException;
import org.bouncycastle.asn1.ASN1EncodableVector;
import org.bouncycastle.asn1.ASN1ObjectIdentifier;
import org.bouncycastle.asn1.DERInteger;
import org.bouncycastle.asn1.DERSequence;
import org.bouncycastle.asn1.eac.EACObjectIdentifiers;
import org.bouncycastle.eac.operator.EACSignatureVerifier;
import org.bouncycastle.operator.OperatorCreationException;
import org.bouncycastle.operator.OperatorStreamException;
import org.bouncycastle.operator.RuntimeOperatorException;

public class JcaEACSignatureVerifierBuilder
{
  private EACHelper helper = new DefaultEACHelper();
  
  public JcaEACSignatureVerifierBuilder setProvider(String paramString)
  {
    helper = new NamedEACHelper(paramString);
    return this;
  }
  
  public JcaEACSignatureVerifierBuilder setProvider(Provider paramProvider)
  {
    helper = new ProviderEACHelper(paramProvider);
    return this;
  }
  
  public EACSignatureVerifier build(final ASN1ObjectIdentifier paramASN1ObjectIdentifier, PublicKey paramPublicKey)
    throws OperatorCreationException
  {
    Signature localSignature;
    try
    {
      localSignature = helper.getSignature(paramASN1ObjectIdentifier);
      localSignature.initVerify(paramPublicKey);
    }
    catch (NoSuchAlgorithmException localNoSuchAlgorithmException)
    {
      throw new OperatorCreationException("unable to find algorithm: " + localNoSuchAlgorithmException.getMessage(), localNoSuchAlgorithmException);
    }
    catch (NoSuchProviderException localNoSuchProviderException)
    {
      throw new OperatorCreationException("unable to find provider: " + localNoSuchProviderException.getMessage(), localNoSuchProviderException);
    }
    catch (InvalidKeyException localInvalidKeyException)
    {
      throw new OperatorCreationException("invalid key: " + localInvalidKeyException.getMessage(), localInvalidKeyException);
    }
    final SignatureOutputStream localSignatureOutputStream = new SignatureOutputStream(localSignature);
    new EACSignatureVerifier()
    {
      public ASN1ObjectIdentifier getUsageIdentifier()
      {
        return paramASN1ObjectIdentifier;
      }
      
      public OutputStream getOutputStream()
      {
        return localSignatureOutputStream;
      }
      
      public boolean verify(byte[] paramAnonymousArrayOfByte)
      {
        try
        {
          if (paramASN1ObjectIdentifier.on(EACObjectIdentifiers.id_TA_ECDSA)) {
            try
            {
              byte[] arrayOfByte = JcaEACSignatureVerifierBuilder.derEncode(paramAnonymousArrayOfByte);
              return localSignatureOutputStream.verify(arrayOfByte);
            }
            catch (Exception localException)
            {
              return false;
            }
          }
          return localSignatureOutputStream.verify(paramAnonymousArrayOfByte);
        }
        catch (SignatureException localSignatureException)
        {
          throw new RuntimeOperatorException("exception obtaining signature: " + localSignatureException.getMessage(), localSignatureException);
        }
      }
    };
  }
  
  private static byte[] derEncode(byte[] paramArrayOfByte)
    throws IOException
  {
    int i = paramArrayOfByte.length / 2;
    byte[] arrayOfByte1 = new byte[i];
    byte[] arrayOfByte2 = new byte[i];
    System.arraycopy(paramArrayOfByte, 0, arrayOfByte1, 0, i);
    System.arraycopy(paramArrayOfByte, i, arrayOfByte2, 0, i);
    ASN1EncodableVector localASN1EncodableVector = new ASN1EncodableVector();
    localASN1EncodableVector.add(new DERInteger(new BigInteger(1, arrayOfByte1)));
    localASN1EncodableVector.add(new DERInteger(new BigInteger(1, arrayOfByte2)));
    DERSequence localDERSequence = new DERSequence(localASN1EncodableVector);
    return localDERSequence.getEncoded();
  }
  
  private class SignatureOutputStream
    extends OutputStream
  {
    private Signature sig;
    
    SignatureOutputStream(Signature paramSignature)
    {
      sig = paramSignature;
    }
    
    public void write(byte[] paramArrayOfByte, int paramInt1, int paramInt2)
      throws IOException
    {
      try
      {
        sig.update(paramArrayOfByte, paramInt1, paramInt2);
      }
      catch (SignatureException localSignatureException)
      {
        throw new OperatorStreamException("exception in content signer: " + localSignatureException.getMessage(), localSignatureException);
      }
    }
    
    public void write(byte[] paramArrayOfByte)
      throws IOException
    {
      try
      {
        sig.update(paramArrayOfByte);
      }
      catch (SignatureException localSignatureException)
      {
        throw new OperatorStreamException("exception in content signer: " + localSignatureException.getMessage(), localSignatureException);
      }
    }
    
    public void write(int paramInt)
      throws IOException
    {
      try
      {
        sig.update((byte)paramInt);
      }
      catch (SignatureException localSignatureException)
      {
        throw new OperatorStreamException("exception in content signer: " + localSignatureException.getMessage(), localSignatureException);
      }
    }
    
    boolean verify(byte[] paramArrayOfByte)
      throws SignatureException
    {
      return sig.verify(paramArrayOfByte);
    }
  }
}

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

import java.io.OutputStream;
import java.security.SignatureException;
import org.bouncycastle.asn1.ASN1ObjectIdentifier;
import org.bouncycastle.asn1.eac.EACObjectIdentifiers;
import org.bouncycastle.eac.operator.EACSigner;
import org.bouncycastle.operator.RuntimeOperatorException;

class JcaEACSignerBuilder$1
  implements EACSigner
{
  JcaEACSignerBuilder$1(JcaEACSignerBuilder paramJcaEACSignerBuilder, ASN1ObjectIdentifier paramASN1ObjectIdentifier, JcaEACSignerBuilder.SignatureOutputStream paramSignatureOutputStream) {}
  
  public ASN1ObjectIdentifier getUsageIdentifier()
  {
    return val$usageOid;
  }
  
  public OutputStream getOutputStream()
  {
    return val$sigStream;
  }
  
  public byte[] getSignature()
  {
    try
    {
      byte[] arrayOfByte = val$sigStream.getSignature();
      if (val$usageOid.on(EACObjectIdentifiers.id_TA_ECDSA)) {
        return JcaEACSignerBuilder.access$000(arrayOfByte);
      }
      return arrayOfByte;
    }
    catch (SignatureException localSignatureException)
    {
      throw new RuntimeOperatorException("exception obtaining signature: " + localSignatureException.getMessage(), localSignatureException);
    }
  }
}

/* Location:
 * Qualified Name:     org.bouncycastle.eac.operator.jcajce.JcaEACSignerBuilder.1
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.bouncycastle.eac.operator.jcajce;

import java.io.IOException;
import java.io.OutputStream;
import java.security.Signature;
import java.security.SignatureException;
import org.bouncycastle.operator.OperatorStreamException;

class JcaEACSignerBuilder$SignatureOutputStream
  extends OutputStream
{
  private Signature sig;
  
  JcaEACSignerBuilder$SignatureOutputStream(JcaEACSignerBuilder paramJcaEACSignerBuilder, Signature paramSignature)
  {
    sig = paramSignature;
  }
  
  public void write(byte[] paramArrayOfByte, int paramInt1, int paramInt2)
    throws IOException
  {
    try
    {
      sig.update(paramArrayOfByte, paramInt1, paramInt2);
    }
    catch (SignatureException localSignatureException)
    {
      throw new OperatorStreamException("exception in content signer: " + localSignatureException.getMessage(), localSignatureException);
    }
  }
  
  public void write(byte[] paramArrayOfByte)
    throws IOException
  {
    try
    {
      sig.update(paramArrayOfByte);
    }
    catch (SignatureException localSignatureException)
    {
      throw new OperatorStreamException("exception in content signer: " + localSignatureException.getMessage(), localSignatureException);
    }
  }
  
  public void write(int paramInt)
    throws IOException
  {
    try
    {
      sig.update((byte)paramInt);
    }
    catch (SignatureException localSignatureException)
    {
      throw new OperatorStreamException("exception in content signer: " + localSignatureException.getMessage(), localSignatureException);
    }
  }
  
  byte[] getSignature()
    throws SignatureException
  {
    return sig.sign();
  }
}

/* Location:
 * Qualified Name:     org.bouncycastle.eac.operator.jcajce.JcaEACSignerBuilder.SignatureOutputStream
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.bouncycastle.eac.operator.jcajce;

import java.io.IOException;
import java.io.OutputStream;
import java.math.BigInteger;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.security.NoSuchProviderException;
import java.security.PrivateKey;
import java.security.Provider;
import java.security.Signature;
import java.security.SignatureException;
import java.util.Arrays;
import java.util.Hashtable;
import org.bouncycastle.asn1.ASN1Integer;
import org.bouncycastle.asn1.ASN1ObjectIdentifier;
import org.bouncycastle.asn1.ASN1Sequence;
import org.bouncycastle.asn1.eac.EACObjectIdentifiers;
import org.bouncycastle.eac.operator.EACSigner;
import org.bouncycastle.operator.OperatorCreationException;
import org.bouncycastle.operator.OperatorStreamException;
import org.bouncycastle.operator.RuntimeOperatorException;

public class JcaEACSignerBuilder
{
  private static final Hashtable sigNames = new Hashtable();
  private EACHelper helper = new DefaultEACHelper();
  
  public JcaEACSignerBuilder setProvider(String paramString)
  {
    helper = new NamedEACHelper(paramString);
    return this;
  }
  
  public JcaEACSignerBuilder setProvider(Provider paramProvider)
  {
    helper = new ProviderEACHelper(paramProvider);
    return this;
  }
  
  public EACSigner build(String paramString, PrivateKey paramPrivateKey)
    throws OperatorCreationException
  {
    return build((ASN1ObjectIdentifier)sigNames.get(paramString), paramPrivateKey);
  }
  
  public EACSigner build(final ASN1ObjectIdentifier paramASN1ObjectIdentifier, PrivateKey paramPrivateKey)
    throws OperatorCreationException
  {
    Signature localSignature;
    try
    {
      localSignature = helper.getSignature(paramASN1ObjectIdentifier);
      localSignature.initSign(paramPrivateKey);
    }
    catch (NoSuchAlgorithmException localNoSuchAlgorithmException)
    {
      throw new OperatorCreationException("unable to find algorithm: " + localNoSuchAlgorithmException.getMessage(), localNoSuchAlgorithmException);
    }
    catch (NoSuchProviderException localNoSuchProviderException)
    {
      throw new OperatorCreationException("unable to find provider: " + localNoSuchProviderException.getMessage(), localNoSuchProviderException);
    }
    catch (InvalidKeyException localInvalidKeyException)
    {
      throw new OperatorCreationException("invalid key: " + localInvalidKeyException.getMessage(), localInvalidKeyException);
    }
    final SignatureOutputStream localSignatureOutputStream = new SignatureOutputStream(localSignature);
    new EACSigner()
    {
      public ASN1ObjectIdentifier getUsageIdentifier()
      {
        return paramASN1ObjectIdentifier;
      }
      
      public OutputStream getOutputStream()
      {
        return localSignatureOutputStream;
      }
      
      public byte[] getSignature()
      {
        try
        {
          byte[] arrayOfByte = localSignatureOutputStream.getSignature();
          if (paramASN1ObjectIdentifier.on(EACObjectIdentifiers.id_TA_ECDSA)) {
            return JcaEACSignerBuilder.reencode(arrayOfByte);
          }
          return arrayOfByte;
        }
        catch (SignatureException localSignatureException)
        {
          throw new RuntimeOperatorException("exception obtaining signature: " + localSignatureException.getMessage(), localSignatureException);
        }
      }
    };
  }
  
  public static int max(int paramInt1, int paramInt2)
  {
    return paramInt1 > paramInt2 ? paramInt1 : paramInt2;
  }
  
  private static byte[] reencode(byte[] paramArrayOfByte)
  {
    ASN1Sequence localASN1Sequence = ASN1Sequence.getInstance(paramArrayOfByte);
    BigInteger localBigInteger1 = ASN1Integer.getInstance(localASN1Sequence.getObjectAt(0)).getValue();
    BigInteger localBigInteger2 = ASN1Integer.getInstance(localASN1Sequence.getObjectAt(1)).getValue();
    byte[] arrayOfByte1 = localBigInteger1.toByteArray();
    byte[] arrayOfByte2 = localBigInteger2.toByteArray();
    int i = unsignedIntLength(arrayOfByte1);
    int j = unsignedIntLength(arrayOfByte2);
    int k = max(i, j);
    byte[] arrayOfByte3 = new byte[k * 2];
    Arrays.fill(arrayOfByte3, (byte)0);
    copyUnsignedInt(arrayOfByte1, arrayOfByte3, k - i);
    copyUnsignedInt(arrayOfByte2, arrayOfByte3, 2 * k - j);
    return arrayOfByte3;
  }
  
  private static int unsignedIntLength(byte[] paramArrayOfByte)
  {
    int i = paramArrayOfByte.length;
    if (paramArrayOfByte[0] == 0) {
      i--;
    }
    return i;
  }
  
  private static void copyUnsignedInt(byte[] paramArrayOfByte1, byte[] paramArrayOfByte2, int paramInt)
  {
    int i = paramArrayOfByte1.length;
    int j = 0;
    if (paramArrayOfByte1[0] == 0)
    {
      i--;
      j = 1;
    }
    System.arraycopy(paramArrayOfByte1, j, paramArrayOfByte2, paramInt, i);
  }
  
  static
  {
    sigNames.put("SHA1withRSA", EACObjectIdentifiers.id_TA_RSA_v1_5_SHA_1);
    sigNames.put("SHA256withRSA", EACObjectIdentifiers.id_TA_RSA_v1_5_SHA_256);
    sigNames.put("SHA1withRSAandMGF1", EACObjectIdentifiers.id_TA_RSA_PSS_SHA_1);
    sigNames.put("SHA256withRSAandMGF1", EACObjectIdentifiers.id_TA_RSA_PSS_SHA_256);
    sigNames.put("SHA512withRSA", EACObjectIdentifiers.id_TA_RSA_v1_5_SHA_512);
    sigNames.put("SHA512withRSAandMGF1", EACObjectIdentifiers.id_TA_RSA_PSS_SHA_512);
    sigNames.put("SHA1withECDSA", EACObjectIdentifiers.id_TA_ECDSA_SHA_1);
    sigNames.put("SHA224withECDSA", EACObjectIdentifiers.id_TA_ECDSA_SHA_224);
    sigNames.put("SHA256withECDSA", EACObjectIdentifiers.id_TA_ECDSA_SHA_256);
    sigNames.put("SHA384withECDSA", EACObjectIdentifiers.id_TA_ECDSA_SHA_384);
    sigNames.put("SHA512withECDSA", EACObjectIdentifiers.id_TA_ECDSA_SHA_512);
  }
  
  private class SignatureOutputStream
    extends OutputStream
  {
    private Signature sig;
    
    SignatureOutputStream(Signature paramSignature)
    {
      sig = paramSignature;
    }
    
    public void write(byte[] paramArrayOfByte, int paramInt1, int paramInt2)
      throws IOException
    {
      try
      {
        sig.update(paramArrayOfByte, paramInt1, paramInt2);
      }
      catch (SignatureException localSignatureException)
      {
        throw new OperatorStreamException("exception in content signer: " + localSignatureException.getMessage(), localSignatureException);
      }
    }
    
    public void write(byte[] paramArrayOfByte)
      throws IOException
    {
      try
      {
        sig.update(paramArrayOfByte);
      }
      catch (SignatureException localSignatureException)
      {
        throw new OperatorStreamException("exception in content signer: " + localSignatureException.getMessage(), localSignatureException);
      }
    }
    
    public void write(int paramInt)
      throws IOException
    {
      try
      {
        sig.update((byte)paramInt);
      }
      catch (SignatureException localSignatureException)
      {
        throw new OperatorStreamException("exception in content signer: " + localSignatureException.getMessage(), localSignatureException);
      }
    }
    
    byte[] getSignature()
      throws SignatureException
    {
      return sig.sign();
    }
  }
}

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

import java.security.NoSuchAlgorithmException;
import java.security.NoSuchProviderException;
import java.security.Signature;

class NamedEACHelper
  extends EACHelper
{
  private final String providerName;
  
  NamedEACHelper(String paramString)
  {
    providerName = paramString;
  }
  
  protected Signature createSignature(String paramString)
    throws NoSuchProviderException, NoSuchAlgorithmException
  {
    return Signature.getInstance(paramString, providerName);
  }
}

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

import java.security.NoSuchAlgorithmException;
import java.security.Provider;
import java.security.Signature;

class ProviderEACHelper
  extends EACHelper
{
  private final Provider provider;
  
  ProviderEACHelper(Provider paramProvider)
  {
    provider = paramProvider;
  }
  
  protected Signature createSignature(String paramString)
    throws NoSuchAlgorithmException
  {
    return Signature.getInstance(paramString, provider);
  }
}

/* Location:
 * Qualified Name:     org.bouncycastle.eac.operator.jcajce.ProviderEACHelper
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.bouncycastle.mozilla;

import java.io.ByteArrayInputStream;
import java.security.InvalidKeyException;
import java.security.KeyFactory;
import java.security.NoSuchAlgorithmException;
import java.security.NoSuchProviderException;
import java.security.PublicKey;
import java.security.Signature;
import java.security.SignatureException;
import java.security.spec.InvalidKeySpecException;
import java.security.spec.X509EncodedKeySpec;
import org.bouncycastle.asn1.ASN1InputStream;
import org.bouncycastle.asn1.ASN1Object;
import org.bouncycastle.asn1.ASN1ObjectIdentifier;
import org.bouncycastle.asn1.ASN1Primitive;
import org.bouncycastle.asn1.ASN1Sequence;
import org.bouncycastle.asn1.DERBitString;
import org.bouncycastle.asn1.mozilla.PublicKeyAndChallenge;
import org.bouncycastle.asn1.x509.AlgorithmIdentifier;
import org.bouncycastle.asn1.x509.SubjectPublicKeyInfo;

public class SignedPublicKeyAndChallenge
  extends ASN1Object
{
  private ASN1Sequence spkacSeq;
  private PublicKeyAndChallenge pkac;
  private AlgorithmIdentifier signatureAlgorithm;
  private DERBitString signature;
  
  private static ASN1Sequence toDERSequence(byte[] paramArrayOfByte)
  {
    try
    {
      ByteArrayInputStream localByteArrayInputStream = new ByteArrayInputStream(paramArrayOfByte);
      ASN1InputStream localASN1InputStream = new ASN1InputStream(localByteArrayInputStream);
      return (ASN1Sequence)localASN1InputStream.readObject();
    }
    catch (Exception localException)
    {
      throw new IllegalArgumentException("badly encoded request");
    }
  }
  
  public SignedPublicKeyAndChallenge(byte[] paramArrayOfByte)
  {
    spkacSeq = toDERSequence(paramArrayOfByte);
    pkac = PublicKeyAndChallenge.getInstance(spkacSeq.getObjectAt(0));
    signatureAlgorithm = AlgorithmIdentifier.getInstance(spkacSeq.getObjectAt(1));
    signature = ((DERBitString)spkacSeq.getObjectAt(2));
  }
  
  public ASN1Primitive toASN1Primitive()
  {
    return spkacSeq;
  }
  
  public PublicKeyAndChallenge getPublicKeyAndChallenge()
  {
    return pkac;
  }
  
  public boolean verify()
    throws NoSuchAlgorithmException, SignatureException, NoSuchProviderException, InvalidKeyException
  {
    return verify(null);
  }
  
  public boolean verify(String paramString)
    throws NoSuchAlgorithmException, SignatureException, NoSuchProviderException, InvalidKeyException
  {
    Signature localSignature = null;
    if (paramString == null) {
      localSignature = Signature.getInstance(signatureAlgorithm.getObjectId().getId());
    } else {
      localSignature = Signature.getInstance(signatureAlgorithm.getObjectId().getId(), paramString);
    }
    PublicKey localPublicKey = getPublicKey(paramString);
    localSignature.initVerify(localPublicKey);
    DERBitString localDERBitString = new DERBitString(pkac);
    localSignature.update(localDERBitString.getBytes());
    return localSignature.verify(signature.getBytes());
  }
  
  public PublicKey getPublicKey(String paramString)
    throws NoSuchAlgorithmException, NoSuchProviderException, InvalidKeyException
  {
    SubjectPublicKeyInfo localSubjectPublicKeyInfo = pkac.getSubjectPublicKeyInfo();
    try
    {
      DERBitString localDERBitString = new DERBitString(localSubjectPublicKeyInfo);
      X509EncodedKeySpec localX509EncodedKeySpec = new X509EncodedKeySpec(localDERBitString.getBytes());
      AlgorithmIdentifier localAlgorithmIdentifier = localSubjectPublicKeyInfo.getAlgorithmId();
      KeyFactory localKeyFactory = KeyFactory.getInstance(localAlgorithmIdentifier.getObjectId().getId(), paramString);
      return localKeyFactory.generatePublic(localX509EncodedKeySpec);
    }
    catch (InvalidKeySpecException localInvalidKeySpecException)
    {
      
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