Exemplo n.º 1
0
        ///////////////////////////////////////////////////////////////////////

        private static Release ParseLine(
            Configuration configuration,
            int releaseId,
            int lineIndex,
            string line,
            ref string error
            )
        {
            if (configuration == null)
            {
                error = "Invalid configuration.";
                return(null);
            }

            if (line == null)
            {
                error = "Invalid release data line.";
                return(null);
            }

            line = line.Trim(Characters.Space);

            if (line.Length == 0)
            {
                error = "Empty release data line.";
                return(null);
            }

            string[] fields = line.Split(Field.Separator);

            if (fields.Length < Field.Count)
            {
                error = String.Format(
                    "Potential protocol mismatch, release data " +
                    "line #{0} has {1} fields, expected {2} fields.",
                    lineIndex, fields.Length, Field.Count);

                return(null);
            }

            //
            // NOTE: Using a null UriFormat value here causes it to use
            //       the one associated with the configuration instead.
            //
            string protocolId = fields[Field.ProtocolId]; /* string */

            string uriFormat = IsSelfProtocol(protocolId) ?
                               Defaults.SelfUriFormat : null;

            Release release = new Release(
                configuration, releaseId, protocolId,
                ParseOps.HexString(fields[Field.PublicKeyToken]),
                fields[Field.Name] /* string */,
                ParseOps.Culture(fields[Field.Culture]),
                ParseOps.Version(fields[Field.PatchLevel]),
                ParseOps.DateTime(fields[Field.TimeStamp]),
                ParseOps.Uri(fields[Field.BaseUri]), uriFormat,
                ParseOps.HexString(fields[Field.Md5Hash]),
                ParseOps.HexString(fields[Field.Sha1Hash]),
                ParseOps.HexString(fields[Field.Sha512Hash]),
                ParseOps.Notes(fields[Field.Notes]));

            Trace(configuration, String.Format(
                      "Release #{0} originated on line #{1}.", releaseId, lineIndex),
                  TraceCategory);

            release.Dump();

            return(release);
        }
Exemplo n.º 2
0
        ///////////////////////////////////////////////////////////////////////

        public static bool IsStrongNameSigned(
            Assembly assembly,
            ref byte[] publicKeyToken,
            ref string error
            )
        {
            if (assembly == null)
            {
                error = "assembly is invalid";
                return(false);
            }

            AssemblyName assemblyName = assembly.GetName();

            if (assemblyName == null)
            {
                error = "assembly has invalid name";
                return(false);
            }

            byte[] publicKey = assemblyName.GetPublicKey();

            if (publicKey == null)
            {
                error = "assembly has invalid public key";
                return(false);
            }

            Evidence evidence = assembly.Evidence;

            if (evidence == null)
            {
                error = "assembly has invalid evidence";
                return(false);
            }

            IEnumerator enumerator = evidence.GetHostEnumerator();

            if (enumerator == null)
            {
                error = "assembly has invalid evidence enumerator";
                return(false);
            }

            while (enumerator.MoveNext())
            {
                StrongName strongName = enumerator.Current as StrongName;

                if (strongName == null)
                {
                    continue;
                }

                StrongNamePublicKeyBlob strongNamePublicKey =
                    strongName.PublicKey;

                if (strongNamePublicKey == null)
                {
                    error = "assembly strong name has invalid public key";
                    return(false);
                }

                if (GenericOps <byte> .Equals(ParseOps.HexString(
                                                  strongNamePublicKey.ToString()), publicKey))
                {
                    publicKeyToken = assemblyName.GetPublicKeyToken();

                    if (publicKeyToken == null)
                    {
                        error = "assembly has invalid public key token";
                        return(false);
                    }

                    return(true);
                }
            }

            error = "assembly is not signed";
            return(false);
        }