Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

how to verify a digitally signed file?

Posted on 2011-02-20
4
Medium Priority
?
825 Views
Last Modified: 2012-08-14
I am using the following code to check for a signature and it works great.  except, if the file is modified it still returns that it is signed.  I want to further check that the signature is still valid but I can't seem to find the right function to do it.  Please help if you can!

uses jwawincrypt;

function issigned(const f: string): boolean;
var
  SignerInfo: PCmsgSignerInfo;
  CertInfo: TCertInfo;
  Msg:HCRYPTMSG;
  StoreHandle:HCERTSTORE;
  CertContext: PCertContext;
  Filepath: WideString;
  CertName: array[0..255] of WideChar;
  CT:Dword;
  DataSize: Cardinal;
begin
  filepath:=f;
  signerinfo:=nil;

  CT:=0;
  DataSize:=0;
  result:=false;
  try
  if (f <> '') and CryptQueryObject(CERT_QUERY_OBJECT_FILE, @FilePath[1], CERT_QUERY_CONTENT_FLAG_PKCS7_SIGNED_EMBED, CERT_QUERY_FORMAT_FLAG_BINARY, 0, nil, @CT, nil, @StoreHandle, @Msg, nil)
    and (CT = CERT_QUERY_CONTENT_PKCS7_SIGNED_EMBED) and CryptMsgGetParam(Msg,CMSG_SIGNER_INFO_PARAM,0,nil,DataSize) then
    begin
      try
        Getmem(SignerInfo,DataSize);
        CryptMsgGetParam(Msg, CMSG_SIGNER_INFO_PARAM, 0, SignerInfo, DataSize);
        fillchar(certinfo, sizeof(certinfo), #0);
        certinfo.Issuer:=signerinfo^.Issuer;
        CertInfo.SerialNumber := SignerInfo^.SerialNumber;
        CertContext:=CertFindCertificateInStore(StoreHandle, X509_ASN_ENCODING or PKCS_7_ASN_ENCODING,0,CERT_FIND_SUBJECT_CERT, @CertInfo, nil);
        result:=(CertGetNameStringW(CertContext, CERT_NAME_FRIENDLY_DISPLAY_TYPE, 0, nil, CertName, 256) > 0);
      finally
         if assigned(signerinfo) then
           FreeMem(SignerInfo);
         CertCloseStore(StoreHandle, 0);
         CryptMsgClose(Msg);
      end;
    end;
  except
  end;
end;

Open in new window

0
Comment
Question by:DSOM
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 27

Expert Comment

by:BigRat
ID: 34941760
CertVerifyTimeValidity Function perhaps?

http://msdn.microsoft.com/en-us/library/aa376091(v=vs.85).aspx

0
 

Accepted Solution

by:
DSOM earned 0 total points
ID: 34943399
I found what I was looking for here after spending a lot of timing finding out what I was looking for ;)

http://www.experts-exchange.com/Programming/Languages/Pascal/Delphi/Q_20318315.html

0
 

Author Closing Comment

by:DSOM
ID: 34986419
Found answer from another question here.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Suggested Courses

670 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question