sunmscapi

16:53:20.253 INFO  jd.cli.Main - Decompiling sunmscapi.jar
package sun.security.mscapi;

import java.net.JarURLConnection;
import java.net.URL;
import java.security.PrivilegedExceptionAction;

class JarVerifierImpl$1
  implements PrivilegedExceptionAction
{
  JarVerifierImpl$1(JarVerifierImpl paramJarVerifierImpl, URL paramURL) {}
  
  public Object run()
    throws Exception
  {
    JarURLConnection localJarURLConnection = (JarURLConnection)val$url.openConnection();
    
    return localJarURLConnection.getJarFile();
  }
}

/* Location:
 * Qualified Name:     sun.security.mscapi.JarVerifierImpl.1
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package sun.security.mscapi;

import java.security.CodeSource;
import java.security.PrivilegedAction;
import java.security.ProtectionDomain;

final class JarVerifierImpl$2
  implements PrivilegedAction
{
  JarVerifierImpl$2(Class paramClass) {}
  
  public Object run()
  {
    CodeSource localCodeSource = val$cc.getProtectionDomain().getCodeSource();
    return localCodeSource.getLocation();
  }
}

/* Location:
 * Qualified Name:     sun.security.mscapi.JarVerifierImpl.2
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package sun.security.mscapi;

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.JarURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.security.AccessController;
import java.security.CodeSource;
import java.security.NoSuchProviderException;
import java.security.PrivilegedAction;
import java.security.PrivilegedActionException;
import java.security.PrivilegedExceptionAction;
import java.security.ProtectionDomain;
import java.security.cert.Certificate;
import java.security.cert.CertificateException;
import java.security.cert.CertificateFactory;
import java.security.cert.X509Certificate;
import java.util.Enumeration;
import java.util.Vector;
import java.util.jar.Attributes;
import java.util.jar.Attributes.Name;
import java.util.jar.JarEntry;
import java.util.jar.JarException;
import java.util.jar.JarFile;
import java.util.jar.Manifest;
import java.util.zip.ZipEntry;

final class JarVerifierImpl
{
  private static final boolean debug = false;
  private URL jarURL;
  
  JarVerifierImpl(URL paramURL)
  {
    jarURL = paramURL;
  }
  
  void verify(X509Certificate paramX509Certificate)
    throws JarException, IOException
  {
    try
    {
      verifyJars(jarURL, null, paramX509Certificate);
    }
    catch (NoSuchProviderException localNoSuchProviderException)
    {
      throw new JarException("Cannot verify " + jarURL.toString());
    }
    catch (CertificateException localCertificateException)
    {
      throw new JarException("Cannot verify " + jarURL.toString());
    }
  }
  
  private void verifyJars(URL paramURL, Vector paramVector, X509Certificate paramX509Certificate)
    throws NoSuchProviderException, CertificateException, IOException
  {
    String str1 = paramURL.toString();
    if ((paramVector == null) || (!paramVector.contains(str1)))
    {
      String str2 = verifySingleJar(paramURL, paramX509Certificate);
      if (paramVector != null) {
        paramVector.addElement(str1);
      }
      if (str2 != null)
      {
        if (paramVector == null)
        {
          paramVector = new Vector();
          paramVector.addElement(str1);
        }
        verifyManifestClassPathJars(paramURL, str2, paramVector, paramX509Certificate);
      }
    }
  }
  
  private void verifyManifestClassPathJars(URL paramURL, String paramString, Vector paramVector, X509Certificate paramX509Certificate)
    throws NoSuchProviderException, CertificateException, IOException
  {
    String[] arrayOfString = parseAttrClasspath(paramString);
    try
    {
      for (int i = 0; i < arrayOfString.length; i++)
      {
        localObject = new URL(paramURL, arrayOfString[i]);
        verifyJars((URL)localObject, paramVector, paramX509Certificate);
      }
    }
    catch (MalformedURLException localMalformedURLException)
    {
      Object localObject = new MalformedURLException("The JAR file " + paramURL.toString() + " contains invalid URLs in its Class-Path attribute");
      
      ((MalformedURLException)localObject).initCause(localMalformedURLException);
      throw ((Throwable)localObject);
    }
  }
  
  private String verifySingleJar(URL paramURL, X509Certificate paramX509Certificate)
    throws NoSuchProviderException, CertificateException, IOException
  {
    final URL localURL = paramURL.getProtocol().equalsIgnoreCase("jar") ? paramURL : new URL("jar:" + paramURL.toString() + "!/");
    
    JarFile localJarFile = null;
    try
    {
      try
      {
        localJarFile = (JarFile)AccessController.doPrivileged(new PrivilegedExceptionAction()
        {
          public Object run()
            throws Exception
          {
            JarURLConnection localJarURLConnection = (JarURLConnection)localURL.openConnection();
            
            return localJarURLConnection.getJarFile();
          }
        });
      }
      catch (PrivilegedActionException localPrivilegedActionException)
      {
        localObject1 = new SecurityException("Cannot verify " + localURL.toString());
        
        ((SecurityException)localObject1).initCause(localPrivilegedActionException);
        throw ((Throwable)localObject1);
      }
      byte[] arrayOfByte = new byte['?'];
      Object localObject1 = new Vector();
      
      Enumeration localEnumeration = localJarFile.entries();
      while (localEnumeration.hasMoreElements())
      {
        localObject2 = (JarEntry)localEnumeration.nextElement();
        ((Vector)localObject1).addElement(localObject2);
        localObject3 = localJarFile.getInputStream((ZipEntry)localObject2);
        try
        {
          int i;
          while ((i = ((InputStream)localObject3).read(arrayOfByte, 0, arrayOfByte.length)) != -1) {}
        }
        finally
        {
          ((InputStream)localObject3).close();
        }
      }
      Object localObject2 = localJarFile.getManifest();
      if (localObject2 == null) {
        throw new JarException(paramURL.toString() + " is not signed.");
      }
      Object localObject3 = localJarFile.entries();
      Object localObject4;
      while (((Enumeration)localObject3).hasMoreElements())
      {
        localObject4 = (JarEntry)((Enumeration)localObject3).nextElement();
        if (!((JarEntry)localObject4).isDirectory())
        {
          Certificate[] arrayOfCertificate = ((JarEntry)localObject4).getCertificates();
          if ((arrayOfCertificate == null) || (arrayOfCertificate.length == 0))
          {
            if (!((JarEntry)localObject4).getName().startsWith("META-INF")) {
              throw new JarException(paramURL.toString() + " has unsigned entries - " + ((JarEntry)localObject4).getName());
            }
          }
          else
          {
            int j = 0;
            
            int k = 0;
            X509Certificate[] arrayOfX509Certificate;
            while ((arrayOfX509Certificate = getAChain(arrayOfCertificate, j)) != null)
            {
              if (paramX509Certificate.equals(arrayOfX509Certificate[0]))
              {
                k = 1;
                break;
              }
              j += arrayOfX509Certificate.length;
            }
            if (k == 0) {
              throw new JarException(paramURL.toString() + " is not signed by a" + " trusted signer.");
            }
          }
        }
      }
      return ((Manifest)localObject2).getMainAttributes().getValue(Attributes.Name.CLASS_PATH);
    }
    finally
    {
      if (localJarFile != null) {
        localJarFile = null;
      }
    }
  }
  
  private static String[] parseAttrClasspath(String paramString)
    throws JarException
  {
    paramString = paramString.trim();
    
    int i = paramString.indexOf(' ');
    String str = null;
    Vector localVector = new Vector();
    int j = 0;
    do
    {
      if (i > 0)
      {
        str = paramString.substring(0, i);
        
        paramString = paramString.substring(i + 1).trim();
        i = paramString.indexOf(' ');
      }
      else
      {
        str = paramString;
        j = 1;
      }
      if (str.endsWith(".jar")) {
        localVector.addElement(str);
      } else {
        throw new JarException("The provider contains un-verifiable components");
      }
    } while (j == 0);
    String[] arrayOfString = new String[localVector.size()];
    localVector.copyInto(arrayOfString);
    
    return arrayOfString;
  }
  
  private static X509Certificate[] getAChain(Certificate[] paramArrayOfCertificate, int paramInt)
  {
    if (paramInt > paramArrayOfCertificate.length - 1) {
      return null;
    }
    for (int i = paramInt; i < paramArrayOfCertificate.length - 1; i++) {
      if (!((X509Certificate)paramArrayOfCertificate[(i + 1)]).getSubjectDN().equals(((X509Certificate)paramArrayOfCertificate[i]).getIssuerDN())) {
        break;
      }
    }
    int j = i - paramInt + 1;
    X509Certificate[] arrayOfX509Certificate = new X509Certificate[j];
    for (int k = 0; k < j; k++) {
      arrayOfX509Certificate[k] = ((X509Certificate)paramArrayOfCertificate[(paramInt + k)]);
    }
    return arrayOfX509Certificate;
  }
  
  static boolean doVerification(Class paramClass, String paramString)
  {
    X509Certificate localX509Certificate;
    try
    {
      CertificateFactory localCertificateFactory = CertificateFactory.getInstance("X.509");
      
      localObject = paramString.getBytes("UTF8");
      localX509Certificate = (X509Certificate)localCertificateFactory.generateCertificate(new ByteArrayInputStream((byte[])localObject));
    }
    catch (Exception localException1)
    {
      return false;
    }
    URL localURL = (URL)AccessController.doPrivileged(new PrivilegedAction()
    {
      public Object run()
      {
        CodeSource localCodeSource = val$cc.getProtectionDomain().getCodeSource();
        return localCodeSource.getLocation();
      }
    });
    if (localURL == null) {
      return false;
    }
    Object localObject = new JarVerifierImpl(localURL);
    try
    {
      ((JarVerifierImpl)localObject).verify(localX509Certificate);
    }
    catch (Exception localException2)
    {
      return false;
    }
    return true;
  }
}

/* Location:
 * Qualified Name:     sun.security.mscapi.JarVerifierImpl
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package sun.security.mscapi;

abstract class Key
  implements java.security.Key
{
  protected long hCryptProv = 0L;
  protected long hCryptKey = 0L;
  protected int keyLength = 0;
  
  protected Key(long paramLong1, long paramLong2, int paramInt)
  {
    hCryptProv = paramLong1;
    hCryptKey = paramLong2;
    keyLength = paramInt;
  }
  
  protected void finalize()
    throws Throwable
  {
    try
    {
      synchronized (this)
      {
        cleanUp(hCryptProv, hCryptKey);
        hCryptProv = 0L;
        hCryptKey = 0L;
      }
    }
    finally
    {
      super.finalize();
    }
  }
  
  private static native void cleanUp(long paramLong1, long paramLong2);
  
  public int bitLength()
  {
    return keyLength;
  }
  
  public long getHCryptKey()
  {
    return hCryptKey;
  }
  
  public long getHCryptProvider()
  {
    return hCryptProv;
  }
  
  public abstract String getAlgorithm();
  
  public String getFormat()
  {
    return null;
  }
  
  public byte[] getEncoded()
  {
    return null;
  }
  
  protected static native String getContainerName(long paramLong);
  
  protected static native String getKeyType(long paramLong);
}

/* Location:
 * Qualified Name:     sun.security.mscapi.Key
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package sun.security.mscapi;

import java.util.Enumeration;
import java.util.Iterator;

class KeyStore$1
  implements Enumeration
{
  KeyStore$1(KeyStore paramKeyStore, Iterator paramIterator) {}
  
  public boolean hasMoreElements()
  {
    return val$iter.hasNext();
  }
  
  public Object nextElement()
  {
    KeyStore.KeyEntry localKeyEntry = (KeyStore.KeyEntry)val$iter.next();
    return localKeyEntry.getAlias();
  }
}

/* Location:
 * Qualified Name:     sun.security.mscapi.KeyStore.1
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package sun.security.mscapi;

import java.math.BigInteger;
import java.security.InvalidKeyException;
import java.security.KeyStoreException;
import java.security.cert.CertificateException;
import java.security.cert.X509Certificate;
import java.security.interfaces.RSAPrivateCrtKey;
import java.util.UUID;

class KeyStore$KeyEntry
{
  private Key privateKey;
  private X509Certificate[] certChain;
  private String alias;
  
  KeyStore$KeyEntry(KeyStore paramKeyStore, Key paramKey, X509Certificate[] paramArrayOfX509Certificate)
  {
    this(paramKeyStore, null, paramKey, paramArrayOfX509Certificate);
  }
  
  KeyStore$KeyEntry(KeyStore paramKeyStore, String paramString, Key paramKey, X509Certificate[] paramArrayOfX509Certificate)
  {
    privateKey = paramKey;
    certChain = paramArrayOfX509Certificate;
    if (paramString == null) {
      alias = Integer.toString(paramArrayOfX509Certificate[0].hashCode());
    } else {
      alias = paramString;
    }
  }
  
  String getAlias()
  {
    return alias;
  }
  
  void setAlias(String paramString)
  {
    alias = paramString;
  }
  
  Key getPrivateKey()
  {
    return privateKey;
  }
  
  void setPrivateKey(RSAPrivateCrtKey paramRSAPrivateCrtKey)
    throws InvalidKeyException, KeyStoreException
  {
    byte[] arrayOfByte1 = paramRSAPrivateCrtKey.getModulus().toByteArray();
    
    int i = arrayOfByte1[0] == 0 ? (arrayOfByte1.length - 1) * 8 : arrayOfByte1.length * 8;
    
    byte[] arrayOfByte2 = KeyStore.access$000(this$0, i, arrayOfByte1, paramRSAPrivateCrtKey.getPublicExponent().toByteArray(), paramRSAPrivateCrtKey.getPrivateExponent().toByteArray(), paramRSAPrivateCrtKey.getPrimeP().toByteArray(), paramRSAPrivateCrtKey.getPrimeQ().toByteArray(), paramRSAPrivateCrtKey.getPrimeExponentP().toByteArray(), paramRSAPrivateCrtKey.getPrimeExponentQ().toByteArray(), paramRSAPrivateCrtKey.getCrtCoefficient().toByteArray());
    
    privateKey = KeyStore.access$100(this$0, arrayOfByte2, "{" + UUID.randomUUID().toString() + "}", i);
  }
  
  X509Certificate[] getCertificateChain()
  {
    return certChain;
  }
  
  void setCertificateChain(X509Certificate[] paramArrayOfX509Certificate)
    throws CertificateException, KeyStoreException
  {
    for (int i = 0; i < paramArrayOfX509Certificate.length; i++)
    {
      byte[] arrayOfByte = paramArrayOfX509Certificate[i].getEncoded();
      if ((i == 0) && (privateKey != null)) {
        KeyStore.access$300(this$0, KeyStore.access$200(this$0), alias, arrayOfByte, arrayOfByte.length, privateKey.getHCryptProvider(), privateKey.getHCryptKey());
      } else {
        KeyStore.access$300(this$0, KeyStore.access$200(this$0), alias, arrayOfByte, arrayOfByte.length, 0L, 0L);
      }
    }
    certChain = paramArrayOfX509Certificate;
  }
}

/* Location:
 * Qualified Name:     sun.security.mscapi.KeyStore.KeyEntry
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package sun.security.mscapi;

public final class KeyStore$MY
  extends KeyStore
{
  public KeyStore$MY()
  {
    super("MY");
  }
}

/* Location:
 * Qualified Name:     sun.security.mscapi.KeyStore.MY
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package sun.security.mscapi;

public final class KeyStore$ROOT
  extends KeyStore
{
  public KeyStore$ROOT()
  {
    super("ROOT");
  }
}

/* Location:
 * Qualified Name:     sun.security.mscapi.KeyStore.ROOT
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package sun.security.mscapi;

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.math.BigInteger;
import java.security.AccessController;
import java.security.InvalidKeyException;
import java.security.KeyStoreException;
import java.security.KeyStoreSpi;
import java.security.NoSuchAlgorithmException;
import java.security.SecurityPermission;
import java.security.UnrecoverableKeyException;
import java.security.cert.Certificate;
import java.security.cert.CertificateException;
import java.security.cert.CertificateFactory;
import java.security.cert.X509Certificate;
import java.security.interfaces.RSAPrivateCrtKey;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
import java.util.Enumeration;
import java.util.Iterator;
import java.util.UUID;
import sun.security.action.GetPropertyAction;

abstract class KeyStore
  extends KeyStoreSpi
{
  public static final class MY
    extends KeyStore
  {
    public MY()
    {
      super();
    }
  }
  
  public static final class ROOT
    extends KeyStore
  {
    public ROOT()
    {
      super();
    }
  }
  
  class KeyEntry
  {
    private Key privateKey;
    private X509Certificate[] certChain;
    private String alias;
    
    KeyEntry(Key paramKey, X509Certificate[] paramArrayOfX509Certificate)
    {
      this(null, paramKey, paramArrayOfX509Certificate);
    }
    
    KeyEntry(String paramString, Key paramKey, X509Certificate[] paramArrayOfX509Certificate)
    {
      privateKey = paramKey;
      certChain = paramArrayOfX509Certificate;
      if (paramString == null) {
        alias = Integer.toString(paramArrayOfX509Certificate[0].hashCode());
      } else {
        alias = paramString;
      }
    }
    
    String getAlias()
    {
      return alias;
    }
    
    void setAlias(String paramString)
    {
      alias = paramString;
    }
    
    Key getPrivateKey()
    {
      return privateKey;
    }
    
    void setPrivateKey(RSAPrivateCrtKey paramRSAPrivateCrtKey)
      throws InvalidKeyException, KeyStoreException
    {
      byte[] arrayOfByte1 = paramRSAPrivateCrtKey.getModulus().toByteArray();
      
      int i = arrayOfByte1[0] == 0 ? (arrayOfByte1.length - 1) * 8 : arrayOfByte1.length * 8;
      
      byte[] arrayOfByte2 = KeyStore.this.generatePrivateKeyBlob(i, arrayOfByte1, paramRSAPrivateCrtKey.getPublicExponent().toByteArray(), paramRSAPrivateCrtKey.getPrivateExponent().toByteArray(), paramRSAPrivateCrtKey.getPrimeP().toByteArray(), paramRSAPrivateCrtKey.getPrimeQ().toByteArray(), paramRSAPrivateCrtKey.getPrimeExponentP().toByteArray(), paramRSAPrivateCrtKey.getPrimeExponentQ().toByteArray(), paramRSAPrivateCrtKey.getCrtCoefficient().toByteArray());
      
      privateKey = KeyStore.this.storePrivateKey(arrayOfByte2, "{" + UUID.randomUUID().toString() + "}", i);
    }
    
    X509Certificate[] getCertificateChain()
    {
      return certChain;
    }
    
    void setCertificateChain(X509Certificate[] paramArrayOfX509Certificate)
      throws CertificateException, KeyStoreException
    {
      for (int i = 0; i < paramArrayOfX509Certificate.length; i++)
      {
        byte[] arrayOfByte = paramArrayOfX509Certificate[i].getEncoded();
        if ((i == 0) && (privateKey != null)) {
          KeyStore.this.storeCertificate(KeyStore.access$200(KeyStore.this), alias, arrayOfByte, arrayOfByte.length, privateKey.getHCryptProvider(), privateKey.getHCryptKey());
        } else {
          KeyStore.this.storeCertificate(KeyStore.access$200(KeyStore.this), alias, arrayOfByte, arrayOfByte.length, 0L, 0L);
        }
      }
      certChain = paramArrayOfX509Certificate;
    }
  }
  
  private CertificateFactory certificateFactory = null;
  private static final String KEYSTORE_COMPATIBILITY_MODE_PROP = "sun.security.mscapi.keyStoreCompatibilityMode";
  private final boolean keyStoreCompatibilityMode;
  private Collection<KeyEntry> entries = new ArrayList();
  private final String storeName;
  
  KeyStore(String paramString)
  {
    String str = (String)AccessController.doPrivileged(new GetPropertyAction("sun.security.mscapi.keyStoreCompatibilityMode"));
    if ("false".equalsIgnoreCase(str)) {
      keyStoreCompatibilityMode = false;
    } else {
      keyStoreCompatibilityMode = true;
    }
    storeName = paramString;
  }
  
  public java.security.Key engineGetKey(String paramString, char[] paramArrayOfChar)
    throws NoSuchAlgorithmException, UnrecoverableKeyException
  {
    if (paramString == null) {
      return null;
    }
    if ((paramArrayOfChar != null) && (!keyStoreCompatibilityMode)) {
      throw new UnrecoverableKeyException("Password must be null");
    }
    if (!engineIsKeyEntry(paramString)) {
      return null;
    }
    for (KeyEntry localKeyEntry : entries) {
      if (paramString.equals(localKeyEntry.getAlias())) {
        return localKeyEntry.getPrivateKey();
      }
    }
    return null;
  }
  
  public Certificate[] engineGetCertificateChain(String paramString)
  {
    if (paramString == null) {
      return null;
    }
    for (KeyEntry localKeyEntry : entries) {
      if (paramString.equals(localKeyEntry.getAlias()))
      {
        X509Certificate[] arrayOfX509Certificate = localKeyEntry.getCertificateChain();
        
        return (Certificate[])arrayOfX509Certificate.clone();
      }
    }
    return null;
  }
  
  public Certificate engineGetCertificate(String paramString)
  {
    if (paramString == null) {
      return null;
    }
    for (KeyEntry localKeyEntry : entries) {
      if (paramString.equals(localKeyEntry.getAlias()))
      {
        X509Certificate[] arrayOfX509Certificate = localKeyEntry.getCertificateChain();
        return arrayOfX509Certificate[0];
      }
    }
    return null;
  }
  
  public Date engineGetCreationDate(String paramString)
  {
    if (paramString == null) {
      return null;
    }
    return new Date();
  }
  
  public void engineSetKeyEntry(String paramString, java.security.Key paramKey, char[] paramArrayOfChar, Certificate[] paramArrayOfCertificate)
    throws KeyStoreException
  {
    if (paramString == null) {
      throw new KeyStoreException("alias must not be null");
    }
    if ((paramArrayOfChar != null) && (!keyStoreCompatibilityMode)) {
      throw new KeyStoreException("Password must be null");
    }
    if ((paramKey instanceof RSAPrivateCrtKey))
    {
      Object localObject = null;
      int i = 0;
      for (KeyEntry localKeyEntry : entries) {
        if (paramString.equals(localKeyEntry.getAlias()))
        {
          i = 1;
          localObject = localKeyEntry;
          break;
        }
      }
      if (i == 0)
      {
        localObject = new KeyEntry(paramString, null, (X509Certificate[])paramArrayOfCertificate);
        
        entries.add(localObject);
      }
      ((KeyEntry)localObject).setAlias(paramString);
      try
      {
        ((KeyEntry)localObject).setPrivateKey((RSAPrivateCrtKey)paramKey);
        ((KeyEntry)localObject).setCertificateChain((X509Certificate[])paramArrayOfCertificate);
      }
      catch (CertificateException localCertificateException)
      {
        throw new KeyStoreException(localCertificateException);
      }
      catch (InvalidKeyException localInvalidKeyException)
      {
        throw new KeyStoreException(localInvalidKeyException);
      }
    }
    else
    {
      throw new UnsupportedOperationException("Cannot assign the key to the given alias.");
    }
  }
  
  public void engineSetKeyEntry(String paramString, byte[] paramArrayOfByte, Certificate[] paramArrayOfCertificate)
    throws KeyStoreException
  {
    throw new UnsupportedOperationException("Cannot assign the encoded key to the given alias.");
  }
  
  public void engineSetCertificateEntry(String paramString, Certificate paramCertificate)
    throws KeyStoreException
  {
    if (paramString == null) {
      throw new KeyStoreException("alias must not be null");
    }
    if ((paramCertificate instanceof X509Certificate))
    {
      X509Certificate[] arrayOfX509Certificate = { (X509Certificate)paramCertificate };
      
      Object localObject = null;
      int i = 0;
      for (KeyEntry localKeyEntry : entries) {
        if (paramString.equals(localKeyEntry.getAlias()))
        {
          i = 1;
          localObject = localKeyEntry;
          break;
        }
      }
      if (i == 0)
      {
        localObject = new KeyEntry(paramString, null, arrayOfX509Certificate);
        
        entries.add(localObject);
      }
      if (((KeyEntry)localObject).getPrivateKey() == null)
      {
        ((KeyEntry)localObject).setAlias(paramString);
        try
        {
          ((KeyEntry)localObject).setCertificateChain(arrayOfX509Certificate);
        }
        catch (CertificateException localCertificateException)
        {
          throw new KeyStoreException(localCertificateException);
        }
      }
    }
    else
    {
      throw new UnsupportedOperationException("Cannot assign the certificate to the given alias.");
    }
  }
  
  public void engineDeleteEntry(String paramString)
    throws KeyStoreException
  {
    if (paramString == null) {
      throw new KeyStoreException("alias must not be null");
    }
    for (KeyEntry localKeyEntry : entries) {
      if (paramString.equals(localKeyEntry.getAlias()))
      {
        X509Certificate[] arrayOfX509Certificate = localKeyEntry.getCertificateChain();
        if (arrayOfX509Certificate != null) {
          try
          {
            byte[] arrayOfByte = arrayOfX509Certificate[0].getEncoded();
            removeCertificate(getName(), paramString, arrayOfByte, arrayOfByte.length);
          }
          catch (CertificateException localCertificateException)
          {
            throw new KeyStoreException("Cannot remove entry: " + localCertificateException);
          }
        }
        Key localKey = localKeyEntry.getPrivateKey();
        if (localKey != null) {
          destroyKeyContainer(Key.getContainerName(localKey.getHCryptProvider()));
        }
        entries.remove(localKeyEntry);
        break;
      }
    }
  }
  
  public Enumeration engineAliases()
  {
    final Iterator localIterator = entries.iterator();
    
    new Enumeration()
    {
      public boolean hasMoreElements()
      {
        return localIterator.hasNext();
      }
      
      public Object nextElement()
      {
        KeyStore.KeyEntry localKeyEntry = (KeyStore.KeyEntry)localIterator.next();
        return localKeyEntry.getAlias();
      }
    };
  }
  
  public boolean engineContainsAlias(String paramString)
  {
    Enumeration localEnumeration = engineAliases();
    while (localEnumeration.hasMoreElements())
    {
      String str = (String)localEnumeration.nextElement();
      if (str.equals(paramString)) {
        return true;
      }
    }
    return false;
  }
  
  public int engineSize()
  {
    return entries.size();
  }
  
  public boolean engineIsKeyEntry(String paramString)
  {
    if (paramString == null) {
      return false;
    }
    for (KeyEntry localKeyEntry : entries) {
      if (paramString.equals(localKeyEntry.getAlias())) {
        return localKeyEntry.getPrivateKey() != null;
      }
    }
    return false;
  }
  
  public boolean engineIsCertificateEntry(String paramString)
  {
    for (KeyEntry localKeyEntry : entries) {
      if (paramString.equals(localKeyEntry.getAlias())) {
        return localKeyEntry.getPrivateKey() == null;
      }
    }
    return false;
  }
  
  public String engineGetCertificateAlias(Certificate paramCertificate)
  {
    for (KeyEntry localKeyEntry : entries) {
      if ((certChain != null) && (certChain[0].equals(paramCertificate))) {
        return localKeyEntry.getAlias();
      }
    }
    return null;
  }
  
  public void engineStore(OutputStream paramOutputStream, char[] paramArrayOfChar)
    throws IOException, NoSuchAlgorithmException, CertificateException
  {
    if ((paramOutputStream != null) && (!keyStoreCompatibilityMode)) {
      throw new IOException("Keystore output stream must be null");
    }
    if ((paramArrayOfChar != null) && (!keyStoreCompatibilityMode)) {
      throw new IOException("Keystore password must be null");
    }
  }
  
  public void engineLoad(InputStream paramInputStream, char[] paramArrayOfChar)
    throws IOException, NoSuchAlgorithmException, CertificateException
  {
    if ((paramInputStream != null) && (!keyStoreCompatibilityMode)) {
      throw new IOException("Keystore input stream must be null");
    }
    if ((paramArrayOfChar != null) && (!keyStoreCompatibilityMode)) {
      throw new IOException("Keystore password must be null");
    }
    SecurityManager localSecurityManager = System.getSecurityManager();
    if (localSecurityManager != null) {
      localSecurityManager.checkPermission(new SecurityPermission("authProvider.SunMSCAPI"));
    }
    entries.clear();
    try
    {
      loadKeysOrCertificateChains(getName(), entries);
    }
    catch (KeyStoreException localKeyStoreException)
    {
      throw new IOException(localKeyStoreException);
    }
  }
  
  private void generateCertificateChain(String paramString, Collection paramCollection, Collection<KeyEntry> paramCollection1)
  {
    try
    {
      X509Certificate[] arrayOfX509Certificate = new X509Certificate[paramCollection.size()];
      
      int i = 0;
      for (Object localObject = paramCollection.iterator(); ((Iterator)localObject).hasNext(); i++) {
        arrayOfX509Certificate[i] = ((X509Certificate)((Iterator)localObject).next());
      }
      localObject = new KeyEntry(paramString, null, arrayOfX509Certificate);
      
      paramCollection1.add(localObject);
    }
    catch (Throwable localThrowable) {}
  }
  
  private void generateRSAKeyAndCertificateChain(String paramString, long paramLong1, long paramLong2, int paramInt, Collection paramCollection, Collection<KeyEntry> paramCollection1)
  {
    try
    {
      X509Certificate[] arrayOfX509Certificate = new X509Certificate[paramCollection.size()];
      
      int i = 0;
      for (Object localObject = paramCollection.iterator(); ((Iterator)localObject).hasNext(); i++) {
        arrayOfX509Certificate[i] = ((X509Certificate)((Iterator)localObject).next());
      }
      localObject = new KeyEntry(paramString, new RSAPrivateKey(paramLong1, paramLong2, paramInt), arrayOfX509Certificate);
      
      paramCollection1.add(localObject);
    }
    catch (Throwable localThrowable) {}
  }
  
  private void generateCertificate(byte[] paramArrayOfByte, Collection paramCollection)
  {
    try
    {
      ByteArrayInputStream localByteArrayInputStream = new ByteArrayInputStream(paramArrayOfByte);
      if (certificateFactory == null) {
        certificateFactory = CertificateFactory.getInstance("X.509");
      }
      Collection localCollection = certificateFactory.generateCertificates(localByteArrayInputStream);
      paramCollection.addAll(localCollection);
    }
    catch (CertificateException localCertificateException) {}catch (Throwable localThrowable) {}
  }
  
  private String getName()
  {
    return storeName;
  }
  
  private native void loadKeysOrCertificateChains(String paramString, Collection<KeyEntry> paramCollection)
    throws KeyStoreException;
  
  private native void storeCertificate(String paramString1, String paramString2, byte[] paramArrayOfByte, int paramInt, long paramLong1, long paramLong2)
    throws CertificateException, KeyStoreException;
  
  private native void removeCertificate(String paramString1, String paramString2, byte[] paramArrayOfByte, int paramInt)
    throws CertificateException, KeyStoreException;
  
  private native void destroyKeyContainer(String paramString)
    throws KeyStoreException;
  
  private native byte[] generatePrivateKeyBlob(int paramInt, byte[] paramArrayOfByte1, byte[] paramArrayOfByte2, byte[] paramArrayOfByte3, byte[] paramArrayOfByte4, byte[] paramArrayOfByte5, byte[] paramArrayOfByte6, byte[] paramArrayOfByte7, byte[] paramArrayOfByte8)
    throws InvalidKeyException;
  
  private native RSAPrivateKey storePrivateKey(byte[] paramArrayOfByte, String paramString, int paramInt)
    throws KeyStoreException;
}

/* Location:
 * Qualified Name:     sun.security.mscapi.KeyStore
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package sun.security.mscapi;

import java.io.Serializable;
import java.security.ProviderException;
import java.security.SecureRandomSpi;

public final class PRNG
  extends SecureRandomSpi
  implements Serializable
{
  private static native byte[] generateSeed(int paramInt, byte[] paramArrayOfByte);
  
  protected void engineSetSeed(byte[] paramArrayOfByte)
  {
    if (paramArrayOfByte != null) {
      generateSeed(-1, paramArrayOfByte);
    }
  }
  
  protected void engineNextBytes(byte[] paramArrayOfByte)
  {
    if ((paramArrayOfByte != null) && 
      (generateSeed(0, paramArrayOfByte) == null)) {
      throw new ProviderException("Error generating random bytes");
    }
  }
  
  protected byte[] engineGenerateSeed(int paramInt)
  {
    byte[] arrayOfByte = generateSeed(paramInt, null);
    if (arrayOfByte == null) {
      throw new ProviderException("Error generating seed bytes");
    }
    return arrayOfByte;
  }
}

/* Location:
 * Qualified Name:     sun.security.mscapi.PRNG
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package sun.security.mscapi;

import java.math.BigInteger;
import java.security.AlgorithmParameters;
import java.security.InvalidAlgorithmParameterException;
import java.security.InvalidKeyException;
import java.security.KeyException;
import java.security.KeyFactory;
import java.security.KeyStoreException;
import java.security.NoSuchAlgorithmException;
import java.security.PrivateKey;
import java.security.ProviderException;
import java.security.PublicKey;
import java.security.SecureRandom;
import java.security.interfaces.RSAKey;
import java.security.interfaces.RSAPublicKey;
import java.security.spec.AlgorithmParameterSpec;
import java.security.spec.InvalidKeySpecException;
import java.security.spec.PKCS8EncodedKeySpec;
import java.security.spec.X509EncodedKeySpec;
import javax.crypto.BadPaddingException;
import javax.crypto.CipherSpi;
import javax.crypto.IllegalBlockSizeException;
import javax.crypto.NoSuchPaddingException;
import javax.crypto.SecretKey;
import javax.crypto.ShortBufferException;
import javax.crypto.spec.SecretKeySpec;
import sun.security.rsa.RSAKeyFactory;

public final class RSACipher
  extends CipherSpi
{
  private static final byte[] B0 = new byte[0];
  private static final int MODE_ENCRYPT = 1;
  private static final int MODE_DECRYPT = 2;
  private static final int MODE_SIGN = 3;
  private static final int MODE_VERIFY = 4;
  private static final String PAD_PKCS1 = "PKCS1Padding";
  private static final int PAD_PKCS1_LENGTH = 11;
  private int mode;
  private String paddingType;
  private int paddingLength = 0;
  private byte[] buffer;
  private int bufOfs;
  private int outputSize;
  private Key publicKey;
  private Key privateKey;
  
  public RSACipher()
  {
    SunMSCAPI.verifySelfIntegrity(getClass());
    paddingType = "PKCS1Padding";
  }
  
  protected void engineSetMode(String paramString)
    throws NoSuchAlgorithmException
  {
    if (!paramString.equalsIgnoreCase("ECB")) {
      throw new NoSuchAlgorithmException("Unsupported mode " + paramString);
    }
  }
  
  protected void engineSetPadding(String paramString)
    throws NoSuchPaddingException
  {
    if (paramString.equalsIgnoreCase("PKCS1Padding")) {
      paddingType = "PKCS1Padding";
    } else {
      throw new NoSuchPaddingException("Padding " + paramString + " not supported");
    }
  }
  
  protected int engineGetBlockSize()
  {
    return 0;
  }
  
  protected int engineGetOutputSize(int paramInt)
  {
    return outputSize;
  }
  
  protected byte[] engineGetIV()
  {
    return null;
  }
  
  protected AlgorithmParameters engineGetParameters()
  {
    return null;
  }
  
  protected void engineInit(int paramInt, java.security.Key paramKey, SecureRandom paramSecureRandom)
    throws InvalidKeyException
  {
    init(paramInt, paramKey);
  }
  
  protected void engineInit(int paramInt, java.security.Key paramKey, AlgorithmParameterSpec paramAlgorithmParameterSpec, SecureRandom paramSecureRandom)
    throws InvalidKeyException, InvalidAlgorithmParameterException
  {
    if (paramAlgorithmParameterSpec != null) {
      throw new InvalidAlgorithmParameterException("Parameters not supported");
    }
    init(paramInt, paramKey);
  }
  
  protected void engineInit(int paramInt, java.security.Key paramKey, AlgorithmParameters paramAlgorithmParameters, SecureRandom paramSecureRandom)
    throws InvalidKeyException, InvalidAlgorithmParameterException
  {
    if (paramAlgorithmParameters != null) {
      throw new InvalidAlgorithmParameterException("Parameters not supported");
    }
    init(paramInt, paramKey);
  }
  
  private void init(int paramInt, java.security.Key paramKey)
    throws InvalidKeyException
  {
    int i;
    switch (paramInt)
    {
    case 1: 
    case 3: 
      paddingLength = 11;
      i = 1;
      break;
    case 2: 
    case 4: 
      paddingLength = 0;
      i = 0;
      break;
    default: 
      throw new InvalidKeyException("Unknown mode: " + paramInt);
    }
    if (!(paramKey instanceof Key)) {
      if ((paramKey instanceof RSAPublicKey))
      {
        RSAPublicKey localRSAPublicKey = (RSAPublicKey)paramKey;
        
        BigInteger localBigInteger1 = localRSAPublicKey.getModulus();
        BigInteger localBigInteger2 = localRSAPublicKey.getPublicExponent();
        
        RSAKeyFactory.checkKeyLengths(localBigInteger1.bitLength() + 7 & 0xFFFFFFF8, localBigInteger2, -1, 16384);
        
        byte[] arrayOfByte1 = localBigInteger1.toByteArray();
        byte[] arrayOfByte2 = localBigInteger2.toByteArray();
        
        int j = arrayOfByte1[0] == 0 ? (arrayOfByte1.length - 1) * 8 : arrayOfByte1.length * 8;
        
        byte[] arrayOfByte3 = RSASignature.generatePublicKeyBlob(j, arrayOfByte1, arrayOfByte2);
        try
        {
          paramKey = RSASignature.importPublicKey(arrayOfByte3, j);
        }
        catch (KeyStoreException localKeyStoreException)
        {
          throw new InvalidKeyException(localKeyStoreException);
        }
      }
      else
      {
        throw new InvalidKeyException("Unsupported key type: " + paramKey);
      }
    }
    if ((paramKey instanceof PublicKey))
    {
      mode = (i != 0 ? 1 : 4);
      publicKey = ((Key)paramKey);
      privateKey = null;
      outputSize = (publicKey.bitLength() / 8);
    }
    else if ((paramKey instanceof PrivateKey))
    {
      mode = (i != 0 ? 3 : 2);
      privateKey = ((Key)paramKey);
      publicKey = null;
      outputSize = (privateKey.bitLength() / 8);
    }
    else
    {
      throw new InvalidKeyException("Unknown key type: " + paramKey);
    }
    bufOfs = 0;
    buffer = new byte[outputSize];
  }
  
  private void update(byte[] paramArrayOfByte, int paramInt1, int paramInt2)
  {
    if ((paramInt2 == 0) || (paramArrayOfByte == null)) {
      return;
    }
    if (bufOfs + paramInt2 > buffer.length - paddingLength)
    {
      bufOfs = (buffer.length + 1);
      return;
    }
    System.arraycopy(paramArrayOfByte, paramInt1, buffer, bufOfs, paramInt2);
    bufOfs += paramInt2;
  }
  
  private byte[] doFinal()
    throws BadPaddingException, IllegalBlockSizeException
  {
    if (bufOfs > buffer.length) {
      throw new IllegalBlockSizeException("Data must not be longer than " + (buffer.length - paddingLength) + " bytes");
    }
    try
    {
      byte[] arrayOfByte1 = buffer;
      byte[] arrayOfByte2;
      switch (mode)
      {
      case 3: 
        return encryptDecrypt(arrayOfByte1, bufOfs, privateKey.getHCryptKey(), true);
      case 4: 
        return encryptDecrypt(arrayOfByte1, bufOfs, publicKey.getHCryptKey(), false);
      case 1: 
        return encryptDecrypt(arrayOfByte1, bufOfs, publicKey.getHCryptKey(), true);
      case 2: 
        return encryptDecrypt(arrayOfByte1, bufOfs, privateKey.getHCryptKey(), false);
      }
      throw new AssertionError("Int
1 2

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