Tips on how to select a certificate store to properly verify S/MIME signatures in web applications

Read the below if you get Untrusted status when checking signatures

A message signature includes the certificate which was used to sign the message. This certificate must be trusted by your system in order to pass the message signature verification. To validate a certificate (determine if it's trusted), this certificate must be issued by an organization which has its own valid certificate available in the list of certification authorities. In Internet Explorer, you can find the list of certification authorities in "Intermediate Certification Authorities" or "Trusted Root Certification Authorities" tabs of Certificates dialog. This dialog lists the certificates available to the currently logged user (i.e. your Windows user).

Web applications, however, are executed under context of another user (such as ASPNET system user). System users often have smaller number of certificates available to them. Thus, even if your web application is running on the same machine where you're accessing it via browser (the client and the server are the same computer) the certificate which passes validation against the certificate store available to your currently logged user may not pass the same validation under ASPNET user context. This may result in getting different results of running WebForms (ASP.NET) and WinForms versions of this sample project.

To workaround this, you can add the required certification authorities into the certificate store of ASPNET user as follows:

  1. export the certificates of your Windows user into a file (using Export feature of Internet Explorer's Certificates dialog or using your WinForms application utilizing MailBee.NET)
  2. then import these certificates from the file into the certificate store of ASPNET user (using your web application utilizing MailBee.NET).

Alternatively, you can just export the required certification authorities' certificates into a file (using IE's Export feature) and then refer to this file when checking the certificate of the signature for validity. This approach is used in the current sample project. You can specify the path to the certification authorities' store file (in .P7b format) in "CA Certificate Store" textbox.

An example of the certificate which is present in the certification authorities store of your user but may be missing in ASPNET user's store is "Thawte Personal Freemail Issuing CA". Thus, to let your web application check signatures built with certificates issued by "Thawte Personal Freemail Issuing CA", you'll need to export this certificate from "Intermediate Certification Authorities" tab of IE's Certificates dialog into a file, and then specify the path to this file in "CA Certificate Store" textbox.

The certificate store file (if specified in "CA Certificate Store") does not replace the default system store of ASPNET user. MailBee.NET will search both stores for certificates. Thus, it's permitted but not required to have all the certificates of your Windows user be exported into a file. At your discretion, you may export only those certificates which are missing in ASPNET user store.

If you run this sample under ASP.NET Development server (not IIS), it may run under your Windows user, not ASPNET system user. Moreover, it will be executed on your local computer (where you may have all the required certificates in the system store). Under IIS, which is commonly used at production stage, results will be different (and your application won't find the required certificates in the system store).