Index: native-password-manager/src/org/netbeans/modules/keyring/fallback/FallbackProvider.java =================================================================== --- native-password-manager.orig/src/org/netbeans/modules/keyring/fallback/FallbackProvider.java 2011-07-18 13:04:37.141522563 +0200 +++ native-password-manager/src/org/netbeans/modules/keyring/fallback/FallbackProvider.java 2011-07-18 13:09:34.194995561 +0200 @@ -42,49 +42,41 @@ package org.netbeans.modules.keyring.fallback; -import java.util.Arrays; -import java.util.HashMap; -import java.util.Map; 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.util.Lookup; -import org.openide.util.NbBundle; -import org.openide.util.NbPreferences; -import org.openide.util.lookup.ServiceProvider; /** * Platform-independent keyring provider using a master password and the user directory. */ -@ServiceProvider(service=KeyringProvider.class, position=1000) -public class FallbackProvider implements KeyringProvider, Callable { +public class FallbackProvider implements KeyringProvider { 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; - + private IPreferences prefs; + + // simple interface for a generic preferences store + public interface IPreferences { + byte[] getByteArray(String key, byte[] def); + void putByteArray(String key, byte[] val); + void remove(String key); + } + + public FallbackProvider(EncryptionProvider encryption, IPreferences prefs) { + this.encryption = encryption; + this.prefs = prefs; + } + public boolean enabled() { - for (EncryptionProvider p : Lookup.getDefault().lookupAll(EncryptionProvider.class)) { - if (p.enabled()) { - encryption = p; - Preferences prefs = prefs(); - Utils.goMinusR(prefs); - p.encryptionChangingCallback(this); - if (!testSampleKey(prefs)) { - continue; - } - LOG.log(Level.FINE, "Using provider: {0}", p); + if (encryption.enabled()) { + if (testSampleKey()) { + LOG.log(Level.FINE, "Using provider: {0}", encryption); return true; } } @@ -92,65 +84,20 @@ return false; } - private boolean testSampleKey(Preferences prefs) { - byte[] ciphertext = prefs.getByteArray(SAMPLE_KEY, null); - if (ciphertext == null) { - encryption.freshKeyring(true); - if (_save(SAMPLE_KEY, (SAMPLE_KEY + UUID.randomUUID()).toCharArray(), - NbBundle.getMessage(FallbackProvider.class, "FallbackProvider.sample_key.description"))) { - LOG.fine("saved sample key"); - return true; - } else { - LOG.fine("could not save sample key"); - return false; - } - } else { - encryption.freshKeyring(false); - while (true) { - try { - if (new String(encryption.decrypt(ciphertext)).startsWith(SAMPLE_KEY)) { - LOG.fine("succeeded in decrypting sample key"); - return true; - } else { - LOG.fine("wrong result decrypting sample key"); - } - } catch (Exception x) { - LOG.log(Level.FINE, "failed to decrypt sample key", x); - } - if (!encryption.decryptionFailed()) { - LOG.fine("sample key decryption failed"); - return promptToDelete(prefs); - } - LOG.fine("will retry decryption of sample key"); - } - } - } - - private boolean promptToDelete(Preferences prefs) { - Object result = DialogDisplayer.getDefault().notify(new NotifyDescriptor.Confirmation( - NbBundle.getMessage(FallbackProvider.class, "FallbackProvider.msg_clear_keys"), - NbBundle.getMessage(FallbackProvider.class, "FallbackProvider.title_clear_keys"), - NotifyDescriptor.OK_CANCEL_OPTION)); - if (result == NotifyDescriptor.OK_OPTION) { - try { - LOG.log(Level.FINE, "agreed to delete stored passwords: {0}", Arrays.asList(prefs.keys())); - prefs.clear(); - return testSampleKey(prefs); - } catch (BackingStoreException x) { - LOG.log(Level.INFO, null, x); - } + private boolean testSampleKey() { + encryption.freshKeyring(true); + if (_save(SAMPLE_KEY, (SAMPLE_KEY + UUID.randomUUID()).toCharArray(), + "Sample value ensuring that decryption is working.")) { + LOG.fine("saved sample key"); + return true; } else { - LOG.fine("refused to delete stored passwords"); + LOG.fine("could not save sample key"); + return false; } - return false; - } - - private Preferences prefs() { - return NbPreferences.forModule(Keyring.class).node(encryption.id()); } public char[] read(String key) { - byte[] ciphertext = prefs().getByteArray(key, null); + byte[] ciphertext = prefs.getByteArray(key, null); if (ciphertext == null) { return null; } @@ -166,47 +113,18 @@ _save(key, password, description); } private boolean _save(String key, char[] password, String description) { - Preferences prefs = prefs(); try { prefs.putByteArray(key, encryption.encrypt(password)); } catch (Exception x) { LOG.log(Level.FINE, "failed to encrypt password for " + key, x); return false; } - if (description != null) { - // Preferences interface gives no access to *.properties comments, so: - prefs.put(key + DESCRIPTION, description); - } return true; } public void delete(String key) { - Preferences prefs = prefs(); prefs.remove(key); prefs.remove(key + DESCRIPTION); } - public Void call() throws Exception { // encryption changing - LOG.fine("encryption changing"); - Map saved = new HashMap(); - Preferences prefs = prefs(); - for (String k : prefs.keys()) { - if (k.endsWith(DESCRIPTION)) { - continue; - } - byte[] ciphertext = prefs.getByteArray(k, null); - if (ciphertext == null) { - continue; - } - saved.put(k, encryption.decrypt(ciphertext)); - } - LOG.log(Level.FINE, "reencrypting keys: {0}", saved.keySet()); - encryption.encryptionChanged(); - for (Map.Entry entry : saved.entrySet()) { - prefs.putByteArray(entry.getKey(), encryption.encrypt(entry.getValue())); - } - LOG.fine("encryption changing finished"); - return null; - } - } Index: native-password-manager/src/org/netbeans/modules/keyring/gnome/GnomeProvider.java =================================================================== --- native-password-manager.orig/src/org/netbeans/modules/keyring/gnome/GnomeProvider.java 2011-07-18 13:04:37.141522563 +0200 +++ native-password-manager/src/org/netbeans/modules/keyring/gnome/GnomeProvider.java 2011-07-18 13:05:00.841640080 +0200 @@ -43,16 +43,11 @@ package org.netbeans.modules.keyring.gnome; import com.sun.jna.Pointer; -import java.text.MessageFormat; -import java.util.MissingResourceException; import java.util.logging.Level; import java.util.logging.Logger; import static org.netbeans.modules.keyring.gnome.GnomeKeyringLibrary.*; import org.netbeans.spi.keyring.KeyringProvider; -import org.openide.util.NbBundle; -import org.openide.util.lookup.ServiceProvider; -@ServiceProvider(service=KeyringProvider.class, position=100) public class GnomeProvider implements KeyringProvider { private static final Logger LOG = Logger.getLogger(GnomeProvider.class.getName()); @@ -74,14 +69,7 @@ LOG.fine("no GNOME_KEYRING_* environment variable set"); return false; } - String appName; - try { - appName = MessageFormat.format( - NbBundle.getBundle("org.netbeans.core.windows.view.ui.Bundle").getString("CTL_MainWindow_Title_No_Project"), - /*System.getProperty("netbeans.buildnumber")*/"…"); - } catch (MissingResourceException x) { - appName = "NetBeans"; // NOI18N - } + String appName = "JOSM"; try { // Need to do this somewhere, or we get warnings on console. // Also used by confirmation dialogs to give the app access to the login keyring. Index: native-password-manager/src/org/netbeans/modules/keyring/kde/KWalletProvider.java =================================================================== --- native-password-manager.orig/src/org/netbeans/modules/keyring/kde/KWalletProvider.java 2011-07-18 13:04:37.149522597 +0200 +++ native-password-manager/src/org/netbeans/modules/keyring/kde/KWalletProvider.java 2011-07-18 13:05:00.849640122 +0200 @@ -45,20 +45,15 @@ 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.logging.Level; import java.util.logging.Logger; import org.netbeans.spi.keyring.KeyringProvider; -import org.openide.util.NbBundle; -import org.openide.util.lookup.ServiceProvider; /** * * @author psychollek, ynov */ -@ServiceProvider(service=KeyringProvider.class, position=99) public class KWalletProvider implements KeyringProvider{ private static final Logger logger = Logger.getLogger(KWalletProvider.class.getName()); @@ -221,13 +216,7 @@ } private char[] getApplicationName(boolean version){ - String appName; - try { - appName = MessageFormat.format(NbBundle.getBundle("org.netbeans.core.windows.view.ui.Bundle").getString("CTL_MainWindow_Title_No_Project"),version ? System.getProperty("netbeans.buildnumber"):""); - } catch (MissingResourceException x) { - appName = "NetBeans"+(version? " "+System.getProperty("netbeans.buildnumber"):""); - } - return appName.toCharArray(); + return "JOSM".toCharArray(); } private void warning(String descr) { Index: native-password-manager/src/org/netbeans/modules/keyring/mac/MacProvider.java =================================================================== --- native-password-manager.orig/src/org/netbeans/modules/keyring/mac/MacProvider.java 2011-07-18 13:04:37.157522639 +0200 +++ native-password-manager/src/org/netbeans/modules/keyring/mac/MacProvider.java 2011-07-18 13:05:00.849640122 +0200 @@ -47,26 +47,19 @@ import java.util.logging.Level; import java.util.logging.Logger; import org.netbeans.spi.keyring.KeyringProvider; -import org.openide.util.Utilities; -import org.openide.util.lookup.ServiceProvider; -@ServiceProvider(service=KeyringProvider.class, position=200) public class MacProvider implements KeyringProvider { private static final Logger LOG = Logger.getLogger(MacProvider.class.getName()); public boolean enabled() { - if (Boolean.getBoolean("netbeans.keyring.no.native")) { - LOG.fine("native keyring integration disabled"); - return false; - } - return Utilities.isMac(); + return true; // test elsewhere if we are on a mac } public char[] read(String key) { try { byte[] serviceName = key.getBytes("UTF-8"); - byte[] accountName = "NetBeans".getBytes("UTF-8"); + byte[] accountName = "JOSM".getBytes("UTF-8"); int[] dataLength = new int[1]; Pointer[] data = new Pointer[1]; error("find", SecurityLibrary.LIBRARY.SecKeychainFindGenericPassword(null, serviceName.length, serviceName, @@ -86,7 +79,7 @@ delete(key); // XXX supposed to use SecKeychainItemModifyContent instead, but this seems like too much work try { byte[] serviceName = key.getBytes("UTF-8"); - byte[] accountName = "NetBeans".getBytes("UTF-8"); + byte[] accountName = "JOSM".getBytes("UTF-8"); // Keychain Access seems to expect UTF-8, so do not use Utils.chars2Bytes: byte[] data = new String(password).getBytes("UTF-8"); error("save", SecurityLibrary.LIBRARY.SecKeychainAddGenericPassword(null, serviceName.length, serviceName, @@ -100,7 +93,7 @@ public void delete(String key) { try { byte[] serviceName = key.getBytes("UTF-8"); - byte[] accountName = "NetBeans".getBytes("UTF-8"); + byte[] accountName = "JOSM".getBytes("UTF-8"); Pointer[] itemRef = new Pointer[1]; error("find (for delete)", SecurityLibrary.LIBRARY.SecKeychainFindGenericPassword(null, serviceName.length, serviceName, accountName.length, accountName, null, null, itemRef)); Index: native-password-manager/src/org/netbeans/modules/keyring/win32/Win32Protect.java =================================================================== --- native-password-manager.orig/src/org/netbeans/modules/keyring/win32/Win32Protect.java 2011-07-18 13:04:37.165522672 +0200 +++ native-password-manager/src/org/netbeans/modules/keyring/win32/Win32Protect.java 2011-07-18 13:05:00.849640122 +0200 @@ -54,28 +54,18 @@ import java.util.logging.Logger; import org.netbeans.modules.keyring.impl.Utils; import org.netbeans.modules.keyring.spi.EncryptionProvider; -import org.openide.util.Utilities; -import org.openide.util.lookup.ServiceProvider; /** * Data protection utility for Microsoft Windows. * XXX org.tmatesoft.svn.core.internal.util.jna.SVNWinCrypt is a possibly more robust implementation * (though it seems to set CRYPTPROTECT_UI_FORBIDDEN which we do not necessarily want). */ -@ServiceProvider(service=EncryptionProvider.class, position=100) public class Win32Protect implements EncryptionProvider { private static final Logger LOG = Logger.getLogger(Win32Protect.class.getName()); public @Override boolean enabled() { - if (!Utilities.isWindows()) { - LOG.fine("not running on Windows"); - return false; - } - if (Boolean.getBoolean("netbeans.keyring.no.native")) { - LOG.fine("native keyring integration disabled"); - return false; - } + // asssume, we have windows os try { if (CryptLib.INSTANCE == null) { LOG.fine("loadLibrary -> null");