Ejemplo n.º 1
0
        public JarIndividualEntry(string entryText)
        {
            Attributes = JarAttributes.From(entryText);

            // Set up some properties to simplify tasks
            string name = null;

            if (Attributes.TryGetValue("Name", out name))
            {
                Name = name;
            }

            RawText = entryText;

            // Only look for xxx-DIGEST for now.
            // There are also xxx-DIGEST-yyy attributes for language specific files we need to deal with later
            string digestAttributeKey = Attributes.Keys.FirstOrDefault(key => key.EndsWith("-Digest", StringComparison.OrdinalIgnoreCase));

            if (!String.IsNullOrEmpty(digestAttributeKey))
            {
                string manifestDigest = Attributes[digestAttributeKey];
                HashAlgorithmName = JarUtils.GetHashAlgorithmFromDigest(digestAttributeKey, "-Digest");
                DigestValue       = Attributes[digestAttributeKey];
            }
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Verify the x-Digest-Manifest-Main-Attributes attribute if it exists, otherwise, verify the individual file attributes
 /// in the signature file and compare their digests to the digests calculated over the individual sections in the manifest
 /// file.
 /// </summary>
 /// <returns>True if the verification succeeded, false otherwise.</returns>
 public bool VerifyDigestManifestMain(JarManifestFile manifestFile)
 {
     if (HasDigestManifestMainAttributes)
     {
         string digestAttributeKey = MainAttributes.Keys.FirstOrDefault(key => key.EndsWith("-Digest-Manifest-Main-Attributes", StringComparison.OrdinalIgnoreCase));
         JarUtils.GetHashAlgorithmFromDigest(digestAttributeKey, "-Digest-Manifest-Main-Attributes");
         return(String.Equals(MainAttributes[digestAttributeKey],
                              manifestFile.GetMainAttributesDigest(JarUtils.GetHashAlgorithmFromDigest(digestAttributeKey, "-Digest-Manifest-Main-Attributes"))));
     }
     else
     {
         return(VerifySignatureSourceFileDigests(manifestFile));
     }
 }
Ejemplo n.º 3
0
        /// <summary>
        /// Verify all the x-Digest-Manifest attributes.
        /// </summary>
        /// <param name="manifest">The JAR manifest (META-INF/MANIFEST.MF)</param>
        /// <returns>True if all the digests were verified, false if any verification failed or there are no x-Digest-Manifest attributes in the signature file.</returns>
        public bool VerifyDigestManifest(JarManifestFile manifest)
        {
            if (ManifestHashDigestAttributes.Count() > 0)
            {
                return(ManifestHashDigestAttributes.All(
                           a => String.Equals(MainAttributes[a], manifest.GetManifestDigest(JarUtils.GetHashAlgorithmFromDigest(a, "-Digest-Manifest")))
                           ));
            }

            return(false);
        }