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

[AuthenticationServices] Updates for Xcode13 Beta3 #12203

Merged

Conversation

tj-devel709
Copy link
Contributor

Closed #12043 in favor of this PR.
I tried to squash and rebase on top of main for this PR so hopefully I didn't miss any commits!

@tj-devel709 tj-devel709 added the note-highlight Worth calling out specifically in release notes label Jul 23, 2021
@tj-devel709 tj-devel709 added this to the xcode13.0 milestone Jul 23, 2021

[Mac (12,0), iOS (15,0), MacCatalyst (15,0)]
[Export ("privateKeys")]
NSObject[] PrivateKeys { get; }
Copy link
Contributor

Choose a reason for hiding this comment

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

+/*! @abstract Private SecKeys returned from the AuthenticationServices extension.
+ */
+@property (nonatomic, readonly) NSArray *privateKeys API_AVAILABLE(ios(15.0), macos(12.0)) API_UNAVAILABLE(tvos, watchos);

SecKey is a type - so it should be an array of them

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmm, so I see that SecKey is created in this manual class here src/Security/Certificate.cs.
The namespace is Security, but when I add 'using Security' the compiler still says that it cannot find the reference.

Copy link
Contributor

Choose a reason for hiding this comment

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

That might require some changes in the generator. It does not seems to allow SecKey at the moment.

Still it's important because SecKey is not a subclass of NSObject, so the binding are incorrect without that fix.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should I create an issue and link that in the binding?

Copy link
Contributor

Choose a reason for hiding this comment

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

yes, comment the bindings and create an issue
also add it to the checklist for xcode13

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Clarification: leave a comment saying this should be SecKey or comment out this whole property and leave a note there about it?

Copy link
Contributor

Choose a reason for hiding this comment

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

Why ?

  • It's not usable as an NSObject (since SecKey is not a subclass of it)
  • if we forget it (or lack time to update) then we're not creating a future breaking change

It's always easier to add (later) than to remove :)
IOW never add something "new" that's not right / needs to be fixed

Copy link
Member

Choose a reason for hiding this comment

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

Not an issue with the generator. SecKey was in a #if COREBUILD moving the #if to provide the minimum fixed the problem. I have pushed the fix.

src/authenticationservices.cs Outdated Show resolved Hide resolved
[DisableDefaultCtor]
interface ASAuthorizationPlatformPublicKeyCredentialAssertionRequest : ASAuthorizationPublicKeyCredentialAssertionRequest
{
[Sealed]
Copy link
Contributor

Choose a reason for hiding this comment

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

why ? iow worth a comment

Copy link
Contributor Author

@tj-devel709 tj-devel709 Jul 26, 2021

Choose a reason for hiding this comment

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

So I actually don't remember told me to add the Sealed or if I saw a suggestion somewhere, perhaps @dalexsoto told me?
But when I remove it, I get these build errors: https://gist.github.com/tj-devel709/d459d9e717a186486deab6479f57c050

Copy link
Contributor

Choose a reason for hiding this comment

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

That error is because you're using the same selector for multiple methods/properties.

Why is that called PlatformAllowedCredentials if the selector is allowedCredentials ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh I just remembered what is going on! Alex did help me with this one a few weeks ago!

So there are two different classes that use this similar "allowedCredentials" header: ASAuthorizationPlatformPublicKeyCredentialAssertionRequest and ASAuthorizationSecurityKeyPublicKeyCredentialAssertionRequest

The return type of the former is ASAuthorizationPlatformPublicKeyCredentialDescriptor[]
and the return type of the second one is ASAuthorizationSecurityKeyPublicKeyCredentialDescriptor[]

but they both are overriding a property from the protocol ASAuthorizationPublicKeyCredentialAssertionRequest
which has the base property "allowedCredentials" that is of type IASAuthorizationPublicKeyCredentialDescriptor[]

So to get past this typing confusion, Alex suggested giving them different names and sealing the properties in the child classes. I definitely should have made a comment because I had already forgotten about this.

Copy link
Contributor

Choose a reason for hiding this comment

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

That used to be a problem but C# now have covariant returns
https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/proposals/csharp-9.0/covariant-returns

I wonder if just using [Override] would work...
or if more change are needed

The main problem with this rename-approach is that it's not easily discoverable by developers - so they might still use the original (base) one and have to deal with casts

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Using just the Override attribute gives me the following errors

I was wondering if maybe the protocol interface method needs a virtual attribute?

[The Sealed Attribute] Instructs the generator to flag the generated method as sealed. 
If this attribute is not specified, the default is to generate a virtual method 
(either a virtual method, an abstract method or an override depending on how other attributes are used).

This method is marked abstract and is maybe not virtual by default because of that?

Copy link
Contributor

Choose a reason for hiding this comment

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

it's not a big deal, let's land this as-is (unless someone else objects) and I might have a have a quick look

[DisableDefaultCtor]
interface ASAuthorizationSecurityKeyPublicKeyCredentialAssertionRequest : ASAuthorizationPublicKeyCredentialAssertionRequest
{
[Sealed]
Copy link
Contributor

Choose a reason for hiding this comment

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

same

src/authenticationservices.cs Outdated Show resolved Hide resolved
src/authenticationservices.cs Outdated Show resolved Hide resolved
NSData HttpBody { get; set; }

[Export ("privateKeys", ArgumentSemantic.Assign)]
NSObject[] PrivateKeys { get; set; }
Copy link
Contributor

Choose a reason for hiding this comment

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

likely SecKey[]

IntPtr Constructor (nint algorithm);

[Export ("algorithm")]
nint Algorithm { get; }
Copy link
Contributor

Choose a reason for hiding this comment

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

+@property (nonatomic, readonly) ASCOSEAlgorithmIdentifier algorithm;

why not use the type ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I cannot find this type in our bindings using grep

Copy link
Contributor

Choose a reason for hiding this comment

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

it might be new... not sure why xtro did not pick it up
you need to track the header files to see/learn why :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmm okay so the headers didn't really reveal anything to me: @abstract A COSE algorithm indentifier.
but looking at the web docs and looking up what ASCOSEAlgorithmIdentifier reveals that it is a type alias and has this:
typedef NSInteger ASCOSEAlgorithmIdentifier;
But I am not sure if this is any better?
https://developer.apple.com/documentation/authenticationservices/ascosealgorithmidentifier?language=objc

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll keep looking at this after the meeting though

Copy link
Contributor

Choose a reason for hiding this comment

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

It's not how most enums are defined - and it seems sharpie does not process them when defined this way.

API_AVAILABLE(macos(12.0), ios(15.0)) API_UNAVAILABLE(watchos)
typedef NSInteger ASCOSEAlgorithmIdentifier NS_TYPED_EXTENSIBLE_ENUM;

/*! @abstract The COSE algorithm identifier representing ECDSA with SHA-256.
 */
API_AVAILABLE(macos(12.0), ios(15.0)) API_UNAVAILABLE(watchos)
static ASCOSEAlgorithmIdentifier const ASCOSEAlgorithmIdentifierES256 = -7;

/Applications/Xcode_13.0.0-beta3.app//Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/System/Library/Frameworks/AuthenticationServices.framework/Headers/ASCOSEConstants.h

Also check for ASCOSEEllipticCurveIdentifier since it might suffer from the same nine issue

Copy link
Contributor Author

Choose a reason for hiding this comment

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

AH thanks for finding this! I will grep the header files next time!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Interestingly, ASCOSEEllipticCurveIdentifier is only declared but not used

Copy link
Contributor

Choose a reason for hiding this comment

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

some new (b4?) API might eventually use it
but no need to bind it until we have a need for it :)


public static /* ASAuthorizationSecurityKeyPublicKeyCredentialDescriptorTransport[] */ NSString[] GetAllSupportedPublicKeyCredentialDescriptorTransports () {
return NSArray.ArrayFromHandle<NSString> (ASAuthorizationAllSupportedPublicKeyCredentialDescriptorTransports ());
}
Copy link
Contributor

Choose a reason for hiding this comment

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

you have ASAuthorizationSecurityKeyPublicKeyCredentialDescriptorTransport defined
there's no point in exposing the list (only) as NSString

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Are you suggesting to do something like this?

public static ASAuthorizationSecurityKeyPublicKeyCredentialDescriptorTransport[] GetAllSupportedPublicKeyCredentialDescriptorTransports () {
	return NSArray.ArrayFromHandle<ASAuthorizationSecurityKeyPublicKeyCredentialDescriptorTransport> (ASAuthorizationAllSupportedPublicKeyCredentialDescriptorTransports ());
}

Copy link
Contributor

Choose a reason for hiding this comment

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

For the API signature ? yes
Not sure the implementation will compile...

Copy link
Contributor Author

@tj-devel709 tj-devel709 Jul 27, 2021

Choose a reason for hiding this comment

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

it does not currently compile since ASAuthorizationSecurityKeyPublicKeyCredentialDescriptorTransport is an enum and it complains saying that it needs to be a reference type:

error CS0452: The type 'ASAuthorizationSecurityKeyPublicKeyCredentialDescriptorTransport' must 
be a reference type in order to use it as parameter 'T' in the generic type or method 
'NSArray.ArrayFromHandle<T>(IntPtr)'

Should I try turning the enum into an interface so that it can be a reference type?

Copy link
Contributor

Choose a reason for hiding this comment

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

no, you just need a bit more code
You already get an array of NSString and you can create an array of the enum and convert each string constant into it's enum value

@vs-mobiletools-engineering-service2
Copy link
Collaborator

❌ [PR 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)

GitHub pages

Results can be found in the following github pages (it might take some time to publish):

Test results

1 tests failed, 88 tests passed.

Failed tests

  • monotouch-test/Mac Catalyst/Debug [dotnet]: Failed (Tests run: 2630 Passed: 2485 Inconclusive: 35 Failed: 3 Ignored: 142)

Pipeline on Agent XAMBOT-1101.BigSur'
Merge d398ac6 into de86250

@vs-mobiletools-engineering-service2
Copy link
Collaborator

❌ [PR 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)

GitHub pages

Results can be found in the following github pages (it might take some time to publish):

Test results

1 tests failed, 88 tests passed.

Failed tests

  • monotouch-test/Mac Catalyst/Debug [dotnet]: Failed (Tests run: 2630 Passed: 2485 Inconclusive: 35 Failed: 3 Ignored: 142)

Pipeline on Agent XAMBOT-1102.BigSur'
Merge 833b168 into c0651c9

src/authenticationservices.cs Outdated Show resolved Hide resolved
@@ -1002,6 +1003,18 @@ enum ASAuthorizationSecurityKeyPublicKeyCredentialDescriptorTransport {
Bluetooth,
}

[Mac (12,0), iOS (15,0), MacCatalyst (15,0), NoWatch, NoTV]
[Native]
enum ASCOSEAlgorithmIdentifier : long {
Copy link
Contributor

Choose a reason for hiding this comment

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

ASCoseAlgorithmIdentifier

[Mac (12,0), iOS (15,0), MacCatalyst (15,0), NoWatch, NoTV]
[Native]
enum ASCOSEAlgorithmIdentifier : long {
Es256 = -7,
Copy link
Contributor

Choose a reason for hiding this comment

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

but ES256 since two-letters acronyms remains uppercase in .net
3+ letters acronyms become Pascal-cased

@vs-mobiletools-engineering-service2
Copy link
Collaborator

❌ [PR 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)

GitHub pages

Results can be found in the following github pages (it might take some time to publish):

Test results

2 tests failed, 87 tests passed.

Failed tests

  • monotouch-test/Mac Catalyst/Debug [dotnet]: Failed (Tests run: 2630 Passed: 2488 Inconclusive: 35 Failed: 1 Ignored: 141)
  • xcframework-test/Mac Catalyst/Debug: TimedOut (Execution timed out after 1200 seconds.
    No test log file was produced)

Pipeline on Agent XAMBOT-1102.BigSur'
Merge c426195 into f611cd8

@vs-mobiletools-engineering-service2
Copy link
Collaborator

✅ [PR Build] Tests passed on Build. ✅

Tests passed 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)

GitHub pages

Results can be found in the following github pages (it might take some time to publish):

🎉 All 89 tests passed 🎉

Pipeline on Agent XAMBOT-1104.BigSur'
Merge 67bd7d4 into 38140f2

@vs-mobiletools-engineering-service2
Copy link
Collaborator

✅ [PR Build] Tests passed on Build. ✅

Tests passed 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)

GitHub pages

Results can be found in the following github pages (it might take some time to publish):

🎉 All 89 tests passed 🎉

Pipeline on Agent XAMBOT-1100.BigSur'
Merge fb56728 into 448cc6e

@vs-mobiletools-engineering-service2
Copy link
Collaborator

✅ [PR Build] Tests passed on Build. ✅

Tests passed 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)

GitHub pages

Results can be found in the following github pages (it might take some time to publish):

🎉 All 89 tests passed 🎉

Pipeline on Agent XAMBOT-1105.BigSur'
Merge 182b8cb into 448cc6e

@vs-mobiletools-engineering-service2
Copy link
Collaborator

❌ [PR 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)

GitHub pages

Results can be found in the following github pages (it might take some time to publish):

Test results

3 tests failed, 87 tests passed.

Failed tests

  • introspection/Mac Catalyst/Debug [dotnet]: TimedOut (Execution timed out after 1200 seconds.
    No test log file was produced)
  • monotouch-test/Mac Catalyst/Debug [dotnet]: Failed (Tests run: 2630 Passed: 2490 Inconclusive: 35 Failed: 1 Ignored: 139)
  • dont link/Mac Catalyst/Debug: TimedOut (Execution timed out after 1200 seconds.
    No test log file was produced)

Pipeline on Agent XAMBOT-1103.BigSur'
Merge 7508c47 into fda13f2

@mandel-macaque
Copy link
Member

@mandel-macaque mandel-macaque merged commit 68a5091 into xamarin:main Aug 4, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
note-highlight Worth calling out specifically in release notes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants