[26335] | 1 | diff -r src-netbeans-524f40b94a30-origin/org/netbeans/modules/keyring/fallback/FallbackProvider.java src/org/netbeans/modules/keyring/fallback/FallbackProvider.java
|
---|
| 2 | 45,47d44
|
---|
| 3 | < import java.util.Arrays;
|
---|
| 4 | < import java.util.HashMap;
|
---|
| 5 | < import java.util.Map;
|
---|
| 6 | 49d45
|
---|
| 7 | < import java.util.concurrent.Callable;
|
---|
| 8 | 52,54d47
|
---|
| 9 | < import java.util.prefs.BackingStoreException;
|
---|
| 10 | < import java.util.prefs.Preferences;
|
---|
| 11 | < import org.netbeans.api.keyring.Keyring;
|
---|
| 12 | 58,63d50
|
---|
| 13 | < import org.openide.DialogDisplayer;
|
---|
| 14 | < import org.openide.NotifyDescriptor;
|
---|
| 15 | < import org.openide.util.Lookup;
|
---|
| 16 | < import org.openide.util.NbBundle;
|
---|
| 17 | < import org.openide.util.NbPreferences;
|
---|
| 18 | < import org.openide.util.lookup.ServiceProvider;
|
---|
| 19 | 68,69c55
|
---|
| 20 | < @ServiceProvider(service=KeyringProvider.class, position=1000)
|
---|
| 21 | < public class FallbackProvider implements KeyringProvider, Callable<Void> {
|
---|
| 22 | ---
|
---|
| 23 | > public class FallbackProvider implements KeyringProvider {
|
---|
| 24 | 76c62,75
|
---|
| 25 | <
|
---|
| 26 | ---
|
---|
| 27 | > private IPreferences pre;
|
---|
| 28 | >
|
---|
| 29 | > // simple interface for a generic preferences store
|
---|
| 30 | > public interface IPreferences {
|
---|
| 31 | > String get(String key, String def);
|
---|
| 32 | > void put(String key, String val);
|
---|
| 33 | > void remove(String key);
|
---|
| 34 | > }
|
---|
| 35 | >
|
---|
| 36 | > public FallbackProvider(EncryptionProvider encryption, IPreferences pref) {
|
---|
| 37 | > this.encryption = encryption;
|
---|
| 38 | > this.pre = pref;
|
---|
| 39 | > }
|
---|
| 40 | >
|
---|
| 41 | 78,87c77,79
|
---|
| 42 | < for (EncryptionProvider p : Lookup.getDefault().lookupAll(EncryptionProvider.class)) {
|
---|
| 43 | < if (p.enabled()) {
|
---|
| 44 | < encryption = p;
|
---|
| 45 | < Preferences prefs = prefs();
|
---|
| 46 | < Utils.goMinusR(prefs);
|
---|
| 47 | < p.encryptionChangingCallback(this);
|
---|
| 48 | < if (!testSampleKey(prefs)) {
|
---|
| 49 | < continue;
|
---|
| 50 | < }
|
---|
| 51 | < LOG.log(Level.FINE, "Using provider: {0}", p);
|
---|
| 52 | ---
|
---|
| 53 | > if (encryption.enabled()) {
|
---|
| 54 | > if (testSampleKey()) {
|
---|
| 55 | > LOG.log(Level.FINE, "Using provider: {0}", encryption);
|
---|
| 56 | 95,106c87,92
|
---|
| 57 | < private boolean testSampleKey(Preferences prefs) {
|
---|
| 58 | < byte[] ciphertext = prefs.getByteArray(SAMPLE_KEY, null);
|
---|
| 59 | < if (ciphertext == null) {
|
---|
| 60 | < encryption.freshKeyring(true);
|
---|
| 61 | < if (_save(SAMPLE_KEY, (SAMPLE_KEY + UUID.randomUUID()).toCharArray(),
|
---|
| 62 | < NbBundle.getMessage(FallbackProvider.class, "FallbackProvider.sample_key.description"))) {
|
---|
| 63 | < LOG.fine("saved sample key");
|
---|
| 64 | < return true;
|
---|
| 65 | < } else {
|
---|
| 66 | < LOG.fine("could not save sample key");
|
---|
| 67 | < return false;
|
---|
| 68 | < }
|
---|
| 69 | ---
|
---|
| 70 | > private boolean testSampleKey() {
|
---|
| 71 | > encryption.freshKeyring(true);
|
---|
| 72 | > if (_save(SAMPLE_KEY, (SAMPLE_KEY + UUID.randomUUID()).toCharArray(),
|
---|
| 73 | > "Sample value ensuring that decryption is working.")) {
|
---|
| 74 | > LOG.fine("saved sample key");
|
---|
| 75 | > return true;
|
---|
| 76 | 108,143c94,95
|
---|
| 77 | < encryption.freshKeyring(false);
|
---|
| 78 | < while (true) {
|
---|
| 79 | < try {
|
---|
| 80 | < if (new String(encryption.decrypt(ciphertext)).startsWith(SAMPLE_KEY)) {
|
---|
| 81 | < LOG.fine("succeeded in decrypting sample key");
|
---|
| 82 | < return true;
|
---|
| 83 | < } else {
|
---|
| 84 | < LOG.fine("wrong result decrypting sample key");
|
---|
| 85 | < }
|
---|
| 86 | < } catch (Exception x) {
|
---|
| 87 | < LOG.log(Level.FINE, "failed to decrypt sample key", x);
|
---|
| 88 | < }
|
---|
| 89 | < if (!encryption.decryptionFailed()) {
|
---|
| 90 | < LOG.fine("sample key decryption failed");
|
---|
| 91 | < return promptToDelete(prefs);
|
---|
| 92 | < }
|
---|
| 93 | < LOG.fine("will retry decryption of sample key");
|
---|
| 94 | < }
|
---|
| 95 | < }
|
---|
| 96 | < }
|
---|
| 97 | <
|
---|
| 98 | < private boolean promptToDelete(Preferences prefs) {
|
---|
| 99 | < Object result = DialogDisplayer.getDefault().notify(new NotifyDescriptor.Confirmation(
|
---|
| 100 | < NbBundle.getMessage(FallbackProvider.class, "FallbackProvider.msg_clear_keys"),
|
---|
| 101 | < NbBundle.getMessage(FallbackProvider.class, "FallbackProvider.title_clear_keys"),
|
---|
| 102 | < NotifyDescriptor.OK_CANCEL_OPTION));
|
---|
| 103 | < if (result == NotifyDescriptor.OK_OPTION) {
|
---|
| 104 | < try {
|
---|
| 105 | < LOG.log(Level.FINE, "agreed to delete stored passwords: {0}", Arrays.asList(prefs.keys()));
|
---|
| 106 | < prefs.clear();
|
---|
| 107 | < return testSampleKey(prefs);
|
---|
| 108 | < } catch (BackingStoreException x) {
|
---|
| 109 | < LOG.log(Level.INFO, null, x);
|
---|
| 110 | < }
|
---|
| 111 | < } else {
|
---|
| 112 | < LOG.fine("refused to delete stored passwords");
|
---|
| 113 | ---
|
---|
| 114 | > LOG.fine("could not save sample key");
|
---|
| 115 | > return false;
|
---|
| 116 | 145,149d96
|
---|
| 117 | < return false;
|
---|
| 118 | < }
|
---|
| 119 | <
|
---|
| 120 | < private Preferences prefs() {
|
---|
| 121 | < return NbPreferences.forModule(Keyring.class).node(encryption.id());
|
---|
| 122 | 153c100,101
|
---|
| 123 | < byte[] ciphertext = prefs().getByteArray(key, null);
|
---|
| 124 | ---
|
---|
| 125 | > String ciphertext_string = pre.get(key, null);
|
---|
| 126 | > byte[] ciphertext = ciphertext_string == null ? null : Utils.chars2Bytes(ciphertext_string.toCharArray());
|
---|
| 127 | 169d116
|
---|
| 128 | < Preferences prefs = prefs();
|
---|
| 129 | 171c118,120
|
---|
| 130 | < prefs.putByteArray(key, encryption.encrypt(password));
|
---|
| 131 | ---
|
---|
| 132 | > byte[] encryptedPasswordByteArray = encryption.encrypt(password);
|
---|
| 133 | > String encryptedPassword = encryptedPasswordByteArray == null ? null : String.valueOf(Utils.bytes2Chars(encryptedPasswordByteArray));
|
---|
| 134 | > pre.put(key, encryptedPassword);
|
---|
| 135 | 178c127
|
---|
| 136 | < prefs.put(key + DESCRIPTION, description);
|
---|
| 137 | ---
|
---|
| 138 | > pre.put(key + DESCRIPTION, description);
|
---|
| 139 | 184,209c133,134
|
---|
| 140 | < Preferences prefs = prefs();
|
---|
| 141 | < prefs.remove(key);
|
---|
| 142 | < prefs.remove(key + DESCRIPTION);
|
---|
| 143 | < }
|
---|
| 144 | <
|
---|
| 145 | < public Void call() throws Exception { // encryption changing
|
---|
| 146 | < LOG.fine("encryption changing");
|
---|
| 147 | < Map<String,char[]> saved = new HashMap<String,char[]>();
|
---|
| 148 | < Preferences prefs = prefs();
|
---|
| 149 | < for (String k : prefs.keys()) {
|
---|
| 150 | < if (k.endsWith(DESCRIPTION)) {
|
---|
| 151 | < continue;
|
---|
| 152 | < }
|
---|
| 153 | < byte[] ciphertext = prefs.getByteArray(k, null);
|
---|
| 154 | < if (ciphertext == null) {
|
---|
| 155 | < continue;
|
---|
| 156 | < }
|
---|
| 157 | < saved.put(k, encryption.decrypt(ciphertext));
|
---|
| 158 | < }
|
---|
| 159 | < LOG.log(Level.FINE, "reencrypting keys: {0}", saved.keySet());
|
---|
| 160 | < encryption.encryptionChanged();
|
---|
| 161 | < for (Map.Entry<String,char[]> entry : saved.entrySet()) {
|
---|
| 162 | < prefs.putByteArray(entry.getKey(), encryption.encrypt(entry.getValue()));
|
---|
| 163 | < }
|
---|
| 164 | < LOG.fine("encryption changing finished");
|
---|
| 165 | < return null;
|
---|
| 166 | ---
|
---|
| 167 | > pre.remove(key);
|
---|
| 168 | > pre.remove(key + DESCRIPTION);
|
---|
| 169 | diff -r src-netbeans-524f40b94a30-origin/org/netbeans/modules/keyring/gnome/GnomeProvider.java src/org/netbeans/modules/keyring/gnome/GnomeProvider.java
|
---|
| 170 | 46,47d45
|
---|
| 171 | < import java.text.MessageFormat;
|
---|
| 172 | < import java.util.MissingResourceException;
|
---|
| 173 | 52,53d49
|
---|
| 174 | < import org.openide.util.NbBundle;
|
---|
| 175 | < import org.openide.util.lookup.ServiceProvider;
|
---|
| 176 | 55d50
|
---|
| 177 | < @ServiceProvider(service=KeyringProvider.class, position=100)
|
---|
| 178 | 77,84c72
|
---|
| 179 | < String appName;
|
---|
| 180 | < try {
|
---|
| 181 | < appName = MessageFormat.format(
|
---|
| 182 | < NbBundle.getBundle("org.netbeans.core.windows.view.ui.Bundle").getString("CTL_MainWindow_Title_No_Project"),
|
---|
| 183 | < /*System.getProperty("netbeans.buildnumber")*/"…");
|
---|
| 184 | < } catch (MissingResourceException x) {
|
---|
| 185 | < appName = "NetBeans"; // NOI18N
|
---|
| 186 | < }
|
---|
| 187 | ---
|
---|
| 188 | > String appName = "JOSM";
|
---|
| 189 | diff -r src-netbeans-524f40b94a30-origin/org/netbeans/modules/keyring/kde/KWalletProvider.java src/org/netbeans/modules/keyring/kde/KWalletProvider.java
|
---|
| 190 | 48d47
|
---|
| 191 | < import java.text.MessageFormat;
|
---|
| 192 | 50d48
|
---|
| 193 | < import java.util.MissingResourceException;
|
---|
| 194 | 54,55d51
|
---|
| 195 | < import org.openide.util.NbBundle;
|
---|
| 196 | < import org.openide.util.lookup.ServiceProvider;
|
---|
| 197 | 61d56
|
---|
| 198 | < @ServiceProvider(service=KeyringProvider.class, position=99)
|
---|
| 199 | 224,230c219
|
---|
| 200 | < String appName;
|
---|
| 201 | < try {
|
---|
| 202 | < appName = MessageFormat.format(NbBundle.getBundle("org.netbeans.core.windows.view.ui.Bundle").getString("CTL_MainWindow_Title_No_Project"),version ? System.getProperty("netbeans.buildnumber"):"");
|
---|
| 203 | < } catch (MissingResourceException x) {
|
---|
| 204 | < appName = "NetBeans"+(version? " "+System.getProperty("netbeans.buildnumber"):"");
|
---|
| 205 | < }
|
---|
| 206 | < return appName.toCharArray();
|
---|
| 207 | ---
|
---|
| 208 | > return "JOSM".toCharArray();
|
---|
| 209 | diff -r src-netbeans-524f40b94a30-origin/org/netbeans/modules/keyring/mac/MacProvider.java src/org/netbeans/modules/keyring/mac/MacProvider.java
|
---|
| 210 | 50,51d49
|
---|
| 211 | < import org.openide.util.Utilities;
|
---|
| 212 | < import org.openide.util.lookup.ServiceProvider;
|
---|
| 213 | 53d50
|
---|
| 214 | < @ServiceProvider(service=KeyringProvider.class, position=200)
|
---|
| 215 | 59,63c56
|
---|
| 216 | < if (Boolean.getBoolean("netbeans.keyring.no.native")) {
|
---|
| 217 | < LOG.fine("native keyring integration disabled");
|
---|
| 218 | < return false;
|
---|
| 219 | < }
|
---|
| 220 | < return Utilities.isMac();
|
---|
| 221 | ---
|
---|
| 222 | > return true; // test elsewhere if we are on a mac
|
---|
| 223 | 69c62
|
---|
| 224 | < byte[] accountName = "NetBeans".getBytes("UTF-8");
|
---|
| 225 | ---
|
---|
| 226 | > byte[] accountName = "JOSM".getBytes("UTF-8");
|
---|
| 227 | 89c82
|
---|
| 228 | < byte[] accountName = "NetBeans".getBytes("UTF-8");
|
---|
| 229 | ---
|
---|
| 230 | > byte[] accountName = "JOSM".getBytes("UTF-8");
|
---|
| 231 | 103c96
|
---|
| 232 | < byte[] accountName = "NetBeans".getBytes("UTF-8");
|
---|
| 233 | ---
|
---|
| 234 | > byte[] accountName = "JOSM".getBytes("UTF-8");
|
---|
| 235 | diff -r src-netbeans-524f40b94a30-origin/org/netbeans/modules/keyring/win32/Win32Protect.java src/org/netbeans/modules/keyring/win32/Win32Protect.java
|
---|
| 236 | 57,58d56
|
---|
| 237 | < import org.openide.util.Utilities;
|
---|
| 238 | < import org.openide.util.lookup.ServiceProvider;
|
---|
| 239 | 65d62
|
---|
| 240 | < @ServiceProvider(service=EncryptionProvider.class, position=100)
|
---|
| 241 | 71,78c68
|
---|
| 242 | < if (!Utilities.isWindows()) {
|
---|
| 243 | < LOG.fine("not running on Windows");
|
---|
| 244 | < return false;
|
---|
| 245 | < }
|
---|
| 246 | < if (Boolean.getBoolean("netbeans.keyring.no.native")) {
|
---|
| 247 | < LOG.fine("native keyring integration disabled");
|
---|
| 248 | < return false;
|
---|
| 249 | < }
|
---|
| 250 | ---
|
---|
| 251 | > // asssume, we have windows os
|
---|