org.eclipse.equinox.security_1.1.100.v20120522-1841

cryption.1
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.equinox.internal.security.storage;

import org.eclipse.equinox.internal.security.storage.friends.IStorageTask;

class JavaEncryption$2
  implements IStorageTask
{
  final JavaEncryption this$0;
  
  JavaEncryption$2(JavaEncryption paramJavaEncryption)
  {
    this$0 = paramJavaEncryption;
  }
  
  public void execute()
  {
    this$0.internalDetect();
  }
}

/* Location:
 * Qualified Name:     org.eclipse.equinox.internal.security.storage.JavaEncryption.2
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.equinox.internal.security.storage;

import java.security.InvalidAlgorithmParameterException;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.security.Provider;
import java.security.SecureRandom;
import java.security.Security;
import java.security.spec.InvalidKeySpecException;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Map.Entry;
import java.util.Set;
import javax.crypto.BadPaddingException;
import javax.crypto.Cipher;
import javax.crypto.IllegalBlockSizeException;
import javax.crypto.NoSuchPaddingException;
import javax.crypto.SecretKey;
import javax.crypto.SecretKeyFactory;
import javax.crypto.spec.PBEKeySpec;
import javax.crypto.spec.PBEParameterSpec;
import org.eclipse.core.runtime.jobs.IJobManager;
import org.eclipse.core.runtime.jobs.ILock;
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.core.runtime.preferences.ConfigurationScope;
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
import org.eclipse.equinox.internal.security.auth.AuthPlugin;
import org.eclipse.equinox.internal.security.auth.nls.SecAuthMessages;
import org.eclipse.equinox.internal.security.storage.friends.IStorageTask;
import org.eclipse.equinox.internal.security.storage.friends.IUICallbacks;
import org.eclipse.equinox.security.storage.StorageException;
import org.eclipse.osgi.util.NLS;

public class JavaEncryption
{
  private static final String SECRET_KEY_FACTORY = "SecretKeyFactory.";
  private static final String CIPHER = "Cipher.";
  private static final String sampleText = "sample text for roundtrip testing";
  private static final PasswordExt samplePassword = new PasswordExt(new PBEKeySpec("password1".toCharArray()), "abc");
  private static ILock lock = Job.getJobManager().newLock();
  private static final int SALT_ITERATIONS = 10;
  private String keyFactoryAlgorithm = null;
  private String cipherAlgorithm = null;
  private boolean initialized = false;
  private HashMap availableCiphers;
  
  public String getKeyFactoryAlgorithm()
  {
    return keyFactoryAlgorithm;
  }
  
  public String getCipherAlgorithm()
  {
    return cipherAlgorithm;
  }
  
  /* Error */
  public void setAlgorithms(String cipherAlgorithm, String keyFactoryAlgorithm)
  {
    // Byte code:
    //   0: getstatic 375	org/eclipse/equinox/internal/security/storage/JavaEncryption:lock	Lorg/eclipse/core/runtime/jobs/ILock;
    //   3: invokeinterface 442 1 0
    //   8: aload_0
    //   9: aload_1
    //   10: putfield 372	org/eclipse/equinox/internal/security/storage/JavaEncryption:cipherAlgorithm	Ljava/lang/String;
    //   13: aload_0
    //   14: aload_2
    //   15: putfield 373	org/eclipse/equinox/internal/security/storage/JavaEncryption:keyFactoryAlgorithm	Ljava/lang/String;
    //   18: goto +14 -> 32
    //   21: astore_3
    //   22: getstatic 375	org/eclipse/equinox/internal/security/storage/JavaEncryption:lock	Lorg/eclipse/core/runtime/jobs/ILock;
    //   25: invokeinterface 443 1 0
    //   30: aload_3
    //   31: athrow
    //   32: getstatic 375	org/eclipse/equinox/internal/security/storage/JavaEncryption:lock	Lorg/eclipse/core/runtime/jobs/ILock;
    //   35: invokeinterface 443 1 0
    //   40: return
    // Line number table:
    //   Java source line #69	-> byte code offset #0
    //   Java source line #70	-> byte code offset #8
    //   Java source line #71	-> byte code offset #13
    //   Java source line #72	-> byte code offset #21
    //   Java source line #73	-> byte code offset #22
    //   Java source line #74	-> byte code offset #30
    //   Java source line #73	-> byte code offset #32
    //   Java source line #75	-> byte code offset #40
    // Local variable table:
    //   start	length	slot	name	signature
    //   0	41	0	this	JavaEncryption
    //   0	41	1	cipherAlgorithm	String
    //   0	41	2	keyFactoryAlgorithm	String
    //   21	10	3	localObject	Object
    // Exception table:
    //   from	to	target	type
    //   0	21	21	finally
  }
  
  /* Error */
  private void init()
    throws StorageException
  {
    // Byte code:
    //   0: aload_0
    //   1: getfield 371	org/eclipse/equinox/internal/security/storage/JavaEncryption:initialized	Z
    //   4: ifeq +4 -> 8
    //   7: return
    //   8: aload_0
    //   9: iconst_1
    //   10: putfield 371	org/eclipse/equinox/internal/security/storage/JavaEncryption:initialized	Z
    //   13: getstatic 375	org/eclipse/equinox/internal/security/storage/JavaEncryption:lock	Lorg/eclipse/core/runtime/jobs/ILock;
    //   16: invokeinterface 442 1 0
    //   21: invokestatic 408	org/eclipse/equinox/internal/security/storage/CallbacksProvider:getDefault	()Lorg/eclipse/equinox/internal/security/storage/CallbacksProvider;
    //   24: invokevirtual 409	org/eclipse/equinox/internal/security/storage/CallbacksProvider:getCallback	()Lorg/eclipse/equinox/internal/security/storage/friends/IUICallbacks;
    //   27: astore_1
    //   28: aload_1
    //   29: ifnonnull +10 -> 39
    //   32: aload_0
    //   33: invokevirtual 414	org/eclipse/equinox/internal/security/storage/JavaEncryption:internalInitialize	()V
    //   36: goto +31 -> 67
    //   39: aload_1
    //   40: new 217	org/eclipse/equinox/internal/security/storage/JavaEncryption$1
    //   43: dup
    //   44: aload_0
    //   45: invokespecial 422	org/eclipse/equinox/internal/security/storage/JavaEncryption$1:<init>	(Lorg/eclipse/equinox/internal/security/storage/JavaEncryption;)V
    //   48: invokeinterface 445 2 0
    //   53: goto +14 -> 67
    //   56: astore_2
    //   57: getstatic 375	org/eclipse/equinox/internal/security/storage/JavaEncryption:lock	Lorg/eclipse/core/runtime/jobs/ILock;
    //   60: invokeinterface 443 1 0
    //   65: aload_2
    //   66: athrow
    //   67: getstatic 375	org/eclipse/equinox/internal/security/storage/JavaEncryption:lock	Lorg/eclipse/core/runtime/jobs/ILock;
    //   70: invokeinterface 443 1 0
    //   75: return
    // Line number table:
    //   Java source line #78	-> byte code offset #0
    //   Java source line #79	-> byte code offset #7
    //   Java source line #80	-> byte code offset #8
    //   Java source line #83	-> byte code offset #13
    //   Java source line #84	-> byte code offset #21
    //   Java source line #85	-> byte code offset #28
    //   Java source line #86	-> byte code offset #32
    //   Java source line #88	-> byte code offset #39
    //   Java source line #94	-> byte code offset #56
    //   Java source line #95	-> byte code offset #57
    //   Java source line #96	-> byte code offset #65
    //   Java source line #95	-> byte code offset #67
    //   Java source line #97	-> byte code offset #75
    // Local variable table:
    //   start	length	slot	name	signature
    //   0	76	0	this	JavaEncryption
    //   27	13	1	callback	IUICallbacks
    //   56	10	2	localObject	Object
    // Exception table:
    //   from	to	target	type
    //   13	56	56	finally
  }
  
  protected void internalInitialize()
    throws StorageException
  {
    if ((cipherAlgorithm != null) && (keyFactoryAlgorithm != null))
    {
      if (roundtrip(cipherAlgorithm, keyFactoryAlgorithm)) {
        return;
      }
      String msg = NLS.bind(SecAuthMessages.noAlgorithm, cipherAlgorithm);
      StorageException e = new StorageException(0, msg);
      AuthPlugin.getDefault().logError(msg, e);
      throw e;
    }
    if ((cipherAlgorithm == null) || (keyFactoryAlgorithm == null))
    {
      IEclipsePreferences eclipseNode = new ConfigurationScope().getNode("org.eclipse.equinox.security");
      cipherAlgorithm = eclipseNode.get("org.eclipse.equinox.security.preferences.cipher", "PBEWithMD5AndDES");
      keyFactoryAlgorithm = eclipseNode.get("org.eclipse.equinox.security.preferences.keyFactory", "PBEWithMD5AndDES");
    }
    if (roundtrip(cipherAlgorithm, keyFactoryAlgorithm)) {
      return;
    }
    String unavailableCipher = cipherAlgorithm;
    
    detect();
    if (availableCiphers.size() == 0) {
      throw new StorageException(0, SecAuthMessages.noAlgorithms);
    }
    cipherAlgorithm = ((String)availableCiphers.keySet().iterator().next());
    keyFactoryAlgorithm = ((String)availableCiphers.get(cipherAlgorithm));
    
    String msg = NLS.bind(SecAuthMessages.usingAlgorithm, unavailableCipher, cipherAlgorithm);
    AuthPlugin.getDefault().logMessage(msg);
  }
  
  public CryptoData encrypt(PasswordExt passwordExt, byte[] clearText)
    throws StorageException
  {
    init();
    return internalEncrypt(passwordExt, clearText);
  }
  
  private CryptoData internalEncrypt(PasswordExt passwordExt, byte[] clearText)
    throws StorageException
  {
    try
    {
      SecretKeyFactory keyFactory = SecretKeyFactory.getInstance(keyFactoryAlgorithm);
      SecretKey key = keyFactory.generateSecret(passwordExt.getPassword());
      
      byte[] salt = new byte[8];
      SecureRandom random = new SecureRandom();
      random.nextBytes(salt);
      PBEParameterSpec entropy = new PBEParameterSpec(salt, 10);
      
      Cipher c = Cipher.getInstance(cipherAlgorithm);
      c.init(1, key, entropy);
      
      byte[] result = c.doFinal(clearText);
      return new CryptoData(passwordExt.getModuleID(), salt, result);
    }
    catch (InvalidKeyException e)
    {
      handle(e, 2);
      return null;
    }
    catch (InvalidAlgorithmParameterException e)
    {
      handle(e, 2);
      return null;
    }
    catch (IllegalBlockSizeException e)
    {
      handle(e, 2);
      return null;
    }
    catch (BadPaddingException e)
    {
      handle(e, 2);
      return null;
    }
    catch (InvalidKeySpecException e)
    {
      handle(e, 0);
      return null;
    }
    catch (NoSuchPaddingException e)
    {
      handle(e, 0);
      return null;
    }
    catch (NoSuchAlgorithmException e)
    {
      handle(e, 0);
    }
    return null;
  }
  
  public byte[] decrypt(PasswordExt passwordExt, CryptoData encryptedData)
    throws StorageException, IllegalStateException, IllegalBlockSizeException, BadPaddingException
  {
    init();
    return internalDecrypt(passwordExt, encryptedData);
  }
  
  private byte[] internalDecrypt(PasswordExt passwordExt, CryptoData encryptedData)
    throws StorageException, IllegalStateException, IllegalBlockSizeException, BadPaddingException
  {
    try
    {
      SecretKeyFactory keyFactory = SecretKeyFactory.getInstance(keyFactoryAlgorithm);
      SecretKey key = keyFactory.generateSecret(passwordExt.getPassword());
      
      PBEParameterSpec entropy = new PBEParameterSpec(encryptedData.getSalt(), 10);
      
      Cipher c = Cipher.getInstance(cipherAlgorithm);
      c.init(2, key, entropy);
      
      return c.doFinal(encryptedData.getData());
    }
    catch (InvalidAlgorithmParameterException e)
    {
      handle(e, 0);
      return null;
    }
    catch (InvalidKeyException e)
    {
      handle(e, 0);
      return null;
    }
    catch (InvalidKeySpecException e)
    {
      handle(e, 0);
      return null;
    }
    catch (NoSuchPaddingException e)
    {
      handle(e, 0);
      return null;
    }
    catch (NoSuchAlgorithmException e)
    {
      handle(e, 0);
    }
    return null;
  }
  
  private void handle(Exception e, int internalCode)
    throws StorageException
  {
    if (AuthPlugin.DEBUG_LOGIN_FRAMEWORK) {
      e.printStackTrace();
    }
    StorageException exception = new StorageException(internalCode, e);
    throw exception;
  }
  
  public HashMap detect()
  {
    IUICallbacks callback = CallbacksProvider.getDefault().getCallback();
    if (callback == null) {
      return internalDetect();
    }
    IStorageTask task = new IStorageTask()
    {
      public void execute()
      {
        internalDetect();
      }
    };
    try
    {
      callback.execute(task);
    }
    catch (StorageException e)
    {
      AuthPlugin.getDefault().logError(e.getMessage(), e);
    }
    return availableCiphers;
  }
  
  public HashMap internalDetect()
  {
    Set ciphers = findProviders("Cipher.");
    Set keyFactories = findProviders("SecretKeyFactory.");
    availableCiphers = new HashMap(ciphers.size());
    for (Iterator i = ciphers.iterator(); i.hasNext();)
    {
      String cipher = (String)i.next();
      if ((keyFactories.contains(cipher)) && 
        (roundtrip(cipher, cipher))) {
        availableCiphers.put(cipher, cipher);
      } else {
        for (Iterator j = keyFactories.iterator(); j.hasNext();)
        {
          String keyFactory = (String)j.next();
          if (roundtrip(cipher, keyFactory)) {
            availableCiphers.put(cipher, keyFactory);
          }
        }
      }
    }
    return availableCiphers;
  }
  
  private Set findProviders(String prefix)
  {
    Provider[] providers = Security.getProviders();
    Set algorithms = new HashSet();
    int prefixLength = prefix.length();
    for (int i = 0; i < providers.length; i++) {
      for (Iterator j = providers[i].entrySet().iterator(); j.hasNext();)
      {
        Map.Entry entry = (Map.Entry)j.next();
        Object key = entry.getKey();
        if (key != null) {
          if ((key instanceof String))
          {
            String value = (String)key;
            if (value.indexOf(' ') == -1) {
              if (value.startsWith(prefix))
              {
                String keyFactory = value.substring(prefixLength);
                algorithms.add(keyFactory);
              }
            }
          }
        }
      }
    }
    return algorithms;
  }
  
  private boolean roundtrip(String testCipher, String testKeyFactory)
  {
    boolean storeInitState = initialized;
    String storedCipherAlgorithm = cipherAlgorithm;
    String storedKeyAlgorithm = keyFactoryAlgorithm;
    initialized = true;
    try
    {
      cipherAlgorithm = testCipher;
      keyFactoryAlgorithm = testKeyFactory;
      CryptoData encrypted = internalEncrypt(samplePassword, StorageUtils.getBytes("sample text for roundtrip testing"));
      byte[] roundtripBytes = internalDecrypt(samplePassword, encrypted);
      String result = StorageUtils.getString(roundtripBytes);
      return "sample text for roundtrip testing".equals(result);
    }
    catch (Exception localException)
    {
      return false;
    }
    finally
    {
      cipherAlgorithm = storedCipherAlgorithm;
      keyFactoryAlgorithm = storedKeyAlgorithm;
      initialized = storeInitState;
    }
  }
}

/* Location:
 * Qualified Name:     org.eclipse.equinox.internal.security.storage.JavaEncryption
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.equinox.internal.security.storage;

import javax.crypto.spec.PBEKeySpec;

public class PasswordExt
{
  public final PBEKeySpec password;
  public final String moduleID;
  
  public PasswordExt(PBEKeySpec password, String moduleID)
  {
    this.moduleID = moduleID;
    this.password = password;
  }
  
  public PBEKeySpec getPassword()
  {
    return password;
  }
  
  public String getModuleID()
  {
    return moduleID;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.equinox.internal.security.storage.PasswordExt
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.equinox.internal.security.storage;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.ArrayList;
import java.util.List;
import javax.crypto.BadPaddingException;
import javax.crypto.IllegalBlockSizeException;
import javax.crypto.spec.PBEKeySpec;
import org.eclipse.equinox.internal.security.auth.AuthPlugin;
import org.eclipse.equinox.internal.security.auth.nls.SecAuthMessages;
import org.eclipse.equinox.security.storage.EncodingUtils;
import org.eclipse.equinox.security.storage.StorageException;
import org.eclipse.equinox.security.storage.provider.IPreferencesContainer;
import org.eclipse.osgi.util.NLS;

public class PasswordManagement
{
  private static final String DIGEST_ALGORITHM = "MD5";
  private static final String PASSWORD_RECOVERY_NODE = "/org.eclipse.equinox.secure.storage/recovery";
  protected static final String RECOVERY_PSEUDO_ID = "org.eclipse.equinox.security.recoveryModule";
  private static final String PASSWORD_RECOVERY_KEY = "org.eclipse.equinox.security.internal.recovery.password";
  private static final String PASSWORD_RECOVERY_QUESTION = "org.eclipse.equinox.security.internal.recovery.question";
  
  public static void setupRecovery(String[][] challengeResponse, String moduleID, IPreferencesContainer container)
  {
    SecurePreferencesRoot root = ((SecurePreferencesContainer)container).getRootData();
    SecurePreferences node = recoveryNode(root, moduleID);
    if (challengeResponse == null)
    {
      node.remove("org.eclipse.equinox.security.internal.recovery.password");
      for (int i = 0; i < 2; i++)
      {
        String key = "org.eclipse.equinox.security.internal.recovery.question" + Integer.toString(i + 1);
        node.remove(key);
      }
      root.markModified();
      return;
    }
    String internalPassword = mashPassword(challengeResponse[1]);
    
    PasswordExt internalPasswordExt = new PasswordExt(new PBEKeySpec(internalPassword.toCharArray()), "org.eclipse.equinox.security.recoveryModule");
    try
    {
      password = root.getPassword(moduleID, container, false);
    }
    catch (StorageException e)
    {
      PasswordExt password;
      AuthPlugin.getDefault().logError(SecAuthMessages.failedCreateRecovery, e);
      return;
    }
    try
    {
      PasswordExt password;
      byte[] data = StorageUtils.getBytes(new String(password.getPassword().getPassword()));
      CryptoData encryptedValue = root.getCipher().encrypt(internalPasswordExt, data);
      node.internalPut("org.eclipse.equinox.security.internal.recovery.password", encryptedValue.toString());
      root.markModified();
    }
    catch (StorageException e)
    {
      AuthPlugin.getDefault().logError(SecAuthMessages.failedCreateRecovery, e);
      return;
    }
    for (int i = 0; i < challengeResponse[0].length; i++)
    {
      String key = "org.eclipse.equinox.security.internal.recovery.question" + Integer.toString(i + 1);
      try
      {
        node.put(key, challengeResponse[0][i], false, (SecurePreferencesContainer)container);
      }
      catch (StorageException localStorageException1) {}
    }
  }
  
  public static String[] getPasswordRecoveryQuestions(SecurePreferencesRoot root, String moduleID)
  {
    List questions = new ArrayList();
    SecurePreferences node = recoveryNode(root, moduleID);
    for (int i = 0;; i++)
    {
      String key = "org.eclipse.equinox.security.internal.recovery.question" + Integer.toString(i + 1);
      if (!node.hasKey(key)) {
        break;
      }
      try
      {
        String question = node.get(key, null, null);
        if (question == null) {
          break;
        }
        questions.add(question);
      }
      catch (StorageException localStorageException) {}
    }
    String[] result = new String[questions.size()];
    return (String[])questions.toArray(result);
  }
  
  public static String recoverPassword(String[] answers, SecurePreferencesRoot root, String moduleID)
  {
    String internalPassword = mashPassword(answers);
    
    SecurePreferences node = recoveryNode(root, moduleID);
    PasswordExt internalPasswordExt = new PasswordExt(new PBEKeySpec(internalPassword.toCharArray()), "org.eclipse.equinox.security.recoveryModule");
    try
    {
      CryptoData encryptedData = new CryptoData(node.internalGet("org.eclipse.equinox.security.internal.recovery.password"));
      byte[] data = root.getCipher().decrypt(internalPasswordExt, encryptedData);
      return StorageUtils.getString(data);
    }
    catch (IllegalStateException localIllegalStateException)
    {
      return null;
    }
    catch (IllegalBlockSizeException localIllegalBlockSizeException)
    {
      return null;
    }
    catch (BadPaddingException localBadPaddingException)
    {
      return null;
    }
    catch (StorageException localStorageException) {}
    return null;
  }
  
  private static SecurePreferences recoveryNode(SecurePreferences root, String moduleID)
  {
    return root.node("/org.eclipse.equinox.secure.storage/recovery").node(moduleID);
  }
  
  private static String mashPassword(String[] answers)
  {
    StringBuffer tmp = new StringBuffer();
    for (int i = 0; i < answers.length; i++) {
      tmp.append(answers[i].trim());
    }
    StringBuffer mix = new StringBuffer();
    int pos = tmp.length() - 1;
    for (int i = 0; i <= pos; i++)
    {
      mix.append(tmp.charAt(i));
      if (i < pos) {
        mix.append(tmp.charAt(pos));
      }
      pos--;
    }
    String internalPassword;
    try
    {
      MessageDigest digest = MessageDigest.getInstance("MD5");
      byte[] digested = digest.digest(StorageUtils.getBytes(mix.toString()));
      internalPassword = EncodingUtils.encodeBase64(digested);
    }
    catch (NoSuchAlgorithmException localNoSuchAlgorithmException)
    {
      String internalPassword;
      String msg = NLS.bind(SecAuthMessages.noDigest, "MD5");
      AuthPlugin.getDefault().logMessage(msg);
      internalPassword = mix.toString();
    }
    return internalPassword;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.equinox.internal.security.storage.PasswordManagement
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.equinox.internal.security.storage;

import javax.crypto.spec.PBEKeySpec;
import org.eclipse.equinox.security.storage.provider.IPreferencesContainer;
import org.eclipse.equinox.security.storage.provider.PasswordProvider;

public class PasswordProviderModuleExt
{
  private final PasswordProvider providerModule;
  private final String moduleID;
  
  public PasswordProviderModuleExt(PasswordProvider module, String moduleID)
  {
    providerModule = module;
    this.moduleID = moduleID;
  }
  
  public String getID()
  {
    return moduleID;
  }
  
  public PBEKeySpec getPassword(IPreferencesContainer container, int passwordType)
  {
    return providerModule.getPassword(container, passwordType);
  }
  
  public boolean changePassword(Exception e, IPreferencesContainer controller)
  {
    return providerModule.retryOnError(e, controller);
  }
}

/* Location:
 * Qualified Name:     org.eclipse.equinox.internal.security.storage.PasswordProviderModuleExt
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.equinox.internal.security.storage;

import java.util.Comparator;

class PasswordProviderSelector$1
  implements Comparator
{
  final PasswordProviderSelector this$0;
  
  PasswordProviderSelector$1(PasswordProviderSelector paramPasswordProviderSelector)
  {
    this$0 = paramPasswordProviderSelector;
  }
  
  public int compare(Object o1, Object o2)
  {
    int p1 = priority;
    int p2 = priority;
    return p2 - p1;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.equinox.internal.security.storage.PasswordProviderSelector.1
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.equinox.internal.security.storage;

import java.util.List;
import org.eclipse.core.runtime.IConfigurationElement;

public class PasswordProviderSelector$ExtStorageModule
{
  public String moduleID;
  public IConfigurationElement element;
  public int priority;
  public String name;
  public String description;
  public List hints;
  final PasswordProviderSelector this$0;
  
  public PasswordProviderSelector$ExtStorageModule(PasswordProviderSelector paramPasswordProviderSelector, String id, IConfigurationElement element, int priority, String name, String description, List hints)
  {
    this$0 = paramPasswordProviderSelector;
    this.element = element;
    moduleID = id;
    this.priority = priority;
    this.name = name;
    this.description = description;
    this.hints = hints;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.equinox.internal.security.storage.PasswordProviderSelector.ExtStorageModule
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.equinox.internal.security.storage;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.IContributor;
import org.eclipse.core.runtime.IExtension;
import org.eclipse.core.runtime.IExtensionPoint;
import org.eclipse.core.runtime.IExtensionRegistry;
import org.eclipse.core.runtime.IRegistryEventListener;
import org.eclipse.core.runtime.RegistryFactory;
import org.eclipse.core.runtime.preferences.ConfigurationScope;
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
import org.eclipse.equinox.internal.security.auth.AuthPlugin;
import org.eclipse.equinox.internal.security.auth.nls.SecAuthMessages;
import org.eclipse.equinox.security.storage.StorageException;
import org.eclipse.equinox.security.storage.provider.PasswordProvider;
import org.eclipse.osgi.util.NLS;

public class PasswordProviderSelector
  implements IRegistryEventListener
{
  private static final String EXTENSION_POINT = "org.eclipse.equinox.security.secureStorage";
  private static final String STORAGE_MODULE = "provider";
  private static final String MODULE_PRIORITY = "priority";
  private static final String MODULE_DESCRIPTION = "description";
  private static final String CLASS_NAME = "class";
  private static final String HINTS_NAME = "hint";
  private static final String HINT_VALUE = "value";
  private Map modules = new HashMap(5);
  
  public class ExtStorageModule
  {
    public String moduleID;
    public IConfigurationElement element;
    public int priority;
    public String name;
    public String description;
    public List hints;
    
    public ExtStorageModule(String id, IConfigurationElement element, int priority, String name, String description, List hints)
    {
      this.element = element;
      moduleID = id;
      this.priority = priority;
      this.name = name;
      this.description = description;
      this.hints = hints;
    }
  }
  
  private static PasswordProviderSelector instance = null;
  
  public static PasswordProviderSelector getInstance()
  {
    if (instance == null)
    {
      instance = new PasswordProviderSelector();
      IExtensionRegistry registry = RegistryFactory.getRegistry();
      registry.addListener(instance, "org.eclipse.equinox.security.secureStorage");
    }
    return instance;
  }
  
  public static void stop()
  {
    if (instance != null)
    {
      IExtensionRegistry registry = RegistryFactory.getRegistry();
      registry.removeListener(instance);
      instance = null;
    }
  }
  
  public List findAvailableModules(String expectedID)
  {
    IExtensionRegistry registry = RegistryFactory.getRegistry();
    IExtensionPoint point = registry.getExtensionPoint("org.eclipse.equinox.security.secureStorage");
    IExtension[] extensions = point.getExtensions();
    
    ArrayList allAvailableModules = new ArrayList(extensions.length);
    for (int i = 0; i < extensions.length; i++)
    {
      String moduleID = extensions[i].getUniqueIdentifier();
      if (moduleID != null)
      {
        moduleID = moduleID.toLowerCase();
        if ((expectedID == null) || (expectedID.equals(moduleID)))
        {
          IConfigurationElement[] elements = extensions[i].getConfigurationElements();
          if (elements.length != 0)
          {
            IConfigurationElement element = elements[0];
            if (!"provider".equals(element.getName()))
            {
              reportError(SecAuthMessages.unexpectedConfigElement, element.getName(), element, null);
            }
            else
            {
              String attribute = element.getAttribute("priority");
              int priority = -1;
              if (attribute != null)
              {
                priority = Integer.parseInt(attribute);
                if (priority < 0) {
                  priority = 0;
                }
                if (priority > 10) {
                  priority = 10;
                }
              }
              String name = extensions[i].getLabel();
              
              String description = element.getAttribute("description");
              
              List suppliedHints = null;
              IConfigurationElement[] hints = element.getChildren("hint");
              if (hints.length != 0)
              {
                suppliedHints = new ArrayList(hints.length);
                for (int j = 0; j < hints.length; j++)
                {
                  String hint = hints[j].getAttribute("value");
                  if (hint != null) {
                    suppliedHints.add(hint);
                  }
                }
              }
              allAvailableModules.add(new ExtStorageModule(moduleID, element, priority, name, description, suppliedHints));
            }
          }
        }
      }
    }
    Collections.sort(allAvailableModules, new Comparator()
    {
      public int compare(Object o1, Object o2)
      {
        int p1 = priority;
        int p2 = priority;
        return p2 - p1;
      }
    });
    return allAvailableModules;
  }
  
  public PasswordProviderModuleExt findStorageModule(String expectedID)
    throws StorageException
  {
    if (expectedID != null) {
      expectedID = expectedID.toLowerCase();
    }
    synchronized (modules)
    {
      if (modules.containsKey(expectedID)) {
        return (PasswordProviderModuleExt)modules.get(expectedID);
      }
    }
    List allAvailableModules = findAvailableModules(expectedID);
    HashSet disabledModules = getDisabledModules();
    for (Iterator i = allAvailableModules.iterator(); i.hasNext();)
    {
      ExtStorageModule module = (ExtStorageModule)i.next();
      if ((expectedID != null) || (disabledModules == null) || (!disabledModules.contains(moduleID)))
      {
        try
        {
          clazz = element.createExecutableExtension("class");
        }
        catch (CoreException e)
        {
          Object clazz;
          reportError(SecAuthMessages.instantiationFailed, element.getAttribute("class"), element, e);
          continue;
        }
        Object clazz;
        if ((clazz instanceof PasswordProvider))
        {
          PasswordProviderModuleExt result = new PasswordProviderModuleExt((PasswordProvider)clazz, moduleID);
          synchronized (modules)
          {
            if (expectedID == null) {
              modules.put(null, result);
            }
            modules.put(moduleID, result);
          }
          return result;
        }
      }
    }
    String msg;
    String msg;
    if (expectedID == null) {
      msg = SecAuthMessages.noSecureStorageModules;
    } else {
      msg = NLS.bind(SecAuthMessages.noSecureStorageModule, expectedID);
    }
    throw new StorageException(1, msg);
  }
  
  private void reportError(String template, String arg, IConfigurationElement element, Throwable e)
  {
    String supplier = element.getContributor().getName();
    String message = NLS.bind(template, arg, supplier);
    AuthPlugin.getDefault().logError(message, e);
  }
  
  public void added(IExtension[] extensions)
  {
    clearCaches();
  }
  
  public void added(IExtensionPoint[] extensionPoints)
  {
    clearCaches();
  }
  
  public void removed(IExtension[] extensions)
  {
    clearCaches();
  }
  
  public void removed(IExtensionPoint[] extensionPoints)
  {
    clearCaches();
  }
  
  public void clearCaches()
  {
    synchronized (modules)
    {
      modules.clear();
      
      SecurePreferencesMapper.clearPasswordCache();
    }
  }
  
  public boolean isLoggedIn()
  {
    synchronized (modules)
    {
      return modules.size() != 0;
    }
  }
  
  protected HashSet getDisabledModules()
  {
    IEclipsePreferences node = new ConfigurationScope().getNode("org.eclipse.equinox.security");
    String tmp = node.get("org.eclipse.equinox.security.preferences.disabledProviders", null);
    if ((tmp == null) || (tmp.length() == 0)) {
      return null;
    }
    HashSet disabledModules = new HashSet();
    String[] disabledProviders = tmp.split(",");
    for (int i = 0; i < disabledProviders.length; i++) {
      disabledModules.add(disabledProviders[i]);
    }
    return disabledModules;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.equinox.internal.security.storage.PasswordProviderSelector
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.equinox.internal.security.storage;

public class PersistedPath
{
  private static final String DOUBLE_SLASH = "//";
  private final String key;
  private final String path;
  
  public PersistedPath(String path, String key)
  {
    this.key = key;
    this.path = path;
  }
  
  public String getKey()
  {
    return key;
  }
  
  public String getPath()
  {
    return path;
  }
  
  public String toString()
  {
    int pathLength = path == null ? 0 : path.length();
    String result;
    String result;
    if (key.indexOf('/') == -1)
    {
      String result;
      if (pathLength == 0) {
        result = key;
      } else {
        result = path + '/' + key;
      }
    }
    else
    {
      String result;
      if (pathLength == 0) {
        result = "//" + key;
      } else {
        result = path + "//" + key;
      }
    }
    return result;
  }
  
  public PersistedPath(String fullPath)
  {
    int index = fullPath.indexOf("//");
    if (index == -1)
    {
      int lastIndex = fullPath.lastIndexOf('/');
      if (lastIndex == -1)
      {
        path = null;
        key = fullPath;
      }
      else
      {
        path = fullPath.substring(0, lastIndex);
        key = fullPath.substring(lastIndex + 1);
      }
    }
    else
    {
      path = fullPath.substring(0, index);
      key = fullPath.substring(index + 2);
    }
  }
}

/* Location:
 * Qualified Name:     org.eclipse.equinox.internal.security.storage.PersistedPath
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.equinox.internal.security.storage;

import java.io.IOException;
import java.io.PrintStream;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Properties;
import java.util.Set;
import javax.crypto.BadPaddingException;
import javax.crypto.IllegalBlockSizeException;
import org.eclipse.equinox.internal.security.auth.AuthPlugin;
import org.eclipse.equinox.internal.security.auth.nls.SecAuthMessages;
import org.eclipse.equinox.internal.security.storage.friends.InternalExchangeUtils;
import org.eclipse.equinox.security.storage.StorageException;
import org.eclipse.osgi.util.NLS;

public class SecurePreferences
{
  protected static final String DEFAULT_PASSWORD_ID = "org.eclipse.equinox.security.noModule";
  private static final String PATH_SEPARATOR = String.valueOf('/');
  private static final String[] EMPTY_STRING_ARRAY = new String[0];
  private static final String FALSE = "false";
  private static final String TRUE = "true";
  private boolean removed = false;
  protected final SecurePreferences parent;
  private final String name;
  protected Map children;
  private Map values;
  private SecurePreferencesRoot root = null;
  
  public SecurePreferences(SecurePreferences parent, String name)
  {
    this.parent = parent;
    this.name = name;
  }
  
  public SecurePreferences parent()
  {
    checkRemoved();
    return parent;
  }
  
  public String name()
  {
    checkRemoved();
    return name;
  }
  
  public String absolutePath()
  {
    checkRemoved();
    if (parent == null) {
      return PATH_SEPARATOR;
    }
    String parentPath = parent.absolutePath();
    if (PATH_SEPARATOR.equals(parentPath)) {
      return parentPath + name;
    }
    return parentPath + PATH_SEPARATOR + name;
  }
  
  public SecurePreferences node(String pathName)
  {
    checkRemoved();
    validatePath(pathName);
    return navigateToNode(pathName, true);
  }
  
  public boolean nodeExists(String pathName)
  {
    checkRemoved();
    validatePath(pathName);
    return navigateToNode(pathName, false) != null;
  }
  
  public String[] keys()
  {
    checkRemoved();
    if (values == null) {
      return EMPTY_STRING_ARRAY;
    }
    Set keys = values.keySet();
    int size = keys.size();
    String[] result = new String[size];
    int pos = 0;
    for (Iterator i = keys.iterator(); i.hasNext();) {
      result[(pos++)] = ((String)i.next());
    }
    return result;
  }
  
  public String[] childrenNames()
  {
    checkRemoved();
    if (children == null) {
      return EMPTY_STRING_ARRAY;
    }
    Set keys = children.keySet();
    int size = keys.size();
    String[] result = new String[size];
    int pos = 0;
    for (Iterator i = keys.iterator(); i.hasNext();) {
      result[(pos++)] = ((String)i.next());
    }
    return result;
  }
  
  protected SecurePreferencesRoot getRoot()
  {
    if (root == null)
    {
      SecurePreferences result = this;
      while (result.parent() != null) {
        result = result.parent();
      }
      root = ((SecurePreferencesRoot)result);
    }
    return root;
  }
  
  protected SecurePreferences navigateToNode(String pathName, boolean create)
  {
    if ((pathName == null) || (pathName.length() == 0)) {
      return this;
    }
    int pos = pathName.indexOf('/');
    if (pos == -1) {
      return getChild(pathName, create);
    }
    if (pos == 0) {
      return getRoot().navigateToNode(pathName.substring(1), create);
    }
    String topSegment = pathName.substring(0, pos);
    String otherSegments = pathName.substring(pos + 1);
    SecurePreferences child = getChild(topSegment, create);
    if ((child == null) && (!create)) {
      return null;
    }
    return child.navigateToNode(otherSegments, create);
  }
  
  private synchronized SecurePreferences getChild(String segment, boolean create)
  {
    if (children == null) {
      if (create) {
        children = new HashMap(5);
      } else {
        return null;
      }
    }
    SecurePreferences child = (SecurePreferences)children.get(segment);
    if ((!create) || (child != null)) {
      return child;
    }
    child = new SecurePreferences(this, segment);
    children.put(segment, child);
    return child;
  }
  
  public void flush()
    throws IOException
  {
    getRoot().flush();
  }
  
  public void flush(Properties properties, String parentsPath)
  {
    String thisNodePath;
    String thisNodePath;
    if (name == null)
    {
      thisNodePath = null;
    }
    else
    {
      String thisNodePath;
      if (parentsPath == null) {
        thisNodePath = PATH_SEPARATOR + name;
      } else {
        thisNodePath = parentsPath + PATH_SEPARATOR + name;
      }
    }
    if (values != null) {
      for (Iterator i = values.keySet().iterator(); i.hasNext();)
      {
        String key = (String)i.next();
        PersistedPath extenalTag = new PersistedPath(thisNodePath, key);
        properties.setProperty(extenalTag.toString(), (String)values.get(key));
      }
    }
    if (children != null) {
      for (Iterator i = children.entrySet().iterator(); i.hasNext();)
      {
        Map.Entry entry = (Map.En
1 2 3 4 5

Further reading...

For more information on Java 1.5 Tiger, you may find Java 1.5 Tiger, A developer's Notebook by D. Flanagan and B. McLaughlin from O'Reilly of interest.

New!JAR listings


Copyright 2006-2019. Infinite Loop Ltd