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);

            if (File.Exists(path))
            {
                return(MobileProvision.LoadFromFile(path));
            }

            var index = OpenIndex(MobileProvision.ProfileDirectory, IndexFileName);
            var latestCreationDate = DateTime.MinValue;

            foreach (var profile in index.ProvisioningProfiles)
            {
                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))
                {
                    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)));
                }

                failures?.Add($"The profile '{profile.Name}' is not applicable because its Name and Uuid ({profile.Uuid}) do not match '{name}'.");
            }

            return(null);
        }
Ejemplo n.º 2
0
        public static IList <MobileProvision> GetMobileProvisions(MobileProvisionPlatform platform, string bundleIdentifier, MobileProvisionDistributionType type, IList <X509Certificate2> developerCertificates, bool includeExpired = false, bool unique = false)
        {
            var extension   = MobileProvision.GetFileExtension(platform);
            var dictionary  = new Dictionary <string, int> ();
            var thumbprints = new HashSet <string> ();
            var list        = new List <MobileProvision> ();
            MobileProvisionDistributionType dist;
            var     plist = OpenIndex();
            var     now   = DateTime.UtcNow;
            PString identifier;
            PString fileName;
            PArray  platforms;
            PArray  profiles;
            PArray  array;

            if (bundleIdentifier == null)
            {
                throw new ArgumentNullException(nameof(bundleIdentifier));
            }

            if (developerCertificates == null)
            {
                throw new ArgumentNullException(nameof(developerCertificates));
            }

            foreach (var certificate in developerCertificates)
            {
                thumbprints.Add(certificate.Thumbprint);
            }

            if (thumbprints.Count == 0)
            {
                return(list);
            }

            if (!plist.TryGetValue("ProvisioningProfiles", out profiles))
            {
                return(list);
            }

            // iterate over the profiles in reverse order so that we load newer profiles first (optimization for the 'unique' case)
            for (int i = profiles.Count - 1; i >= 0; i--)
            {
                var profile = profiles[i] as PDictionary;

                if (profile == null || !profile.TryGetValue("FileName", out fileName) || !fileName.Value.EndsWith(extension, StringComparison.Ordinal))
                {
                    continue;
                }

                if (!profile.TryGetValue("Platforms", out platforms) || !Contains(platforms, platform))
                {
                    continue;
                }

                if (!includeExpired)
                {
                    PDate expirationDate;

                    if (!profile.TryGetValue("ExpirationDate", out expirationDate))
                    {
                        continue;
                    }

                    if (expirationDate.Value < now)
                    {
                        continue;
                    }
                }

                if (type != MobileProvisionDistributionType.Any)
                {
                    PString value;

                    if (!profile.TryGetValue("Distribution", out value) || !Enum.TryParse(value.Value, out dist))
                    {
                        continue;
                    }

                    if ((type & dist) == 0)
                    {
                        continue;
                    }
                }

                if (!profile.TryGetValue("ApplicationIdentifier", out identifier))
                {
                    continue;
                }

                string id = identifier.Value;
                int    dot;

                // Note: the ApplicationIdentifier will be in the form "7V723M9SQ5.com.xamarin.app-name", so we'll need to trim the leading TeamIdentifierPrefix
                if ((dot = id.IndexOf('.')) != -1)
                {
                    id = id.Substring(dot + 1);
                }

                if (id.Length > 0 && id[id.Length - 1] == '*')
                {
                    // 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))
                    {
                        continue;
                    }
                }
                else if (id != bundleIdentifier)
                {
                    // the CFBundleIdentifier provided by our caller does not match this provisioning profile
                    continue;
                }

                if (!profile.TryGetValue("DeveloperCertificates", out array))
                {
                    continue;
                }

                foreach (var cert in array.OfType <PDictionary> ())
                {
                    PString thumbprint;

                    if (!cert.TryGetValue("Thumbprint", out thumbprint))
                    {
                        continue;
                    }

                    if (!thumbprints.Contains(thumbprint.Value))
                    {
                        continue;
                    }

                    if (unique)
                    {
                        PDate   creationDate;
                        PString name;
                        int     index;

                        if (!profile.TryGetValue("Name", out name))
                        {
                            break;
                        }

                        if (dictionary.TryGetValue(name.Value, out index))
                        {
                            if (!profile.TryGetValue("CreationDate", out creationDate))
                            {
                                break;
                            }

                            if (creationDate.Value > list[index].CreationDate)
                            {
                                list[index] = MobileProvision.LoadFromFile(Path.Combine(MobileProvision.ProfileDirectory, fileName.Value));
                            }
                        }
                        else
                        {
                            var provision = MobileProvision.LoadFromFile(Path.Combine(MobileProvision.ProfileDirectory, fileName.Value));
                            dictionary.Add(name.Value, list.Count);
                            list.Add(provision);
                        }
                    }
                    else
                    {
                        var provision = MobileProvision.LoadFromFile(Path.Combine(MobileProvision.ProfileDirectory, fileName.Value));
                        list.Add(provision);
                    }
                    break;
                }
            }

            return(list);
        }
Ejemplo n.º 3
0
        public static IList <MobileProvision> GetMobileProvisions(MobileProvisionPlatform platform, MobileProvisionDistributionType type, IList <X509Certificate2> developerCertificates, bool includeExpired = false, bool unique = false)
        {
            var extension   = MobileProvision.GetFileExtension(platform);
            var dictionary  = new Dictionary <string, int> ();
            var thumbprints = new HashSet <string> ();
            var list        = new List <MobileProvision> ();
            MobileProvisionDistributionType dist;
            var     plist = OpenIndex();
            var     now   = DateTime.UtcNow;
            PString fileName;
            PArray  platforms;
            PArray  profiles;
            PArray  array;

            if (developerCertificates == null)
            {
                throw new ArgumentNullException(nameof(developerCertificates));
            }

            foreach (var certificate in developerCertificates)
            {
                thumbprints.Add(certificate.Thumbprint);
            }

            if (thumbprints.Count == 0)
            {
                return(list);
            }

            if (!plist.TryGetValue("ProvisioningProfiles", out profiles))
            {
                return(list);
            }

            // iterate over the profiles in reverse order so that we load newer profiles first (optimization for the 'unique' case)
            for (int i = profiles.Count - 1; i >= 0; i--)
            {
                var profile = profiles[i] as PDictionary;

                if (profile == null || !profile.TryGetValue("FileName", out fileName) || !fileName.Value.EndsWith(extension, StringComparison.Ordinal))
                {
                    continue;
                }

                if (!profile.TryGetValue("Platforms", out platforms) || !Contains(platforms, platform))
                {
                    continue;
                }

                if (!includeExpired)
                {
                    PDate expirationDate;

                    if (!profile.TryGetValue("ExpirationDate", out expirationDate))
                    {
                        continue;
                    }

                    if (expirationDate.Value < now)
                    {
                        continue;
                    }
                }

                if (type != MobileProvisionDistributionType.Any)
                {
                    PString value;

                    if (!profile.TryGetValue("Distribution", out value) || !Enum.TryParse(value.Value, out dist))
                    {
                        continue;
                    }

                    if ((type & dist) == 0)
                    {
                        continue;
                    }
                }

                if (!profile.TryGetValue("DeveloperCertificates", out array))
                {
                    continue;
                }

                foreach (var cert in array.OfType <PDictionary> ())
                {
                    PString thumbprint;

                    if (!cert.TryGetValue("Thumbprint", out thumbprint))
                    {
                        continue;
                    }

                    if (!thumbprints.Contains(thumbprint.Value))
                    {
                        continue;
                    }

                    if (unique)
                    {
                        PDate   creationDate;
                        PString name;
                        int     index;

                        if (!profile.TryGetValue("Name", out name))
                        {
                            break;
                        }

                        if (dictionary.TryGetValue(name.Value, out index))
                        {
                            if (!profile.TryGetValue("CreationDate", out creationDate))
                            {
                                break;
                            }

                            if (creationDate.Value > list[index].CreationDate)
                            {
                                list[index] = MobileProvision.LoadFromFile(Path.Combine(MobileProvision.ProfileDirectory, fileName.Value));
                            }
                        }
                        else
                        {
                            var provision = MobileProvision.LoadFromFile(Path.Combine(MobileProvision.ProfileDirectory, fileName.Value));
                            dictionary.Add(name.Value, list.Count);
                            list.Add(provision);
                        }
                    }
                    else
                    {
                        var provision = MobileProvision.LoadFromFile(Path.Combine(MobileProvision.ProfileDirectory, fileName.Value));
                        list.Add(provision);
                    }
                    break;
                }
            }

            return(list);
        }
Ejemplo n.º 4
0
        public static IList <MobileProvision> GetMobileProvisions(MobileProvisionPlatform platform, bool includeExpired = false, bool unique = false)
        {
            var     extension  = MobileProvision.GetFileExtension(platform);
            var     dictionary = new Dictionary <string, int> ();
            var     list       = new List <MobileProvision> ();
            var     plist      = OpenIndex();
            var     now        = DateTime.UtcNow;
            PString fileName;
            PArray  platforms;
            PArray  profiles;

            if (!plist.TryGetValue("ProvisioningProfiles", out profiles))
            {
                return(list);
            }

            // iterate over the profiles in reverse order so that we load newer profiles first (optimization for the 'unique' case)
            for (int i = profiles.Count - 1; i >= 0; i--)
            {
                var profile = profiles[i] as PDictionary;

                if (profile == null || !profile.TryGetValue("FileName", out fileName) || !fileName.Value.EndsWith(extension, StringComparison.Ordinal))
                {
                    continue;
                }

                if (!profile.TryGetValue("Platforms", out platforms) || !Contains(platforms, platform))
                {
                    continue;
                }

                if (!includeExpired)
                {
                    PDate expirationDate;

                    if (!profile.TryGetValue("ExpirationDate", out expirationDate))
                    {
                        continue;
                    }

                    if (expirationDate.Value < now)
                    {
                        continue;
                    }
                }

                if (unique)
                {
                    PDate   creationDate;
                    PString name;
                    int     index;

                    if (!profile.TryGetValue("Name", out name))
                    {
                        continue;
                    }

                    if (dictionary.TryGetValue(name.Value, out index))
                    {
                        if (!profile.TryGetValue("CreationDate", out creationDate))
                        {
                            continue;
                        }

                        if (creationDate.Value > list[index].CreationDate)
                        {
                            list[index] = MobileProvision.LoadFromFile(Path.Combine(MobileProvision.ProfileDirectory, fileName.Value));
                        }
                    }
                    else
                    {
                        var provision = MobileProvision.LoadFromFile(Path.Combine(MobileProvision.ProfileDirectory, fileName.Value));
                        dictionary.Add(name.Value, list.Count);
                        list.Add(provision);
                    }
                }
                else
                {
                    var provision = MobileProvision.LoadFromFile(Path.Combine(MobileProvision.ProfileDirectory, fileName.Value));
                    list.Add(provision);
                }
            }

            return(list);
        }
Ejemplo n.º 5
0
        public static MobileProvision GetMobileProvision(MobileProvisionPlatform platform, string name)
        {
            var extension = MobileProvision.GetFileExtension(platform);
            var path      = Path.Combine(MobileProvision.ProfileDirectory, name + extension);

            if (File.Exists(path))
            {
                return(MobileProvision.LoadFromFile(path));
            }

            var     plist = OpenIndex();
            var     latestCreationDate = DateTime.MinValue;
            PDate   creationDate;
            PString fileName;
            PArray  platforms;
            PArray  profiles;
            PString value;

            path = null;

            if (plist.TryGetValue("ProvisioningProfiles", out profiles))
            {
                foreach (var profile in profiles.OfType <PDictionary> ())
                {
                    if (!profile.TryGetValue("FileName", out fileName) || !fileName.Value.EndsWith(extension, StringComparison.Ordinal))
                    {
                        continue;
                    }

                    if (!profile.TryGetValue("Platforms", out platforms) || !Contains(platforms, platform))
                    {
                        continue;
                    }

                    if (!profile.TryGetValue("Uuid", out value))
                    {
                        continue;
                    }

                    if (name == value.Value)
                    {
                        return(MobileProvision.LoadFromFile(Path.Combine(MobileProvision.ProfileDirectory, fileName.Value)));
                    }

                    if (!profile.TryGetValue("Name", out value))
                    {
                        continue;
                    }

                    if (name != value.Value)
                    {
                        continue;
                    }

                    if (!profile.TryGetValue("CreationDate", out creationDate))
                    {
                        continue;
                    }

                    if (creationDate.Value > latestCreationDate)
                    {
                        path = Path.Combine(MobileProvision.ProfileDirectory, fileName.Value);
                        latestCreationDate = creationDate.Value;
                    }
                }
            }

            if (path == null)
            {
                return(null);
            }

            return(MobileProvision.LoadFromFile(path));
        }
Ejemplo n.º 6
0
        /// <summary>
        /// All installed provisioning profiles, sorted by newest first.
        /// </summary>
        public static IList <MobileProvision> GetAllInstalledProvisions(MobileProvisionPlatform platform, bool includeExpired)
        {
            if (!Directory.Exists(ProfileDirectory))
            {
                return(new MobileProvision[0]);
            }

            var    uuids = new Dictionary <string, MobileProvision> ();
            var    list  = new List <MobileProvision> ();
            var    now   = DateTime.Now;
            string pattern;

            switch (platform)
            {
            case MobileProvisionPlatform.MacOS:
                pattern = "*.provisionprofile";
                break;

            case MobileProvisionPlatform.tvOS:
            case MobileProvisionPlatform.iOS:
                pattern = "*.mobileprovision";
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(platform));
            }

            foreach (var file in Directory.EnumerateFiles(ProfileDirectory, pattern))
            {
                try {
                    var data = File.ReadAllBytes(file);

                    var m = new MobileProvision();
                    m.Load(PDictionary.FromBinaryXml(data));
                    m.Data = data;

                    if (includeExpired || m.ExpirationDate > now)
                    {
                        if (uuids.ContainsKey(m.Uuid))
                        {
                            // we always want the most recently created/updated provision
                            if (m.CreationDate > uuids[m.Uuid].CreationDate)
                            {
                                int index = list.IndexOf(uuids[m.Uuid]);
                                uuids[m.Uuid] = m;
                                list[index]   = m;
                            }
                        }
                        else
                        {
                            uuids.Add(m.Uuid, m);
                            list.Add(m);
                        }
                    }
                } catch (Exception ex) {
                    LoggingService.LogWarning("Error reading " + platform + " provision file '" + file + "'", ex);
                }
            }

            //newest first
            list.Sort((x, y) => y.CreationDate.CompareTo(x.CreationDate));

            return(list);
        }
        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);
            var dictionary  = new Dictionary <string, int> ();
            var thumbprints = new HashSet <string> ();
            var list        = new List <MobileProvision> ();
            var now         = DateTime.UtcNow;

            if (bundleIdentifier == null)
            {
                throw new ArgumentNullException(nameof(bundleIdentifier));
            }

            if (developerCertificates == null)
            {
                throw new ArgumentNullException(nameof(developerCertificates));
            }

            foreach (var certificate in developerCertificates)
            {
                thumbprints.Add(certificate.Thumbprint);
            }

            if (thumbprints.Count == 0)
            {
                return(list);
            }

            // iterate over the profiles in reverse order so that we load newer profiles first (optimization for the 'unique' case)
            for (int i = index.ProvisioningProfiles.Count - 1; i >= 0; i--)
            {
                var profile = index.ProvisioningProfiles[i];

                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))
                {
                    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)
                {
                    failures?.Add($"The profile '{profile.Name}' is not applicable because it has expired ({profile.ExpirationDate}).");
                    continue;
                }

                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;

                // Note: the ApplicationIdentifier will be in the form "7V723M9SQ5.com.xamarin.app-name", so we'll need to trim the leading TeamIdentifierPrefix
                if ((dot = id.IndexOf('.')) != -1)
                {
                    id = id.Substring(dot + 1);
                }

                if (id.Length > 0 && id[id.Length - 1] == '*')
                {
                    // 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))
                    {
                        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))
                    {
                        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;

                        if (dictionary.TryGetValue(profile.Name, out idx))
                        {
                            if (profile.CreationDate > list[idx].CreationDate)
                            {
                                list[idx] = MobileProvision.LoadFromFile(Path.Combine(MobileProvision.ProfileDirectory, profile.FileName));
                            }
                        }
                        else
                        {
                            var provision = MobileProvision.LoadFromFile(Path.Combine(MobileProvision.ProfileDirectory, profile.FileName));
                            dictionary.Add(profile.Name, list.Count);
                            list.Add(provision);
                        }
                    }
                    else
                    {
                        var provision = MobileProvision.LoadFromFile(Path.Combine(MobileProvision.ProfileDirectory, profile.FileName));
                        list.Add(provision);
                    }
                    break;
                }
            }

            return(list);
        }
        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);
            var dictionary  = new Dictionary <string, int> ();
            var thumbprints = new HashSet <string> ();
            var list        = new List <MobileProvision> ();
            var now         = DateTime.UtcNow;

            if (developerCertificates == null)
            {
                throw new ArgumentNullException(nameof(developerCertificates));
            }

            foreach (var certificate in developerCertificates)
            {
                thumbprints.Add(certificate.Thumbprint);
            }

            if (thumbprints.Count == 0)
            {
                return(list);
            }

            // iterate over the profiles in reverse order so that we load newer profiles first (optimization for the 'unique' case)
            for (int i = index.ProvisioningProfiles.Count - 1; i >= 0; i--)
            {
                var profile = index.ProvisioningProfiles[i];

                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))
                {
                    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)
                {
                    failures?.Add($"The profile '{profile.Name}' is not applicable because it has expired ({profile.ExpirationDate}).");
                    continue;
                }

                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))
                    {
                        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;

                        if (dictionary.TryGetValue(profile.Name, out idx))
                        {
                            if (profile.CreationDate > list[idx].CreationDate)
                            {
                                list[idx] = MobileProvision.LoadFromFile(Path.Combine(MobileProvision.ProfileDirectory, profile.FileName));
                            }
                        }
                        else
                        {
                            var provision = MobileProvision.LoadFromFile(Path.Combine(MobileProvision.ProfileDirectory, profile.FileName));
                            dictionary.Add(profile.Name, list.Count);
                            list.Add(provision);
                        }
                    }
                    else
                    {
                        var provision = MobileProvision.LoadFromFile(Path.Combine(MobileProvision.ProfileDirectory, profile.FileName));
                        list.Add(provision);
                    }
                    break;
                }
            }

            return(list);
        }
            internal static ProvisioningProfile Load(string fileName)
            {
                var provision = MobileProvision.LoadFromFile(fileName);

                return(new ProvisioningProfile(fileName, provision));
            }
Ejemplo n.º 10
0
        public static IList <MobileProvision> GetMobileProvisions(MobileProvisionPlatform platform, string bundleIdentifier, MobileProvisionDistributionType type, bool includeExpired = false)
        {
            var extension   = MobileProvision.GetFileExtension(platform);
            var thumbprints = new HashSet <string> ();
            var list        = new List <MobileProvision> ();
            MobileProvisionDistributionType dist;
            var     plist = OpenIndex();
            var     now   = DateTime.Now;
            PString identifier;
            PString fileName;
            PArray  platforms;
            PArray  profiles;

            if (bundleIdentifier == null)
            {
                throw new ArgumentNullException(nameof(bundleIdentifier));
            }

            if (thumbprints.Count == 0)
            {
                return(list);
            }

            if (!plist.TryGetValue("ProvisioningProfiles", out profiles))
            {
                return(list);
            }

            foreach (var profile in profiles.OfType <PDictionary> ())
            {
                if (!profile.TryGetValue("FileName", out fileName) || !fileName.Value.EndsWith(extension, StringComparison.Ordinal))
                {
                    continue;
                }

                if (!profile.TryGetValue("Platforms", out platforms) || !Contains(platforms, platform))
                {
                    continue;
                }

                if (!includeExpired)
                {
                    PDate expirationDate;

                    if (!profile.TryGetValue("ExpirationDate", out expirationDate))
                    {
                        continue;
                    }

                    if (expirationDate.Value < now)
                    {
                        continue;
                    }
                }

                if (type != MobileProvisionDistributionType.Any)
                {
                    PString value;

                    if (!profile.TryGetValue("Distribution", out value) || !Enum.TryParse(value.Value, out dist))
                    {
                        continue;
                    }

                    if ((type & dist) == 0)
                    {
                        continue;
                    }
                }

                if (!profile.TryGetValue("ApplicationIdentifier", out identifier))
                {
                    continue;
                }

                string id = identifier.Value;
                int    dot;

                // Note: the ApplicationIdentifier will be in the form "7V723M9SQ5.com.xamarin.app-name", so we'll need to trim the leading TeamIdentifierPrefix
                if ((dot = id.IndexOf('.')) != -1)
                {
                    id = id.Substring(dot + 1);
                }

                if (id.Length > 0 && id[id.Length - 1] == '*')
                {
                    // 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))
                    {
                        continue;
                    }
                }
                else if (id != bundleIdentifier)
                {
                    // the CFBundleIdentifier provided by our caller does not match this provisioning profile
                    continue;
                }

                var provision = MobileProvision.LoadFromFile(Path.Combine(MobileProvision.ProfileDirectory, fileName.Value));
                list.Add(provision);
            }

            return(list);
        }
Ejemplo n.º 11
0
        public static IList <MobileProvision> GetMobileProvisions(MobileProvisionPlatform platform, MobileProvisionDistributionType type, IList <X509Certificate2> developerCertificates, bool includeExpired = false)
        {
            var extension   = MobileProvision.GetFileExtension(platform);
            var thumbprints = new HashSet <string> ();
            var list        = new List <MobileProvision> ();
            MobileProvisionDistributionType dist;
            var     plist = OpenIndex();
            var     now   = DateTime.Now;
            PString fileName;
            PArray  platforms;
            PArray  profiles;
            PArray  array;

            if (developerCertificates == null)
            {
                throw new ArgumentNullException(nameof(developerCertificates));
            }

            foreach (var certificate in developerCertificates)
            {
                thumbprints.Add(certificate.Thumbprint);
            }

            if (thumbprints.Count == 0)
            {
                return(list);
            }

            if (!plist.TryGetValue("ProvisioningProfiles", out profiles))
            {
                return(list);
            }

            foreach (var profile in profiles.OfType <PDictionary> ())
            {
                if (!profile.TryGetValue("FileName", out fileName) || !fileName.Value.EndsWith(extension, StringComparison.Ordinal))
                {
                    continue;
                }

                if (!profile.TryGetValue("Platforms", out platforms) || !Contains(platforms, platform))
                {
                    continue;
                }

                if (!includeExpired)
                {
                    PDate expirationDate;

                    if (!profile.TryGetValue("ExpirationDate", out expirationDate))
                    {
                        continue;
                    }

                    if (expirationDate.Value < now)
                    {
                        continue;
                    }
                }

                if (type != MobileProvisionDistributionType.Any)
                {
                    PString value;

                    if (!profile.TryGetValue("Distribution", out value) || !Enum.TryParse(value.Value, out dist))
                    {
                        continue;
                    }

                    if ((type & dist) == 0)
                    {
                        continue;
                    }
                }

                if (!profile.TryGetValue("DeveloperCertificates", out array))
                {
                    continue;
                }

                foreach (var cert in array.OfType <PDictionary> ())
                {
                    PString thumbprint;

                    if (!cert.TryGetValue("Thumbprint", out thumbprint))
                    {
                        continue;
                    }

                    if (thumbprints.Contains(thumbprint.Value))
                    {
                        var provision = MobileProvision.LoadFromFile(Path.Combine(MobileProvision.ProfileDirectory, fileName.Value));
                        list.Add(provision);
                        break;
                    }
                }
            }

            return(list);
        }
Ejemplo n.º 12
0
        public static IList <MobileProvision> GetMobileProvisions(MobileProvisionPlatform platform, MobileProvisionDistributionType type, bool includeExpired = false)
        {
            var extension = MobileProvision.GetFileExtension(platform);
            var list      = new List <MobileProvision> ();
            MobileProvisionDistributionType dist;
            var     plist = OpenIndex();
            var     now   = DateTime.Now;
            PString fileName;
            PArray  platforms;
            PArray  profiles;

            if (!plist.TryGetValue("ProvisioningProfiles", out profiles))
            {
                return(list);
            }

            foreach (var profile in profiles.OfType <PDictionary> ())
            {
                if (!profile.TryGetValue("FileName", out fileName) || !fileName.Value.EndsWith(extension, StringComparison.Ordinal))
                {
                    continue;
                }

                if (!profile.TryGetValue("Platforms", out platforms) || !Contains(platforms, platform))
                {
                    continue;
                }

                if (!includeExpired)
                {
                    PDate expirationDate;

                    if (!profile.TryGetValue("ExpirationDate", out expirationDate))
                    {
                        continue;
                    }

                    if (expirationDate.Value < now)
                    {
                        continue;
                    }
                }

                if (type != MobileProvisionDistributionType.Any)
                {
                    PString value;

                    if (!profile.TryGetValue("Distribution", out value) || !Enum.TryParse(value.Value, out dist))
                    {
                        continue;
                    }

                    if ((type & dist) == 0)
                    {
                        continue;
                    }
                }

                var provision = MobileProvision.LoadFromFile(Path.Combine(MobileProvision.ProfileDirectory, fileName.Value));
                list.Add(provision);
            }

            return(list);
        }
Ejemplo n.º 13
0
        public static IList <MobileProvision> GetMobileProvisions(MobileProvisionPlatform platform, bool includeExpired = false, bool unique = false)
        {
            var     extension  = MobileProvision.GetFileExtension(platform);
            var     dictionary = new Dictionary <string, int> ();
            var     list       = new List <MobileProvision> ();
            var     plist      = OpenIndex();
            var     now        = DateTime.Now;
            PString fileName;
            PArray  platforms;
            PArray  profiles;

            if (!plist.TryGetValue("ProvisioningProfiles", out profiles))
            {
                return(list);
            }

            foreach (var profile in profiles.OfType <PDictionary> ())
            {
                if (!profile.TryGetValue("FileName", out fileName) || !fileName.Value.EndsWith(extension, StringComparison.Ordinal))
                {
                    continue;
                }

                if (!profile.TryGetValue("Platforms", out platforms) || !Contains(platforms, platform))
                {
                    continue;
                }

                if (!includeExpired)
                {
                    PDate expirationDate;

                    if (!profile.TryGetValue("ExpirationDate", out expirationDate))
                    {
                        continue;
                    }

                    if (expirationDate.Value < now)
                    {
                        continue;
                    }
                }

                if (unique)
                {
                    PDate   creationDate;
                    PString name;
                    int     index;

                    if (!profile.TryGetValue("Name", out name))
                    {
                        continue;
                    }

                    if (dictionary.TryGetValue(name.Value, out index))
                    {
                        if (!profile.TryGetValue("CreationDate", out creationDate))
                        {
                            continue;
                        }

                        if (creationDate.Value > list[index].CreationDate)
                        {
                            list[index] = MobileProvision.LoadFromFile(Path.Combine(MobileProvision.ProfileDirectory, fileName.Value));
                        }
                    }
                    else
                    {
                        var provision = MobileProvision.LoadFromFile(Path.Combine(MobileProvision.ProfileDirectory, fileName.Value));
                        dictionary.Add(name.Value, list.Count);
                        list.Add(provision);
                    }
                }
                else
                {
                    var provision = MobileProvision.LoadFromFile(Path.Combine(MobileProvision.ProfileDirectory, fileName.Value));
                    list.Add(provision);
                }
            }

            return(list);
        }