Skip to content

Commit

Permalink
[CoreWLan] Add XCode13 beta 1 support. (#12103)
Browse files Browse the repository at this point in the history
Added support for MacCatalyst and cleaned the backlog.


Co-authored-by: Rolf Bjarne Kvinge <rolf@xamarin.com>
  • Loading branch information
mandel-macaque and rolfbjarne committed Jul 19, 2021
1 parent dba3bf3 commit a96421f
Show file tree
Hide file tree
Showing 12 changed files with 648 additions and 235 deletions.
365 changes: 365 additions & 0 deletions src/CoreWlan/CWKeychain.cs
@@ -0,0 +1,365 @@
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 */ nint domain, NSDataRef ssid, out SecIdentityRef identity);

#if NET
[SupportedOSPlatform ("macos10.9")]
#else
[Mac (10,9)]
#endif
public static bool TryFindWiFiEAPIdentity (CWKeychainDomain domain, NSData ssid, out SecIdentity? identity, out OSStatus status)
{
identity = null;
IntPtr outPtr = IntPtr.Zero;
status = CWKeychainCopyWiFiEAPIdentity ((nint) (long) domain, ssid.GetHandle (), out outPtr);
if (status == 0) {
identity = new SecIdentity (outPtr, true);
}

return status == 0;
}

#if NET
[SupportedOSPlatform ("macos10.9")]
#else
[Mac (10,9)]
#endif
public static bool TryFindWiFiEAPIdentity (CWKeychainDomain domain, NSData ssid, out SecIdentity? identity)
=> TryFindWiFiEAPIdentity (domain, ssid, out identity, out var _);

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

#if NET
[SupportedOSPlatform ("macos10.9")]
#else
[Mac (10,9)]
#endif
public static bool TryDeleteWiFiEAPUsernameAndPassword (CWKeychainDomain domain, NSData ssid, out OSStatus status)
{
status = CWKeychainDeleteWiFiEAPUsernameAndPassword ((nint) (long) domain, ssid.GetHandle ());
return status == 0;
}

#if NET
[SupportedOSPlatform ("macos10.9")]
#else
[Mac (10,9)]
#endif
public static bool TryDeleteWiFiEAPUsernameAndPassword (CWKeychainDomain domain, NSData ssid)
=> TryDeleteWiFiEAPUsernameAndPassword (domain, ssid, out var _);

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

#if NET
[SupportedOSPlatform ("macos10.9")]
#else
[Mac (10,9)]
#endif
public static bool TryDeleteWiFiPassword (CWKeychainDomain domain, NSData ssid, out OSStatus status)
{
status = CWKeychainDeleteWiFiPassword ((nint) (long) domain, ssid.GetHandle ());
return status == 0;
}

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

#if NET
[SupportedOSPlatform ("macos10.9")]
#else
[Mac (10,9)]
#endif
[DllImport (Constants.CoreWlanLibrary)]
static extern OSStatus CWKeychainFindWiFiEAPUsernameAndPassword (/* CWKeychainDomain */ nint 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, out OSStatus status)
{
username = null;
password = null;
NSStringRef usernamePtr = IntPtr.Zero;
NSStringRef passwordPtr = IntPtr.Zero;
status = CWKeychainFindWiFiEAPUsernameAndPassword ((nint) (long) domain, ssid.GetHandle (), out usernamePtr, out passwordPtr);
if (usernamePtr != IntPtr.Zero) {
username = Runtime.GetNSObject<NSString> (usernamePtr, false);
}
if (passwordPtr != IntPtr.Zero) {
password = Runtime.GetNSObject<NSString> (passwordPtr, false);
}
return status == 0;
}

#if NET
[SupportedOSPlatform ("macos10.9")]
#else
[Mac (10,9)]
#endif
public static bool TryFindWiFiEAPUsernameAndPassword (CWKeychainDomain domain, NSData ssid, out NSString? username, out NSString? password)
=> TryFindWiFiEAPUsernameAndPassword (domain, ssid, out username, out password, out var _);

#if NET
[SupportedOSPlatform ("macos10.9")]
#else
[Mac (10,9)]
#endif
public static bool TryFindWiFiEAPUsernameAndPassword (CWKeychainDomain domain, NSData ssid, out string? username, out string? password, out OSStatus status)
{
var result = TryFindWiFiEAPUsernameAndPassword (domain, ssid, out NSString? nsUsername, out NSString? nsPassword, out status);
username = nsUsername?.ToString ();
password = nsPassword?.ToString ();
return result;
}

#if NET
[SupportedOSPlatform ("macos10.9")]
#else
[Mac (10,9)]
#endif
public static bool TryFindWiFiEAPUsernameAndPassword (CWKeychainDomain domain, NSData ssid, out string? username, out string? password)
=> TryFindWiFiEAPUsernameAndPassword (domain, ssid, out username, out password, out var _);

#if NET
[SupportedOSPlatform ("macos10.9")]
#else
[Mac (10,9)]
#endif
[DllImport (Constants.CoreWlanLibrary)]
static extern OSStatus CWKeychainFindWiFiPassword (/* CWKeychainDomain */ nint 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, out OSStatus status)
{
password = null;
NSStringRef passwordPtr = IntPtr.Zero;
status = CWKeychainFindWiFiPassword ((nint) (long) domain, ssid.GetHandle (), out passwordPtr);
if (passwordPtr != IntPtr.Zero) {
password = Runtime.GetNSObject<NSString> (passwordPtr, false);
}
return status == 0;
}

#if NET
[SupportedOSPlatform ("macos10.9")]
#else
[Mac (10,9)]
#endif
public static bool TryFindWiFiPassword (CWKeychainDomain domain, NSData ssid, out NSString? password)
=> TryFindWiFiPassword (domain, ssid, out password, out var _);

#if NET
[SupportedOSPlatform ("macos10.9")]
#else
[Mac (10,9)]
#endif
public static bool TryFindWiFiPassword (CWKeychainDomain domain, NSData ssid, out string? password, out OSStatus status)
{
var result = TryFindWiFiPassword (domain, ssid, out NSString? nsPassword, out status);
password = nsPassword?.ToString ();
return result;
}

#if NET
[SupportedOSPlatform ("macos10.9")]
#else
[Mac (10,9)]
#endif
public static bool TryFindWiFiPassword (CWKeychainDomain domain, NSData ssid, out string? password)
=> TryFindWiFiPassword (domain, ssid, out password, out var _);

#if NET
[SupportedOSPlatform ("macos10.9")]
#else
[Mac (10,9)]
#endif
[DllImport (Constants.CoreWlanLibrary)]
static extern OSStatus CWKeychainSetWiFiEAPIdentity (/* CWKeychainDomain */ nint 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, out OSStatus status)
{
status = CWKeychainSetWiFiEAPIdentity ((nint) (long) domain, ssid.GetHandle (), identity.GetHandle ()!);
return status == 0;
}

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

#if NET
[SupportedOSPlatform ("macos10.9")]
#else
[Mac (10,9)]
#endif
[DllImport (Constants.CoreWlanLibrary)]
static extern OSStatus CWKeychainSetWiFiEAPUsernameAndPassword (/* CWKeychainDomain */ nint 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, out OSStatus status)
{
status = CWKeychainSetWiFiEAPUsernameAndPassword ((nint) (long) domain, ssid.GetHandle (), username.GetHandle ()!, password.GetHandle ()!);
return status == 0;
}

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

#if NET
[SupportedOSPlatform ("macos10.9")]
#else
[Mac (10, 9)]
#endif
public static bool TrySetWiFiEAPUsernameAndPassword (CWKeychainDomain domain, NSData ssid, string? username, string? password, out OSStatus status)
{
var usernamePtr = CFString.CreateNative (username);
var pwdPtr = CFString.CreateNative (password);
status = CWKeychainSetWiFiEAPUsernameAndPassword ((nint) (long) domain, ssid.GetHandle (), usernamePtr, pwdPtr);
CFString.ReleaseNative (usernamePtr);
CFString.ReleaseNative (pwdPtr);
return status == 0;
}

#if NET
[SupportedOSPlatform ("macos10.9")]
#else
[Mac (10, 9)]
#endif
public static bool TrySetWiFiEAPUsernameAndPassword (CWKeychainDomain domain, NSData ssid, string? username, string? password)
=> TrySetWiFiEAPUsernameAndPassword (domain, ssid, username, password, out var _);

#if NET
[SupportedOSPlatform ("macos10.9")]
#else
[Mac (10,9)]
#endif
[DllImport (Constants.CoreWlanLibrary)]
static extern OSStatus CWKeychainSetWiFiPassword (/* CWKeychainDomain */ nint 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, out OSStatus status)
{
status = CWKeychainSetWiFiPassword ((nint) (long) domain, ssid.GetHandle (), password.GetHandle ());
return status == 0;
}

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

#if NET
[SupportedOSPlatform ("macos10.9")]
#else
[Mac (10,9)]
#endif
public static bool TrySetWiFiPassword (CWKeychainDomain domain, NSData ssid, string password, out OSStatus status)
{
var pwdPtr = CFString.CreateNative (password);
status = CWKeychainSetWiFiPassword ((nint) (long) domain, ssid.GetHandle (), pwdPtr);
CFString.ReleaseNative (pwdPtr);
return status == 0;
}

#if NET
[SupportedOSPlatform ("macos10.9")]
#else
[Mac (10,9)]
#endif
public static bool TrySetWiFiPassword (CWKeychainDomain domain, NSData ssid, string password)
=> TrySetWiFiPassword (domain, ssid, password, out var _);


[DllImport (Constants.CoreWlanLibrary)]
static extern OSStatus CWKeychainCopyEAPIdentityList (CFArrayRef list);

public static bool TryGetEAPIdentityList (NSArray? list, out OSStatus status)
{
status = CWKeychainCopyEAPIdentityList (list.GetHandle ()!);
return status == 0;
}

public static bool TryGetEAPIdentityList (NSArray? list)
=> TryGetEAPIdentityList (list, out var _);
}
}

8 comments on commit a96421f

@vs-mobiletools-engineering-service2
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❌ [CI Build] Tests failed on Build ❌

Tests failed on Build.

API diff

✅ API Diff from stable

View API diff

API & Generator diff

ℹ️ API Diff (from PR only) (please review changes)
ℹ️ Generator Diff (please review changes)

Packages generated

View packages

Test results

1 tests failed, 220 tests passed.

Failed tests

  • monotouch-test/Mac Catalyst/Debug [dotnet]: Failed (Tests run: 2626 Passed: 2490 Inconclusive: 35 Failed: 1 Ignored: 135)

Pipeline on Agent XAMBOT-1028.BigSur'
[CoreWLan] Add XCode13 beta 1 support. (#12103)

@vs-mobiletools-engineering-service2
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔥 Tests failed catastrophically on VSTS: device tests tvOS 🔥

Not enough free space in the host.

Pipeline on Agent
[CoreWLan] Add XCode13 beta 1 support. (#12103)

@vs-mobiletools-engineering-service2
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Tests were not ran (VSTS: device tests tvOS). ⚠️

Results were skipped for this run due to provisioning problems Azure Devops. Please contact the bot administrator.

Pipeline on Agent
[CoreWLan] Add XCode13 beta 1 support. (#12103)

@vs-mobiletools-engineering-service2
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Tests were not ran (VSTS: device tests iOS). ⚠️

Results were skipped for this run due to provisioning problems Azure Devops. Please contact the bot administrator.

Pipeline on Agent
[CoreWLan] Add XCode13 beta 1 support. (#12103)

@vs-mobiletools-engineering-service2
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Tests passed on macOS Mac Catalina (10.15) ✅

Tests passed

All tests on macOS X Mac Catalina (10.15) passed.

Pipeline on Agent
[CoreWLan] Add XCode13 beta 1 support. (#12103)

@vs-mobiletools-engineering-service2
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Tests passed on macOS Mac Mojave (10.14) ✅

Tests passed

All tests on macOS X Mac Mojave (10.14) passed.

Pipeline on Agent
[CoreWLan] Add XCode13 beta 1 support. (#12103)

@vs-mobiletools-engineering-service2
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Tests passed on macOS Mac High Sierra (10.13) ✅

Tests passed

All tests on macOS X Mac High Sierra (10.13) passed.

Pipeline on Agent
[CoreWLan] Add XCode13 beta 1 support. (#12103)

@vs-mobiletools-engineering-service2
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Tests were not ran (VSTS: device tests iOS32b). ⚠️

Results were skipped for this run due to provisioning problems Azure Devops. Please contact the bot administrator.

Pipeline on Agent
[CoreWLan] Add XCode13 beta 1 support. (#12103)

Please sign in to comment.