当前位置:网站首页>[golang | grpc] generate certificates using OpenSSL
[golang | grpc] generate certificates using OpenSSL
2022-07-02 17:57:00 【Field potato】
Environmental Science :
OpenSSL:3.0.4
1. secret key
1.1 establish RSA Private key
Use openssl genrsa
# Generate 1024 Bit private key , Output to console
openssl genrsa 1024
# Generate 2048 Bit private key , Save to server.key In file
openssl genrsa -out server.key 2048
# Generate 2048 Private key with encryption ( Enter the password interactively ), Save to server_passphrase.key In file
openssl genrsa -out server_passphrase.key -des3 2048
-out
: Output the private key to the specified file , If not, it will be output to the console2048
: Generate 2048 Bit of private key-des3
: Generate encrypted private key
1.2 Use RSA Private key generates public key
# If it is an encrypted private key , You need to enter the private key password interactively
openssl rsa -in server.key -pubout -out server_public.key
-in
: Import private key file-pubout
: Output public key-out
: Save the output public key to the specified file
1.3 View key
1.3.1 View private key
openssl rsa -in server.key -text
1.3.2 View public key
openssl rsa -RSAPublicKey_in -in server_public.key -text
2. Certificate request file
With the private key , I can create Certificate Signing Request
(csr, Certificate request file ). Use the private key pair csr Conduct sign
( Signature ), meanwhile csr Contains the public key corresponding to the private key
2.1 Use the existing private key to create csr
2.1.1 Use interactive mode
Use openssl req
# Use private key server.key Generate in interactive mode csr,
openssl req -new -key server.key -out server.csr
- Generally speaking , When interacting, directly knock
enter
Just go , Indicates use default ; If you want some fields to be empty , You can enter.
Knock againenter
-new
: Generate a new csr-key
: Use the specified private key for signing , meanwhile csr It will contain the public key corresponding to the private key-out
: The generated csr Save to the specified file
2.1.2 Use profile
New configuration file csr.cnf
[req]
prompt = no
distinguished_name = dn
req_extensions = ext
input_password = tian # Password to encrypt the private key
[dn]
CN = www.feistyduck.com # Common Name Common name , Usually the website host name
emailAddress = [email protected]
O = Feisty Duck Ltd # Organization organization
L = London # Locality home
C = GB # Country Country , Such as China :CN
[ext]
subjectAltName = DNS:www.feistyduck.com,DNS:feistyduck.com
Add :
http://www.sina.com.cn/
For example ,http
Is the protocol used for communication ,sina.com.cn
Is the domain name ,www
Is the name of the machine that provides the service ( Server name ), Server name + The domain name is the host name , namelywww.sina.com.cn
It's the host namesubjectAltName
(X.509 ExpandingSAN
), If only CN, Then a certificate usually corresponds to only one hostname , If you want to use a certificate with multiple host names , adoptsubjectAltName
To configure , Generally speaking , Host names contain at least two , One beltwww.
Of , One without ; You can also use wildcards , such asshannont.com
and*.shannont.com
Use the configuration file to generate csr
openssl req -new -config csr.cnf -key server.key -out server2.csr
-config
: Specify the configuration file to use
2.2 see csr The content of
openssl req -in server.csr -text -noout
- csr Contains public key , Signature and fields with non empty input value during previous interaction
- The current version of the summary algorithm defaults to
sha256
-text
: Output csr In the form of text-noout
: No output-----BEGIN CERTIFICATE REQUEST-----...-----END CERTIFICATE REQUEST-----
Content between
3. certificate
3.1 Self signed certificate
With csr after , You don't have to go CA Apply for a certificate , Most of the time, the development stage can apply for a self signed certificate for self-test ( Is to use your private key to sign the certificate )
3.1.1 Use csr Generate Certificate
Use openssl x509
command
# If the signature uses an encrypted private key, you need to enter the private key password interactively
openssl x509 -req -days 365 -in server.csr -signkey server.key -out server.crt
x509
: X.509 It is the format standard of public key certificate in cryptography-req
: Indicate that the input file is csr-days
: How long is the certificate valid-in
: Input file-signkey
: Equate to-key
, Indicate the private key used for signing
3.1.2 Use the private key to generate the certificate directly
# Interactive mode , You need to enter the country , organization , Location and other field values , If it is an encrypted private key , Also enter the private key password
openssl req -new -x509 -days 365 -key server.key -out server2.crt
# Use the above csr The configuration file of generates the certificate directly
openssl req -new -x509 -days 365 -key server.key -config csr.cnf -out server3.crt
# Use -subj Option specifies the country , organization , Location and other field values , If it is an encrypted private key , Also enter the private key password
openssl req -new -x509 -days 365 -key server.key -out server4.crt -subj "/C=CN/L=ShangHai"
3.2 Check the certificate
The part of the certificate about the public key is exactly the same as 1.3.2 Contents of public key in section
openssl x509 -text -in server.crt -noout
3.3 Check the certificate
Use openssl s_server
Create a server, The default port is 4433
, Import certificate and private key
openssl s_server -cert server.crt -key server.key -www
Open the browser , Input https://127.0.0.1:4433
, Get the following , Need manual trust
边栏推荐
- 基数排序的简单理解
- HDU - 1114 Piggy Bank (full backpack)
- No such file or directory: ‘/tmp/tmpxxx/tmpxxx.py‘
- 外包干了五年,废了...
- Huimang micro IO MCU ft60f010a-urt
- Two pieces of nature a day! Duan Fengfeng, an alumnus of the University of science and technology of China, was the third Chinese winner of the belby medal
- Outsourcing for five years, abandoned
- JDBC
- PMS150C应广单片机开发案例
- 原装应广单片机 MCU芯片PMS152 SOP8封装 单片机开发
猜你喜欢
Two pieces of nature a day! Duan Fengfeng, an alumnus of the University of science and technology of China, was the third Chinese winner of the belby medal
Yingguang single chip microcomputer development specification pmc131 with AD chip to detect battery voltage single chip microcomputer sop8/14
[how is the network connected] Chapter 6 requests arrive at the server and respond to the client (end)
ORA-19838 -- 恢复控制文件到备库
自定义一个loading指令
【Zuul】com.netflix.zuul.exception.ZuulException: Hystrix Readed time out
Modbus protocol communication exception
智能水电表能耗监测云平台
Modbus protocol communication exception
售价仅40元,树莓派Pico开发板加入WiFi模块,刚上市就脱销
随机推荐
MySQL -- basic concept of database
原厂原装 应广单片机PMS134方案开发应用案例
[comment le réseau se connecte] chapitre 6: demande d'accès au serveur et réponse au client (terminé)
Keras深度学习实战——基于VGG19模型实现性别分类
Aloam code reading and summary
easyAI笔记——深度学习
[today in history] July 2: BitTorrent came out; The commercial system linspire was acquired; Sony deploys Playstation now
Laravel文档阅读笔记-Custom Authentication Login And Registration Using Laravel 8
【Zuul】com. netflix. zuul. exception. ZuulException: Hystrix Readed time out
透过华为军团看科技之变(六):智慧公路
Modbus协议通信异常
阿里云子账户 - 权限策略 - 授权给某个账户某个 OSS Bucket 的完全控制权限
Virtual lab basic experiment tutorial -7 Polarization (2)
aloam 代码阅读与总结
嵌入式开发板 ~ 说明
Daily question - xiaolele changes the number
辉芒微IO单片机FT60F010A-URT
体验一下阿里云文字识别OCR
Wechat applet - arrows floating up and down
Editor编辑器扩展在Scene View添加按钮和logo