Changeset 30822 in osm
- Timestamp:
- 2014-11-29T16:30:52+01:00 (10 years ago)
- Location:
- applications/editors/josm/plugins/native-password-manager
- Files:
-
- 2 added
- 2 deleted
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/native-password-manager/.classpath
r30442 r30822 2 2 <classpath> 3 3 <classpathentry kind="src" path="src"/> 4 <classpathentry kind="lib" path="lib/jna.jar"/>5 4 <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/> 6 5 <classpathentry combineaccessrules="false" kind="src" path="/JOSM"/> 6 <classpathentry combineaccessrules="false" kind="src" path="/JOSM-jna"/> 7 7 <classpathentry kind="output" path="build"/> 8 8 </classpath> -
applications/editors/josm/plugins/native-password-manager/README
r26335 r30822 18 18 19 19 Original code: 20 http://hg.netbeans.org/main/file/524f40b94a30/keyring.impl and 21 http://hg.netbeans.org/main/file/524f40b94a30/keyring 20 http://hg.netbeans.org/main/file/9413a02b6f0c/keyring.impl 21 http://hg.netbeans.org/main/file/9413a02b6f0c/keyring 22 http://hg.netbeans.org/main/file/9413a02b6f0c/keyring.fallback 22 23 Patch: 23 24 netbeans-keyring-patches.diff -
applications/editors/josm/plugins/native-password-manager/build.xml
r30530 r30822 6 6 <!-- enter the *lowest* JOSM version this plugin is currently compatible with --> 7 7 <property name="plugin.main.version" value="7001"/> 8 <property name="plugin.author" value="Paul Hartmann"/> 9 <property name="plugin.class" value="org.openstreetmap.josm.plugins.npm.NPMPlugin"/> 10 <property name="plugin.description" value="Use your system''s password manager to store the API username and password. (KWallet and gnome-keyring are supported.)"/> 11 <property name="plugin.icon" value="images/lock24x24.png"/> 12 <property name="plugin.link" value="http://wiki.openstreetmap.org/wiki/JOSM/Plugins/Native_Password_Manager"/> 13 <property name="plugin.requires" value="jna"/> 8 14 9 15 <!-- … … 14 20 <import file="../build-common.xml"/> 15 21 16 <!-- classpath --> 17 <path id="classpath"> 18 <fileset dir="${plugin.lib.dir}" includes="**/*.jar"/> 19 <pathelement path="${josm}"/> 20 </path> 21 <!-- 22 ********************************************************** 23 ** compile - complies the source tree 24 ** Overrides the target from build-common.xml 25 ********************************************************** 26 --> 27 <target name="compile" depends="init"> 28 <echo message="compiling sources for ${plugin.jar} ..."/> 29 <javac srcdir="src" classpathref="classpath" debug="true" destdir="${plugin.build.dir}" includeantruntime="false"> 30 <compilerarg value="-Xlint:deprecation"/> 31 <compilerarg value="-Xlint:unchecked"/> 32 </javac> 33 </target> 34 35 <!-- 36 ********************************************************** 37 ** dist - creates the plugin jar 38 ********************************************************** 39 --> 40 <target name="dist" depends="compile,revision"> 41 <echo message="creating ${ant.project.name}.jar ... "/> 42 <copy todir="${plugin.build.dir}/images"> 43 <fileset dir="images"/> 44 </copy> 45 <copy todir="${plugin.build.dir}/data"> 46 <fileset dir="data"/> 47 </copy> 48 <copy todir="${plugin.build.dir}"> 49 <fileset dir="."> 50 <include name="README"/> 51 <include name="LICENSE"/> 52 <include name="gpl-2-cp.txt"/> 53 <include name="gpl-3.txt"/> 54 </fileset> 55 </copy> 56 <jar destfile="${plugin.jar}" basedir="${plugin.build.dir}"> 57 <!-- 58 ************************************************ 59 ** configure these properties. Most of them will be copied to the plugins 60 ** manifest file. Property values will also show up in the list available 61 ** plugins: http://josm.openstreetmap.de/wiki/Plugins. 62 ** 63 ************************************************ 64 --> 65 <manifest> 66 <attribute name="Author" value="Paul Hartmann"/> 67 <attribute name="Plugin-Class" value="org.openstreetmap.josm.plugins.npm.NPMPlugin"/> 68 <attribute name="Main-Class" value="org.openstreetmap.josm.plugins.npm.NPMPlugin"/> 69 <attribute name="Plugin-Date" value="${version.entry.commit.date}"/> 70 <attribute name="Plugin-Description" value="Use your system''s password manager to store the API username and password. (KWallet and gnome-keyring are supported.)"/> 71 <attribute name="Plugin-Icon" value="images/lock24x24.png"/> 72 <attribute name="Plugin-Link" value="http://wiki.openstreetmap.org/wiki/JOSM/Plugins/Native_Password_Manager"/> 73 <attribute name="Plugin-Mainversion" value="${plugin.main.version}"/> 74 <attribute name="Plugin-Version" value="${version.entry.commit.revision}"/> 75 </manifest> 76 <zipfileset src="${plugin.lib.dir}/jna.jar"/> 77 </jar> 78 </target> 22 <fileset id="plugin.requires.jars" dir="${plugin.dist.dir}"> 23 <include name="jna.jar"/> 24 </fileset> 25 79 26 </project> -
applications/editors/josm/plugins/native-password-manager/src/org/netbeans/modules/keyring/fallback/FallbackProvider.java
r30737 r30822 43 43 package org.netbeans.modules.keyring.fallback; 44 44 45 import java. util.UUID;45 import java.security.SecureRandom; 46 46 import java.util.logging.Level; 47 47 import java.util.logging.Logger; 48 48 49 import org.netbeans.modules.keyring.spi.EncryptionProvider; 49 50 import org.netbeans.spi.keyring.KeyringProvider; … … 73 74 } 74 75 76 @Override 75 77 public boolean enabled() { 76 78 if (encryption.enabled()) { … … 86 88 private boolean testSampleKey() { 87 89 encryption.freshKeyring(true); 88 if (_save(SAMPLE_KEY, (SAMPLE_KEY + UUID.randomUUID()).toCharArray(), 90 byte[] randomArray = new byte[36]; 91 new SecureRandom().nextBytes(randomArray); 92 if (_save(SAMPLE_KEY, (SAMPLE_KEY + new String(randomArray)).toCharArray(), 89 93 "Sample value ensuring that decryption is working.")) { 90 94 LOG.fine("saved sample key"); -
applications/editors/josm/plugins/native-password-manager/src/org/netbeans/modules/keyring/gnome/GnomeKeyringLibrary.java
r26335 r30822 43 43 package org.netbeans.modules.keyring.gnome; 44 44 45 import com.sun.jna.DefaultTypeMapper; 46 import com.sun.jna.FromNativeContext; 45 47 import com.sun.jna.Library; 46 48 import com.sun.jna.Native; 47 49 import com.sun.jna.Pointer; 48 50 import com.sun.jna.Structure; 51 import com.sun.jna.ToNativeContext; 52 import com.sun.jna.TypeConverter; 53 import java.io.File; 54 import java.util.Arrays; 55 import java.util.Collections; 56 import java.util.List; 57 import java.util.Map; 49 58 50 59 /** … … 55 64 public interface GnomeKeyringLibrary extends Library { 56 65 57 GnomeKeyringLibrary LIBRARY = (GnomeKeyringLibrary) Native.loadLibrary("gnome-keyring", GnomeKeyringLibrary.class); 66 class LibFinder { 67 private static final String GENERIC = "gnome-keyring"; 68 // http://packages.ubuntu.com/search?suite=precise&arch=any&mode=exactfilename&searchon=contents&keywords=libgnome-keyring.so.0 69 private static final String EXPLICIT_ONEIRIC = "/usr/lib/libgnome-keyring.so.0"; 70 private static Object load(Map<?,?> options) { 71 try { 72 return Native.loadLibrary(GENERIC, GnomeKeyringLibrary.class, options); 73 } catch (UnsatisfiedLinkError x) { 74 // #203735: on Oneiric, may have trouble finding right lib. 75 // Precise is using multiarch (#211401) which should work automatically using JNA 3.4+ (#211403). 76 // Unclear if this workaround is still needed for Oneiric with 3.4, but seems harmless to leave it in for now. 77 if (new File(EXPLICIT_ONEIRIC).isFile()) { 78 return Native.loadLibrary(EXPLICIT_ONEIRIC, GnomeKeyringLibrary.class, options); 79 } else { 80 throw x; 81 } 82 } 83 } 84 private LibFinder() {} 85 } 86 87 GnomeKeyringLibrary LIBRARY = (GnomeKeyringLibrary) LibFinder.load(Collections.singletonMap(OPTION_TYPE_MAPPER, new DefaultTypeMapper() { 88 { 89 addTypeConverter(Boolean.TYPE, new TypeConverter() { // #198921 90 @Override public Object toNative(Object value, ToNativeContext context) { 91 return Boolean.TRUE.equals(value) ? 1 : 0; 92 } 93 @Override public Object fromNative(Object value, FromNativeContext context) { 94 return ((Integer) value).intValue() != 0; 95 } 96 @Override public Class<?> nativeType() { 97 // gint is 32-bit int 98 return Integer.class; 99 } 100 }); 101 } 102 })); 58 103 59 104 boolean gnome_keyring_is_available(); … … 98 143 public /*GnomeKeyringAttributeList*/Pointer attributes; 99 144 public String secret; 145 146 @Override 147 protected List<String> getFieldOrder() { 148 return Arrays.asList( new String[] { 149 "keyring", 150 "item_id", 151 "attributes", 152 "secret", 153 } ); 154 } 100 155 } 101 156 -
applications/editors/josm/plugins/native-password-manager/src/org/netbeans/modules/keyring/gnome/GnomeProvider.java
r26335 r30822 43 43 package org.netbeans.modules.keyring.gnome; 44 44 45 import com.sun.jna.Pointer; 45 import static org.netbeans.modules.keyring.gnome.GnomeKeyringLibrary.GNOME_KEYRING_ITEM_GENERIC_SECRET; 46 import static org.netbeans.modules.keyring.gnome.GnomeKeyringLibrary.GnomeKeyringAttribute_SIZE; 47 import static org.netbeans.modules.keyring.gnome.GnomeKeyringLibrary.LIBRARY; 48 46 49 import java.util.logging.Level; 47 50 import java.util.logging.Logger; 48 import static org.netbeans.modules.keyring.gnome.GnomeKeyringLibrary.*; 51 52 import org.netbeans.modules.keyring.gnome.GnomeKeyringLibrary.GnomeKeyringFound; 49 53 import org.netbeans.spi.keyring.KeyringProvider; 54 55 import com.sun.jna.Pointer; 50 56 51 57 public class GnomeProvider implements KeyringProvider { -
applications/editors/josm/plugins/native-password-manager/src/org/netbeans/modules/keyring/kde/KWalletProvider.java
r30738 r30822 70 70 } 71 71 CommandResult result = runCommand("isEnabled"); 72 if(new String(result.retVal).equals("true")) { 72 if(new String(result.retVal).equals("true")) { 73 73 return updateHandler(); 74 } 74 } 75 75 return false; 76 } ;76 } 77 77 78 78 @Override 79 79 public char[] read(String key){ 80 80 if (updateHandler()){ 81 CommandResult result = runCommand("readPassword", handler, getApplicationName(), key.toCharArray(), getApplicationName( true));81 CommandResult result = runCommand("readPassword", handler, getApplicationName(), key.toCharArray(), getApplicationName()); 82 82 if (result.exitCode != 0){ 83 83 warning("read action returned not 0 exitCode"); … … 87 87 return null; 88 88 //throw new KwalletException("read"); 89 } ;89 } 90 90 91 91 @Override … … 95 95 if (updateHandler()){ 96 96 CommandResult result = runCommand("writePassword", handler , getApplicationName() 97 , key.toCharArray(), password , getApplicationName( true));97 , key.toCharArray(), password , getApplicationName()); 98 98 if (result.exitCode != 0 || (new String(result.retVal)).equals("-1")){ 99 99 warning("save action failed"); … … 102 102 } 103 103 //throw new KwalletException("save"); 104 } ;104 } 105 105 106 106 @Override … … 108 108 if (updateHandler()){ 109 109 CommandResult result = runCommand("removeEntry" ,handler, 110 getApplicationName() , key.toCharArray() , getApplicationName( true));110 getApplicationName() , key.toCharArray() , getApplicationName()); 111 111 if (result.exitCode != 0 || (new String(result.retVal)).equals("-1")){ 112 112 warning("delete action failed"); … … 115 115 } 116 116 //throw new KwalletException("delete"); 117 } ;117 } 118 118 119 119 private boolean updateHandler(){ … … 122 122 } 123 123 handler = new String(handler).equals("")? "0".toCharArray() : handler; 124 CommandResult result = runCommand("isOpen",handler); 124 CommandResult result = runCommand("isOpen",handler); 125 125 if(new String(result.retVal).equals("true")){ 126 126 return true; 127 127 } 128 128 char[] localWallet = defaultLocalWallet; 129 result = runCommand("localWallet"); 130 if(result.exitCode == 0) { 129 result = runCommand("localWallet"); 130 if(result.exitCode == 0) { 131 131 localWallet = result.retVal; 132 132 } 133 134 if(new String(localWallet).contains(".service")) { 133 134 if(new String(localWallet).contains(".service")) { 135 135 //Temporary workaround for the bug in kdelibs/kdeui/util/kwallet.cpp 136 136 //The bug was fixed http://svn.reviewboard.kde.org/r/5885/diff/ … … 138 138 return false; 139 139 } 140 result = runCommand("open", localWallet , "0".toCharArray(), getApplicationName( true));141 if(result.exitCode == 2) { 140 result = runCommand("open", localWallet , "0".toCharArray(), getApplicationName()); 141 if(result.exitCode == 2) { 142 142 warning("time out happened while accessing KWallet"); 143 143 //don't try to open KWallet anymore until bug https://bugs.kde.org/show_bug.cgi?id=259229 is fixed 144 144 timeoutHappened = true; 145 145 return false; 146 } 146 } 147 147 if(result.exitCode != 0 || new String(result.retVal).equals("-1")) { 148 148 warning("failed to access KWallet"); 149 149 return false; 150 } 150 } 151 151 handler = result.retVal; 152 152 return true; 153 153 } 154 155 154 155 156 156 157 157 private CommandResult runCommand(String command,char[]... commandArgs) { … … 175 175 } 176 176 Process pr = rt.exec(argv); 177 String line; 178 177 179 178 try (BufferedReader input = new BufferedReader(new InputStreamReader(pr.getInputStream()))) { 179 180 String line; 180 181 while((line = input.readLine()) != null) { 181 182 if (!retVal.equals("")){ … … 183 184 } 184 185 retVal = retVal.concat(line); 185 } 186 } 187 186 } 187 } 188 188 try (BufferedReader input = new BufferedReader(new InputStreamReader(pr.getErrorStream()))) { 189 190 String line; 189 191 while((line = input.readLine()) != null) { 190 192 if (!errVal.equals("")){ … … 199 201 logger.log(Level.FINE, "application exit with code {0} for commandString: {1}; errVal: {2}", 200 202 new Object[]{exitCode, Arrays.toString(argv), errVal}); 201 } 203 } 202 204 } catch (InterruptedException ex) { 203 205 logger.log(Level.FINE, … … 210 212 } 211 213 return new CommandResult(exitCode, retVal.trim().toCharArray(), errVal.trim()); 212 } 214 } 213 215 214 216 private char[] getApplicationName(){ 215 return getApplicationName(false); 216 } 217 218 private char[] getApplicationName(boolean version){ 219 return "JOSM".toCharArray(); 217 return "JOSM".toCharArray(); // NOI18N 220 218 } 221 219 222 220 private void warning(String descr) { 223 221 logger.log(Level.WARNING, "Something went wrong: {0}", descr); 224 } 225 222 } 223 226 224 private class CommandResult { 227 225 private int exitCode; … … 231 229 this.exitCode = exitCode; 232 230 this.retVal = retVal; 233 } 231 } 234 232 } 235 233 -
applications/editors/josm/plugins/native-password-manager/src/org/netbeans/modules/keyring/mac/MacProvider.java
r26335 r30822 77 77 78 78 public void save(String key, char[] password, String description) { 79 delete(key); // XXX supposed to use SecKeychainItemModifyContent instead, but this seems like too much work80 79 try { 81 80 byte[] serviceName = key.getBytes("UTF-8"); … … 83 82 // Keychain Access seems to expect UTF-8, so do not use Utils.chars2Bytes: 84 83 byte[] data = new String(password).getBytes("UTF-8"); 85 error("save", SecurityLibrary.LIBRARY.SecKeychainAddGenericPassword(null, serviceName.length, serviceName, 86 accountName.length, accountName, data.length, data, null)); 84 Pointer[] itemRef = new Pointer[1]; 85 error("find (for save)", SecurityLibrary.LIBRARY.SecKeychainFindGenericPassword(null, serviceName.length, serviceName, 86 accountName.length, accountName, null, null, itemRef)); 87 if (itemRef[0] != null) { 88 error("save (update)", SecurityLibrary.LIBRARY.SecKeychainItemModifyContent(itemRef[0], null, data.length, data)); 89 SecurityLibrary.LIBRARY.CFRelease(itemRef[0]); 90 } else { 91 error("save (new)", SecurityLibrary.LIBRARY.SecKeychainAddGenericPassword(null, serviceName.length, serviceName, 92 accountName.length, accountName, data.length, data, null)); 93 } 87 94 } catch (UnsupportedEncodingException x) { 88 95 LOG.log(Level.WARNING, null, x); … … 100 107 if (itemRef[0] != null) { 101 108 error("delete", SecurityLibrary.LIBRARY.SecKeychainItemDelete(itemRef[0])); 109 SecurityLibrary.LIBRARY.CFRelease(itemRef[0]); 102 110 } 103 111 } catch (UnsupportedEncodingException x) { … … 108 116 private static void error(String msg, int code) { 109 117 if (code != 0 && code != /* errSecItemNotFound, always returned from find it seems */-25300) { 110 // XXX translate, but SecCopyErrorMessageString returns weird CFStringRef 111 LOG.warning(msg + ": " + code); 118 Pointer translated = SecurityLibrary.LIBRARY.SecCopyErrorMessageString(code, null); 119 String str; 120 if (translated == null) { 121 str = String.valueOf(code); 122 } else { 123 char[] buf = new char[(int) SecurityLibrary.LIBRARY.CFStringGetLength(translated)]; 124 for (int i = 0; i < buf.length; i++) { 125 buf[i] = SecurityLibrary.LIBRARY.CFStringGetCharacterAtIndex(translated, i); 126 } 127 SecurityLibrary.LIBRARY.CFRelease(translated); 128 str = new String(buf) + " (" + code + ")"; 129 } 130 LOG.log(Level.WARNING, "{0}: {1}", new Object[] {msg, str}); 112 131 } 113 132 } -
applications/editors/josm/plugins/native-password-manager/src/org/netbeans/modules/keyring/mac/SecurityLibrary.java
r26335 r30822 65 65 ); 66 66 67 int SecKeychainItemModifyContent( 68 Pointer/*SecKeychainItemRef*/ itemRef, 69 Pointer/*SecKeychainAttributeList**/ attrList, 70 int length, 71 byte[] data 72 ); 73 67 74 int SecKeychainFindGenericPassword( 68 75 Pointer keychainOrArray, … … 73 80 int[] passwordLength, 74 81 Pointer[] passwordData, 75 Pointer [] itemRef82 Pointer/*SecKeychainItemRef*/[] itemRef 76 83 ); 77 84 … … 80 87 ); 81 88 89 Pointer/*CFString*/ SecCopyErrorMessageString( 90 int status, 91 Pointer reserved 92 ); 93 94 // http://developer.apple.com/library/mac/#documentation/CoreFoundation/Reference/CFStringRef/Reference/reference.html 95 96 long/*CFIndex*/ CFStringGetLength( 97 Pointer/*CFStringRef*/ theString 98 ); 99 100 char/*UniChar*/ CFStringGetCharacterAtIndex( 101 Pointer/*CFStringRef*/ theString, 102 long/*CFIndex*/ idx 103 ); 104 105 void CFRelease( 106 Pointer/*CFTypeRef*/ cf 107 ); 108 82 109 } -
applications/editors/josm/plugins/native-password-manager/src/org/netbeans/modules/keyring/win32/Win32Protect.java
r26335 r30822 49 49 import com.sun.jna.WString; 50 50 import com.sun.jna.win32.StdCallLibrary; 51 51 52 import java.util.Arrays; 53 import java.util.List; 52 54 import java.util.concurrent.Callable; 53 55 import java.util.logging.Level; 54 56 import java.util.logging.Logger; 55 import org.netbeans.modules.keyring.impl.Utils; 57 58 import org.netbeans.modules.keyring.utils.Utils; 56 59 import org.netbeans.modules.keyring.spi.EncryptionProvider; 57 60 … … 161 164 ((Memory) pbData).clear(); 162 165 } 166 167 @Override 168 protected List<String> getFieldOrder() { 169 return Arrays.asList( new String[] { 170 "cbData", 171 "pbData", 172 } ); 173 } 163 174 } 164 175 -
applications/editors/josm/plugins/native-password-manager/src/org/openstreetmap/josm/plugins/npm/InitializationWizard.java
r30737 r30822 460 460 } 461 461 462 /** 463 * Close the dialog and discard all changes. 464 */ 462 465 class CancelAction extends AbstractAction { 463 466 public CancelAction() { … … 478 481 } 479 482 483 /** 484 * Go to the previous page. 485 */ 480 486 class BackAction extends AbstractAction { 481 487 public BackAction() {
Note:
See TracChangeset
for help on using the changeset viewer.