Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
115 changes: 84 additions & 31 deletions Xamarin.MacDev/MobileProvisionIndex.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

using System;
using System.IO;
using System.Linq;
using System.Collections.Generic;
using System.Security.Cryptography.X509Certificates;

Expand Down Expand Up @@ -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<string> failures = null)
{
var extension = MobileProvision.GetFileExtension (platform);
var path = Path.Combine (MobileProvision.ProfileDirectory, name + extension);
Expand All @@ -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));
Expand All @@ -390,7 +395,7 @@ public static MobileProvision GetMobileProvision (MobileProvisionPlatform platfo
return MobileProvision.LoadFromFile (path);
}

public static IList<MobileProvision> GetMobileProvisions (MobileProvisionPlatform platform, bool includeExpired = false, bool unique = false)
public static IList<MobileProvision> GetMobileProvisions (MobileProvisionPlatform platform, bool includeExpired = false, bool unique = false, List<string> failures = null)
{
var index = OpenIndex (MobileProvision.ProfileDirectory, IndexFileName);
var extension = MobileProvision.GetFileExtension (platform);
Expand All @@ -402,14 +407,20 @@ public static IList<MobileProvision> 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;
Expand All @@ -431,7 +442,7 @@ public static IList<MobileProvision> GetMobileProvisions (MobileProvisionPlatfor
return list;
}

public static IList<MobileProvision> GetMobileProvisions (MobileProvisionPlatform platform, MobileProvisionDistributionType type, bool includeExpired = false, bool unique = false)
public static IList<MobileProvision> GetMobileProvisions (MobileProvisionPlatform platform, MobileProvisionDistributionType type, bool includeExpired = false, bool unique = false, List<string> failures = null)
{
var index = OpenIndex (MobileProvision.ProfileDirectory, IndexFileName);
var extension = MobileProvision.GetFileExtension (platform);
Expand All @@ -443,17 +454,25 @@ public static IList<MobileProvision> 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;
Expand All @@ -475,7 +494,7 @@ public static IList<MobileProvision> GetMobileProvisions (MobileProvisionPlatfor
return list;
}

public static IList<MobileProvision> GetMobileProvisions (MobileProvisionPlatform platform, MobileProvisionDistributionType type, IList<X509Certificate2> developerCertificates, bool includeExpired = false, bool unique = false)
public static IList<MobileProvision> GetMobileProvisions (MobileProvisionPlatform platform, MobileProvisionDistributionType type, IList<X509Certificate2> developerCertificates, bool includeExpired = false, bool unique = false, List<string> failures = null)
{
var index = OpenIndex (MobileProvision.ProfileDirectory, IndexFileName);
var extension = MobileProvision.GetFileExtension (platform);
Expand All @@ -497,21 +516,31 @@ public static IList<MobileProvision> 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;
Expand All @@ -535,7 +564,7 @@ public static IList<MobileProvision> GetMobileProvisions (MobileProvisionPlatfor
return list;
}

public static IList<MobileProvision> GetMobileProvisions (MobileProvisionPlatform platform, string bundleIdentifier, MobileProvisionDistributionType type, bool includeExpired = false, bool unique = false)
public static IList<MobileProvision> GetMobileProvisions (MobileProvisionPlatform platform, string bundleIdentifier, MobileProvisionDistributionType type, bool includeExpired = false, bool unique = false, List<string> failures = null)
{
var index = OpenIndex (MobileProvision.ProfileDirectory, IndexFileName);
var extension = MobileProvision.GetFileExtension (platform);
Expand All @@ -550,17 +579,25 @@ public static IList<MobileProvision> 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;
Expand All @@ -573,10 +610,13 @@ public static IList<MobileProvision> 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;
}

Expand All @@ -600,7 +640,7 @@ public static IList<MobileProvision> GetMobileProvisions (MobileProvisionPlatfor
return list;
}

public static IList<MobileProvision> GetMobileProvisions (MobileProvisionPlatform platform, string bundleIdentifier, MobileProvisionDistributionType type, IList<X509Certificate2> developerCertificates, bool includeExpired = false, bool unique = false)
public static IList<MobileProvision> GetMobileProvisions (MobileProvisionPlatform platform, string bundleIdentifier, MobileProvisionDistributionType type, IList<X509Certificate2> developerCertificates, bool includeExpired = false, bool unique = false, List<string> failures = null)
{
var index = OpenIndex (MobileProvision.ProfileDirectory, IndexFileName);
var extension = MobileProvision.GetFileExtension (platform);
Expand All @@ -625,17 +665,25 @@ public static IList<MobileProvision> 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;
Expand All @@ -648,16 +696,21 @@ public static IList<MobileProvision> 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;
Expand Down