Changeset 30822 in osm for applications/editors/josm/plugins/native-password-manager/src/org/netbeans/modules/keyring/mac/MacProvider.java
- Timestamp:
- 2014-11-29T16:30:52+01:00 (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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 }
Note:
See TracChangeset
for help on using the changeset viewer.