Note : This should not be made in production mode.
I’ve been banging my head for a while into figuring out how to generate a basic certificate as a file and that i can load in my asp project. I have to mention that I am not (yet) to familiar with using and securing webapi projects with certificates, but my goal is to easily start working with grpc under docker and this quick solution is of great help.
The DigitalOcean article was a great help.
Install choco (https://jcutrer.com/windows/install-chocolatey-choco-windows10)
Create a script that generates (without the certificate authority) the certificate and the private key.
At heart the encryption mechanism between the client and server using an asymmetric encryption (RSA). These certificates do just that.
The bat file that we will create will generate the private key (used by the server to decript the message) and the public key (.crt file).
To understand more about the file formats that certificates have : Cer vs CRT
The bat file:
openssl req -passin pass:fS5MG5ksj -newkey rsa:4096 -nodes -keyout domain.key -x509 -days 365 -out domain.crt -subj "/C=RO/O=DIGITTECK/OU=COMX/CN=Root"
Notice here that i added a network password which we will be providing in the asp project
Create a pfx file which will be used by the server
openssl pkcs12 -export -out domain.pfx -inkey domain.key -in domain.crt
Create the Asp Grpc Server
Edit the appsettings file to define the certificate path:
You can do the same thing in code by configuring the webbuilder, but this is not recommended:
Asp Grpc Client
Configure the client to load the certificate: