org-netbeans-modules-keyring-impl

16:39:58.775 INFO  jd.cli.Main - Decompiling org-netbeans-modules-keyring-impl.jar
package org.netbeans.modules.keyring.fallback;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.Callable;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.prefs.BackingStoreException;
import java.util.prefs.Preferences;
import org.netbeans.api.keyring.Keyring;
import org.netbeans.modules.keyring.impl.Utils;
import org.netbeans.modules.keyring.spi.EncryptionProvider;
import org.netbeans.spi.keyring.KeyringProvider;
import org.openide.DialogDisplayer;
import org.openide.NotifyDescriptor;
import org.openide.NotifyDescriptor.Confirmation;
import org.openide.util.Lookup;
import org.openide.util.NbBundle;
import org.openide.util.NbPreferences;

public class FallbackProvider
  implements KeyringProvider, Callable<Void>
{
  private static final Logger LOG = Logger.getLogger(FallbackProvider.class.getName());
  private static final String DESCRIPTION = ".description";
  private static final String SAMPLE_KEY = "__sample__";
  private EncryptionProvider encryption;
  
  public boolean enabled()
  {
    for (EncryptionProvider localEncryptionProvider : Lookup.getDefault().lookupAll(EncryptionProvider.class)) {
      if (localEncryptionProvider.enabled())
      {
        encryption = localEncryptionProvider;
        LOG.log(Level.FINE, "Using provider: {0}", localEncryptionProvider);
        Preferences localPreferences = prefs();
        Utils.goMinusR(localPreferences);
        localEncryptionProvider.encryptionChangingCallback(this);
        if (testSampleKey(localPreferences)) {
          return true;
        }
      }
    }
    LOG.fine("No provider");
    return false;
  }
  
  private boolean testSampleKey(Preferences paramPreferences)
  {
    byte[] arrayOfByte = paramPreferences.getByteArray("__sample__", null);
    if (arrayOfByte == null)
    {
      encryption.freshKeyring(true);
      if (_save("__sample__", ("__sample__" + UUID.randomUUID()).toCharArray(), NbBundle.getMessage(FallbackProvider.class, "FallbackProvider.sample_key.description")))
      {
        LOG.fine("saved sample key");
        return true;
      }
      LOG.fine("could not save sample key");
      return promptToDelete(paramPreferences);
    }
    encryption.freshKeyring(false);
    for (;;)
    {
      try
      {
        if (new String(encryption.decrypt(arrayOfByte)).startsWith("__sample__"))
        {
          LOG.fine("succeeded in decrypting sample key");
          return true;
        }
        LOG.fine("wrong result decrypting sample key");
      }
      catch (Exception localException)
      {
        LOG.log(Level.FINE, "failed to decrypt sample key", localException);
      }
      if (!encryption.decryptionFailed())
      {
        LOG.fine("sample key decryption failed");
        return promptToDelete(paramPreferences);
      }
      LOG.fine("will retry decryption of sample key");
    }
  }
  
  private boolean promptToDelete(Preferences paramPreferences)
  {
    Object localObject = DialogDisplayer.getDefault().notify(new NotifyDescriptor.Confirmation(NbBundle.getMessage(FallbackProvider.class, "FallbackProvider.msg_clear_keys"), NbBundle.getMessage(FallbackProvider.class, "FallbackProvider.title_clear_keys"), 2));
    if (localObject == NotifyDescriptor.OK_OPTION) {
      try
      {
        LOG.log(Level.FINE, "agreed to delete stored passwords: {0}", Arrays.asList(paramPreferences.keys()));
        paramPreferences.clear();
        return testSampleKey(paramPreferences);
      }
      catch (BackingStoreException localBackingStoreException)
      {
        LOG.log(Level.INFO, null, localBackingStoreException);
      }
    } else {
      LOG.fine("refused to delete stored passwords");
    }
    return false;
  }
  
  private Preferences prefs()
  {
    return NbPreferences.forModule(Keyring.class).node(encryption.id());
  }
  
  public char[] read(String paramString)
  {
    byte[] arrayOfByte = prefs().getByteArray(paramString, null);
    if (arrayOfByte == null) {
      return null;
    }
    try
    {
      return encryption.decrypt(arrayOfByte);
    }
    catch (Exception localException)
    {
      LOG.log(Level.FINE, "failed to decrypt password for " + paramString, localException);
    }
    return null;
  }
  
  public void save(String paramString1, char[] paramArrayOfChar, String paramString2)
  {
    _save(paramString1, paramArrayOfChar, paramString2);
  }
  
  private boolean _save(String paramString1, char[] paramArrayOfChar, String paramString2)
  {
    Preferences localPreferences = prefs();
    try
    {
      localPreferences.putByteArray(paramString1, encryption.encrypt(paramArrayOfChar));
    }
    catch (Exception localException)
    {
      LOG.log(Level.FINE, "failed to encrypt password for " + paramString1, localException);
      return false;
    }
    if (paramString2 != null) {
      localPreferences.put(paramString1 + ".description", paramString2);
    }
    return true;
  }
  
  public void delete(String paramString)
  {
    Preferences localPreferences = prefs();
    localPreferences.remove(paramString);
    localPreferences.remove(paramString + ".description");
  }
  
  public Void call()
    throws Exception
  {
    LOG.fine("encryption changing");
    HashMap localHashMap = new HashMap();
    Preferences localPreferences = prefs();
    for (String str : localPreferences.keys()) {
      if (!str.endsWith(".description"))
      {
        byte[] arrayOfByte = localPreferences.getByteArray(str, null);
        if (arrayOfByte != null) {
          localHashMap.put(str, encryption.decrypt(arrayOfByte));
        }
      }
    }
    LOG.log(Level.FINE, "reencrypting keys: {0}", localHashMap.keySet());
    encryption.encryptionChanged();
    for (??? = localHashMap.entrySet().iterator(); ((Iterator)???).hasNext();)
    {
      Map.Entry localEntry = (Map.Entry)((Iterator)???).next();
      localPreferences.putByteArray((String)localEntry.getKey(), encryption.encrypt((char[])localEntry.getValue()));
    }
    LOG.fine("encryption changing finished");
    return null;
  }
}

/* Location:
 * Qualified Name:     org.netbeans.modules.keyring.fallback.FallbackProvider
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package org.netbeans.modules.keyring.fallback;

import org.openide.util.Mutex.Action;

class MasterPasswordEncryption$1
  implements Mutex.Action<char[][]>
{
  MasterPasswordEncryption$1(MasterPasswordEncryption paramMasterPasswordEncryption) {}
  
  public char[][] run()
  {
    return new MasterPasswordPanel().display(MasterPasswordEncryption.access$000(this$0));
  }
}

/* Location:
 * Qualified Name:     org.netbeans.modules.keyring.fallback.MasterPasswordEncryption.1
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package org.netbeans.modules.keyring.fallback;

import java.awt.GraphicsEnvironment;
import java.security.spec.AlgorithmParameterSpec;
import java.util.Arrays;
import java.util.UUID;
import java.util.concurrent.Callable;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.prefs.Preferences;
import javax.crypto.Cipher;
import javax.crypto.SecretKey;
import javax.crypto.SecretKeyFactory;
import javax.crypto.spec.PBEKeySpec;
import javax.crypto.spec.PBEParameterSpec;
import org.netbeans.api.keyring.Keyring;
import org.netbeans.modules.keyring.impl.Utils;
import org.netbeans.modules.keyring.spi.EncryptionProvider;
import org.openide.util.Mutex;
import org.openide.util.Mutex.Action;
import org.openide.util.NbPreferences;

public class MasterPasswordEncryption
  implements EncryptionProvider
{
  private static final Logger LOG = Logger.getLogger(MasterPasswordEncryption.class.getName());
  private static final String ENCRYPTION_ALGORITHM = "PBEWithSHA1AndDESede";
  private SecretKeyFactory KEY_FACTORY;
  private AlgorithmParameterSpec PARAM_SPEC;
  private Cipher encrypt;
  private Cipher decrypt;
  private boolean unlocked;
  private Callable<Void> encryptionChanging;
  private char[] newMasterPassword;
  private boolean fresh;
  
  public boolean enabled()
  {
    if (GraphicsEnvironment.isHeadless())
    {
      LOG.fine("disabling master password encryption in headless mode");
      return false;
    }
    try
    {
      KEY_FACTORY = SecretKeyFactory.getInstance("PBEWithSHA1AndDESede");
      encrypt = Cipher.getInstance("PBEWithSHA1AndDESede");
      decrypt = Cipher.getInstance("PBEWithSHA1AndDESede");
      Preferences localPreferences = NbPreferences.forModule(Keyring.class);
      Utils.goMinusR(localPreferences);
      String str = "salt";
      byte[] arrayOfByte = localPreferences.getByteArray(str, null);
      if (arrayOfByte == null)
      {
        arrayOfByte = UUID.randomUUID().toString().getBytes();
        localPreferences.putByteArray(str, arrayOfByte);
      }
      PARAM_SPEC = new PBEParameterSpec(arrayOfByte, 20);
      LOG.warning("Falling back to master password encryption; add -J-Dorg.netbeans.modules.keyring.level=0 to netbeans.conf to see why native keyrings could not be loaded");
      
      return true;
    }
    catch (Exception localException)
    {
      LOG.log(Level.INFO, "Cannot initialize security using PBEWithSHA1AndDESede", localException);
    }
    return false;
  }
  
  public String id()
  {
    return "general";
  }
  
  public byte[] encrypt(char[] paramArrayOfChar)
    throws Exception
  {
    if (!unlockIfNecessary()) {
      throw new Exception("cannot unlock");
    }
    try
    {
      return doEncrypt(paramArrayOfChar);
    }
    catch (Exception localException)
    {
      unlocked = false;
      throw localException;
    }
  }
  
  public char[] decrypt(byte[] paramArrayOfByte)
    throws Exception
  {
    AtomicBoolean localAtomicBoolean = new AtomicBoolean();
    if (!unlockIfNecessary(localAtomicBoolean)) {
      throw new Exception("cannot unlock");
    }
    try
    {
      return doDecrypt(paramArrayOfByte);
    }
    catch (Exception localException1)
    {
      unlocked = false;
      throw localException1;
    }
    finally
    {
      if (localAtomicBoolean.get()) {
        try
        {
          encryptionChanging.call();
        }
        catch (Exception localException3)
        {
          LOG.log(Level.FINE, "failed to change encryption", localException3);
        }
      }
    }
  }
  
  private boolean unlockIfNecessary()
  {
    AtomicBoolean localAtomicBoolean = new AtomicBoolean();
    boolean bool = unlockIfNecessary(localAtomicBoolean);
    if (localAtomicBoolean.get()) {
      try
      {
        encryptionChanging.call();
      }
      catch (Exception localException)
      {
        LOG.log(Level.FINE, "failed to change encryption", localException);
      }
    }
    return bool;
  }
  
  private boolean unlockIfNecessary(AtomicBoolean paramAtomicBoolean)
  {
    if (unlocked) {
      return true;
    }
    char[][] arrayOfChar = (char[][])Mutex.EVENT.readAccess(new Mutex.Action()
    {
      public char[][] run()
      {
        return new MasterPasswordPanel().display(fresh);
      }
    });
    if (arrayOfChar == null)
    {
      LOG.fine("cancelled master password dialog");
      return false;
    }
    try
    {
      unlock(arrayOfChar[0]);
      Arrays.fill(arrayOfChar[0], '\000');
      if (arrayOfChar.length == 2)
      {
        newMasterPassword = arrayOfChar[1];
        LOG.fine("will set new master password");
        paramAtomicBoolean.set(true);
      }
      return true;
    }
    catch (Exception localException)
    {
      LOG.log(Level.FINE, "failed to initialize ciphers", localException);
    }
    return false;
  }
  
  void unlock(char[] paramArrayOfChar)
    throws Exception
  {
    LOG.fine("switching to new master password");
    PBEKeySpec localPBEKeySpec = new PBEKeySpec(paramArrayOfChar);
    SecretKey localSecretKey = KEY_FACTORY.generateSecret(localPBEKeySpec);
    encrypt.init(1, localSecretKey, PARAM_SPEC);
    decrypt.init(2, localSecretKey, PARAM_SPEC);
    unlocked = true;
  }
  
  byte[] doEncrypt(char[] paramArrayOfChar)
    throws Exception
  {
    assert (unlocked);
    byte[] arrayOfByte1 = Utils.chars2Bytes(paramArrayOfChar);
    byte[] arrayOfByte2 = encrypt.doFinal(arrayOfByte1);
    Arrays.fill(arrayOfByte1, (byte)0);
    return arrayOfByte2;
  }
  
  char[] doDecrypt(byte[] paramArrayOfByte)
    throws Exception
  {
    assert (unlocked);
    byte[] arrayOfByte = decrypt.doFinal(paramArrayOfByte);
    char[] arrayOfChar = Utils.bytes2Chars(arrayOfByte);
    Arrays.fill(arrayOfByte, (byte)0);
    return arrayOfChar;
  }
  
  public boolean decryptionFailed()
  {
    unlocked = false;
    return unlockIfNecessary();
  }
  
  public void encryptionChangingCallback(Callable<Void> paramCallable)
  {
    encryptionChanging = paramCallable;
  }
  
  public void encryptionChanged()
  {
    assert (newMasterPassword != null);
    LOG.fine("encryption changed");
    try
    {
      unlock(newMasterPassword);
    }
    catch (Exception localException)
    {
      LOG.log(Level.FINE, "failed to initialize ciphers", localException);
    }
    Arrays.fill(newMasterPassword, '\000');
    newMasterPassword = null;
  }
  
  public void freshKeyring(boolean paramBoolean)
  {
    fresh = paramBoolean;
  }
}

/* Location:
 * Qualified Name:     org.netbeans.modules.keyring.fallback.MasterPasswordEncryption
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package org.netbeans.modules.keyring.fallback;

import java.util.Arrays;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JLabel;
import javax.swing.JPasswordField;
import org.openide.NotificationLineSupport;
import org.openide.util.NbBundle;

class MasterPasswordPanel$1
  implements Runnable
{
  MasterPasswordPanel$1(MasterPasswordPanel paramMasterPasswordPanel, NotificationLineSupport paramNotificationLineSupport, JButton paramJButton) {}
  
  public void run()
  {
    if (MasterPasswordPanel.access$000(this$0).getPassword().length == 0)
    {
      val$notification.setInformationMessage(NbBundle.getMessage(MasterPasswordPanel.class, "MasterPasswordPanel.enter_password"));
      val$ok.setEnabled(false);
      return;
    }
    boolean bool = MasterPasswordPanel.access$100(this$0).isSelected();
    MasterPasswordPanel.access$200(this$0).setEnabled(bool);
    MasterPasswordPanel.access$300(this$0).setEnabled(bool);
    MasterPasswordPanel.access$400(this$0).setEnabled(bool);
    MasterPasswordPanel.access$500(this$0).setEnabled(bool);
    if (bool)
    {
      if (MasterPasswordPanel.access$300(this$0).getPassword().length == 0)
      {
        val$notification.setInformationMessage(NbBundle.getMessage(MasterPasswordPanel.class, "MasterPasswordPanel.enter_new_password"));
        val$ok.setEnabled(false);
        return;
      }
      if (!Arrays.equals(MasterPasswordPanel.access$300(this$0).getPassword(), MasterPasswordPanel.access$500(this$0).getPassword()))
      {
        val$notification.setInformationMessage(NbBundle.getMessage(MasterPasswordPanel.class, "MasterPasswordPanel.password_mismatch"));
        val$ok.setEnabled(false);
        return;
      }
    }
    val$notification.clearMessages();
    val$ok.setEnabled(true);
  }
}

/* Location:
 * Qualified Name:     org.netbeans.modules.keyring.fallback.MasterPasswordPanel.1
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package org.netbeans.modules.keyring.fallback;

import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;

class MasterPasswordPanel$2
  implements DocumentListener
{
  MasterPasswordPanel$2(MasterPasswordPanel paramMasterPasswordPanel, Runnable paramRunnable) {}
  
  public void insertUpdate(DocumentEvent paramDocumentEvent)
  {
    val$update.run();
  }
  
  public void removeUpdate(DocumentEvent paramDocumentEvent)
  {
    val$update.run();
  }
  
  public void changedUpdate(DocumentEvent paramDocumentEvent) {}
}

/* Location:
 * Qualified Name:     org.netbeans.modules.keyring.fallback.MasterPasswordPanel.2
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package org.netbeans.modules.keyring.fallback;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

class MasterPasswordPanel$3
  implements ActionListener
{
  MasterPasswordPanel$3(MasterPasswordPanel paramMasterPasswordPanel, Runnable paramRunnable) {}
  
  public void actionPerformed(ActionEvent paramActionEvent)
  {
    val$update.run();
  }
}

/* Location:
 * Qualified Name:     org.netbeans.modules.keyring.fallback.MasterPasswordPanel.3
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package org.netbeans.modules.keyring.fallback;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Arrays;
import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.GroupLayout.ParallelGroup;
import javax.swing.GroupLayout.SequentialGroup;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.LayoutStyle.ComponentPlacement;
import javax.swing.UIDefaults;
import javax.swing.UIManager;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
import javax.swing.text.Document;
import org.openide.DialogDisplayer;
import org.openide.NotificationLineSupport;
import org.openide.NotifyDescriptor;
import org.openide.awt.Mnemonics;
import org.openide.util.NbBundle;

class MasterPasswordPanel
  extends JPanel
{
  private JTextArea explanation;
  private JScrollPane explanationScroll;
  private JPasswordField masterPasswordField;
  private JLabel masterPasswordLabel;
  private JPasswordField newField1;
  private JPasswordField newField2;
  private JLabel newLabel1;
  private JLabel newLabel2;
  private JCheckBox setNewBox;
  
  public MasterPasswordPanel()
  {
    initComponents();
  }
  
  public char[][] display(boolean paramBoolean)
  {
    final JButton localJButton = new JButton(NbBundle.getMessage(MasterPasswordPanel.class, "MasterPasswordPanel.ok"));
    localJButton.setDefaultCapable(true);
    NotifyDescriptor localNotifyDescriptor = new NotifyDescriptor(this, NbBundle.getMessage(MasterPasswordPanel.class, "MasterPasswordPanel.enter_master_password"), 2, -1, new Object[] { localJButton, NotifyDescriptor.CANCEL_OPTION }, localJButton);
    
    final NotificationLineSupport localNotificationLineSupport = localNotifyDescriptor.createNotificationLineSupport();
    setNewBox.setEnabled(!paramBoolean);
    final Runnable local1 = new Runnable()
    {
      public void run()
      {
        if (masterPasswordField.getPassword().length == 0)
        {
          localNotificationLineSupport.setInformationMessage(NbBundle.getMessage(MasterPasswordPanel.class, "MasterPasswordPanel.enter_password"));
          localJButton.setEnabled(false);
          return;
        }
        boolean bool = setNewBox.isSelected();
        newLabel1.setEnabled(bool);
        newField1.setEnabled(bool);
        newLabel2.setEnabled(bool);
        newField2.setEnabled(bool);
        if (bool)
        {
          if (newField1.getPassword().length == 0)
          {
            localNotificationLineSupport.setInformationMessage(NbBundle.getMessage(MasterPasswordPanel.class, "MasterPasswordPanel.enter_new_password"));
            localJButton.setEnabled(false);
            return;
          }
          if (!Arrays.equals(newField1.getPassword(), newField2.getPassword()))
          {
            localNotificationLineSupport.setInformationMessage(NbBundle.getMessage(MasterPasswordPanel.class, "MasterPasswordPanel.password_mismatch"));
            localJButton.setEnabled(false);
            return;
          }
        }
        localNotificationLineSupport.clearMessages();
        localJButton.setEnabled(true);
      }
    };
    DocumentListener local2 = new DocumentListener()
    {
      public void insertUpdate(DocumentEvent paramAnonymousDocumentEvent)
      {
        local1.run();
      }
      
      public void removeUpdate(DocumentEvent paramAnonymousDocumentEvent)
      {
        local1.run();
      }
      
      public void changedUpdate(DocumentEvent paramAnonymousDocumentEvent) {}
    };
    local1.run();
    masterPasswordField.getDocument().addDocumentListener(local2);
    newField1.getDocument().addDocumentListener(local2);
    newField2.getDocument().addDocumentListener(local2);
    setNewBox.addActionListener(new ActionListener()
    {
      public void actionPerformed(ActionEvent paramAnonymousActionEvent)
      {
        local1.run();
      }
    });
    if (DialogDisplayer.getDefault().notify(localNotifyDescriptor) != localJButton) {
      return (char[][])null;
    }
    char[] arrayOfChar = masterPasswordField.getPassword();
    return new char[][] { setNewBox.isSelected() ? new char[][] { arrayOfChar, newField1.getPassword() } : arrayOfChar };
  }
  
  private void initComponents()
  {
    masterPasswordLabel = new JLabel();
    masterPasswordField = new JPasswordField();
    setNewBox = new JCheckBox();
    newLabel1 = new JLabel();
    newField1 = new JPasswordField();
    newLabel2 = new JLabel();
    newField2 = new JPasswordField();
    explanationScroll = new JScrollPane();
    explanation = new JTextArea();
    
    masterPasswordLabel.setLabelFor(masterPasswordField);
    Mnemonics.setLocalizedText(masterPasswordLabel, NbBundle.getMessage(MasterPasswordPanel.class, "MasterPasswordPanel.masterPasswordLabel.text"));
    
    Mnemonics.setLocalizedText(setNewBox, NbBundle.getMessage(MasterPasswordPanel.class, "MasterPasswordPanel.setNewBox.text"));
    
    newLabel1.setLabelFor(newField1);
    Mnemonics.setLocalizedText(newLabel1, NbBundle.getMessage(MasterPasswordPanel.class, "MasterPasswordPanel.newLabel1.text"));
    newLabel1.setEnabled(false);
    
    newField1.setEnabled(false);
    
    newLabel2.setLabelFor(newField2);
    Mnemonics.setLocalizedText(newLabel2, NbBundle.getMessage(MasterPasswordPanel.class, "MasterPasswordPanel.newLabel2.text"));
    newLabel2.setEnabled(false);
    
    newField2.setEnabled(false);
    
    explanationScroll.setBorder(null);
    
    explanation.setBackground(UIManager.getDefaults().getColor("Label.background"));
    explanation.setEditable(false);
    explanation.setLineWrap(true);
    explanation.setText(NbBundle.getMessage(MasterPasswordPanel.class, "MasterPasswordPanel.explanation.text"));
    explanation.setWrapStyleWord(true);
    explanationScroll.setViewportView(explanation);
    
    GroupLayout localGroupLayout = new GroupLayout(this);
    setLayout(localGroupLayout);
    localGroupLayout.setHorizontalGroup(localGroupLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(GroupLayout.Alignment.TRAILING, localGroupLayout.createSequentialGroup().addContainerGap().addGroup(localGroupLayout.createParallelGroup(GroupLayout.Alignment.TRAILING).addComponent(explanationScroll, GroupLayout.Alignment.LEADING).addGroup(GroupLayout.Alignment.LEADING, localGroupLayout.createSequentialGroup().addGroup(localGroupLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addComponent(newLabel1).addComponent(newLabel2).addComponent(masterPasswordLabel)).addPreferredGap(LayoutStyle.ComponentPlacement.RELATED).addGroup(localGroupLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addComponent(masterPasswordField, -1, 224, 32767).addComponent(newField2, -1, 224, 32767).addComponent(newField1, -1, 224, 32767))).addComponent(setNewBox, GroupLayout.Alignment.LEADING)).addContainerGap()));
    
    localGroupLayout.setVerticalGroup(localGroupLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(localGroupLayout.createSequentialGroup().addContainerGap(-1, 32767).addGroup(localGroupLayout.createParallelGroup(GroupLayout.Alignment.BASELINE).addComponent(masterPasswordLabel).addComponent(masterPasswordField, -2, -1, -2)).addGap(18, 18, 18).addComponent(setNewBox).addPreferredGap(LayoutStyle.ComponentPlacement.RELATED).addGroup(localGroupLayout.createParallelGroup(GroupLayout.Alignment.BASELINE).addComponent(newLabel1).addComponent(newField1, -2, -1, -2)).addPreferredGap(LayoutStyle.ComponentPlacement.RELATED).addGroup(localGroupLayout.createParallelGroup(GroupLayout.Alignment.BASELINE).addComponent(newLabel2).addComponent(newField2, -2, -1, -2)).addGap(18, 18, 18).addComponent(explanationScroll, -2, 98, -2)));
  }
}

/* Location:
 * Qualified Name:     org.netbeans.modules.keyring.fallback.MasterPasswordPanel
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package org.netbeans.modules.keyring.gnome;

import com.sun.jna.Pointer;
import com.sun.jna.Structure;

public class GnomeKeyringLibrary$GnomeKeyringFound
  extends Structure
{
  public String keyring;
  public int item_id;
  public Pointer attributes;
  public String secret;
}

/* Location:
 * Qualified Name:     org.netbeans.modules.keyring.gnome.GnomeKeyringLibrary.GnomeKeyringFound
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package org.netbeans.modules.keyring.gnome;

import com.sun.jna.Library;
import com.sun.jna.Native;
import com.sun.jna.Pointer;
import com.sun.jna.Structure;

public abstract interface GnomeKeyringLibrary
  extends Library
{
  public static final GnomeKeyringLibrary LIBRARY = (GnomeKeyringLibrary)Native.loadLibrary("gnome-keyring", GnomeKeyringLibrary.class);
  public static final int GNOME_KEYRING_ITEM_GENERIC_SECRET = 0;
  public static final int GnomeKeyringAttribute_SIZE = Pointer.SIZE * 3;
  
  public abstract boolean gnome_keyring_is_available();
  
  public abstract void gnome_keyring_attribute_list_append_string(Pointer paramPointer, String paramString1, String paramString2);
  
  public abstract void gnome_keyring_attribute_list_free(Pointer paramPointer);
  
  public abstract int gnome_keyring_item_create_sync(String paramString1, int paramInt, String paramString2, Pointer paramPointer, String paramString3, boolean paramBoolean, int[] paramArrayOfInt);
  
  public abstract int gnome_keyring_item_delete_sync(String paramString, int paramInt);
  
  public abstract int gnome_keyring_find_items_sync(int paramInt, Pointer paramPointer, Pointer[] paramArrayOfPointer);
  
  public abstract void gnome_keyring_found_list_free(Pointer paramPointer);
  
  public abstract void g_set_application_name(String paramString);
  
  public abstract Pointer g_array_new(int paramInt1, int paramInt2, int paramInt3);
  
  public abstract int g_list_length(Pointer paramPointer);
  
  public abstract GnomeKeyringFound g_list_nth_data(Pointer paramPointer, int paramInt);
  
  public static class GnomeKeyringFound
    extends Structure
  {
    public String keyring;
    public int item_id;
    public Pointer attributes;
    public String secret;
  }
}

/* Location:
 * Qualified Name:     org.netbeans.modules.keyring.gnome.GnomeKeyringLibrary
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package org.netbeans.modules.keyring.gnome;

import com.sun.jna.Pointer;
import java.text.MessageFormat;
import java.util.Iterator;
import java.util.Map;
import java.util.MissingResourceException;
import java.util.ResourceBundle;
import java.util.Set;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.netbeans.spi.keyring.KeyringProvider;
import org.openide.util.NbBundle;

public class GnomeProvider
  implements KeyringProvider
{
  private static final Logger LOG = Logger.getLogger(GnomeProvider.class.getName());
  private static final String KEY = "key";
  
  public boolean enabled()
  {
    if (Boolean.getBoolean("netbeans.keyring.no.native"))
    {
      LOG.fine("native keyring integration disabled");
      return false;
    }
    int i = 0;
    for (Object localObject = System.getenv().keySet().iterator(); ((Iterator)localObject).hasNext();)
    {
      String str = (String)((Iterator)localObject).next();
      if (str.startsWith("GNOME_KEYRING_"))
      {
        i = 1;
        break;
      }
    }
    if (i == 0)
    {
      LOG.fine("no GNOME_KEYRING_* environment variable set");
      return false;
    }
    try
    {
      localObject = MessageFormat.format(NbBundle.getBundle("org.netbeans.core.windows.view.ui.Bundle").getString("CTL_MainWindow_Title_No_Project"), new Object[] { "�" });
    }
    catch (MissingResourceException localMissingResourceException)
    {
      localObject = "NetBeans";
    }
    try
    {
      GnomeKeyringLibrary.LIBRARY.g_set_application_name((String)localObject);
      if (!GnomeKeyringLibrary.LIBRARY.gnome_keyring_is_available()) {
        return false;
      }
      read("NoNeXiStEnT");
      return true;
    }
    catch (Throwable localThrowable)
    {
      LOG.log(Level.FINE, null, localThrowable);
    }
    return false;
  }
  
  public char[] read(String paramString)
  {
    Pointer[] arrayOfPointer = new Pointer[1];
    Pointer localPointer = GnomeKeyringLibrary.LIBRARY.g_array_new(0, 0, GnomeKeyringLibrary.GnomeKeyringAttribute_SIZE);
    try
    {
      GnomeKeyringLibrary.LIBRARY.gnome_keyring_attribute_list_append_string(localPointer, "key", paramString);
      error(GnomeKeyringLibrary.LIBRARY.gnome_keyring_find_items_sync(0, localPointer, arrayOfPointer));
    }
    finally
    {
      GnomeKeyringLibrary.LIBRARY.gnome_keyring_attribute_list_free(localPointer);
    }
    if (arrayOfPointer[0] != null) {
      try
      {
        if (GnomeKeyringLibrary.LIBRARY.g_list_length(arrayOfPointer[0]) > 0)
        {
          GnomeKeyringLibrary.GnomeKeyringFound localGnomeKeyringFound = GnomeKeyringLibrary.LIBRARY.g_list_nth_data(arrayOfPointer[0], 0);
          if (localGnomeKeyringFound != null)
          {
            if (secret != null) {
              return secret.toCharArray();
            }
            LOG.warning("#183670: GnomeKeyringFound.secret == null");
            delete(paramString);
          }
          else
          {
            LOG.warning("#183670: GList<GnomeKeyringFound>[0].result == null");
          }
        }
      }
      finally
      {
        GnomeKeyringLibrary.LIBRARY.gnome_keyring_found_list_free(arrayOfPointer[0]);
      }
    }
    return null;
  }
  
  public void save(String paramString1, char[] paramArrayOfChar, String paramString2)
  {
    Pointer localPointer = GnomeKeyringLibrary.LIBRARY.g_array_new(0, 0, GnomeKeyringLibrary.GnomeKeyringAttribute_SIZE);
    try
    {
      GnomeKeyringLibrary.LIBRARY.gnome_keyring_attribute_list_append_string(localPointer, "key", paramString1);
      int[] arrayOfInt = new int[1];
      error(GnomeKeyringLibrary.LIBRARY.gnome_keyring_item_create_sync(null, 0, paramString2 != null ? paramString2 : paramString1, localPointer, new String(paramArrayOfChar), true, arrayOfInt));
    }
    finally
    {
      GnomeKeyringLibrary.LIBRARY.gnome_keyring_attribute_list_free(localPointer);
    }
  }
  
  public void delete(String paramString)
  {
    Pointer[] arrayOfPointer = new Pointer[1];
    Pointer localPointer = GnomeKeyringLibrary.LIBRARY.g_array_new(0, 0, GnomeKeyringLibrary.GnomeKeyringAttribute_SIZE);
    try
    {
      GnomeKeyringLibrary.LIBRARY.gnome_keyring_attribute_list_append_string(localPointer, "key", paramString);
      error(GnomeKeyringLibrary.LIBRARY.gnome_keyring_find_items_sync(0, localPointer, arrayOfPointer));
    }
    finally
    {
      GnomeKeyringLibrary.LIBRARY.gnome_keyring_attribute_list_free(localPointer);
    }
    if (arrayOfPointer[0] == null) {
      return;
    }
    int i;
    try
    {
      if (GnomeKeyringLibrary.LIBRARY.g_list_length(arrayOfPointer[0]) > 0)
      {
        GnomeKeyringLibrary.GnomeKeyringFound localGnomeKeyringFound = GnomeKeyringLibrary.LIBRARY.g_list_nth_data(arrayOfPointer[0], 0);
        i = item_id;
      }
      else
      {
        i = 0;
      }
    }
    finally
    {
      GnomeKeyringLibrary.LIBRARY.gnome_keyring_found_list_free(arrayOfPointer[0]);
    }
    if (i > 0) {
      if (("SunOS".equals(System.getProperty("os.name"))) && ("5.10".equals(System.getProperty("os.version")))) {
        save(paramString, new char[0], null);
      } else {
        error(GnomeKeyringLibrary.LIBRARY.gnome_keyring_item_delete_sync(null, i));
      }
    }
  }
  
  private static String[] ERRORS = { "OK", "DENIED", "NO_KEYRING_DAEMON", "ALREADY_UNLOCKED", "NO_SUCH_KEYRING", "BAD_ARGUMENTS", "IO_ERROR", "CANCELLED", "KEYRING_ALREADY_EXISTS", "NO_MATCH" };
  
  private static void error(int paramInt)
  {
    if ((paramInt != 0) && (paramInt != 9)) {
      LOG.log(Level.WARNING, "gnome-keyring error: {0}", ERRORS[paramInt]);
    }
  }
}

/* Location:
 * Qualified Name:     org.netbeans.modules.keyring.gnome.GnomeProvider
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package org.netbeans.modules.keyring.impl;

import java.io.File;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.prefs.Preferences;

public class Utils
{
  private static final Logger LOG = Logger.getLogger(Utils.class.getName());
  
  public static byte[] chars2Bytes(char[] paramArrayOfChar)
  {
    byte[] arrayOfByte = new byte[paramArrayOfChar.length * 2];
    for (int i = 0; i < paramArrayOfChar.length; i++)
    {
      arrayOfByte[(i * 2)] = ((byte)(paramArrayOfChar[i] / '?'));
      arrayOfByte[(i * 2 + 1)] = ((byte)(paramArrayOfChar[i] % '?'));
    }
    return arrayOfByte;
  }
  
  public static char[] bytes2Chars(byte[] paramArrayOfByte)
  {
    char[] arrayOfChar = new char[paramArrayOfByte.length / 2];
    for (int i = 0; i < arrayOfChar.length; i++) {
      arrayOfChar[i] = ((char)(paramArrayOfByte[(i * 2)] * 256 + paramArrayOfByte[(i * 2 + 1)]));
    }
    return arrayOfChar;
  }
  
  public static void goMinusR(Preferences paramPreferences)
  {
    File localFile = new File(System.getProperty("netbeans.user"), new StringBuilder().append("config/Preferences").append(paramPreferences.absolutePath()).toString().replace('/', File.separatorChar) + ".properties");
    if (localFile.isFile())
    {
      localFile.setReadable(false, false);
      localFile.setReadable(true, true);
      LOG.log(Level.FINE, "chmod go-r {0}", localFile);
    }
    else
    {
      LOG.log(Level.FINE, "no such file to chmod: {0}", localFile);
    }
  }
}

/* Location:
 * Qualified Name:     org.netbeans.modules.keyring.impl.Utils
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package org.netbeans.modules.keyring.kde;

public class KWalletProvider$KwalletException
  extends RuntimeException
{
  public KWalletProvider$KwalletException(KWalletProvider paramKWalletProvider, String paramString)
  {
    super("error while trying to access KWallet, during " + paramString);
  }
}

/* Location:
 * Qualified Name:     org.netbeans.modules.keyring.kde.KWalletProvider.KwalletException
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package org.netbeans.modules.keyring.kde;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.text.MessageFormat;
import java.util.Arrays;
import java.util.MissingResourceException;
import java.util.ResourceBundle;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.netbeans.spi.keyring.KeyringProvider;
import org.openide.util.NbBundle;

public class KWalletProvider
  implements KeyringProvider
{
  private static final Logger logger = Logger.getLogger(KWalletProvider.class.getName());
  private char[] handler;
  
  public KWalletProvider()
  {
    handler = "0".toCharArray();
  }
  
  public boolean enabled()
  {
    if (Boolean.getBoolean("netbeans.keyring.no.native"))
    {
      logger.fine("native keyring integration disabled");
      return false;
    }
    if (new String(runCommand("isEnabled", new char[0][])).equals("true")) {
      return updateHandler();
    }
    return false;
  }
  
  public char[] read(String paramString)
  {
    if (updateHandler())
    {
      char[] arrayOfChar = runCommand("readPassword", new char[][] { handler, getApplicationName(), paramString.toCharArray(), getApplicationName(true) });
      return arrayOfChar.length > 0 ? arrayOfChar : null;
    }
    throw new KwalletException("read");
  }
  
  public void save(String paramString1, char[] paramArrayOfChar, String paramString2)
  {
    if (updateHandler())
    {
      if (new String(runCommand("writePassword", new char[][] { handler, getApplicationName(), paramString1.toCharArray(), paramArrayOfChar, getApplicationName(true) })).equals("-1")) {
        throw new KwalletException("save");
      }
      return;
    }
    throw new KwalletException("save");
  }
  
  public void delete(String paramString)
  {
    if (updateHandler())
    {
      if (new String(runCommand("removeEntry", new char[][] { handler, getApplicationName(), paramString.toCharArray(), getApplicationName(true) })).equals("-1")) {
        throw new KwalletException("delete");
      }
      return;
    }
    throw new KwalletException("delete");
  }
  
  private boolean updateHandler()
  {
    handler = (new String(handler).equals("") ? "0".toCharArray() : handler);
    if (new String(runCommand("isOpen", new char[][] { handler })).equals("true")) {
      return true;
    }
    char[] arrayOfChar = runCommand("localWallet", new char[0][]);
    handler = runCommand("open", new char[][] { arrayOfChar, "0".toCharArray(), getApplicationName(true) });
    if (!new String(handler).equals("-1")) {
      return true;
    }
    return false;
  }
  
  private char[] runCommand(String paramString, char[]... paramVarArgs)
  {
    String[] arrayOfString = new String[paramVarArgs.length + 4];
    arrayOfString[0] = "qdbus";
    arrayOfString[1] = "org.kde.kwalletd";
    arrayOfString[2] = "/modules/kwalletd";
    arrayOfString[3] = ("org.kde.KWallet." + paramString);
    for (int i = 0; i < paramVarArgs.length; i++) {
      arrayOfString[(i + 4)] = new String(paramVarArgs[i]);
    }
    Runtime localRuntime = Runtime.getRuntime();
    String str1 = "";
    try
    {
      if (logger.isLoggable(Level.FINE)) {
        logger.log(Level.FINE, "executing {0}", Arrays.toString(arrayOfString));
      }
      Process localProcess = localRuntime.exec(arrayOfString);
      
      BufferedReader localBufferedReader = new BufferedReader(new InputStreamReader(localProcess.getInputStream()));
      String str2;
      while ((str2 = localBufferedReader.readLine()) != null)
      {
        if (!str1.equals("")) {
          str1 = str1.concat("\n");
        }
        str1 = str1.concat(str2);
      }
      localBufferedReader.close();
      localBufferedReader = new BufferedReader(new InputStreamReader(localProcess.getErrorStream()));
      while ((str2 = localBufferedReader.readLine()) != null)
      {
        if (!str1.equals("")) {
          str1 = str1.concat("\n");
        }
        str1 = str1.concat(str2);
      }
      localBufferedReader.close();
      
      int j = localProcess.waitFor();
      if (logger.isLoggable(Level.FINE)) {
        logger.log(Level.FINE, "application exit with code {0} for commandString: {1}", new Object[] { Integer.valueOf(j), Arrays.toString(arrayOfString) });
      }
    }
    catch (InterruptedException localInterruptedException)
    {
      logger.log(Level.FINE, "exception thrown while invoking the command \"" + Arrays.toString(arrayOfString) + "\"", localInterruptedException);
    }
    catch (IOException localIOException)
    {
      logger.log(Level.FINE, "exception thrown while invoking the command \"" + Arrays.toString(arrayOfString) + "\"", localIOException);
    }
    return str1.trim().toCharArray();
  }
  
  private char[] getApplicationName()
  {
    return getApplicationName(false);
  }
  
  private char
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