Merge remote-tracking branch 'origin/main' into bump-main-in-xcode14-2022-09-12
This commit is contained in:
Коммит
68eb7d401f
|
@ -0,0 +1,5 @@
|
|||
{
|
||||
"author": "Microsoft",
|
||||
"name": "macOS Binding Library",
|
||||
"description": "Projekt pro vytvoření knihovny vazeb .NET pro macOS"
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
{
|
||||
"author": "Microsoft",
|
||||
"name": "macOS Binding Library",
|
||||
"description": "Ein Projekt zum Erstellen einer .NET macOS-Bindungsbibliothek"
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
{
|
||||
"author": "Microsoft",
|
||||
"name": "macOS Binding Library",
|
||||
"description": "A project for creating a .NET macOS binding library"
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
{
|
||||
"author": "Microsoft",
|
||||
"name": "macOS Binding Library",
|
||||
"description": "Proyecto para crear una biblioteca de enlaces de macOS de .NET"
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
{
|
||||
"author": "Microsoft",
|
||||
"name": "macOS Binding Library",
|
||||
"description": "Projet de création d’une bibliothèque de liaisons .NET macOS"
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
{
|
||||
"author": "Microsoft",
|
||||
"name": "macOS Binding Library",
|
||||
"description": "Progetto per la creazione di una libreria di binding macOS .NET"
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
{
|
||||
"author": "Microsoft",
|
||||
"name": "macOS Binding Library",
|
||||
"description": ".NET macOS バインド ライブラリを作成するためのプロジェクト"
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
{
|
||||
"author": "Microsoft",
|
||||
"name": "macOS Binding Library",
|
||||
"description": ".NET macOS 바인딩 라이브러리를 만들기 위한 프로젝트"
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
{
|
||||
"author": "Microsoft",
|
||||
"name": "macOS Binding Library",
|
||||
"description": "Projekt służący do tworzenia biblioteki powiązań platformy .NET 6 dla systemu macOS"
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
{
|
||||
"author": "Microsoft",
|
||||
"name": "macOS Binding Library",
|
||||
"description": "Um projeto para criar uma biblioteca de vinculação do macOS .NET"
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
{
|
||||
"author": "Майкрософт",
|
||||
"name": "macOS Binding Library",
|
||||
"description": "Проект для создания библиотеки привязок .NET для macOS"
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
{
|
||||
"author": "Microsoft",
|
||||
"name": "macOS Binding Library",
|
||||
"description": "Bir .NET macOS bağlama kitaplığı oluşturmaya yönelik proje"
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
{
|
||||
"author": "Microsoft",
|
||||
"name": "macOS Binding Library",
|
||||
"description": "用于创建 .NET macOS 绑定库的项目"
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
{
|
||||
"author": "Microsoft",
|
||||
"name": "macOS Binding Library",
|
||||
"description": "用於建立 .NET 6 macOS 繫結程式庫的專案"
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
{
|
||||
"$schema": "http://json.schemastore.org/template",
|
||||
"author": "Microsoft",
|
||||
"classifications": [ "macOS", "Mobile" ],
|
||||
"identity": "Microsoft.macOS.macOSBinding",
|
||||
"name": "macOS Binding Library",
|
||||
"description": "A project for creating a .NET macOS binding library",
|
||||
"shortName": "macosbinding",
|
||||
"tags": {
|
||||
"language": "C#",
|
||||
"type": "project"
|
||||
},
|
||||
"sourceName": "macOSBinding1",
|
||||
"preferNameDirectory": true,
|
||||
"primaryOutputs": [
|
||||
{ "path": "macOSBinding1.csproj" }
|
||||
],
|
||||
"defaultName": "macOSBinding1"
|
||||
}
|
|
@ -0,0 +1,70 @@
|
|||
namespace macOSBinding1
|
||||
{
|
||||
|
||||
// The first step to creating a binding is to add your native framework ("MyLibrary.xcframework")
|
||||
// to the project.
|
||||
// Open your binding csproj and add a section like this
|
||||
// <ItemGroup>
|
||||
// <NativeReference Include="MyLibrary.xcframework">
|
||||
// <Kind>Framework</Kind>
|
||||
// <Frameworks></Frameworks>
|
||||
// </NativeReference>
|
||||
// </ItemGroup>
|
||||
//
|
||||
// Once you've added it, you will need to customize it for your specific library:
|
||||
// - Change the Include to the correct path/name of your library
|
||||
// - Change Kind to Static (.a) or Framework (.framework/.xcframework) based upon the library kind and extension.
|
||||
// - Dynamic (.dylib) is a third option but rarely if ever valid, and only on macOS and Mac Catalyst
|
||||
// - If your library depends on other frameworks, add them inside <Frameworks></Frameworks>
|
||||
// Example:
|
||||
// <NativeReference Include="libs\MyTestFramework.xcframework">
|
||||
// <Kind>Framework</Kind>
|
||||
// <Frameworks>CoreLocation ModelIO</Frameworks>
|
||||
// </NativeReference>
|
||||
//
|
||||
// Once you've done that, you're ready to move on to binding the API...
|
||||
//
|
||||
// Here is where you'd define your API definition for the native Objective-C library.
|
||||
//
|
||||
// For example, to bind the following Objective-C class:
|
||||
//
|
||||
// @interface Widget : NSObject {
|
||||
// }
|
||||
//
|
||||
// The C# binding would look like this:
|
||||
//
|
||||
// [BaseType (typeof (NSObject))]
|
||||
// interface Widget {
|
||||
// }
|
||||
//
|
||||
// To bind Objective-C properties, such as:
|
||||
//
|
||||
// @property (nonatomic, readwrite, assign) CGPoint center;
|
||||
//
|
||||
// You would add a property definition in the C# interface like so:
|
||||
//
|
||||
// [Export ("center")]
|
||||
// CGPoint Center { get; set; }
|
||||
//
|
||||
// To bind an Objective-C method, such as:
|
||||
//
|
||||
// -(void) doSomething:(NSObject *)object atIndex:(NSInteger)index;
|
||||
//
|
||||
// You would add a method definition to the C# interface like so:
|
||||
//
|
||||
// [Export ("doSomething:atIndex:")]
|
||||
// void DoSomething (NSObject object, nint index);
|
||||
//
|
||||
// Objective-C "constructors" such as:
|
||||
//
|
||||
// -(id)initWithElmo:(ElmoMuppet *)elmo;
|
||||
//
|
||||
// Can be bound as:
|
||||
//
|
||||
// [Export ("initWithElmo:")]
|
||||
// NativeHandle Constructor (ElmoMuppet elmo);
|
||||
//
|
||||
// For more information, see https://aka.ms/ios-binding
|
||||
//
|
||||
|
||||
}
|
|
@ -0,0 +1,4 @@
|
|||
namespace macOSBinding1
|
||||
{
|
||||
|
||||
}
|
|
@ -0,0 +1,14 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0-macos</TargetFramework>
|
||||
<RootNamespace Condition="'$(name)' != '$(name{-VALUE-FORMS-}safe_namespace)'">macOSBinding1</RootNamespace>
|
||||
<Nullable>enable</Nullable>
|
||||
<ImplicitUsings>true</ImplicitUsings>
|
||||
<IsBindingProject>true</IsBindingProject>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ObjcBindingApiDefinition Include="ApiDefinition.cs" />
|
||||
<ObjcBindingCoreSource Include="StructsAndEnums.cs" />
|
||||
</ItemGroup>
|
||||
</Project>
|
|
@ -0,0 +1,5 @@
|
|||
{
|
||||
"author": "Microsoft",
|
||||
"name": "tvOS Binding Library",
|
||||
"description": "Projekt pro vytvoření knihovny vazeb .NET pro tvOS"
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
{
|
||||
"author": "Microsoft",
|
||||
"name": "tvOS Binding Library",
|
||||
"description": "Ein Projekt zum Erstellen einer .NET tvOS-Bindungsbibliothek"
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
{
|
||||
"author": "Microsoft",
|
||||
"name": "tvOS Binding Library",
|
||||
"description": "A project for creating a .NET tvOS binding library"
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
{
|
||||
"author": "Microsoft",
|
||||
"name": "tvOS Binding Library",
|
||||
"description": "Proyecto para crear una biblioteca de enlaces de tvOS de .NET"
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
{
|
||||
"author": "Microsoft",
|
||||
"name": "tvOS Binding Library",
|
||||
"description": "Projet de création d’une bibliothèque de liaisons .NET tvOS"
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
{
|
||||
"author": "Microsoft",
|
||||
"name": "tvOS Binding Library",
|
||||
"description": "Progetto per la creazione di una libreria di binding tvOS .NET"
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
{
|
||||
"author": "Microsoft",
|
||||
"name": "tvOS Binding Library",
|
||||
"description": ".NET tvOS バインド ライブラリを作成するためのプロジェクト"
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
{
|
||||
"author": "Microsoft",
|
||||
"name": "tvOS Binding Library",
|
||||
"description": ".NET tvOS 바인딩 라이브러리를 만들기 위한 프로젝트"
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
{
|
||||
"author": "Microsoft",
|
||||
"name": "tvOS Binding Library",
|
||||
"description": "Projekt służący do tworzenia biblioteki powiązań platformy .NET 6 dla systemu tvOS"
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
{
|
||||
"author": "Microsoft",
|
||||
"name": "tvOS Binding Library",
|
||||
"description": "Um projeto para criar uma biblioteca de vinculação do tvOS .NET"
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
{
|
||||
"author": "Майкрософт",
|
||||
"name": "tvOS Binding Library",
|
||||
"description": "Проект для создания библиотеки привязок .NET для tvOS"
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
{
|
||||
"author": "Microsoft",
|
||||
"name": "tvOS Binding Library",
|
||||
"description": "Bir .NET tvOS bağlama kitaplığı oluşturmaya yönelik proje"
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
{
|
||||
"author": "Microsoft",
|
||||
"name": "tvOS Binding Library",
|
||||
"description": "用于创建 .NET tvOS 绑定库的项目"
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
{
|
||||
"author": "Microsoft",
|
||||
"name": "tvOS Binding Library",
|
||||
"description": "用於建立 .NET 6 tvOS 繫結程式庫的專案"
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
{
|
||||
"$schema": "http://json.schemastore.org/template",
|
||||
"author": "Microsoft",
|
||||
"classifications": [ "tvOS", "Mobile" ],
|
||||
"identity": "Microsoft.tvOS.tvOSBinding",
|
||||
"name": "tvOS Binding Library",
|
||||
"description": "A project for creating a .NET tvOS binding library",
|
||||
"shortName": "tvosbinding",
|
||||
"tags": {
|
||||
"language": "C#",
|
||||
"type": "project"
|
||||
},
|
||||
"sourceName": "tvOSBinding1",
|
||||
"preferNameDirectory": true,
|
||||
"primaryOutputs": [
|
||||
{ "path": "tvOSBinding1.csproj" }
|
||||
],
|
||||
"defaultName": "tvOSBinding1"
|
||||
}
|
|
@ -0,0 +1,70 @@
|
|||
namespace tvOSBinding1
|
||||
{
|
||||
|
||||
// The first step to creating a binding is to add your native framework ("MyLibrary.xcframework")
|
||||
// to the project.
|
||||
// Open your binding csproj and add a section like this
|
||||
// <ItemGroup>
|
||||
// <NativeReference Include="MyLibrary.xcframework">
|
||||
// <Kind>Framework</Kind>
|
||||
// <Frameworks></Frameworks>
|
||||
// </NativeReference>
|
||||
// </ItemGroup>
|
||||
//
|
||||
// Once you've added it, you will need to customize it for your specific library:
|
||||
// - Change the Include to the correct path/name of your library
|
||||
// - Change Kind to Static (.a) or Framework (.framework/.xcframework) based upon the library kind and extension.
|
||||
// - Dynamic (.dylib) is a third option but rarely if ever valid, and only on macOS and Mac Catalyst
|
||||
// - If your library depends on other frameworks, add them inside <Frameworks></Frameworks>
|
||||
// Example:
|
||||
// <NativeReference Include="libs\MyTestFramework.xcframework">
|
||||
// <Kind>Framework</Kind>
|
||||
// <Frameworks>CoreLocation ModelIO</Frameworks>
|
||||
// </NativeReference>
|
||||
//
|
||||
// Once you've done that, you're ready to move on to binding the API...
|
||||
//
|
||||
// Here is where you'd define your API definition for the native Objective-C library.
|
||||
//
|
||||
// For example, to bind the following Objective-C class:
|
||||
//
|
||||
// @interface Widget : NSObject {
|
||||
// }
|
||||
//
|
||||
// The C# binding would look like this:
|
||||
//
|
||||
// [BaseType (typeof (NSObject))]
|
||||
// interface Widget {
|
||||
// }
|
||||
//
|
||||
// To bind Objective-C properties, such as:
|
||||
//
|
||||
// @property (nonatomic, readwrite, assign) CGPoint center;
|
||||
//
|
||||
// You would add a property definition in the C# interface like so:
|
||||
//
|
||||
// [Export ("center")]
|
||||
// CGPoint Center { get; set; }
|
||||
//
|
||||
// To bind an Objective-C method, such as:
|
||||
//
|
||||
// -(void) doSomething:(NSObject *)object atIndex:(NSInteger)index;
|
||||
//
|
||||
// You would add a method definition to the C# interface like so:
|
||||
//
|
||||
// [Export ("doSomething:atIndex:")]
|
||||
// void DoSomething (NSObject object, nint index);
|
||||
//
|
||||
// Objective-C "constructors" such as:
|
||||
//
|
||||
// -(id)initWithElmo:(ElmoMuppet *)elmo;
|
||||
//
|
||||
// Can be bound as:
|
||||
//
|
||||
// [Export ("initWithElmo:")]
|
||||
// NativeHandle Constructor (ElmoMuppet elmo);
|
||||
//
|
||||
// For more information, see https://aka.ms/ios-binding
|
||||
//
|
||||
|
||||
}
|
|
@ -0,0 +1,4 @@
|
|||
namespace tvOSBinding1
|
||||
{
|
||||
|
||||
}
|
|
@ -0,0 +1,14 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0-tvos</TargetFramework>
|
||||
<RootNamespace Condition="'$(name)' != '$(name{-VALUE-FORMS-}safe_namespace)'">tvOSBinding1</RootNamespace>
|
||||
<Nullable>enable</Nullable>
|
||||
<ImplicitUsings>true</ImplicitUsings>
|
||||
<IsBindingProject>true</IsBindingProject>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ObjcBindingApiDefinition Include="ApiDefinition.cs" />
|
||||
<ObjcBindingCoreSource Include="StructsAndEnums.cs" />
|
||||
</ItemGroup>
|
||||
</Project>
|
|
@ -975,6 +975,7 @@
|
|||
<FindAotCompiler
|
||||
SessionId="$(BuildSessionId)"
|
||||
Condition="'$(IsMacEnabled)' == 'true' And '$(_RunAotCompiler)' == 'true'"
|
||||
KeepTemporaryOutput="$(FindAotCompilerKeepKeepTemporaryOutput)"
|
||||
MonoAotCrossCompiler="@(MonoAotCrossCompiler)"
|
||||
RuntimeIdentifier="$(RuntimeIdentifier)"
|
||||
TargetFrameworkMoniker="$(_ComputedTargetFrameworkMoniker)"
|
||||
|
|
|
@ -7,6 +7,8 @@ using Microsoft.Build.Framework;
|
|||
using Xamarin.Localization.MSBuild;
|
||||
using Xamarin.Utils;
|
||||
|
||||
#nullable enable
|
||||
|
||||
namespace Xamarin.MacDev.Tasks
|
||||
{
|
||||
public abstract class CompileEntitlementsTaskBase : XamarinTask
|
||||
|
@ -46,42 +48,42 @@ namespace Xamarin.MacDev.Tasks
|
|||
#region Inputs
|
||||
|
||||
[Required]
|
||||
public string AppBundleDir { get; set; }
|
||||
public string AppBundleDir { get; set; } = string.Empty;
|
||||
|
||||
[Required]
|
||||
public string AppIdentifier { get; set; }
|
||||
public string AppIdentifier { get; set; } = string.Empty;
|
||||
|
||||
[Required]
|
||||
public string BundleIdentifier { get; set; }
|
||||
public string BundleIdentifier { get; set; } = string.Empty;
|
||||
|
||||
[Required]
|
||||
public ITaskItem CompiledEntitlements { get; set; }
|
||||
public ITaskItem? CompiledEntitlements { get; set; }
|
||||
|
||||
public bool Debug { get; set; }
|
||||
|
||||
public string Entitlements { get; set; }
|
||||
public string Entitlements { get; set; } = string.Empty;
|
||||
|
||||
[Required]
|
||||
public bool IsAppExtension { get; set; }
|
||||
|
||||
public string ProvisioningProfile { get; set; }
|
||||
public string ProvisioningProfile { get; set; } = string.Empty;
|
||||
|
||||
[Required]
|
||||
public string SdkDevPath { get; set; }
|
||||
public string SdkDevPath { get; set; } = string.Empty;
|
||||
|
||||
public bool SdkIsSimulator { get; set; }
|
||||
|
||||
[Required]
|
||||
public string SdkPlatform { get; set; }
|
||||
public string SdkPlatform { get; set; } = string.Empty;
|
||||
|
||||
[Required]
|
||||
public string SdkVersion { get; set; }
|
||||
public string SdkVersion { get; set; } = string.Empty;
|
||||
|
||||
[Output]
|
||||
public ITaskItem EntitlementsInExecutable { get; set; }
|
||||
public ITaskItem? EntitlementsInExecutable { get; set; }
|
||||
|
||||
[Output]
|
||||
public ITaskItem EntitlementsInSignature { get; set; }
|
||||
public ITaskItem? EntitlementsInSignature { get; set; }
|
||||
|
||||
#endregion
|
||||
|
||||
|
@ -139,11 +141,7 @@ namespace Xamarin.MacDev.Tasks
|
|||
}
|
||||
}
|
||||
|
||||
protected virtual bool MergeProfileEntitlements {
|
||||
get { return true; }
|
||||
}
|
||||
|
||||
PString MergeEntitlementString (PString pstr, MobileProvision profile, bool expandWildcards)
|
||||
PString MergeEntitlementString (PString pstr, MobileProvision? profile, bool expandWildcards)
|
||||
{
|
||||
string TeamIdentifierPrefix;
|
||||
string AppIdentifierPrefix;
|
||||
|
@ -151,7 +149,7 @@ namespace Xamarin.MacDev.Tasks
|
|||
if (string.IsNullOrEmpty (pstr.Value))
|
||||
return (PString) pstr.Clone ();
|
||||
|
||||
if (profile == null) {
|
||||
if (profile is null) {
|
||||
if (!warnedTeamIdentifierPrefix && pstr.Value.Contains ("$(TeamIdentifierPrefix)")) {
|
||||
Log.LogWarning (null, null, null, Entitlements, 0, 0, 0, 0, MSBStrings.W0108);
|
||||
warnedTeamIdentifierPrefix = true;
|
||||
|
@ -163,12 +161,12 @@ namespace Xamarin.MacDev.Tasks
|
|||
}
|
||||
}
|
||||
|
||||
if (profile != null && profile.ApplicationIdentifierPrefix.Count > 0)
|
||||
if (profile is not null && profile.ApplicationIdentifierPrefix.Count > 0)
|
||||
AppIdentifierPrefix = profile.ApplicationIdentifierPrefix[0] + ".";
|
||||
else
|
||||
AppIdentifierPrefix = string.Empty;
|
||||
|
||||
if (profile != null && profile.TeamIdentifierPrefix.Count > 0)
|
||||
if (profile is not null && profile.TeamIdentifierPrefix.Count > 0)
|
||||
TeamIdentifierPrefix = profile.TeamIdentifierPrefix[0] + ".";
|
||||
else
|
||||
TeamIdentifierPrefix = AppIdentifierPrefix;
|
||||
|
@ -203,12 +201,12 @@ namespace Xamarin.MacDev.Tasks
|
|||
return new PString (expanded);
|
||||
}
|
||||
|
||||
PArray MergeEntitlementArray (PArray array, MobileProvision profile)
|
||||
PArray? MergeEntitlementArray (PArray array, MobileProvision? profile)
|
||||
{
|
||||
var result = new PArray ();
|
||||
|
||||
foreach (var item in array) {
|
||||
PObject value;
|
||||
PObject? value;
|
||||
|
||||
if (item is PDictionary)
|
||||
value = MergeEntitlementDictionary ((PDictionary) item, profile);
|
||||
|
@ -219,7 +217,7 @@ namespace Xamarin.MacDev.Tasks
|
|||
else
|
||||
value = item.Clone ();
|
||||
|
||||
if (value != null)
|
||||
if (value is not null)
|
||||
result.Add (value);
|
||||
}
|
||||
|
||||
|
@ -229,12 +227,12 @@ namespace Xamarin.MacDev.Tasks
|
|||
return null;
|
||||
}
|
||||
|
||||
PDictionary MergeEntitlementDictionary (PDictionary dict, MobileProvision profile)
|
||||
PDictionary MergeEntitlementDictionary (PDictionary dict, MobileProvision? profile)
|
||||
{
|
||||
var result = new PDictionary ();
|
||||
|
||||
foreach (var item in dict) {
|
||||
PObject value = item.Value;
|
||||
PObject? value = item.Value;
|
||||
|
||||
if (value is PDictionary)
|
||||
value = MergeEntitlementDictionary ((PDictionary) value, profile);
|
||||
|
@ -245,7 +243,7 @@ namespace Xamarin.MacDev.Tasks
|
|||
else
|
||||
value = value.Clone ();
|
||||
|
||||
if (value != null)
|
||||
if (value is not null)
|
||||
result.Add (item.Key, value);
|
||||
}
|
||||
|
||||
|
@ -289,11 +287,11 @@ namespace Xamarin.MacDev.Tasks
|
|||
}
|
||||
}
|
||||
|
||||
protected virtual PDictionary GetCompiledEntitlements (MobileProvision profile, PDictionary template)
|
||||
protected virtual PDictionary GetCompiledEntitlements (MobileProvision? profile, PDictionary template)
|
||||
{
|
||||
var entitlements = new PDictionary ();
|
||||
|
||||
if (profile != null && MergeProfileEntitlements) {
|
||||
if (profile is not null) {
|
||||
// start off with the settings from the provisioning profile
|
||||
foreach (var item in profile.Entitlements) {
|
||||
if (!AllowedProvisioningKeys.Contains (item.Key))
|
||||
|
@ -312,7 +310,7 @@ namespace Xamarin.MacDev.Tasks
|
|||
else
|
||||
value = value.Clone ();
|
||||
|
||||
if (value != null)
|
||||
if (value is not null)
|
||||
entitlements.Add (item.Key, value);
|
||||
}
|
||||
}
|
||||
|
@ -325,7 +323,7 @@ namespace Xamarin.MacDev.Tasks
|
|||
item.Key == "com.apple.developer.icloud-container-identifiers" ||
|
||||
item.Key == "com.apple.developer.icloud-container-environment" ||
|
||||
item.Key == "com.apple.developer.icloud-services") {
|
||||
if (profile == null)
|
||||
if (profile is null)
|
||||
Log.LogWarning (null, null, null, Entitlements, 0, 0, 0, 0, MSBStrings.W0110, item.Key);
|
||||
else if (!profile.Entitlements.ContainsKey (item.Key))
|
||||
Log.LogWarning (null, null, null, Entitlements, 0, 0, 0, 0, MSBStrings.W0111, item.Key);
|
||||
|
@ -333,7 +331,7 @@ namespace Xamarin.MacDev.Tasks
|
|||
var str = value as PString;
|
||||
|
||||
// Ignore ONLY if it is empty, otherwise take the user's value
|
||||
if (str == null || string.IsNullOrEmpty (str.Value))
|
||||
if (str is null || string.IsNullOrEmpty (str.Value))
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -346,7 +344,7 @@ namespace Xamarin.MacDev.Tasks
|
|||
else
|
||||
value = value.Clone ();
|
||||
|
||||
if (value != null)
|
||||
if (value is not null)
|
||||
entitlements[item.Key] = value;
|
||||
}
|
||||
|
||||
|
@ -389,7 +387,7 @@ namespace Xamarin.MacDev.Tasks
|
|||
public override bool Execute ()
|
||||
{
|
||||
MobileProvisionPlatform platform;
|
||||
MobileProvision profile;
|
||||
MobileProvision? profile;
|
||||
PDictionary template;
|
||||
PDictionary compiled;
|
||||
PDictionary archived;
|
||||
|
@ -418,7 +416,7 @@ namespace Xamarin.MacDev.Tasks
|
|||
}
|
||||
|
||||
if (!string.IsNullOrEmpty (ProvisioningProfile)) {
|
||||
if ((profile = GetMobileProvision (platform, ProvisioningProfile)) == null) {
|
||||
if ((profile = GetMobileProvision (platform, ProvisioningProfile)) is null) {
|
||||
Log.LogError (MSBStrings.E0049, ProvisioningProfile);
|
||||
return false;
|
||||
}
|
||||
|
@ -448,7 +446,7 @@ namespace Xamarin.MacDev.Tasks
|
|||
archived = GetArchivedExpandedEntitlements (template, compiled);
|
||||
|
||||
try {
|
||||
Directory.CreateDirectory (Path.GetDirectoryName (CompiledEntitlements.ItemSpec));
|
||||
Directory.CreateDirectory (Path.GetDirectoryName (CompiledEntitlements!.ItemSpec));
|
||||
WriteXcent (compiled, CompiledEntitlements.ItemSpec);
|
||||
} catch (Exception ex) {
|
||||
Log.LogError (MSBStrings.E0114, CompiledEntitlements, ex.Message);
|
||||
|
|
|
@ -12,6 +12,8 @@ namespace Xamarin.MacDev.Tasks {
|
|||
[Required]
|
||||
public ITaskItem[] MonoAotCrossCompiler { get; set; }
|
||||
|
||||
public bool KeepTemporaryOutput { get; set; }
|
||||
|
||||
[Required]
|
||||
public string RuntimeIdentifier { get; set; }
|
||||
|
||||
|
@ -45,9 +47,12 @@ namespace Xamarin.MacDev.Tasks {
|
|||
{
|
||||
var projectPath = Path.GetTempFileName ();
|
||||
var outputFile = Path.GetTempFileName ();
|
||||
var binlog = Path.GetTempFileName ();
|
||||
|
||||
File.Delete (projectPath);
|
||||
projectPath += ".csproj";
|
||||
File.Delete (binlog);
|
||||
binlog += ".binlog";
|
||||
var csproj = $@"<?xml version=""1.0"" encoding=""utf-8""?>
|
||||
<Project Sdk=""Microsoft.NET.Sdk"">
|
||||
<PropertyGroup>
|
||||
|
@ -72,6 +77,7 @@ namespace Xamarin.MacDev.Tasks {
|
|||
arguments.Add ("/p:OutputFilePath=" + outputFile);
|
||||
arguments.Add ("/p:RuntimeIdentifier=" + RuntimeIdentifier);
|
||||
arguments.Add ("/t:ComputeAotCompilerPath");
|
||||
arguments.Add ("/bl:" + binlog);
|
||||
arguments.Add (projectPath);
|
||||
|
||||
var environment = default (Dictionary<string, string>);
|
||||
|
@ -85,8 +91,16 @@ namespace Xamarin.MacDev.Tasks {
|
|||
ExecuteAsync (executable, arguments, environment: environment).Wait ();
|
||||
return File.ReadAllText (outputFile).Trim ();
|
||||
} finally {
|
||||
if (KeepTemporaryOutput) {
|
||||
Log.LogMessage (MessageImportance.Normal, "Temporary files for the FindAotCompiler task:");
|
||||
Log.LogMessage (MessageImportance.Normal, $" Project file: {projectPath}");
|
||||
Log.LogMessage (MessageImportance.Normal, $" Output file: {outputFile}");
|
||||
Log.LogMessage (MessageImportance.Normal, $" Binary log: {binlog}");
|
||||
} else {
|
||||
File.Delete (projectPath);
|
||||
File.Delete (outputFile);
|
||||
File.Delete (binlog);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
<WarningsAsErrors>Nullable</WarningsAsErrors>
|
||||
<NoWarn>$(NoWarn);NU1603</NoWarn> <!-- Xamarin.Messaging.Build.Common 1.6.24 depends on Merq (>= 1.1.0) but Merq 1.1.0 was not found. An approximate best match of Merq 1.1.4 was resolved. -->
|
||||
<NoWarn>$(NoWarn);NU1701</NoWarn> <!-- warning NU1701: Package 'BouncyCastle 1.8.9' was restored using '.NETFramework,Version=v4.6.1, .NETFramework,Version=v4.6.2, .NETFramework,Version=v4.7, .NETFramework,Version=v4.7.1, .NETFramework,Version=v4.7.2, .NETFramework,Version=v4.8' instead of the project target framework '.NETStandard,Version=v2.0'. This package may not be fully compatible with your project. -->
|
||||
<NoWarn>$(NoWarn);MSB3246</NoWarn> <!-- Resolved file has a bad image, no metadata, or is otherwise inaccessible. System.BadImageFormatException: Assembly file 'xamarin-macios/packages/xamarin.ios.hotrestart.client/1.0.93/lib/netstandard2.0/ws2_32.dll' could not be opened - PE image doesn't contain managed metadata. -->
|
||||
</PropertyGroup>
|
||||
<Import Project="..\..\eng\Versions.props" />
|
||||
<ItemGroup>
|
||||
|
|
|
@ -25,9 +25,11 @@ namespace Xamarin.Tests {
|
|||
new TemplateInfo (ApplePlatform.iOS, "ioslib"),
|
||||
new TemplateInfo (ApplePlatform.iOS, "iosbinding", false), // Bindings can not build without a native library assigned
|
||||
new TemplateInfo (ApplePlatform.TVOS, "tvos"),
|
||||
new TemplateInfo (ApplePlatform.TVOS, "tvosbinding", false), // Bindings can not build without a native library assigned
|
||||
new TemplateInfo (ApplePlatform.MacCatalyst, "maccatalyst", execute: true),
|
||||
new TemplateInfo (ApplePlatform.MacCatalyst, "maccatalystbinding", false), // Bindings can not build without a native library assigned
|
||||
new TemplateInfo (ApplePlatform.MacOSX, "macos", execute: true),
|
||||
new TemplateInfo (ApplePlatform.MacOSX, "macosbinding", false), // Bindings can not build without a native library assigned
|
||||
};
|
||||
|
||||
public class TemplateConfig {
|
||||
|
|
|
@ -35,9 +35,9 @@ namespace MonoTouchFixtures.Security {
|
|||
#endif
|
||||
NSData data = NSData.FromStream (certStream);
|
||||
|
||||
var query = new SecRecord (SecKind.Certificate) {
|
||||
Label = $"Internet Widgits Pty Ltd",
|
||||
};
|
||||
var query = RecordTest.CreateSecRecord (SecKind.Certificate,
|
||||
label: $"Internet Widgits Pty Ltd"
|
||||
);
|
||||
var rec = query.Clone ();
|
||||
rec.SetValueRef (new SecCertificate (data));
|
||||
|
||||
|
@ -62,7 +62,7 @@ namespace MonoTouchFixtures.Security {
|
|||
{
|
||||
if (TestRuntime.CheckXcodeVersion (13, 0))
|
||||
Assert.Ignore ("code == errSecInternal (-26276)");
|
||||
using (SecRecord rec = new SecRecord (SecKind.Identity))
|
||||
using (var rec = RecordTest.CreateSecRecord (SecKind.Identity))
|
||||
using (var id = IdentityTest.GetIdentity ()) {
|
||||
rec.SetValueRef (id);
|
||||
SecStatusCode code = SecKeyChain.Add (rec);
|
||||
|
@ -72,7 +72,7 @@ namespace MonoTouchFixtures.Security {
|
|||
if (!TestRuntime.CheckXcodeVersion (5, 0))
|
||||
Assert.Inconclusive ("QueryAsConcreteType does not work before iOS7");
|
||||
|
||||
using (SecRecord rec = new SecRecord (SecKind.Identity)) {
|
||||
using (var rec = RecordTest.CreateSecRecord (SecKind.Identity)) {
|
||||
SecStatusCode code;
|
||||
var match = SecKeyChain.QueryAsConcreteType (rec, out code);
|
||||
if ((match == null) && (code == SecStatusCode.ItemNotFound))
|
||||
|
@ -148,10 +148,10 @@ namespace MonoTouchFixtures.Security {
|
|||
Guid GetID ()
|
||||
{
|
||||
SecStatusCode code;
|
||||
SecRecord queryRec = new SecRecord (SecKind.GenericPassword) {
|
||||
Service = RecordService,
|
||||
Account = RecordAccount,
|
||||
};
|
||||
var queryRec = RecordTest.CreateSecRecord (SecKind.GenericPassword,
|
||||
service: RecordService,
|
||||
account: RecordAccount
|
||||
);
|
||||
var queryResponse = SecKeyChain.QueryAsRecord (queryRec, out code);
|
||||
if (code == SecStatusCode.Success && queryResponse?.Generic != null)
|
||||
return new Guid (NSString.FromData (queryResponse.Generic, NSStringEncoding.UTF8));
|
||||
|
@ -163,10 +163,10 @@ namespace MonoTouchFixtures.Security {
|
|||
public void QueryAsData ()
|
||||
{
|
||||
SecStatusCode code;
|
||||
SecRecord queryRec = new SecRecord (SecKind.GenericPassword) {
|
||||
Service = RecordService,
|
||||
Account = RecordAccount,
|
||||
};
|
||||
var queryRec = RecordTest.CreateSecRecord (SecKind.GenericPassword,
|
||||
service: RecordService,
|
||||
account: RecordAccount
|
||||
);
|
||||
var data = SecKeyChain.QueryAsData (queryRec, true, out code);
|
||||
if (code == SecStatusCode.Success && queryRec != null) {
|
||||
Assert.NotNull (data.Bytes);
|
||||
|
@ -177,10 +177,10 @@ namespace MonoTouchFixtures.Security {
|
|||
public void QueryAsDataArray ()
|
||||
{
|
||||
SecStatusCode code;
|
||||
SecRecord queryRec = new SecRecord (SecKind.GenericPassword) {
|
||||
Service = RecordService,
|
||||
Account = RecordAccount,
|
||||
};
|
||||
var queryRec = RecordTest.CreateSecRecord (SecKind.GenericPassword,
|
||||
service: RecordService,
|
||||
account: RecordAccount
|
||||
);
|
||||
var data = SecKeyChain.QueryAsData (queryRec, true, 1, out code);
|
||||
if (code == SecStatusCode.Success && queryRec != null) {
|
||||
Assert.NotNull (data [0].Bytes);
|
||||
|
@ -189,19 +189,19 @@ namespace MonoTouchFixtures.Security {
|
|||
|
||||
SecStatusCode RemoveID ()
|
||||
{
|
||||
var queryRec = new SecRecord (SecKind.GenericPassword) {
|
||||
Service = RecordService,
|
||||
Account = RecordAccount,
|
||||
};
|
||||
var queryRec = RecordTest.CreateSecRecord (SecKind.GenericPassword,
|
||||
service: RecordService,
|
||||
account: RecordAccount
|
||||
);
|
||||
return SecKeyChain.Remove (queryRec);
|
||||
}
|
||||
|
||||
SecStatusCode SetID (Guid setID)
|
||||
{
|
||||
var queryRec = new SecRecord (SecKind.GenericPassword) {
|
||||
Service = RecordService,
|
||||
Account = RecordAccount,
|
||||
};
|
||||
var queryRec = RecordTest.CreateSecRecord (SecKind.GenericPassword,
|
||||
service: RecordService,
|
||||
account: RecordAccount
|
||||
);
|
||||
var record = queryRec.Clone ();
|
||||
record.Generic = NSData.FromString (Convert.ToString (setID), NSStringEncoding.UTF8);
|
||||
record.Accessible = SecAccessible.Always;
|
||||
|
|
|
@ -51,9 +51,9 @@ namespace MonoTouchFixtures.Security {
|
|||
|
||||
public static void DeleteKeysWithLabel (string label)
|
||||
{
|
||||
var query = new SecRecord (SecKind.Key) {
|
||||
Label = label,
|
||||
};
|
||||
var query = RecordTest.CreateSecRecord (SecKind.Key,
|
||||
label: label
|
||||
);
|
||||
SecStatusCode code;
|
||||
do {
|
||||
// For some reason each call to SecKeyChain will only remove a single key, so do a loop.
|
||||
|
@ -118,7 +118,7 @@ namespace MonoTouchFixtures.Security {
|
|||
var label = $"KeyTest.RoundtripRSAMinPKCS1-{CFBundle.GetMain ().Identifier}-{GetType ().FullName}-{Process.GetCurrentProcess ().Id}";
|
||||
|
||||
try {
|
||||
using (var record = new SecRecord (SecKind.Key)) {
|
||||
using (var record = RecordTest.CreateSecRecord (SecKind.Key)) {
|
||||
record.KeyType = SecKeyType.RSA;
|
||||
record.KeySizeInBits = MinRsaKeySize; // it's not a performance test :)
|
||||
record.Label = label;
|
||||
|
@ -208,7 +208,7 @@ namespace MonoTouchFixtures.Security {
|
|||
var label = $"KeyTest.EncryptTooLarge-{CFBundle.GetMain ().Identifier}-{GetType ().FullName}-{Process.GetCurrentProcess ().Id}";
|
||||
|
||||
try {
|
||||
using (var record = new SecRecord (SecKind.Key)) {
|
||||
using (var record = RecordTest.CreateSecRecord (SecKind.Key)) {
|
||||
record.KeyType = SecKeyType.RSA;
|
||||
record.KeySizeInBits = MinRsaKeySize; // it's not a performance test :)
|
||||
record.Label = label;
|
||||
|
@ -245,7 +245,7 @@ namespace MonoTouchFixtures.Security {
|
|||
var label = $"KeyTest.RoundtripRSA1024OAEP-{CFBundle.GetMain ().Identifier}-{GetType ().FullName}-{Process.GetCurrentProcess ().Id}";
|
||||
|
||||
try {
|
||||
using (var record = new SecRecord (SecKind.Key)) {
|
||||
using (var record = RecordTest.CreateSecRecord (SecKind.Key)) {
|
||||
record.KeyType = SecKeyType.RSA;
|
||||
record.KeySizeInBits = 1024; // it's not a performance test :)
|
||||
record.Label = label;
|
||||
|
@ -299,7 +299,7 @@ namespace MonoTouchFixtures.Security {
|
|||
var label = $"KeyTest.SignVerifyRSAMinPKCS1SHA1-{CFBundle.GetMain ().Identifier}-{GetType ().FullName}-{Process.GetCurrentProcess ().Id}";
|
||||
|
||||
try {
|
||||
using (var record = new SecRecord (SecKind.Key)) {
|
||||
using (var record = RecordTest.CreateSecRecord (SecKind.Key)) {
|
||||
record.KeyType = SecKeyType.RSA;
|
||||
record.KeySizeInBits = MinRsaKeySize; // it's not a performance test :)
|
||||
record.Label = label;
|
||||
|
@ -335,7 +335,7 @@ namespace MonoTouchFixtures.Security {
|
|||
var label = $"KeyTest.SignVerifyECSHA1-{CFBundle.GetMain ().Identifier}-{GetType ().FullName}-{Process.GetCurrentProcess ().Id}";
|
||||
|
||||
try {
|
||||
using (var record = new SecRecord (SecKind.Key)) {
|
||||
using (var record = RecordTest.CreateSecRecord (SecKind.Key)) {
|
||||
record.KeyType = SecKeyType.EC;
|
||||
record.KeySizeInBits = 256; // it's not a performance test :)
|
||||
record.Label = label;
|
||||
|
@ -371,7 +371,7 @@ namespace MonoTouchFixtures.Security {
|
|||
var label = $"KeyTest.GenerateKeyPairTooLargeRSA-{CFBundle.GetMain ().Identifier}-{GetType ().FullName}-{Process.GetCurrentProcess ().Id}";
|
||||
|
||||
try {
|
||||
using (var record = new SecRecord (SecKind.Key)) {
|
||||
using (var record = RecordTest.CreateSecRecord (SecKind.Key)) {
|
||||
record.KeyType = SecKeyType.RSA;
|
||||
// maximum documented as 2048, .NET maximum is 16384
|
||||
record.KeySizeInBits = 16384;
|
||||
|
@ -437,7 +437,7 @@ namespace MonoTouchFixtures.Security {
|
|||
var label = $"KeyTest.BenchmarkNative4096-{CFBundle.GetMain ().Identifier}-{GetType ().FullName}-{Process.GetCurrentProcess ().Id}";
|
||||
|
||||
try {
|
||||
using (var record = new SecRecord (SecKind.Key)) {
|
||||
using (var record = RecordTest.CreateSecRecord (SecKind.Key)) {
|
||||
record.KeyType = SecKeyType.RSA;
|
||||
record.KeySizeInBits = 4096;
|
||||
record.Label = label;
|
||||
|
|
|
@ -5,6 +5,9 @@ using System.Diagnostics;
|
|||
|
||||
using CoreFoundation;
|
||||
using Foundation;
|
||||
#if HAS_LOCALAUTHENTICATION
|
||||
using LocalAuthentication;
|
||||
#endif
|
||||
using Security;
|
||||
#if MONOMAC
|
||||
using AppKit;
|
||||
|
@ -21,13 +24,88 @@ namespace MonoTouchFixtures.Security {
|
|||
[Preserve (AllMembers = true)]
|
||||
public class RecordTest {
|
||||
|
||||
static void InitSecRecord (SecRecord rec)
|
||||
{
|
||||
#if __MACOS__
|
||||
// ignore on macOS 11.* (but not 12+)
|
||||
if (TestRuntime.CheckXcodeVersion (12, 2) && !TestRuntime.CheckXcodeVersion (13, 0))
|
||||
TestRuntime.IgnoreInCI ("Skip on macOS 11.* because it hangs");
|
||||
#endif
|
||||
|
||||
#if HAS_LOCALAUTHENTICATION
|
||||
var context = new LAContext ();
|
||||
context.InteractionNotAllowed = true;
|
||||
rec.AuthenticationContext = context;
|
||||
#else
|
||||
// This is deprecated, but there's no alternative on tvOS
|
||||
rec.AuthenticationUI = SecAuthenticationUI.Fail;
|
||||
#endif
|
||||
}
|
||||
|
||||
public static SecRecord CreateSecRecord (SecKind kind, string? account = null, NSData? valueData = null, SecAccessible? accessible = null, SecProtocol? protocol = null, string? server = null, SecAuthenticationType? authenticationType = null, string? service = null, string? label = null)
|
||||
{
|
||||
var rec = new SecRecord (kind);
|
||||
InitSecRecord (rec);
|
||||
|
||||
if (account is not null)
|
||||
rec.Account = account;
|
||||
|
||||
if (valueData is not null)
|
||||
rec.ValueData = valueData;
|
||||
|
||||
if (accessible is not null)
|
||||
rec.Accessible = accessible.Value;
|
||||
|
||||
if (protocol is not null)
|
||||
rec.Protocol = protocol.Value;
|
||||
|
||||
if (server is not null)
|
||||
rec.Server = server;
|
||||
|
||||
if (authenticationType is not null)
|
||||
rec.AuthenticationType = authenticationType.Value;
|
||||
|
||||
if (service is not null)
|
||||
rec.Service = service;
|
||||
|
||||
if (label is not null)
|
||||
rec.Label = label;
|
||||
|
||||
return rec;
|
||||
}
|
||||
|
||||
public static SecRecord CreateSecRecord (SecIdentity identity)
|
||||
{
|
||||
var rec = new SecRecord (identity);
|
||||
InitSecRecord (rec);
|
||||
return rec;
|
||||
}
|
||||
|
||||
public static SecRecord CreateSecRecord (SecKey key)
|
||||
{
|
||||
var rec = new SecRecord (key);
|
||||
InitSecRecord (rec);
|
||||
return rec;
|
||||
}
|
||||
|
||||
public static SecRecord CreateSecRecord (SecCertificate certificate, string? label = null)
|
||||
{
|
||||
var rec = new SecRecord (certificate);
|
||||
InitSecRecord (rec);
|
||||
|
||||
if (label is not null)
|
||||
rec.Label = label;
|
||||
|
||||
return rec;
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Identity ()
|
||||
{
|
||||
var rec = new SecRecord (SecKind.Identity) {
|
||||
Account = "Username",
|
||||
ValueData = NSData.FromString ("Password"),
|
||||
};
|
||||
var rec = CreateSecRecord (SecKind.Identity,
|
||||
account: "Username",
|
||||
valueData: NSData.FromString ("Password")
|
||||
);
|
||||
|
||||
// prior to iOS7 you had to deal without the class
|
||||
using (var dict = rec.ToDictionary ()) {
|
||||
|
@ -45,16 +123,16 @@ namespace MonoTouchFixtures.Security {
|
|||
|
||||
void Accessible (SecAccessible access)
|
||||
{
|
||||
var rec = new SecRecord (SecKind.GenericPassword) {
|
||||
Account = "Username"
|
||||
};
|
||||
var rec = CreateSecRecord (SecKind.GenericPassword,
|
||||
account: "Username"
|
||||
);
|
||||
SecKeyChain.Remove (rec); // it might already exists (or not)
|
||||
|
||||
rec = new SecRecord (SecKind.GenericPassword) {
|
||||
Account = "Username",
|
||||
ValueData = NSData.FromString ("Password"),
|
||||
Accessible = access
|
||||
};
|
||||
rec = CreateSecRecord (SecKind.GenericPassword,
|
||||
account: "Username",
|
||||
valueData: NSData.FromString ("Password"),
|
||||
accessible: access
|
||||
);
|
||||
|
||||
Assert.That (SecKeyChain.Add (rec), Is.EqualTo (SecStatusCode.Success), "Add");
|
||||
|
||||
|
@ -68,9 +146,9 @@ namespace MonoTouchFixtures.Security {
|
|||
[Test]
|
||||
public void Match ()
|
||||
{
|
||||
var rec = new SecRecord (SecKind.GenericPassword) {
|
||||
Account = "Username",
|
||||
};
|
||||
var rec = CreateSecRecord (SecKind.GenericPassword,
|
||||
account: "Username"
|
||||
);
|
||||
Assert.Null (rec.MatchIssuers, "MatchIssuers");
|
||||
// we do not have a way (except the getter) to craete SecKeyChain instances
|
||||
Assert.Null (rec.MatchItemList, "MatchItemList");
|
||||
|
@ -106,18 +184,18 @@ namespace MonoTouchFixtures.Security {
|
|||
|
||||
void Protocol (SecProtocol protocol)
|
||||
{
|
||||
var rec = new SecRecord (SecKind.InternetPassword) {
|
||||
Account = $"Protocol-{protocol}-{CFBundle.GetMain ().Identifier}-{GetType ().FullName}-{Process.GetCurrentProcess ().Id}",
|
||||
};
|
||||
var rec = CreateSecRecord (SecKind.InternetPassword,
|
||||
account: $"Protocol-{protocol}-{CFBundle.GetMain ().Identifier}-{GetType ().FullName}-{Process.GetCurrentProcess ().Id}"
|
||||
);
|
||||
try {
|
||||
SecKeyChain.Remove (rec); // it might already exists (or not)
|
||||
|
||||
rec = new SecRecord (SecKind.InternetPassword) {
|
||||
Account = "Protocol",
|
||||
ValueData = NSData.FromString ("Password"),
|
||||
Protocol = protocol,
|
||||
Server = "www.xamarin.com"
|
||||
};
|
||||
rec = CreateSecRecord (SecKind.InternetPassword,
|
||||
account: "Protocol",
|
||||
valueData: NSData.FromString ("Password"),
|
||||
protocol: protocol,
|
||||
server: "www.xamarin.com"
|
||||
);
|
||||
|
||||
Assert.That (SecKeyChain.Add (rec), Is.EqualTo (SecStatusCode.Success), "Add");
|
||||
|
||||
|
@ -173,26 +251,26 @@ namespace MonoTouchFixtures.Security {
|
|||
|
||||
void AuthenticationType (SecAuthenticationType type)
|
||||
{
|
||||
var rec = new SecRecord (SecKind.InternetPassword) {
|
||||
Account = "AuthenticationType"
|
||||
};
|
||||
var rec = CreateSecRecord (SecKind.InternetPassword,
|
||||
account: "AuthenticationType"
|
||||
);
|
||||
SecKeyChain.Remove (rec); // it might already exists (or not)
|
||||
|
||||
rec = new SecRecord (SecKind.InternetPassword) {
|
||||
Account = $"{CFBundle.GetMain ().Identifier}-{GetType ().FullName}-{Process.GetCurrentProcess ().Id}",
|
||||
ValueData = NSData.FromString ("Password"),
|
||||
AuthenticationType = type,
|
||||
Server = "www.xamarin.com"
|
||||
};
|
||||
rec = CreateSecRecord (SecKind.InternetPassword,
|
||||
account: $"{CFBundle.GetMain ().Identifier}-{GetType ().FullName}-{Process.GetCurrentProcess ().Id}",
|
||||
valueData: NSData.FromString ("Password"),
|
||||
authenticationType: type,
|
||||
server: "www.xamarin.com"
|
||||
);
|
||||
|
||||
try {
|
||||
Assert.That (SecKeyChain.Add (rec), Is.EqualTo (SecStatusCode.Success), "Add");
|
||||
|
||||
var query = new SecRecord (SecKind.InternetPassword) {
|
||||
Account = rec.Account,
|
||||
AuthenticationType = rec.AuthenticationType,
|
||||
Server = rec.Server,
|
||||
};
|
||||
var query = CreateSecRecord (SecKind.InternetPassword,
|
||||
account: rec.Account,
|
||||
authenticationType: rec.AuthenticationType,
|
||||
server: rec.Server
|
||||
);
|
||||
|
||||
SecStatusCode code;
|
||||
var match = SecKeyChain.QueryAsRecord (query, out code);
|
||||
|
@ -259,10 +337,10 @@ namespace MonoTouchFixtures.Security {
|
|||
public static string GetUserPassword (string username)
|
||||
{
|
||||
string password = null;
|
||||
var searchRecord = new SecRecord (SecKind.InternetPassword) {
|
||||
Server = "Test1",
|
||||
Account = username.ToLower()
|
||||
};
|
||||
var searchRecord = CreateSecRecord (SecKind.InternetPassword,
|
||||
server: "Test1",
|
||||
account: username.ToLower ()
|
||||
);
|
||||
SecStatusCode code;
|
||||
var record = SecKeyChain.QueryAsRecord(searchRecord, out code);
|
||||
if (code == SecStatusCode.Success && record != null)
|
||||
|
@ -273,18 +351,18 @@ namespace MonoTouchFixtures.Security {
|
|||
public static bool SaveUserPassword (string username, string password)
|
||||
{
|
||||
var success = false;
|
||||
var searchRecord = new SecRecord (SecKind.InternetPassword) {
|
||||
Server = "Test1",
|
||||
Account = username.ToLower ()
|
||||
};
|
||||
var searchRecord = CreateSecRecord (SecKind.InternetPassword,
|
||||
server: "Test1",
|
||||
account: username.ToLower ()
|
||||
);
|
||||
SecStatusCode queryCode;
|
||||
var record = SecKeyChain.QueryAsRecord (searchRecord, out queryCode);
|
||||
if (queryCode == SecStatusCode.ItemNotFound) {
|
||||
record = new SecRecord (SecKind.InternetPassword) {
|
||||
Server = "Test1",
|
||||
Account = username.ToLower (),
|
||||
ValueData = NSData.FromString (password)
|
||||
};
|
||||
record = CreateSecRecord (SecKind.InternetPassword,
|
||||
server: "Test1",
|
||||
account: username.ToLower (),
|
||||
valueData: NSData.FromString (password)
|
||||
);
|
||||
var addCode = SecKeyChain.Add (record);
|
||||
success = (addCode == SecStatusCode.Success);
|
||||
}
|
||||
|
@ -299,10 +377,10 @@ namespace MonoTouchFixtures.Security {
|
|||
public static bool ClearUserPassword (string username)
|
||||
{
|
||||
var success = false;
|
||||
var searchRecord = new SecRecord (SecKind.InternetPassword) {
|
||||
Server = "Test1",
|
||||
Account = username.ToLower ()
|
||||
};
|
||||
var searchRecord = CreateSecRecord (SecKind.InternetPassword,
|
||||
server: "Test1",
|
||||
account: username.ToLower ()
|
||||
);
|
||||
SecStatusCode queryCode;
|
||||
var record = SecKeyChain.QueryAsRecord (searchRecord, out queryCode);
|
||||
|
||||
|
@ -325,7 +403,7 @@ namespace MonoTouchFixtures.Security {
|
|||
Assert.Ignore ("code == errSecInternal (-26276)");
|
||||
|
||||
using (var identity = IdentityTest.GetIdentity ())
|
||||
using (var rec = new SecRecord (identity)) {
|
||||
using (var rec = CreateSecRecord (identity)) {
|
||||
SecStatusCode code = SecKeyChain.Add (rec);
|
||||
Assert.True (code == SecStatusCode.DuplicateItem || code == SecStatusCode.Success, "Identity added");
|
||||
|
||||
|
@ -344,7 +422,7 @@ namespace MonoTouchFixtures.Security {
|
|||
{
|
||||
using (var cert = new X509Certificate (CertificateTest.mail_google_com))
|
||||
using (var sc = new SecCertificate (cert))
|
||||
using (var rec = new SecRecord (sc)) {
|
||||
using (var rec = CreateSecRecord (sc)) {
|
||||
Assert.NotNull (rec, "rec is null");
|
||||
|
||||
var ret = rec.GetCertificate ();
|
||||
|
@ -368,7 +446,7 @@ namespace MonoTouchFixtures.Security {
|
|||
using (var trust = new SecTrust (cert, policy)) {
|
||||
trust.Evaluate ();
|
||||
using (SecKey pubkey = trust.GetPublicKey ())
|
||||
using (var rec = new SecRecord (pubkey)) {
|
||||
using (var rec = CreateSecRecord (pubkey)) {
|
||||
Assert.NotNull (rec, "rec is null");
|
||||
|
||||
var ret = rec.GetKey ();
|
||||
|
|
Загрузка…
Ссылка в новой задаче