Skip to content

Commit

Permalink
[Security] Add Xcode 13 beta 4 support.
Browse files Browse the repository at this point in the history
  • Loading branch information
mandel-macaque committed Aug 5, 2021
1 parent 0ffed97 commit ef1de3b
Show file tree
Hide file tree
Showing 9 changed files with 320 additions and 245 deletions.
38 changes: 37 additions & 1 deletion src/Security/Authorization.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,20 @@
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//

#if MONOMAC
#if MONOMAC || __MACCATALYST__

using ObjCRuntime;
using Foundation;
using System;
using System.Runtime.InteropServices;

namespace Security {

#if NET
[SupportedOSPlatform ("maccatalyst15.0")]
#else
[MacCatalyst (15,0)]
#endif
// Untyped enum in ObjC
public enum AuthorizationStatus {
Success = 0,
Expand All @@ -52,6 +58,11 @@ public enum AuthorizationStatus {
BadAddress = -60033,
}

#if NET
[SupportedOSPlatform ("maccatalyst15.0")]
#else
[MacCatalyst (15,0)]
#endif
// typedef UInt32 AuthorizationFlags;
[Flags]
public enum AuthorizationFlags : int {
Expand All @@ -68,18 +79,33 @@ public enum AuthorizationFlags : int {
// For ease of use, we let the user pass the AuthorizationParameters, and we
// create the structure for them with the proper data
//
#if NET
[SupportedOSPlatform ("maccatalyst15.0")]
#else
[MacCatalyst (15,0)]
#endif
public class AuthorizationParameters {
public string PathToSystemPrivilegeTool;
public string Prompt;
public string IconPath;
}

#if NET
[SupportedOSPlatform ("maccatalyst15.0")]
#else
[MacCatalyst (15,0)]
#endif
public class AuthorizationEnvironment {
public string Username;
public string Password;
public bool AddToSharedCredentialPool;
}

#if NET
[SupportedOSPlatform ("maccatalyst15.0")]
#else
[MacCatalyst (15,0)]
#endif
[StructLayout (LayoutKind.Sequential)]
struct AuthorizationItem {
public IntPtr /* AuthorizationString = const char * */ name;
Expand All @@ -88,11 +114,21 @@ struct AuthorizationItem {
public int /* UInt32 */ flags; // zero
}

#if NET
[SupportedOSPlatform ("maccatalyst15.0")]
#else
[MacCatalyst (15,0)]
#endif
unsafe struct AuthorizationItemSet {
public int /* UInt32 */ count;
public AuthorizationItem * /* AuthorizationItem* */ ptrToAuthorization;
}

#if NET
[SupportedOSPlatform ("maccatalyst15.0")]
#else
[MacCatalyst (15,0)]
#endif
public unsafe class Authorization : INativeObject, IDisposable {
IntPtr handle;

Expand Down
32 changes: 32 additions & 0 deletions src/Security/Certificate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -551,11 +551,19 @@ public SecKey (IntPtr handle, bool owns)
[DllImport (Constants.SecurityLibrary, EntryPoint="SecKeyGetTypeID")]
public extern static nint GetTypeID ();

[Deprecated (PlatformName.MacOSX, 12, 0, message: "Use 'SecKeyCreateRandomKey' instead.")]
[Deprecated (PlatformName.iOS, 15, 0, message: "Use 'SecKeyCreateRandomKey' instead.")]
[Deprecated (PlatformName.TvOS, 15, 0, message: "Use 'SecKeyCreateRandomKey' instead.")]
[Deprecated (PlatformName.WatchOS, 8, 0, message: "Use 'SecKeyCreateRandomKey' instead.")]
[DllImport (Constants.SecurityLibrary)]
extern static SecStatusCode SecKeyGeneratePair (IntPtr dictHandle, out IntPtr pubKey, out IntPtr privKey);

// TODO: pull all the TypeRefs needed for the NSDictionary

[Deprecated (PlatformName.MacOSX, 12, 0, message: "Use 'CreateRandomKey' instead.")]
[Deprecated (PlatformName.iOS, 15, 0, message: "Use 'CreateRandomKey' instead.")]
[Deprecated (PlatformName.TvOS, 15, 0, message: "Use 'CreateRandomKey' instead.")]
[Deprecated (PlatformName.WatchOS, 8, 0, message: "Use 'CreateRandomKey' instead.")]
public static SecStatusCode GenerateKeyPair (NSDictionary parameters, out SecKey publicKey, out SecKey privateKey)
{
if (parameters == null)
Expand Down Expand Up @@ -625,9 +633,15 @@ public static SecStatusCode GenerateKeyPair (SecKeyType type, int keySizeInBits,
}
}

[Deprecated (PlatformName.iOS, 15, 0, message: "Use 'SecKeyCreateSignature' instead.")]
[Deprecated (PlatformName.TvOS, 15, 0, message: "Use 'SecKeyCreateSignature' instead.")]
[Deprecated (PlatformName.WatchOS, 8, 0, message: "Use 'SecKeyCreateSignature' instead.")]
[DllImport (Constants.SecurityLibrary)]
extern static SecStatusCode SecKeyRawSign (IntPtr handle, SecPadding padding, IntPtr dataToSign, nint dataToSignLen, IntPtr sig, ref nint sigLen);

[Deprecated (PlatformName.iOS, 15, 0, message: "Use 'CreateSignature' instead.")]
[Deprecated (PlatformName.TvOS, 15, 0, message: "Use 'CreateSignature' instead.")]
[Deprecated (PlatformName.WatchOS, 8, 0, message: "Use 'CreateSignature' instead.")]
public SecStatusCode RawSign (SecPadding padding, IntPtr dataToSign, int dataToSignLen, out byte [] result)
{
if (handle == IntPtr.Zero)
Expand Down Expand Up @@ -661,9 +675,15 @@ unsafe SecStatusCode _RawSign (SecPadding padding, IntPtr dataToSign, int dataTo
return status;
}

[Deprecated (PlatformName.iOS, 15, 0, message: "Use 'SecKeyVerifySignature' instead.")]
[Deprecated (PlatformName.TvOS, 15, 0, message: "Use 'SecKeyVerifySignature' instead.")]
[Deprecated (PlatformName.WatchOS, 8, 0, message: "Use 'SecKeyVerifySignature' instead.")]
[DllImport (Constants.SecurityLibrary)]
extern static SecStatusCode SecKeyRawVerify (IntPtr handle, SecPadding padding, IntPtr signedData, nint signedLen, IntPtr sign, nint signLen);

[Deprecated (PlatformName.iOS, 15, 0, message: "Use 'VerifySignature' instead.")]
[Deprecated (PlatformName.TvOS, 15, 0, message: "Use 'VerifySignature' instead.")]
[Deprecated (PlatformName.WatchOS, 8, 0, message: "Use 'VerifySignature' instead.")]
public unsafe SecStatusCode RawVerify (SecPadding padding, IntPtr signedData, int signedDataLen, IntPtr signature, int signatureLen)
{
if (handle == IntPtr.Zero)
Expand Down Expand Up @@ -694,9 +714,15 @@ public SecStatusCode RawVerify (SecPadding padding, byte [] signedData, byte []
}
}

[Deprecated (PlatformName.iOS, 15, 0, message: "Use 'SecKeyCreateEncryptedData' instead.")]
[Deprecated (PlatformName.TvOS, 15, 0, message: "Use 'SecKeyCreateEncryptedData' instead.")]
[Deprecated (PlatformName.WatchOS, 8, 0, message: "Use 'SecKeyCreateEncryptedData' instead.")]
[DllImport (Constants.SecurityLibrary)]
extern static SecStatusCode SecKeyEncrypt (IntPtr handle, SecPadding padding, IntPtr plainText, nint plainTextLen, IntPtr cipherText, ref nint cipherTextLengh);

[Deprecated (PlatformName.iOS, 15, 0, message: "Use 'CreateEncryptedData' instead.")]
[Deprecated (PlatformName.TvOS, 15, 0, message: "Use 'CreateEncryptedData' instead.")]
[Deprecated (PlatformName.WatchOS, 8, 0, message: "Use 'CreateEncryptedData' instead.")]
public unsafe SecStatusCode Encrypt (SecPadding padding, IntPtr plainText, nint plainTextLen, IntPtr cipherText, ref nint cipherTextLen)
{
if (handle == IntPtr.Zero)
Expand Down Expand Up @@ -729,9 +755,15 @@ public SecStatusCode Encrypt (SecPadding padding, byte [] plainText, out byte []
return Encrypt (padding, plainText, cipherText);
}

[Deprecated (PlatformName.iOS, 15, 0, message: "Use 'SecKeyCreateDecryptedData' instead.")]
[Deprecated (PlatformName.TvOS, 15, 0, message: "Use 'SecKeyCreateDecryptedData' instead.")]
[Deprecated (PlatformName.WatchOS, 8, 0, message: "Use 'SecKeyCreateDecryptedData' instead.")]
[DllImport (Constants.SecurityLibrary)]
extern static SecStatusCode SecKeyDecrypt (IntPtr handle, SecPadding padding, IntPtr cipherTextLen, nint cipherLen, IntPtr plainText, ref nint plainTextLen);

[Deprecated (PlatformName.iOS, 15, 0, message: "Use 'CreateDecryptedData' instead.")]
[Deprecated (PlatformName.TvOS, 15, 0, message: "Use 'CreateDecryptedData' instead.")]
[Deprecated (PlatformName.WatchOS, 8, 0, message: "Use 'CreateDecryptedData' instead.")]
public unsafe SecStatusCode Decrypt (SecPadding padding, IntPtr cipherText, nint cipherTextLen, IntPtr plainText, ref nint plainTextLen)
{
if (handle == IntPtr.Zero)
Expand Down
30 changes: 30 additions & 0 deletions src/Security/Trust.cs
Original file line number Diff line number Diff line change
Expand Up @@ -159,9 +159,17 @@ public SecTrustResult Evaluate ()
}
}

[Deprecated (PlatformName.MacOSX, 12, 0)]
[Deprecated (PlatformName.iOS, 15, 0)]
[Deprecated (PlatformName.WatchOS, 8, 0)]
[Deprecated (PlatformName.TvOS, 15, 0)]
[DllImport (Constants.SecurityLibrary)]
extern static IntPtr /* SecCertificateRef */ SecTrustGetCertificateAtIndex (IntPtr /* SecTrustRef */ trust, nint /* CFIndex */ ix);

[Deprecated (PlatformName.MacOSX, 12, 0, message: "Use the 'GetCertificateChain' method instead.")]
[Deprecated (PlatformName.iOS, 15, 0, message: "Use the 'GetCertificateChain' method instead.")]
[Deprecated (PlatformName.WatchOS, 8, 0, message: "Use the 'GetCertificateChain' method instead.")]
[Deprecated (PlatformName.TvOS, 15, 0, message: "Use the 'GetCertificateChain' method instead.")]
public SecCertificate this [nint index] {
get {
if (handle == IntPtr.Zero)
Expand All @@ -173,6 +181,28 @@ public SecTrustResult Evaluate ()
}
}

#if NET
[SupportedOSPlatform ("ios15.0")]
[SupportedOSPlatform ("tvos15.0")]
[SupportedOSPlatform ("maccatalyst15.0")]
[SupportedOSPlatform ("macos12.0")
#else
[Watch (8,0), TV (15,0), Mac (12,0), iOS (15,0), MacCatalyst (15,0)]
#endif
[DllImport (Constants.SecurityLibrary)]
static extern /* CFArrayRef */ IntPtr SecTrustCopyCertificateChain (/* SecTrustRef */ IntPtr trust);

#if NET
[SupportedOSPlatform ("ios15.0")]
[SupportedOSPlatform ("tvos15.0")]
[SupportedOSPlatform ("maccatalyst15.0")]
[SupportedOSPlatform ("macos12.0")
#else
[Watch (8,0), TV (15,0), Mac (12,0), iOS (15,0), MacCatalyst (15,0)]
#endif
public SecCertificate[] GetCertificateChain ()
=> NSArray.ArrayFromHandle<SecCertificate> (SecTrustCopyCertificateChain (handle));

[Deprecated (PlatformName.iOS, 14,0)]
[Deprecated (PlatformName.MacOSX, 11,0)]
[Deprecated (PlatformName.TvOS, 14,0)]
Expand Down
Loading

0 comments on commit ef1de3b

Please sign in to comment.