示例#1
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));
        }