Skip to content

The Dummy Programmer

Stories of daily programming

  • Home
  • My other dummy projects
  • Games
    • Space Y: An Asteroids clone
  • Services
    • What’s my user agent
    • What’s my IP address
  • About
  • Toggle search form

Become your own certification authority – Part 1

Posted on April 21, 2023January 1, 2024 By No Comments on Become your own certification authority – Part 1

Suppose you developed a web application and you want to install this application in a test environment.

To make the test more meaningful, you would like to install an SSL certificate with the application and use a domain name other than the standard ones, such as .com or .org. Consequently, the SSL certificate cannot be purchased because otherwise you would be limited to the standard domains mentioned above. You could use a self signed certificate, but you would get the annoying message from the browser that the certificate is not secure.

So how can you fix the problem? Follow me and you will see…

What we are going to do

In this post we’re going to see how to create an SSL certificate for an arbitrary domain and the relative CA certificate (Certification Authority) necessary to validate the certificate. In this example we are going to create a wildcard SSL certificate for the domain thedummyprogrammer.local (*.thedummyprogrammer.local).

To create our new SSL certificate, we will use OpenSSL (https://www.openssl.org/) which is usually installed by default in many Linux distributions. You can use OpenSSL on windows too, but I personally prefer to use the Linux version. Specifically, the OpenSSL commands that we will see shortly have been tested on an Ubuntu Desktop 20.04.3 LTS running on a virtual machine on my Windows PC.

Let’s start…

The birth of the certificate *.thedummyprogrammer.local

Now it’s the time… we are going to see step by step what you need to do to create an SSL certificate with his own CA certificate. Note that in all of the listed steps, you can replace “thedummyprogrammer.local” with a domain of your choice.

Run your Linux preferred distribution, open a terminal and follow the steps below.

Step 1: create the private key for the CA certificate

In this step you will be asked for a password. Type the password and take a note of it.

openssl genrsa -des3 -out thedummyprogrammer.local.ca.key

Step 2: create the CA certificate

In this step you will use the key created in step 1. Note the parameter -days 18250: this means that this CA certificate will last 18250 days or 50 years. Normally you would never use such a long expiration date for a certificate, but since it’s a certificate created for testing purposes that’s fine.

openssl req -x509 -new -nodes -key thedummyprogrammer.local.ca.key -sha256 -days 18250 -out thedummyprogrammer.local.ca.pem

When you press Enter, you will be asked:

  • The password for the private key you created in step 1
  • Some question about the certificate. In the following screenshot you can see my answers, basically invented from scratch; you have to insert your own answers
Creating the CA certificate

Step 3: create the configuration file for the CSR

In this step you need to create a text file to create a CSR (Certificate Signing Request). We will call this file “csr-config.conf”, but you can name it as you want. Since I’m using Ubuntu Desktop, I can use GEdit to create the file. So if you have a Linux installation with a graphical interface and you can use GEdit, execute this in your command line:

gedit csr-config.conf

and past this content in your newly created file:

[req]
distinguished_name = req_distinguished_name
req_extensions = v3_req
prompt = no
[req_distinguished_name]
C  =  US
ST  =  US
L  =  New York City
O  =  thedummyprogrammer Inc.
OU  =  IT
CN  =  *.thedummyprogrammer.local
[v3_req]
extendedKeyUsage = serverAuth,clientAuth
subjectAltName = @alt_names
[alt_names]
DNS.1 = *.thedummyprogrammer.local

This is a screenshot of my file:

The csr-config.conf file

Step 4: create the private key for the SSL Certificate

openssl genrsa -des3 -out wildcard.thedummyprogrammer.local.key

Again you will be asked for a password, and again take note of your password and don’t forget it.

Step 5: create the CSR

To create the CSR, execute the following in your terminal:

openssl req -new -newkey rsa:2048 -key wildcard.thedummyprogrammer.local.key -nodes -out wildcard.thedummyprogrammer.local.csr -extensions v3_req -config csr-config.conf

Step 6: create the configuration file for SSL certificate signing

In the same way as step 3, create an empty file and name it “signing-config.conf”. Fill the file with this content:

authorityKeyIdentifier=keyid,issuer
basicConstraints=CA:FALSE
[req_ext]
keyUsage = digitalSignature, nonRepudiation, keyEncipherment, dataEncipherment
extendedKeyUsage = serverAuth, clientAuth
subjectAltName = @alt_names

[alt_names]
DNS.1 = *.thedummyprogrammer.local

Step 7: create the SSL certificate in CRT format

We are ready to create the SSL certificate. Just execute the following in your command line:

openssl x509 -req -in wildcard.thedummyprogrammer.local.csr -CA thedummyprogrammer.local.ca.pem -CAkey thedummyprogrammer.local.ca.key -CAcreateserial -out wildcard.thedummyprogrammer.local.crt -days 18250 -sha256 -extfile signing-config.conf -extensions req_ext

Sometimes you may need to remove the password from the private key. If this is the case, the following command is for you:

openssl rsa -in wildcard.thedummyprogrammer.local.key -out wildcard.thedummyprogrammer_nopass.local.key

You will be asked for the password you chose earlier.

Step 8: create the certificate in PFX format

This is the last step. To create the certificate in PFX format execute the following command:

openssl pkcs12 -export -out wildcard.thedummyprogrammer.local.pfx -inkey wildcard.thedummyprogrammer.local.key -in wildcard.thedummyprogrammer.local.crt

At this point you created at least the following files:

  • thedummyprogrammer.local.ca.key
  • thedummyprogrammer.local.ca.pem
  • wildcard.thedummyprogrammer.local.key
  • wildcard.thedummyprogrammer_nopass.local.key
  • wildcard.thedummyprogrammer.local.crt
  • wildcard.thedumyprogrammer.local.pfx

We are now ready to use them in a practical example. You may be wondering why keep the same certificate in different formats. From what I’ve seen, in some environments it’s easier to use one format rather than another, that’s why it’s convenient to have multiple formats.

I suggest you to save those files in a safe place, along with the passwords to use with the private keys.

We will see in the next post how to use those certificates in a practical example.

SSL Tags:ca certificate, ssl, ubuntu, Windows

Post navigation

Previous Post: Play again with Sensible World of Soccer on your PC
Next Post: Become your own certification authority – Part 2

Related Posts

Become your own certification authority – Part 2 SSL
Self signed certificate with Apache/Ubuntu Apache
Run an Apache website under SSL Apache

Leave a Reply Cancel reply

Please do not insert personal or sensitive data in the comment.


Search

Related posts

  • Become your own certification authority - Part 2
  • Working with C# async / await keywords (part 1 of 3)
  • Working with C# async / await keywords (part 2 of 3)
  • Working with C# async / await keywords (part 3 of 3)

Categories

  • .NET 6 (1)
  • .NET 7 (1)
  • AJAX (1)
  • Android (2)
  • Apache (4)
  • ASP.NET (9)
  • ASP.NET MVC (3)
  • Avalonia UI (1)
  • BCP (1)
  • Bitlocker (2)
  • C# (14)
  • CentOS (4)
  • ClosedXML (1)
  • CLR (1)
  • DNS (1)
  • Encryption (3)
  • Excel (2)
  • FuelPHP (3)
  • Games (2)
  • Google Chrome (1)
  • GSuite (1)
  • HTML (1)
  • Imagick (2)
  • Javascript (1)
  • Kindle (1)
  • LAMP (3)
  • Linux (7)
  • MariaDB (2)
  • Mathematics (2)
  • MySql (4)
  • NPOI (1)
  • Office 365 (1)
  • Perl (1)
  • PHP (6)
  • Programming (1)
  • Remote desktop (1)
  • SFTP (2)
  • Sockets (3)
  • Sql Server (20)
  • Sql Server 2016 (14)
  • Sql Server 2019 (1)
  • SSL (4)
  • Task scheduler (1)
  • Telerik ASP.NET AJAX (2)
  • The Dummy Programmer Chat (2)
  • Threading (5)
  • Tools (1)
  • TPL (3)
  • TypeScript (3)
  • Ubuntu (4)
  • Virtualization software (3)
  • Visual Studio (1)
  • Visual Studio Code (2)
  • VueJS (1)
  • Web fonts (1)
  • Web programming (6)
  • Windows (12)
  • Windows 10 (15)
  • Windows Forms (1)
  • Windows Server (6)

Copyright © 2024 The Dummy Programmer | Privacy Policy | Terms of use |

Powered by PressBook Masonry Dark

Manage Cookie Consent
This site doesn’t collect user personal data and doesn’t install profiling or analytical cookies, either its own or from third parties. Read our privacy policy for more info.
Functional Always active
The technical storage or access is strictly necessary for the legitimate purpose of enabling the use of a specific service explicitly requested by the subscriber or user, or for the sole purpose of carrying out the transmission of a communication over an electronic communications network.
Preferences
The technical storage or access is necessary for the legitimate purpose of storing preferences that are not requested by the subscriber or user.
Statistics
The technical storage or access that is used exclusively for statistical purposes. The technical storage or access that is used exclusively for anonymous statistical purposes. Without a subpoena, voluntary compliance on the part of your Internet Service Provider, or additional records from a third party, information stored or retrieved for this purpose alone cannot usually be used to identify you.
Marketing
The technical storage or access is required to create user profiles to send advertising, or to track the user on a website or across several websites for similar marketing purposes.
Manage options Manage services Manage {vendor_count} vendors Read more about these purposes
View preferences
{title} {title} {title}