From 26002caa90a955bdbc2713985e124a70a392a8d4 Mon Sep 17 00:00:00 2001 From: Rolf Bjarne Kvinge Date: Wed, 4 Oct 2017 12:58:14 +0200 Subject: [PATCH] Add support for optionally explaining why inapplicable provisioning profiles are not applicable. Partially fixes #58251. https://bugzilla.xamarin.com/show_bug.cgi?id=58251 --- Xamarin.MacDev/MobileProvisionIndex.cs | 115 ++++++++++++++++++------- 1 file changed, 84 insertions(+), 31 deletions(-) diff --git a/Xamarin.MacDev/MobileProvisionIndex.cs b/Xamarin.MacDev/MobileProvisionIndex.cs index a3a9d15..5a2437b 100644 --- a/Xamarin.MacDev/MobileProvisionIndex.cs +++ b/Xamarin.MacDev/MobileProvisionIndex.cs @@ -25,6 +25,7 @@ using System; using System.IO; +using System.Linq; using System.Collections.Generic; using System.Security.Cryptography.X509Certificates; @@ -355,7 +356,7 @@ public static MobileProvisionIndex OpenIndex (string profilesDir, string indexNa return index; } - public static MobileProvision GetMobileProvision (MobileProvisionPlatform platform, string name) + public static MobileProvision GetMobileProvision (MobileProvisionPlatform platform, string name, List failures = null) { var extension = MobileProvision.GetFileExtension (platform); var path = Path.Combine (MobileProvision.ProfileDirectory, name + extension); @@ -369,11 +370,15 @@ public static MobileProvision GetMobileProvision (MobileProvisionPlatform platfo path = null; foreach (var profile in index.ProvisioningProfiles) { - if (!profile.FileName.EndsWith (extension, StringComparison.Ordinal)) + if (!profile.FileName.EndsWith (extension, StringComparison.Ordinal)) { + failures?.Add ($"The profile '{profile.Name}' is not applicable because its FileName ({profile.FileName}) does not end with '{extension}'."); continue; + } - if (!profile.Platforms.Contains (platform)) + if (!profile.Platforms.Contains (platform)) { + failures?.Add ($"The profile '{profile.Name}' is not applicable because its platforms ({string.Join (", ", profile.Platforms.Select ((v) => v.ToString ()))}) do not match the requested platform ({platform})."); continue; + } if (name == profile.Name || name == profile.Uuid) return MobileProvision.LoadFromFile (Path.Combine (MobileProvision.ProfileDirectory, profile.FileName)); @@ -390,7 +395,7 @@ public static MobileProvision GetMobileProvision (MobileProvisionPlatform platfo return MobileProvision.LoadFromFile (path); } - public static IList GetMobileProvisions (MobileProvisionPlatform platform, bool includeExpired = false, bool unique = false) + public static IList GetMobileProvisions (MobileProvisionPlatform platform, bool includeExpired = false, bool unique = false, List failures = null) { var index = OpenIndex (MobileProvision.ProfileDirectory, IndexFileName); var extension = MobileProvision.GetFileExtension (platform); @@ -402,14 +407,20 @@ public static IList GetMobileProvisions (MobileProvisionPlatfor for (int i = index.ProvisioningProfiles.Count - 1; i >= 0; i--) { var profile = index.ProvisioningProfiles[i]; - if (!profile.FileName.EndsWith (extension, StringComparison.Ordinal)) + if (!profile.FileName.EndsWith (extension, StringComparison.Ordinal)) { + failures?.Add ($"The profile '{profile.Name}' is not applicable because its FileName ({profile.FileName}) does not end with '{extension}'."); continue; + } - if (!profile.Platforms.Contains (platform)) + if (!profile.Platforms.Contains (platform)) { + failures?.Add ($"The profile '{profile.Name}' is not applicable because its platforms ({string.Join (", ", profile.Platforms.Select ((v) => v.ToString ()))}) do not match the requested platform ({platform})."); continue; + } - if (!includeExpired && profile.ExpirationDate < now) + if (!includeExpired && profile.ExpirationDate < now) { + failures?.Add ($"The profile '{profile.Name}' is not applicable because it has expired ({profile.ExpirationDate})."); continue; + } if (unique) { int idx; @@ -431,7 +442,7 @@ public static IList GetMobileProvisions (MobileProvisionPlatfor return list; } - public static IList GetMobileProvisions (MobileProvisionPlatform platform, MobileProvisionDistributionType type, bool includeExpired = false, bool unique = false) + public static IList GetMobileProvisions (MobileProvisionPlatform platform, MobileProvisionDistributionType type, bool includeExpired = false, bool unique = false, List failures = null) { var index = OpenIndex (MobileProvision.ProfileDirectory, IndexFileName); var extension = MobileProvision.GetFileExtension (platform); @@ -443,17 +454,25 @@ public static IList GetMobileProvisions (MobileProvisionPlatfor for (int i = index.ProvisioningProfiles.Count - 1; i >= 0; i--) { var profile = index.ProvisioningProfiles[i]; - if (!profile.FileName.EndsWith (extension, StringComparison.Ordinal)) + if (!profile.FileName.EndsWith (extension, StringComparison.Ordinal)) { + failures?.Add ($"The profile '{profile.Name}' is not applicable because its FileName ({profile.FileName}) does not end with '{extension}'."); continue; + } - if (!profile.Platforms.Contains (platform)) + if (!profile.Platforms.Contains (platform)) { + failures?.Add ($"The profile '{profile.Name}' is not applicable because its platforms ({string.Join (", ", profile.Platforms.Select ((v) => v.ToString ()))}) do not match the requested platform ({platform})."); continue; + } - if (!includeExpired && profile.ExpirationDate < now) + if (!includeExpired && profile.ExpirationDate < now) { + failures?.Add ($"The profile '{profile.Name}' is not applicable because it has expired ({profile.ExpirationDate})."); continue; + } - if (type != MobileProvisionDistributionType.Any && (profile.Distribution & type) == 0) + if (type != MobileProvisionDistributionType.Any && (profile.Distribution & type) == 0) { + failures?.Add ($"The profile '{profile.Name}' is not applicable because its ({profile.Distribution}) does not match the expected type ({type})."); continue; + } if (unique) { int idx; @@ -475,7 +494,7 @@ public static IList GetMobileProvisions (MobileProvisionPlatfor return list; } - public static IList GetMobileProvisions (MobileProvisionPlatform platform, MobileProvisionDistributionType type, IList developerCertificates, bool includeExpired = false, bool unique = false) + public static IList GetMobileProvisions (MobileProvisionPlatform platform, MobileProvisionDistributionType type, IList developerCertificates, bool includeExpired = false, bool unique = false, List failures = null) { var index = OpenIndex (MobileProvision.ProfileDirectory, IndexFileName); var extension = MobileProvision.GetFileExtension (platform); @@ -497,21 +516,31 @@ public static IList GetMobileProvisions (MobileProvisionPlatfor for (int i = index.ProvisioningProfiles.Count - 1; i >= 0; i--) { var profile = index.ProvisioningProfiles[i]; - if (!profile.FileName.EndsWith (extension, StringComparison.Ordinal)) + if (!profile.FileName.EndsWith (extension, StringComparison.Ordinal)) { + failures?.Add ($"The profile '{profile.Name}' is not applicable because its FileName ({profile.FileName}) does not end with '{extension}'."); continue; + } - if (!profile.Platforms.Contains (platform)) + if (!profile.Platforms.Contains (platform)) { + failures?.Add ($"The profile '{profile.Name}' is not applicable because its platforms ({string.Join (", ", profile.Platforms.Select ((v) => v.ToString ()))}) do not match the requested platform ({platform})."); continue; + } - if (!includeExpired && profile.ExpirationDate < now) + if (!includeExpired && profile.ExpirationDate < now) { + failures?.Add ($"The profile '{profile.Name}' is not applicable because it has expired ({profile.ExpirationDate})."); continue; + } - if (type != MobileProvisionDistributionType.Any && (profile.Distribution & type) == 0) + if (type != MobileProvisionDistributionType.Any && (profile.Distribution & type) == 0) { + failures?.Add ($"The profile '{profile.Name}' is not applicable because its ({profile.Distribution}) does not match the expected type ({type})."); continue; + } foreach (var cert in profile.DeveloperCertificates) { - if (!thumbprints.Contains (cert.Thumbprint)) + if (!thumbprints.Contains (cert.Thumbprint)) { + failures?.Add ($"The profile '{profile.Name}' might not be applicable because its developer certificate (of {profile.DeveloperCertificates.Count} certificates) {cert.Name}'s thumbprint ({cert.Thumbprint}) is not in the list of accepted thumbprints ({string.Join (", ", thumbprints)})."); continue; + } if (unique) { int idx; @@ -535,7 +564,7 @@ public static IList GetMobileProvisions (MobileProvisionPlatfor return list; } - public static IList GetMobileProvisions (MobileProvisionPlatform platform, string bundleIdentifier, MobileProvisionDistributionType type, bool includeExpired = false, bool unique = false) + public static IList GetMobileProvisions (MobileProvisionPlatform platform, string bundleIdentifier, MobileProvisionDistributionType type, bool includeExpired = false, bool unique = false, List failures = null) { var index = OpenIndex (MobileProvision.ProfileDirectory, IndexFileName); var extension = MobileProvision.GetFileExtension (platform); @@ -550,17 +579,25 @@ public static IList GetMobileProvisions (MobileProvisionPlatfor for (int i = index.ProvisioningProfiles.Count - 1; i >= 0; i--) { var profile = index.ProvisioningProfiles[i]; - if (!profile.FileName.EndsWith (extension, StringComparison.Ordinal)) + if (!profile.FileName.EndsWith (extension, StringComparison.Ordinal)) { + failures?.Add ($"The profile '{profile.Name}' is not applicable because its FileName ({profile.FileName}) does not end with '{extension}'."); continue; + } - if (!profile.Platforms.Contains (platform)) + if (!profile.Platforms.Contains (platform)) { + failures?.Add ($"The profile '{profile.Name}' is not applicable because its platforms ({string.Join (", ", profile.Platforms.Select ((v) => v.ToString ()))}) do not match the requested platform ({platform})."); continue; + } - if (!includeExpired && profile.ExpirationDate < now) + if (!includeExpired && profile.ExpirationDate < now) { + failures?.Add ($"The profile '{profile.Name}' is not applicable because it has expired ({profile.ExpirationDate})."); continue; + } - if (type != MobileProvisionDistributionType.Any && (profile.Distribution & type) == 0) + if (type != MobileProvisionDistributionType.Any && (profile.Distribution & type) == 0) { + failures?.Add ($"The profile '{profile.Name}' is not applicable because its ({profile.Distribution}) does not match the expected type ({type})."); continue; + } var id = profile.ApplicationIdentifier; int dot; @@ -573,10 +610,13 @@ public static IList GetMobileProvisions (MobileProvisionPlatfor // Note: this is a wildcard provisioning profile, which means we need to use a substring match id = id.TrimEnd ('*'); - if (!bundleIdentifier.StartsWith (id, StringComparison.Ordinal)) + if (!bundleIdentifier.StartsWith (id, StringComparison.Ordinal)) { + failures?.Add ($"The profile '{profile.Name}' is not applicable because its id ({profile.ApplicationIdentifier}) does not match the bundle identifer {bundleIdentifier}."); continue; + } } else if (id != bundleIdentifier) { // the CFBundleIdentifier provided by our caller does not match this provisioning profile + failures?.Add ($"The profile '{profile.Name}' is not applicable because its id ({profile.ApplicationIdentifier}) does not match the bundle identifer {bundleIdentifier}."); continue; } @@ -600,7 +640,7 @@ public static IList GetMobileProvisions (MobileProvisionPlatfor return list; } - public static IList GetMobileProvisions (MobileProvisionPlatform platform, string bundleIdentifier, MobileProvisionDistributionType type, IList developerCertificates, bool includeExpired = false, bool unique = false) + public static IList GetMobileProvisions (MobileProvisionPlatform platform, string bundleIdentifier, MobileProvisionDistributionType type, IList developerCertificates, bool includeExpired = false, bool unique = false, List failures = null) { var index = OpenIndex (MobileProvision.ProfileDirectory, IndexFileName); var extension = MobileProvision.GetFileExtension (platform); @@ -625,17 +665,25 @@ public static IList GetMobileProvisions (MobileProvisionPlatfor for (int i = index.ProvisioningProfiles.Count - 1; i >= 0; i--) { var profile = index.ProvisioningProfiles[i]; - if (!profile.FileName.EndsWith (extension, StringComparison.Ordinal)) + if (!profile.FileName.EndsWith (extension, StringComparison.Ordinal)) { + failures?.Add ($"The profile '{profile.Name}' is not applicable because its FileName ({profile.FileName}) does not end with '{extension}'."); continue; + } - if (!profile.Platforms.Contains (platform)) + if (!profile.Platforms.Contains (platform)) { + failures?.Add ($"The profile '{profile.Name}' is not applicable because its platforms ({string.Join (", ", profile.Platforms.Select ((v) => v.ToString ()))}) do not match the requested platform ({platform})."); continue; + } - if (!includeExpired && profile.ExpirationDate < now) + if (!includeExpired && profile.ExpirationDate < now) { + failures?.Add ($"The profile '{profile.Name}' is not applicable because it has expired ({profile.ExpirationDate})."); continue; + } - if (type != MobileProvisionDistributionType.Any && (profile.Distribution & type) == 0) + if (type != MobileProvisionDistributionType.Any && (profile.Distribution & type) == 0) { + failures?.Add ($"The profile '{profile.Name}' is not applicable because its ({profile.Distribution}) does not match the expected type ({type})."); continue; + } var id = profile.ApplicationIdentifier; int dot; @@ -648,16 +696,21 @@ public static IList GetMobileProvisions (MobileProvisionPlatfor // Note: this is a wildcard provisioning profile, which means we need to use a substring match id = id.TrimEnd ('*'); - if (!bundleIdentifier.StartsWith (id, StringComparison.Ordinal)) + if (!bundleIdentifier.StartsWith (id, StringComparison.Ordinal)) { + failures?.Add ($"The profile '{profile.Name}' is not applicable because its id ({profile.ApplicationIdentifier}) does not match the bundle identifer {bundleIdentifier}."); continue; + } } else if (id != bundleIdentifier) { // the CFBundleIdentifier provided by our caller does not match this provisioning profile + failures?.Add ($"The profile '{profile.Name}' is not applicable because its id ({profile.ApplicationIdentifier}) does not match the bundle identifer {bundleIdentifier}."); continue; } foreach (var cert in profile.DeveloperCertificates) { - if (!thumbprints.Contains (cert.Thumbprint)) + if (!thumbprints.Contains (cert.Thumbprint)) { + failures?.Add ($"The profile '{profile.Name}' might not be applicable because its developer certificate (of {profile.DeveloperCertificates.Count} certificates) {cert.Name}'s thumbprint ({cert.Thumbprint}) is not in the list of accepted thumbprints ({string.Join (", ", thumbprints)})."); continue; + } if (unique) { int idx;