Michael Wu

The Life of a Cloud Engineer

  • Home
  • Resume
  • Blog
  • Contact

Posted on 04.13.16

How to create a Sha256 Self-Signed Certificate for SMTP secure communication by CertReq

The goal of this post is to create a sha2 TLS certificate for SMTP. Create a Domain Certificate with Sha2 in the template will work. However, if you don`t have a CA in your domain, a self-signed certificate will be a good choice for testing.

The self-signed certificate created by IIS Manager will work but it will be Sha1.

IIS_SelfSignedCert

To create a self-signed Sha2 Certificate, we use a command-line tool called Certreq.exe. Certreq can be used to request certificates from a certification authority (CA), to retrieve a response to a previous request from a CA, to create a new request from a .inf file, to accept and install a response to a request, to construct a cross-certification or qualified subordination request from an existing CA certificate or request, and to sign a cross-certification or qualified subordination request. You can see the detail information in here.

There are three steps to accomplish this task.

  1. Create a .inf file
  2. Run Certreq command
  3. Import the certificate to Trusted Root Certification Authorities (optional)

Test Environment: Windows Server 2008 R2 Standard SP1

Create a .inf file

Create a new Text Document and change the extension to .inf.  Open the file in Notepad. Copy the following text into Notepad.


[Version]
Signature="$Windows NT$

[NewRequest]
Subject = "CN=host.yourdomain.com"
Requesttype = Cert
KeyLength = 2048
FriendlyName = "Sha256 TLS"
Exportable = true
HashAlgorithm = sha256
MachineKeySet = true
KeySpec = 1

Note: Replace “host.yourdomain.com” with your subject name in Line 5. 

Line 6 Requesttype = Cert indicates a self-signed or self-issued certificate. It does not generate a request, but rather a new certificate and then installs the certificate.

Line 12 KeySpec = 1 determines the key can be used for Key Exchange (Required for encryption).

Save the file in C:\temp\RequestPolicy.inf.

Run Certreq Command

Run Command Prompt as administrator. Run the command “certreq -new c:\temp\RequestPolicy.inf“.

certreq

Click Cancel when you see the prompt.

certreq_save_request

Verify the certificate is installed in IIS manager -> Server Certificates.

certreq_installed

Verify the Secure communication in SMTP Virtual Server Properties. You should see the same expiration date with your certificate.

certreq_SMTP

Congratulation! You have Sha2 self-signed certificate for SMTP encryption now.

Import the certificate to Trusted Root Certification Authorities

At this point, SMTP encryption should be working. However, if you take a look the certificate, you will notice the certificate is not trusted.

certreq_trustedCert

To install the certificate in the Trusted Root CA, I use Certificates snap-in in MMC console.

certreq_certMMC

Export the certificate from Personal Certificates. Click next for all options and save as a .cer file.

certreq_certMMC_export

Import the .cer file to the Trusted Root Certification Authorities. Click next to finish.

certreq_certMMC_import

You should see the certificate is trusted now.

certreq_trustedCert2

More

You can add more keys or extensions as needed.  For example, if I want to add a Custom Subject Alternative Name, I can add following extensions.

[Extensions]
; If your client operating system is Windows Server 2008, Windows Server 2008 R2, Windows Vista, or Windows 7
; SANs can be included in the Extensions section by using the following text format. Note 2.5.29.17 is the OID for a SAN extension.

2.5.29.17 = "{text}"
_continue_ = "dns=www01.fabrikam.com&"
_continue_ = "dn=CN=www01,OU=Web Servers,DC=fabrikam,DC=com&"
_continue_ = "url=http://www.fabrikam.com&"
_continue_ = "ipaddress=172.31.10.134&"
_continue_ = "[email protected]&"
_continue_ = "[email protected]&"
_continue_ = "guid=f7c3ac41-b8ce-4fb4-aa58-3d1dc0e36b39&"

However, it failed when I added the DNS Subject Alternative Name in Line 6. I don`t have a solution for this yet. Please leave a comment if you have one. 🙂

References

  • TechNet Certreq
  • Certreq.exe Syntax
  • How to Request a Certificate With a Custom Subject Alternative Name

Categories:IIS

Recent Posts

  • Automating Resource Restriction in Azure subscriptions with Budget Alert, Automation Account, and Azure Policy
  • How to configure the Security Center via Azure Resource Manager (ARM) template
  • How to restrict Account Operators to see the password in LAPS
  • How to join a VM to a domain by PowerShell in Azure
  • How to push an existing repository from VS Code to Azure DevOps by PowerShell

Search

Categories

  • Azure
  • IIS
  • PowerShell
  • SCCM
  • VMware
  • Windows Server

Contact

Email: [email protected] | Powered By the 太初網路

Copyright © 2024 mikewu.org Disclaimer

Connect

FacebookTwitterGoogle +Linkedin