Difference between revisions of "OS X Keychain integration osxkeychain.patch"

From CDOT Wiki
Jump to: navigation, search
 
(No difference)

Latest revision as of 21:07, 8 February 2007

Index: mozilla/toolkit/components/passwordmgr/base/nsPasswordManager.cpp
===================================================================
--- mozilla/toolkit/components/passwordmgr/base/nsPasswordManager.cpp   (revision 17)
+++ mozilla/toolkit/components/passwordmgr/base/nsPasswordManager.cpp   (revision 19)
@@ -222,6 +222,7 @@
 
 nsPasswordManager::~nsPasswordManager()
 {
+   delete inst;
 }
 
 
@@ -2114,3 +2115,70 @@
                                  getter_Copies(str));
   aResult.Assign(str);
 }
+
+int nsPasswordManager::ChangeInternetPassword (SecKeychainItemRef itemRef, int accountNameLength, const char *accountName, int passwordLength, const void *passwordData) {
+
+    int rc = 0;
+   
+   if (accountName && passwordData) {
+       
+       SecKeychainAttribute attrs[] = {{ kSecAccountItemAttr, accountNameLength, (char *)accountName }};
+
+       const SecKeychainAttributeList attributes = { sizeof(attrs) / sizeof(attrs[0]), attrs };
+       rc = SecKeychainItemModifyAttributesAndData (itemRef, &attributes, passwordLength, passwordData);
+       
+   } else {
+   
+       rc = SecKeychainItemModifyAttributesAndData (itemRef, NULL, passwordLength, passwordData);
+               
+   }
+
+   return rc;
+
+}
+
+int nsPasswordManager::RetrieveInternetPassword (
+                               SecKeychainRef keychain/* a reference to the keychain where the entry will be added to. If NULL then the default keychain is used. */,
+                               int serverNameLength, const char *serverName, int securityDomainLength,
+                               const char *securityDomain,int pathLength, 
+                               const char *path, int port, SecProtocolType protocol, SecAuthenticationType authenticationType, 
+                               UInt32 *passwordLength, void **passwordData,SecKeychainItemRef *itemRef){
+   
+   int rc = 0;
+   rc = SecKeychainFindInternetPassword (keychain, serverNameLength, serverName, securityDomainLength,securityDomain,
+                                           NULL, NULL, pathLength, path, port, protocol, authenticationType, passwordLength, passwordData, itemRef);
+
+   return rc;
+   
+ }
+ 
+ int nsPasswordManager::AddInternetPassword (
+                       SecKeychainRef keychain/* a reference to the keychain where the entry will be added to. If NULL then the default keychain is used. */, 
+                       int serverNameLength, const char *serverName /* eg. www.google.com */, 
+                       int securityDomainLength, const char *securityDomain, 
+                       int accountNameLength, const char *accountName /* username */, int pathLength,
+                       const char *path /* the path to the login form eg. www.google.com'/dir' */, 
+                       int port /* the port by which the connection is made to the server: 80,443. etc... etc... */, 
+                       SecProtocolType protocol /* protocol type (ftp, http and so on) */
+                       /* http://developer.apple.com/documentation/Security/Reference/keychainservices/Reference/reference.html#//apple_ref/doc/c_ref/SecProtocolType */, 
+                       SecAuthenticationType authenticationType /* authentication type idetifier */
+                       /* http://developer.apple.com/documentation/Security/Reference/keychainservices/Reference/reference.html#//apple_ref/doc/c_ref/SecAuthenticationType */,
+                       int passwordLength, const void *passwordData /* A pointer to a buffer containing the password data to be stored in the keychain */,
+                       SecKeychainItemRef *itemRef /* a reference to a keychain item */) {
+   int rc = 0;
+   rc = SecKeychainAddInternetPassword (keychain , serverNameLength, serverName, securityDomainLength, 
+           securityDomain, accountNameLength, accountName, pathLength, path, port, protocol, authenticationType, 
+           passwordLength, passwordData, itemRef);
+           
+   return rc;
+}
+
+nsPasswordManager* nsPasswordManager::getInstance(){
+       if (inst == NULL) {
+               inst = new nsPasswordManager;
+       }
+        return inst;
+       
+}
+
+nsPasswordManager* nsPasswordManager::inst = NULL;
Index: mozilla/toolkit/components/passwordmgr/base/nsPasswordManager.h
===================================================================
--- mozilla/toolkit/components/passwordmgr/base/nsPasswordManager.h (revision 17)
+++ mozilla/toolkit/components/passwordmgr/base/nsPasswordManager.h (revision 19)
@@ -49,6 +49,10 @@
 #include "nsIPrefBranch.h"
 #include "nsIPromptFactory.h"
 
+#include <CoreFoundation.h>
+#include <Security.h>
+#include <CoreServices.h>
+
 /* 360565c4-2ef3-4f6a-bab9-94cca891b2a7 */
 #define NS_PASSWORDMANAGER_CID \
 {0x360565c4, 0x2ef3, 0x4f6a, {0xba, 0xb9, 0x94, 0xcc, 0xa8, 0x91, 0xb2, 0xa7}}
@@ -136,8 +140,23 @@
                             nsIAutoCompleteResult* aPreviousResult,
                             nsIDOMHTMLInputElement* aElement,
                             nsIAutoCompleteResult** aResult);
+                           
+   int AddInternetPassword (SecKeychainRef keychain, int serverNameLength, const char *serverName, int securityDomainLength, 
+                           const char *securityDomain, int accountNameLength, const char *accountName, int pathLength,
+                           const char *path, int port, SecProtocolType protocol, SecAuthenticationType authenticationType,
+                           int passwordLength, const void *passwordData, SecKeychainItemRef *itemRef);
+                       
+   int RetrieveInternetPassword (SecKeychainRef keychain, int serverNameLength, const char *serverName, int securityDomainLength,
+                               const char *securityDomain,int pathLength, 
+                               const char *path, int port, SecProtocolType protocol, SecAuthenticationType authenticationType, 
+                               UInt32 *passwordLength, void **passwordData,SecKeychainItemRef *itemRef);
+                               
+   int ChangeInternetPassword (SecKeychainItemRef itemRef, int accountNameLength, const char *accountName, 
+                               int passwordLength, const void *passwordData);
+   static nsPasswordManager* getInstance();