~ubuntu-branches/ubuntu/saucy/monodevelop/saucy-proposed

« back to all changes in this revision

Viewing changes to src/addins/MacPlatform/MacInterop/Keychain.cs

  • Committer: Package Import Robot
  • Author(s): Jo Shields
  • Date: 2012-02-05 10:49:36 UTC
  • mto: (10.3.1)
  • mto: This revision was merged to the branch mainline in revision 25.
  • Revision ID: package-import@ubuntu.com-20120205104936-4ujoylapu24cquuo
Tags: upstream-2.8.6.3+dfsg
ImportĀ upstreamĀ versionĀ 2.8.6.3+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
52
52
                }
53
53
                
54
54
                [DllImport (SecurityLib)]
 
55
                static extern OSStatus SecKeychainItemFreeContent (IntPtr attrList, IntPtr data);
 
56
 
 
57
                [DllImport (SecurityLib)]
 
58
                static extern OSStatus SecKeychainAddGenericPassword (IntPtr keychain, uint serviceNameLength, string serviceName,
 
59
                                                                      uint accountNameLength, string accountName, uint passwordLength,
 
60
                                                                      string passwordData, IntPtr itemRef);
 
61
                [DllImport (SecurityLib)]
 
62
                static extern OSStatus SecKeychainFindGenericPassword (IntPtr keychain, uint serviceNameLength, string serviceName,
 
63
                                                                      uint accountNameLength, string accountName, out uint passwordLength,
 
64
                                                                      out IntPtr passwordData, IntPtr itemRef);
 
65
 
 
66
                [DllImport (SecurityLib)]
 
67
                static extern OSStatus SecKeychainAddInternetPassword (IntPtr keychain, uint serverNameLength, string serverName, uint securityDomainLength,
 
68
                                                                      string securityDomain, uint accountNameLength, string accountName, uint pathLength,
 
69
                                                                      string path, ushort port, int protocol, int authenticationType,
 
70
                                                                      uint passwordLength, string passwordData, IntPtr itemRef);
 
71
                [DllImport (SecurityLib)]
 
72
                static extern OSStatus SecKeychainFindInternetPassword (IntPtr keychain, uint serverNameLength, string serverName, uint securityDomainLength,
 
73
                                                                      string securityDomain, uint accountNameLength, string accountName, uint pathLength,
 
74
                                                                      string path, ushort port, int protocol, int authenticationType,
 
75
                                                                      out uint passwordLength, out IntPtr passwordData, IntPtr itemRef);
 
76
 
 
77
                [DllImport (SecurityLib)]
55
78
                static extern OSStatus SecKeychainSearchCreateFromAttributes (IntPtr keychainOrArray, SecItemClass itemClass, IntPtr attrList, out IntPtr searchRef);
56
79
                
57
80
                [DllImport (SecurityLib)]
316
339
                {
317
340
                        return cert.GetNameInfo (X509NameType.SimpleName, false);
318
341
                }
 
342
 
 
343
                public static void AddInternetPassword (Uri uri, string userName, string password)
 
344
                {
 
345
                        var result = SecKeychainAddInternetPassword (IntPtr.Zero, (uint) uri.Host.Length, uri.Host, 0, null,
 
346
                                                                     (uint) userName.Length, userName, (uint) uri.PathAndQuery.Length, uri.PathAndQuery,
 
347
                                                                     (ushort) uri.Port, 0, 0, (uint) password.Length, password, IntPtr.Zero);
 
348
                        if (result != OSStatus.Ok)
 
349
                                throw new Exception ("Could not add internet password to keychain: " + GetError (result));
 
350
                }
 
351
 
 
352
                public static string FindInternetPassword (Uri uri, string userName)
 
353
                {
 
354
                        uint passwordLength;
 
355
                        IntPtr password;
 
356
                        var result = SecKeychainFindInternetPassword (IntPtr.Zero, (uint) uri.Host.Length, uri.Host, 0, null,
 
357
                                                                      (uint) userName.Length, userName, (uint) uri.PathAndQuery.Length, uri.PathAndQuery,
 
358
                                                                      (ushort) uri.Port, 0, 0, out passwordLength, out password, IntPtr.Zero);
 
359
                        if (result == OSStatus.ItemNotFound)
 
360
                                return null;
 
361
 
 
362
                        if (result != OSStatus.Ok)
 
363
                                throw new Exception ("Could not find internet password: " + GetError (result));
 
364
 
 
365
                        return Marshal.PtrToStringAuto (password, (int) passwordLength);
 
366
                }
319
367
                
320
368
                enum SecItemClass : uint
321
369
                {