Skip to content

Commit f83f84d

Browse files
authored
Add support for optionally explaining why inapplicable provisioning profiles are not applicable. Partially fixes #58251. (#16)
https://bugzilla.xamarin.com/show_bug.cgi?id=58251
1 parent d60d25b commit f83f84d

File tree

1 file changed

+84
-31
lines changed

1 file changed

+84
-31
lines changed

Xamarin.MacDev/MobileProvisionIndex.cs

Lines changed: 84 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525

2626
using System;
2727
using System.IO;
28+
using System.Linq;
2829
using System.Collections.Generic;
2930
using System.Security.Cryptography.X509Certificates;
3031

@@ -355,7 +356,7 @@ public static MobileProvisionIndex OpenIndex (string profilesDir, string indexNa
355356
return index;
356357
}
357358

358-
public static MobileProvision GetMobileProvision (MobileProvisionPlatform platform, string name)
359+
public static MobileProvision GetMobileProvision (MobileProvisionPlatform platform, string name, List<string> failures = null)
359360
{
360361
var extension = MobileProvision.GetFileExtension (platform);
361362
var path = Path.Combine (MobileProvision.ProfileDirectory, name + extension);
@@ -369,11 +370,15 @@ public static MobileProvision GetMobileProvision (MobileProvisionPlatform platfo
369370
path = null;
370371

371372
foreach (var profile in index.ProvisioningProfiles) {
372-
if (!profile.FileName.EndsWith (extension, StringComparison.Ordinal))
373+
if (!profile.FileName.EndsWith (extension, StringComparison.Ordinal)) {
374+
failures?.Add ($"The profile '{profile.Name}' is not applicable because its FileName ({profile.FileName}) does not end with '{extension}'.");
373375
continue;
376+
}
374377

375-
if (!profile.Platforms.Contains (platform))
378+
if (!profile.Platforms.Contains (platform)) {
379+
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}).");
376380
continue;
381+
}
377382

378383
if (name == profile.Name || name == profile.Uuid)
379384
return MobileProvision.LoadFromFile (Path.Combine (MobileProvision.ProfileDirectory, profile.FileName));
@@ -390,7 +395,7 @@ public static MobileProvision GetMobileProvision (MobileProvisionPlatform platfo
390395
return MobileProvision.LoadFromFile (path);
391396
}
392397

393-
public static IList<MobileProvision> GetMobileProvisions (MobileProvisionPlatform platform, bool includeExpired = false, bool unique = false)
398+
public static IList<MobileProvision> GetMobileProvisions (MobileProvisionPlatform platform, bool includeExpired = false, bool unique = false, List<string> failures = null)
394399
{
395400
var index = OpenIndex (MobileProvision.ProfileDirectory, IndexFileName);
396401
var extension = MobileProvision.GetFileExtension (platform);
@@ -402,14 +407,20 @@ public static IList<MobileProvision> GetMobileProvisions (MobileProvisionPlatfor
402407
for (int i = index.ProvisioningProfiles.Count - 1; i >= 0; i--) {
403408
var profile = index.ProvisioningProfiles[i];
404409

405-
if (!profile.FileName.EndsWith (extension, StringComparison.Ordinal))
410+
if (!profile.FileName.EndsWith (extension, StringComparison.Ordinal)) {
411+
failures?.Add ($"The profile '{profile.Name}' is not applicable because its FileName ({profile.FileName}) does not end with '{extension}'.");
406412
continue;
413+
}
407414

408-
if (!profile.Platforms.Contains (platform))
415+
if (!profile.Platforms.Contains (platform)) {
416+
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}).");
409417
continue;
418+
}
410419

411-
if (!includeExpired && profile.ExpirationDate < now)
420+
if (!includeExpired && profile.ExpirationDate < now) {
421+
failures?.Add ($"The profile '{profile.Name}' is not applicable because it has expired ({profile.ExpirationDate}).");
412422
continue;
423+
}
413424

414425
if (unique) {
415426
int idx;
@@ -431,7 +442,7 @@ public static IList<MobileProvision> GetMobileProvisions (MobileProvisionPlatfor
431442
return list;
432443
}
433444

434-
public static IList<MobileProvision> GetMobileProvisions (MobileProvisionPlatform platform, MobileProvisionDistributionType type, bool includeExpired = false, bool unique = false)
445+
public static IList<MobileProvision> GetMobileProvisions (MobileProvisionPlatform platform, MobileProvisionDistributionType type, bool includeExpired = false, bool unique = false, List<string> failures = null)
435446
{
436447
var index = OpenIndex (MobileProvision.ProfileDirectory, IndexFileName);
437448
var extension = MobileProvision.GetFileExtension (platform);
@@ -443,17 +454,25 @@ public static IList<MobileProvision> GetMobileProvisions (MobileProvisionPlatfor
443454
for (int i = index.ProvisioningProfiles.Count - 1; i >= 0; i--) {
444455
var profile = index.ProvisioningProfiles[i];
445456

446-
if (!profile.FileName.EndsWith (extension, StringComparison.Ordinal))
457+
if (!profile.FileName.EndsWith (extension, StringComparison.Ordinal)) {
458+
failures?.Add ($"The profile '{profile.Name}' is not applicable because its FileName ({profile.FileName}) does not end with '{extension}'.");
447459
continue;
460+
}
448461

449-
if (!profile.Platforms.Contains (platform))
462+
if (!profile.Platforms.Contains (platform)) {
463+
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}).");
450464
continue;
465+
}
451466

452-
if (!includeExpired && profile.ExpirationDate < now)
467+
if (!includeExpired && profile.ExpirationDate < now) {
468+
failures?.Add ($"The profile '{profile.Name}' is not applicable because it has expired ({profile.ExpirationDate}).");
453469
continue;
470+
}
454471

455-
if (type != MobileProvisionDistributionType.Any && (profile.Distribution & type) == 0)
472+
if (type != MobileProvisionDistributionType.Any && (profile.Distribution & type) == 0) {
473+
failures?.Add ($"The profile '{profile.Name}' is not applicable because its ({profile.Distribution}) does not match the expected type ({type}).");
456474
continue;
475+
}
457476

458477
if (unique) {
459478
int idx;
@@ -475,7 +494,7 @@ public static IList<MobileProvision> GetMobileProvisions (MobileProvisionPlatfor
475494
return list;
476495
}
477496

478-
public static IList<MobileProvision> GetMobileProvisions (MobileProvisionPlatform platform, MobileProvisionDistributionType type, IList<X509Certificate2> developerCertificates, bool includeExpired = false, bool unique = false)
497+
public static IList<MobileProvision> GetMobileProvisions (MobileProvisionPlatform platform, MobileProvisionDistributionType type, IList<X509Certificate2> developerCertificates, bool includeExpired = false, bool unique = false, List<string> failures = null)
479498
{
480499
var index = OpenIndex (MobileProvision.ProfileDirectory, IndexFileName);
481500
var extension = MobileProvision.GetFileExtension (platform);
@@ -497,21 +516,31 @@ public static IList<MobileProvision> GetMobileProvisions (MobileProvisionPlatfor
497516
for (int i = index.ProvisioningProfiles.Count - 1; i >= 0; i--) {
498517
var profile = index.ProvisioningProfiles[i];
499518

500-
if (!profile.FileName.EndsWith (extension, StringComparison.Ordinal))
519+
if (!profile.FileName.EndsWith (extension, StringComparison.Ordinal)) {
520+
failures?.Add ($"The profile '{profile.Name}' is not applicable because its FileName ({profile.FileName}) does not end with '{extension}'.");
501521
continue;
522+
}
502523

503-
if (!profile.Platforms.Contains (platform))
524+
if (!profile.Platforms.Contains (platform)) {
525+
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}).");
504526
continue;
527+
}
505528

506-
if (!includeExpired && profile.ExpirationDate < now)
529+
if (!includeExpired && profile.ExpirationDate < now) {
530+
failures?.Add ($"The profile '{profile.Name}' is not applicable because it has expired ({profile.ExpirationDate}).");
507531
continue;
532+
}
508533

509-
if (type != MobileProvisionDistributionType.Any && (profile.Distribution & type) == 0)
534+
if (type != MobileProvisionDistributionType.Any && (profile.Distribution & type) == 0) {
535+
failures?.Add ($"The profile '{profile.Name}' is not applicable because its ({profile.Distribution}) does not match the expected type ({type}).");
510536
continue;
537+
}
511538

512539
foreach (var cert in profile.DeveloperCertificates) {
513-
if (!thumbprints.Contains (cert.Thumbprint))
540+
if (!thumbprints.Contains (cert.Thumbprint)) {
541+
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)}).");
514542
continue;
543+
}
515544

516545
if (unique) {
517546
int idx;
@@ -535,7 +564,7 @@ public static IList<MobileProvision> GetMobileProvisions (MobileProvisionPlatfor
535564
return list;
536565
}
537566

538-
public static IList<MobileProvision> GetMobileProvisions (MobileProvisionPlatform platform, string bundleIdentifier, MobileProvisionDistributionType type, bool includeExpired = false, bool unique = false)
567+
public static IList<MobileProvision> GetMobileProvisions (MobileProvisionPlatform platform, string bundleIdentifier, MobileProvisionDistributionType type, bool includeExpired = false, bool unique = false, List<string> failures = null)
539568
{
540569
var index = OpenIndex (MobileProvision.ProfileDirectory, IndexFileName);
541570
var extension = MobileProvision.GetFileExtension (platform);
@@ -550,17 +579,25 @@ public static IList<MobileProvision> GetMobileProvisions (MobileProvisionPlatfor
550579
for (int i = index.ProvisioningProfiles.Count - 1; i >= 0; i--) {
551580
var profile = index.ProvisioningProfiles[i];
552581

553-
if (!profile.FileName.EndsWith (extension, StringComparison.Ordinal))
582+
if (!profile.FileName.EndsWith (extension, StringComparison.Ordinal)) {
583+
failures?.Add ($"The profile '{profile.Name}' is not applicable because its FileName ({profile.FileName}) does not end with '{extension}'.");
554584
continue;
585+
}
555586

556-
if (!profile.Platforms.Contains (platform))
587+
if (!profile.Platforms.Contains (platform)) {
588+
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}).");
557589
continue;
590+
}
558591

559-
if (!includeExpired && profile.ExpirationDate < now)
592+
if (!includeExpired && profile.ExpirationDate < now) {
593+
failures?.Add ($"The profile '{profile.Name}' is not applicable because it has expired ({profile.ExpirationDate}).");
560594
continue;
595+
}
561596

562-
if (type != MobileProvisionDistributionType.Any && (profile.Distribution & type) == 0)
597+
if (type != MobileProvisionDistributionType.Any && (profile.Distribution & type) == 0) {
598+
failures?.Add ($"The profile '{profile.Name}' is not applicable because its ({profile.Distribution}) does not match the expected type ({type}).");
563599
continue;
600+
}
564601

565602
var id = profile.ApplicationIdentifier;
566603
int dot;
@@ -573,10 +610,13 @@ public static IList<MobileProvision> GetMobileProvisions (MobileProvisionPlatfor
573610
// Note: this is a wildcard provisioning profile, which means we need to use a substring match
574611
id = id.TrimEnd ('*');
575612

576-
if (!bundleIdentifier.StartsWith (id, StringComparison.Ordinal))
613+
if (!bundleIdentifier.StartsWith (id, StringComparison.Ordinal)) {
614+
failures?.Add ($"The profile '{profile.Name}' is not applicable because its id ({profile.ApplicationIdentifier}) does not match the bundle identifer {bundleIdentifier}.");
577615
continue;
616+
}
578617
} else if (id != bundleIdentifier) {
579618
// the CFBundleIdentifier provided by our caller does not match this provisioning profile
619+
failures?.Add ($"The profile '{profile.Name}' is not applicable because its id ({profile.ApplicationIdentifier}) does not match the bundle identifer {bundleIdentifier}.");
580620
continue;
581621
}
582622

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

603-
public static IList<MobileProvision> GetMobileProvisions (MobileProvisionPlatform platform, string bundleIdentifier, MobileProvisionDistributionType type, IList<X509Certificate2> developerCertificates, bool includeExpired = false, bool unique = false)
643+
public static IList<MobileProvision> GetMobileProvisions (MobileProvisionPlatform platform, string bundleIdentifier, MobileProvisionDistributionType type, IList<X509Certificate2> developerCertificates, bool includeExpired = false, bool unique = false, List<string> failures = null)
604644
{
605645
var index = OpenIndex (MobileProvision.ProfileDirectory, IndexFileName);
606646
var extension = MobileProvision.GetFileExtension (platform);
@@ -625,17 +665,25 @@ public static IList<MobileProvision> GetMobileProvisions (MobileProvisionPlatfor
625665
for (int i = index.ProvisioningProfiles.Count - 1; i >= 0; i--) {
626666
var profile = index.ProvisioningProfiles[i];
627667

628-
if (!profile.FileName.EndsWith (extension, StringComparison.Ordinal))
668+
if (!profile.FileName.EndsWith (extension, StringComparison.Ordinal)) {
669+
failures?.Add ($"The profile '{profile.Name}' is not applicable because its FileName ({profile.FileName}) does not end with '{extension}'.");
629670
continue;
671+
}
630672

631-
if (!profile.Platforms.Contains (platform))
673+
if (!profile.Platforms.Contains (platform)) {
674+
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}).");
632675
continue;
676+
}
633677

634-
if (!includeExpired && profile.ExpirationDate < now)
678+
if (!includeExpired && profile.ExpirationDate < now) {
679+
failures?.Add ($"The profile '{profile.Name}' is not applicable because it has expired ({profile.ExpirationDate}).");
635680
continue;
681+
}
636682

637-
if (type != MobileProvisionDistributionType.Any && (profile.Distribution & type) == 0)
683+
if (type != MobileProvisionDistributionType.Any && (profile.Distribution & type) == 0) {
684+
failures?.Add ($"The profile '{profile.Name}' is not applicable because its ({profile.Distribution}) does not match the expected type ({type}).");
638685
continue;
686+
}
639687

640688
var id = profile.ApplicationIdentifier;
641689
int dot;
@@ -648,16 +696,21 @@ public static IList<MobileProvision> GetMobileProvisions (MobileProvisionPlatfor
648696
// Note: this is a wildcard provisioning profile, which means we need to use a substring match
649697
id = id.TrimEnd ('*');
650698

651-
if (!bundleIdentifier.StartsWith (id, StringComparison.Ordinal))
699+
if (!bundleIdentifier.StartsWith (id, StringComparison.Ordinal)) {
700+
failures?.Add ($"The profile '{profile.Name}' is not applicable because its id ({profile.ApplicationIdentifier}) does not match the bundle identifer {bundleIdentifier}.");
652701
continue;
702+
}
653703
} else if (id != bundleIdentifier) {
654704
// the CFBundleIdentifier provided by our caller does not match this provisioning profile
705+
failures?.Add ($"The profile '{profile.Name}' is not applicable because its id ({profile.ApplicationIdentifier}) does not match the bundle identifer {bundleIdentifier}.");
655706
continue;
656707
}
657708

658709
foreach (var cert in profile.DeveloperCertificates) {
659-
if (!thumbprints.Contains (cert.Thumbprint))
710+
if (!thumbprints.Contains (cert.Thumbprint)) {
711+
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)}).");
660712
continue;
713+
}
661714

662715
if (unique) {
663716
int idx;

0 commit comments

Comments
 (0)