Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CoreWLan] Add XCode13 beta 1 support. #12103

Merged
merged 7 commits into from
Jul 19, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
231 changes: 231 additions & 0 deletions src/CoreWlan/CWKeychain.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,231 @@
using System;
using System.Runtime.InteropServices;

using CoreFoundation;
using Foundation;
using ObjCRuntime;
using Security;

#if NET
using System.Runtime.Versioning;
#endif


#nullable enable

using OSStatus = System.Int32;
using SecIdentityRef = System.IntPtr;
using CFArrayRef = System.IntPtr;
using NSDataRef = System.IntPtr;
using NSStringRef = System.IntPtr;

namespace CoreWlan {
#if NET
[SupportedOSPlatform ("maccatalyst15.0")]
#else
[MacCatalyst (15,0)]
#endif
public static partial class CWKeychain {

#if NET
[SupportedOSPlatform ("macos10.9")]
#else
[Mac (10,9)]
#endif
[DllImport (Constants.CoreWlanLibrary)]
static extern OSStatus CWKeychainCopyWiFiEAPIdentity (CWKeychainDomain domain, NSDataRef ssid, out SecIdentityRef identity);

#if NET
[SupportedOSPlatform ("macos10.9")]
#else
[Mac (10,9)]
#endif
public static bool FindWiFiEAPIdentity (CWKeychainDomain domain, NSData ssid, out SecIdentity? identity)
mandel-macaque marked this conversation as resolved.
Show resolved Hide resolved
{
identity = null;
IntPtr outPtr = IntPtr.Zero;
var result = CWKeychainCopyWiFiEAPIdentity (domain, ssid.GetHandle (), out outPtr);
if (result == 0)
{
mandel-macaque marked this conversation as resolved.
Show resolved Hide resolved
identity = new SecIdentity (outPtr, true);
}

return result == 0;
}

#if NET
[SupportedOSPlatform ("macos10.9")]
#else
[Mac (10,9)]
#endif
[DllImport (Constants.CoreWlanLibrary)]
static extern OSStatus CWKeychainDeleteWiFiEAPUsernameAndPassword (CWKeychainDomain domain, NSDataRef ssid);

#if NET
[SupportedOSPlatform ("macos10.9")]
#else
[Mac (10,9)]
#endif
public static bool TryDeleteWiFiEAPUsernameAndPassword (CWKeychainDomain domain, NSData ssid)
rolfbjarne marked this conversation as resolved.
Show resolved Hide resolved
=> CWKeychainDeleteWiFiEAPUsernameAndPassword (domain, ssid.GetHandle ()) == 0;

#if NET
[SupportedOSPlatform ("macos10.9")]
#else
[Mac (10,9)]
#endif
[DllImport (Constants.CoreWlanLibrary)]
static extern OSStatus CWKeychainDeleteWiFiPassword (CWKeychainDomain domain, NSDataRef ssid);

#if NET
[SupportedOSPlatform ("macos10.9")]
#else
[Mac (10,9)]
#endif
public static bool TryDeleteWiFiPassword (CWKeychainDomain domain, NSData ssid)
=> CWKeychainDeleteWiFiPassword (domain, ssid.GetHandle ()) == 0;

#if NET
[SupportedOSPlatform ("macos10.9")]
#else
[Mac (10,9)]
#endif
[DllImport (Constants.CoreWlanLibrary)]
static extern OSStatus CWKeychainFindWiFiEAPUsernameAndPassword (CWKeychainDomain domain, NSDataRef ssid, out NSStringRef username, out NSStringRef password);

#if NET
[SupportedOSPlatform ("macos10.9")]
#else
[Mac (10,9)]
#endif
public static bool TryFindWiFiEAPUsernameAndPassword (CWKeychainDomain domain, NSData ssid, out NSString? username, out NSString? password)
rolfbjarne marked this conversation as resolved.
Show resolved Hide resolved
{
username = null;
password = null;
NSStringRef usernamePtr = IntPtr.Zero;
NSStringRef passwordPtr = IntPtr.Zero;
var result = CWKeychainFindWiFiEAPUsernameAndPassword (domain, ssid.GetHandle (), out usernamePtr, out passwordPtr);
if (usernamePtr != IntPtr.Zero) {
username = Runtime.GetNSObject<NSString> (usernamePtr, true);
mandel-macaque marked this conversation as resolved.
Show resolved Hide resolved
}
if (passwordPtr != IntPtr.Zero) {
password= Runtime.GetNSObject<NSString> (passwordPtr, true);
mandel-macaque marked this conversation as resolved.
Show resolved Hide resolved
}
return result == 0;
}

#if NET
[SupportedOSPlatform ("macos10.9")]
#else
[Mac (10,9)]
#endif
[DllImport (Constants.CoreWlanLibrary)]
static extern OSStatus CWKeychainFindWiFiPassword (CWKeychainDomain domain, NSDataRef ssid, out NSStringRef password);

#if NET
[SupportedOSPlatform ("macos10.9")]
#else
[Mac (10,9)]
#endif
public static bool TryFindWiFiPassword (CWKeychainDomain domain, NSData ssid, out NSString? password)
rolfbjarne marked this conversation as resolved.
Show resolved Hide resolved
{
password = null;
NSStringRef passwordPtr = IntPtr.Zero;
var result = CWKeychainFindWiFiPassword (domain, ssid.GetHandle (), out passwordPtr);
if (passwordPtr != IntPtr.Zero) {
password= Runtime.GetNSObject<NSString> (passwordPtr, true);
mandel-macaque marked this conversation as resolved.
Show resolved Hide resolved
}
return result == 0;
}

#if NET
[SupportedOSPlatform ("macos10.9")]
#else
[Mac (10,9)]
#endif
[DllImport (Constants.CoreWlanLibrary)]
static extern OSStatus CWKeychainSetWiFiEAPIdentity (CWKeychainDomain domain, NSDataRef ssid, SecIdentityRef identity);

#if NET
[SupportedOSPlatform ("macos10.9")]
#else
[Mac (10,9)]
#endif
public static bool TrySetWiFiEAPIdentity (CWKeychainDomain domain, NSData ssid, SecIdentity? identity)
=> CWKeychainSetWiFiEAPIdentity (domain, ssid.GetHandle (), identity.GetHandle ()!) == 0;

#if NET
[SupportedOSPlatform ("macos10.9")]
#else
[Mac (10,9)]
#endif
[DllImport (Constants.CoreWlanLibrary)]
static extern OSStatus CWKeychainSetWiFiEAPUsernameAndPassword (CWKeychainDomain domain, NSDataRef ssid, NSStringRef username, NSStringRef password);

#if NET
[SupportedOSPlatform ("macos10.9")]
#else
[Mac (10,9)]
#endif
public static bool TrySetWiFiEAPUsernameAndPassword (CWKeychainDomain domain, NSData ssid, NSString? username, NSString? password)
=> CWKeychainSetWiFiEAPUsernameAndPassword (domain, ssid.GetHandle (), username.GetHandle ()!, password.GetHandle ()!) == 0;

#if NET
[SupportedOSPlatform ("macos10.9")]
#else
[Mac (10, 9)]
#endif
public static bool TrySetWiFiEAPUsernameAndPassword (CWKeychainDomain domain, NSData ssid, string? username, string? password)
{
using (NSString? nsUsername = (username == null)? null : new NSString (username))
using (NSString? nsPassword = (password == null)? null : new NSString (password)) {
rolfbjarne marked this conversation as resolved.
Show resolved Hide resolved
return TrySetWiFiEAPUsernameAndPassword (domain, ssid, nsUsername, nsPassword);
}
}

#if NET
[SupportedOSPlatform ("macos10.9")]
#else
[Mac (10,9)]
#endif
[DllImport (Constants.CoreWlanLibrary)]
static extern OSStatus CWKeychainSetWiFiPassword (CWKeychainDomain domain, NSDataRef ssid, NSStringRef password);

#if NET
[SupportedOSPlatform ("macos10.9")]
#else
[Mac (10,9)]
#endif
public static bool TrySetWiFiPassword (CWKeychainDomain domain, NSData ssid, NSString password)
=> CWKeychainSetWiFiPassword (domain, ssid.GetHandle (), password.GetHandle ()) == 0;

#if NET
[SupportedOSPlatform ("macos10.9")]
#else
[Mac (10,9)]
#endif
public static bool TrySetWiFiPassword (CWKeychainDomain domain, NSData ssid, string password)
{
using (NSString nsPassword = new NSString (password)) {
rolfbjarne marked this conversation as resolved.
Show resolved Hide resolved
return TrySetWiFiPassword (domain, ssid, nsPassword);
}
}


#if NET
[SupportedOSPlatform ("macos10.7")]
#else
[Mac (10,7)]
#endif
[DllImport (Constants.CoreWlanLibrary)]
static extern OSStatus CWKeychainCopyEAPIdentityList (CFArrayRef list);

#if NET
[SupportedOSPlatform ("macos10.7")]
#else
[Mac (10,7)]
#endif
public static bool TryGetEAPIdentityList (NSArray? list)
=> CWKeychainCopyEAPIdentityList (list.GetHandle ()!) == 0;
}
}
50 changes: 50 additions & 0 deletions src/CoreWlan/Enums.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,17 @@
using CoreFoundation;
using ObjCRuntime;
using System;
#if NET
using System.Runtime.Versioning;
#endif

namespace CoreWlan {

#if NET
[SupportedOSPlatform ("maccatalyst15.0")]
#else
[MacCatalyst (15,0)]
#endif
[Native]
[ErrorDomain ("CWErrorDomain")] // enum named `CWErr` in headers
public enum CWStatus : long {
Expand Down Expand Up @@ -46,6 +55,11 @@ public enum CWStatus : long {
Status = -3931,
}

#if NET
[SupportedOSPlatform ("maccatalyst15.0")]
#else
[MacCatalyst (15,0)]
#endif
[Native]
public enum CWPhyMode : ulong {
None = 0,
Expand All @@ -54,8 +68,14 @@ public enum CWPhyMode : ulong {
G = 3,
N = 4,
AC = 5,
AX = 6,
}

#if NET
[SupportedOSPlatform ("maccatalyst15.0")]
#else
[MacCatalyst (15,0)]
#endif
[Native]
public enum CWInterfaceMode : ulong {
None = 0,
Expand All @@ -64,6 +84,11 @@ public enum CWInterfaceMode : ulong {
HostAP = 3,
}

#if NET
[SupportedOSPlatform ("maccatalyst15.0")]
#else
[MacCatalyst (15,0)]
#endif
[Native]
public enum CWSecurity : ulong {
None = 0,
Expand Down Expand Up @@ -94,6 +119,11 @@ public enum CWIbssModeSecurity : ulong {
WEP104 = 2,
}

#if NET
[SupportedOSPlatform ("maccatalyst15.0")]
#else
[MacCatalyst (15,0)]
#endif
[Native]
public enum CWChannelWidth : ulong {
Unknown = 0,
Expand All @@ -103,13 +133,23 @@ public enum CWChannelWidth : ulong {
OneHundredSixtyMHz = 4,
}

#if NET
[SupportedOSPlatform ("maccatalyst15.0")]
#else
[MacCatalyst (15,0)]
#endif
[Native]
public enum CWChannelBand : ulong {
Unknown = 0,
TwoGHz = 1,
FiveGHz = 2,
}

#if NET
[SupportedOSPlatform ("maccatalyst15.0")]
#else
[MacCatalyst (15,0)]
#endif
[Native]
public enum CWCipherKeyFlags : ulong {
None = 0,
Expand All @@ -119,13 +159,23 @@ public enum CWCipherKeyFlags : ulong {
Rx = 1 << 4,
}

#if NET
[SupportedOSPlatform ("maccatalyst15.0")]
#else
[MacCatalyst (15,0)]
#endif
[Native]
public enum CWKeychainDomain : ulong {
None = 0,
User = 1,
System = 2,
}

#if NET
[SupportedOSPlatform ("maccatalyst15.0")]
#else
[MacCatalyst (15,0)]
#endif
[Native]
public enum CWEventType : long {
None = 0,
Expand Down
Loading