Good day!
we successfully created our own certification authority. How can it be useful for our purposes?
With the help of a local certification authority, we can issue certificates and also verify signatures using these certificates.
When issuing a certificate to a user, the certification authority uses a special certificate issuance request Pkcs#10, which has the file format '.csr'. This request contains an encoded sequence that the certification authority knows how to correctly parse. The request includes both the user's public key and the data for creating the certificate (an associative array with user data).
We will discuss how to obtain a certificate issuance request in the next article, but in this one, I want to present the main commands of the certification authority that will help us accomplish our task on the backend.
So, first we need to create a certificate. For this, we use the command:
openssl ca -batch -in user.csr -out user.crt ca — the openSSL command that relates to the certification authority,
-batch — disables confirmation prompts when generating the certificate.
user.csr — the request for certificate creation (file in .csr format).
user.crt — the certificate (the result of the command).
For this command to work, the certification authority must be configured exactly as described . Otherwise, you will need to specify the location of the root certification authority certificate.
Certificate verification command:
openssl cms -verify -in authenticate.cms -inform PEM -CAfile /Users/……/demoCA/ca.crt -out data.filecms — the openSSL command used for signing, verifying, encrypting data, and other cryptographic operations with openSSL.
-verify — in this case, we are performing certificate verification.
authenticate.cms — the file containing the signed data by the certificate issued by the previous command.
-inform PEM — using the PEM format.
-CAfile /Users/……/demoCA/ca.crt — the path to the root certificate. (without this, my command did not work, even though paths to ca.crt are specified in openssl.cfg)
-out data.file — sending the decrypted data to the file data.file.
The algorithm for applying the certificate authority on the backend is as follows:
- User Registration:
- We receive a request to create a certificate and save it in the file user.csr.
- Save the first command of this article in a file with a .bat or .cmd extension. Run this file from the code, after saving the certificate creation request in the file user.csr. We obtain the certificate file user.crt.
- Read the file user.crt and send it to the client.
- User Authentication:
- We receive signed data from the client and save it in the file authenticate.cms.
- Save the second command of this article in a file with a .bat or .cmd extension. Run this file from the code, after saving the signed data from the server in authenticate.cms. We obtain the file with the decrypted data data.file.
- Read data.file and check this data for validity. What exactly to check is described . If the data is valid, the user authentication is considered successful.
Any programming language used for backend development can be used to implement these algorithms.
In the next article, we will explore how to work with the RUTOKEN plugin.
Thank you for your attention!
Source: habr.com
