{"id":1297,"date":"2010-10-25T15:45:34","date_gmt":"2010-10-25T13:45:34","guid":{"rendered":"http:\/\/www.limilabs.com\/blog\/?p=1297"},"modified":"2015-09-11T09:55:38","modified_gmt":"2015-09-11T07:55:38","slug":"validate-smime-emails","status":"publish","type":"post","link":"https:\/\/www.limilabs.com\/blog\/validate-smime-emails","title":{"rendered":"Validate S\/MIME emails"},"content":{"rendered":"<p>In this article we\u2019ll show how to verify digitally signed emails (S\/MIME) using Mail.dll <a href=\"\/mail\">email component<\/a>.<\/p>\n<p>S\/MIME (Secure\/Multipurpose Internet Mail Extensions) is a standard for public key encryption and signing of MIME data.<\/p>\n<p>S\/MIME was originally developed by RSA Data Security. Specification uses Cryptographic Message Syntax, an IETF specification that is identical in most respects with PKCS #7. S\/MIME provides the following cryptographic security services for electronic messaging applications: authentication, message integrity, non-repudiation of origin (using <strong>digital signatures<\/strong>), privacy and data security (using encryption). <\/p>\n<p>S\/MIME signatures are usually done with what&#8217;s called &#8220;detached signatures&#8221;. The signature information is separate from the text being signed. The MIME type for this is multipart\/signed with the second part having a MIME subtype of application\/(x-)pkcs7-signature.  <\/p>\n<p>Sometimes attached signatures (application\/pkcs7-mime; smime-type=&#8221;signed-data&#8221;) format is used. In such case signature and data are represented by single MIME entity. Mail.dll recognizes both detached and attached signatures.<\/p>\n<p>To check if the message has been signed use <em>IsSigned <\/em> property on <em>IMail<\/em> object.<br \/>\n<em>CheckSignature(bool verifySignatureOnly)<\/em> method is used for signature validation.<\/p>\n<h2>Using IMAP protocol<\/h2>\n<pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\r\n\/\/ C# \r\n\r\nusing (Imap imap = new Imap())\r\n{\r\n    imap.Connect(&quot;imap.example.com&quot;); \/\/ or ConnectSSL\r\n    imap.UseBestLogin(&quot;user&quot;, &quot;password&quot;);\r\n\r\n    MailBuilder builder = new MailBuilder();\r\n    foreach (long uid in imap.GetAll())\r\n    {\r\n        IMail email = builder.CreateFromEml(\r\n            imap.GetMessageByUID(uid));\r\n\r\n        \/\/ Check signature\r\n        if (email.IsSigned == true)\r\n            email.CheckSignature(true);\r\n    }\r\n    imap.Close();\r\n}\r\n\r\n<\/pre>\n<pre class=\"brush: vb; title: ; notranslate\" title=\"\">\r\n' VB.NET\r\n\r\nUsing imap As New IMAP()\r\n    imap.Connect(&quot;imap.example.com&quot;) ' or ConnectSSL\r\n    imap.UseBestLogin(&quot;user&quot;, &quot;password&quot;)\r\n\r\n    Dim builder As New MailBuilder()\r\n    For Each uid As Long In imap.GetAll()\r\n        Dim email As IMail = builder.CreateFromEml( _\r\n            imap.GetMessageByUID(uid))\r\n\r\n        ' Check signature\r\n        If email.IsSigned = True Then\r\n            email.CheckSignature(True)\r\n        End If\r\n    Next\r\n    imap.Close()\r\nEnd Using\r\n<\/pre>\n<h2>Using POP3 protocol<\/h2>\n<pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\r\nusing (Pop3 pop3 = new Pop3())\r\n{\r\n    pop3.Connect(&quot;pop3.example.com&quot;); \/\/ or ConnectSSL\r\n    pop3.Login(&quot;user&quot;, &quot;password&quot;);\r\n\r\n    MailBuilder builder = new MailBuilder();\r\n    foreach (string uid in pop3.GetAll())\r\n    {\r\n        IMail email = builder.CreateFromEml(\r\n            pop3.GetMessageByUID(uid));\r\n\r\n        \/\/ Check signature\r\n        if (email.IsSigned == true)\r\n            email.CheckSignature(true);\r\n    }\r\n    pop3.Close();\r\n}\r\n<\/pre>\n<pre class=\"brush: vb; title: ; notranslate\" title=\"\">\r\nUsing pop3 As New Pop3()\r\n    pop3.Connect(&quot;pop3.example.com&quot;) ' or ConnectSSL\r\n    pop3.Login(&quot;user&quot;, &quot;password&quot;)\r\n\r\n    Dim builder As New MailBuilder()\r\n    For Each uid As String In pop3.GetAll()\r\n        Dim email As IMail = builder.CreateFromEml( _\r\n            pop3.GetMessageByUID(uid))\r\n\r\n        ' Check signature\r\n        If email.IsSigned = True Then\r\n            email.CheckSignature(True)\r\n        End If\r\n    Next\r\n    pop3.Close()\r\nEnd Using\r\n<\/pre>\n<p><em>CheckSignature <\/em>method will throw an exception, if it fails to verify the signature.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this article we\u2019ll show how to verify digitally signed emails (S\/MIME) using Mail.dll email component. S\/MIME (Secure\/Multipurpose Internet Mail Extensions) is a standard for public key encryption and signing of MIME data. S\/MIME was originally developed by RSA Data Security. Specification uses Cryptographic Message Syntax, an IETF specification that is identical in most respects [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[15,33,28,77,42,79,49,57],"class_list":["post-1297","post","type-post","status-publish","format-standard","hentry","category-mail-dll","tag-c","tag-email-component","tag-imap","tag-imap-component","tag-pop3","tag-pop3-component","tag-smime","tag-vb-net"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/posts\/1297"}],"collection":[{"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/comments?post=1297"}],"version-history":[{"count":7,"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/posts\/1297\/revisions"}],"predecessor-version":[{"id":4968,"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/posts\/1297\/revisions\/4968"}],"wp:attachment":[{"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/media?parent=1297"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/categories?post=1297"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/tags?post=1297"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}