当前位置:网站首页>[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
边栏推荐
- Keras' deep learning practice -- gender classification based on vgg19 model
- Yingguang single chip microcomputer development specification pmc131 with AD chip to detect battery voltage single chip microcomputer sop8/14
- Outsourcing for five years, abandoned
- Huimang micro IO MCU ft60f010a-urt
- Yilong em78p153k dip14 MCU
- 【網絡是怎樣連接的】第六章 請求到達服務器以及響應給客戶端(完結)
- USB interface powered Bluetooth color light strip controller
- [today in history] July 2: BitTorrent came out; The commercial system linspire was acquired; Sony deploys Playstation now
- Microsoft LDAP 配置页中输入有效的用户名及密码,microsoft ldap 配置页中输入有效的用户名
- WPS inserts a picture and displays it completely
猜你喜欢
阿里云子账户 - 权限策略 - 授权给某个账户某个 OSS Bucket 的完全控制权限
[nonlinear control theory]7_ High gain and High Frequency
MySQL进阶-事务及索引
WPS inserts a picture and displays it completely
ORA-19838 -- 恢复控制文件到备库
Modbus protocol communication exception
Microsoft LDAP 配置页中输入有效的用户名及密码,microsoft ldap 配置页中输入有效的用户名
1288_FreeRTOS中vTaskResume()接口以及中断安全版本接口实现分析
Editor编辑器扩展在Scene View添加按钮和logo
【Zuul】com.netflix.zuul.exception.ZuulException: Hystrix Readed time out
随机推荐
应广单片机开发流程需要注意哪些?
easyAI笔记——机器学习
Chapter 15 string localization and message Dictionary (1)
Keras' deep learning practice -- gender classification based on vgg19 model
Pfc232-sop8/14/16 should be wide-ranging and can be tape programmed with burning program
辉芒微IO单片机FT60F11F-MRB
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
[nonlinear control theory]8_ Comparison of three robust controllers
原装应广单片机 MCU芯片PMS152 SOP8封装 单片机开发
深入理解ThreadLocal
Yingguang single chip microcomputer pms150/pmc150/pms150c consumer single chip microcomputer
Redisson 高性能 Redis 分布式锁源码分析
[how is the network connected] Chapter 6 requests arrive at the server and respond to the client (end)
JDBC
What is the experience of maintaining Wanxing open source vector database
Yilong em78p153k dip14 MCU
辉芒微IO单片机FT60F011A-RB
Modbus protocol communication exception
Redisson high performance redis distributed lock source code analysis
【Golang | gRPC】使用gRPC实现简单远程调用