예제 #1
0
        public override SignatureVerificationResult VerifySignature(string path, string parent)
        {
            // LZMA is just an unsigned stream
            var    svr      = SignatureVerificationResult.UnsupportedFileTypeResult(path, parent);
            string fullPath = svr.FullPath;

            svr.AddDetail(DetailKeys.File, SignCheckResources.DetailSigned, SignCheckResources.NA);

            if (VerifyRecursive)
            {
                string tempPath = svr.TempPath;
                CreateDirectory(tempPath);
                Log.WriteMessage(LogVerbosity.Diagnostic, SignCheckResources.DiagExtractingFileContents, tempPath);

                // Drop the LZMA extensions when decompressing so we don't process the uncompressed file as an LZMA file again
                string destinationFile = Path.Combine(tempPath, Path.GetFileNameWithoutExtension(path));

                // LZMA files are just compressed streams. Decompress and then try to verify the decompressed file.
                LZMAUtils.Decompress(fullPath, destinationFile);

                svr.NestedResults.Add(VerifyFile(destinationFile, parent, containerPath: null));
            }

            return(svr);
        }
예제 #2
0
        public override SignatureVerificationResult VerifySignature(string path, string parent)
        {
            var    svr      = SignatureVerificationResult.UnsupportedFileTypeResult(path, parent);
            string fullPath = svr.FullPath;

            svr.AddDetail(DetailKeys.File, SignCheckResources.DetailSigned, SignCheckResources.NA);

            VerifyContent(svr);
            return(svr);
        }
예제 #3
0
        public override SignatureVerificationResult VerifySignature(string path, string parent)
        {
            if (VerifyXmlSignatures)
            {
                X509Certificate2 xmlCertificate;
                var svr = new SignatureVerificationResult(path, parent);
                svr.IsSigned = IsSigned(svr.FullPath, out xmlCertificate);
                svr.AddDetail(DetailKeys.File, SignCheckResources.DetailSigned, svr.IsSigned);
                return(svr);
            }

            return(SignatureVerificationResult.UnsupportedFileTypeResult(path, parent));
        }
예제 #4
0
        public override SignatureVerificationResult VerifySignature(string path, string parent)
        {
            if (VerifyJarSignatures)
            {
                var svr = new SignatureVerificationResult(path, parent);

                try
                {
                    JarError.ClearErrors();
                    var jarFile = new JarFile(path);
                    svr.IsSigned = jarFile.IsSigned();

                    if (!svr.IsSigned && JarError.HasErrors())
                    {
                        svr.AddDetail(DetailKeys.Error, JarError.GetLastError());
                    }
                    else
                    {
                        foreach (Timestamp timestamp in jarFile.Timestamps)
                        {
                            svr.AddDetail(DetailKeys.Misc, SignCheckResources.DetailTimestamp, timestamp.SignedOn, timestamp.SignatureAlgorithm);
                        }

                        IEnumerable <Timestamp> invalidTimestamps = from ts in jarFile.Timestamps
                                                                    where !ts.IsValid
                                                                    select ts;

                        foreach (Timestamp ts in invalidTimestamps)
                        {
                            svr.AddDetail(DetailKeys.Error, SignCheckResources.DetailTimestampOutisdeCertValidity, ts.SignedOn, ts.EffectiveDate, ts.ExpiryDate);
                            svr.IsSigned = false;
                        }
                    }

                    svr.AddDetail(DetailKeys.File, SignCheckResources.DetailSigned, svr.IsSigned);
                }
                catch (Exception e)
                {
                    svr.AddDetail(DetailKeys.Error, e.Message);
                }

                return(svr);
            }

            return(SignatureVerificationResult.UnsupportedFileTypeResult(path, parent));
        }
예제 #5
0
        public override SignatureVerificationResult VerifySignature(string path, string parent)
        {
            var    svr      = SignatureVerificationResult.UnsupportedFileTypeResult(path, parent);
            string fullPath = svr.FullPath;

            svr.AddDetail(DetailKeys.File, SignCheckResources.DetailSigned, SignCheckResources.NA);

            if (VerifyRecursive)
            {
                using (ZipArchive zipArchive = ZipFile.OpenRead(fullPath))
                {
                    string tempPath = svr.TempPath;
                    CreateDirectory(tempPath);
                    Log.WriteMessage(LogVerbosity.Diagnostic, SignCheckResources.DiagExtractingFileContents, tempPath);

                    foreach (ZipArchiveEntry archiveEntry in zipArchive.Entries)
                    {
                        // Generate an alias for the actual file that has the same extension. We do this to avoid path too long errors so that
                        // containers can be flattened
                        string aliasFileName = Utils.GetHash(archiveEntry.FullName, HashAlgorithmName.MD5.Name) + Path.GetExtension(archiveEntry.FullName);
                        string aliasFullName = Path.Combine(tempPath, aliasFileName);

                        if (File.Exists(aliasFullName))
                        {
                            Log.WriteMessage(LogVerbosity.Normal, SignCheckResources.FileAlreadyExists, aliasFullName);
                        }
                        else
                        {
                            archiveEntry.ExtractToFile(aliasFullName);
                            SignatureVerificationResult archiveEntryResult = VerifyFile(aliasFullName, svr.Filename, archiveEntry.FullName);

                            // Tag the full path into the result detail
                            archiveEntryResult.AddDetail(DetailKeys.File, SignCheckResources.DetailFullName, archiveEntry.FullName);
                            svr.NestedResults.Add(archiveEntryResult);
                        }
                    }

                    DeleteDirectory(tempPath);
                }
            }

            return(svr);
        }
예제 #6
0
 /// <summary>
 /// Verifies the signature of a file.
 /// </summary>
 /// <param name="path">The path of the file to verify</param>
 /// <param name="parent">The parent file of the file to verify or null if this is a top-level file.</param>
 /// <returns>A SignatureVerificationResult containing detail about the verification result.</returns>
 public virtual SignatureVerificationResult VerifySignature(string path, string parent, string virtualPath)
 {
     return(SignatureVerificationResult.UnsupportedFileTypeResult(path, parent, virtualPath));
 }