54
54
[DllImport (SecurityLib)]
55
static extern OSStatus SecKeychainItemFreeContent (IntPtr attrList, IntPtr data);
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);
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);
77
[DllImport (SecurityLib)]
55
78
static extern OSStatus SecKeychainSearchCreateFromAttributes (IntPtr keychainOrArray, SecItemClass itemClass, IntPtr attrList, out IntPtr searchRef);
57
80
[DllImport (SecurityLib)]
317
340
return cert.GetNameInfo (X509NameType.SimpleName, false);
343
public static void AddInternetPassword (Uri uri, string userName, string password)
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));
352
public static string FindInternetPassword (Uri uri, string userName)
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)
362
if (result != OSStatus.Ok)
363
throw new Exception ("Could not find internet password: " + GetError (result));
365
return Marshal.PtrToStringAuto (password, (int) passwordLength);
320
368
enum SecItemClass : uint