当前位置:网站首页>[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
enterJust 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 ,httpIs the protocol used for communication ,sina.com.cnIs the domain name ,wwwIs the name of the machine that provides the service ( Server name ), Server name + The domain name is the host name , namelywww.sina.com.cnIt'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 , adoptsubjectAltNameTo configure , Generally speaking , Host names contain at least two , One beltwww.Of , One without ; You can also use wildcards , such asshannont.comand*.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 
边栏推荐
- 977.有序数组的平方
- Development and application case of pms134 scheme of Yingguang single chip microcomputer with original packaging
- My creation anniversary
- Virtual lab basic experiment tutorial -7 Polarization (2)
- 【Golang | gRPC】使用openssl生成证书
- USB interface powered Bluetooth color light strip controller
- ASEMI整流桥UMB10F参数,UMB10F规格,UMB10F封装
- MySQL --- 数据库的基本操作
- 透过华为军团看科技之变(六):智慧公路
- No such file or directory: ‘/tmp/tmpxxx/tmpxxx.py‘
猜你喜欢

Daily question - "number of daffodils"

pytorch支持32位吗?

【历史上的今天】7 月 2 日:BitTorrent 问世;商业系统 Linspire 被收购;索尼部署 PlayStation Now

Alibaba cloud sub account - Permission Policy - full control permission granted to an account and an OSS bucket
![[how is the network connected] Chapter 6 requests arrive at the server and respond to the client (end)](/img/ef/1ac272dbd0e5c4d08a8f01f61d334d.png)
[how is the network connected] Chapter 6 requests arrive at the server and respond to the client (end)

MySQL --- 數據庫的基本操作

Asemi rectifier bridge umb10f parameters, umb10f specifications, umb10f package

wait_for_gap -- 从主库归档备库恢复归档

Are you holding back on the publicity of the salary system for it posts such as testing, development, operation and maintenance?

Easyai notes - machine learning
随机推荐
【网络是怎样连接的】第五章 探索服务器
[how to connect the network] Chapter 5 explore the server
wait_ for_ Gap -- restore archive from primary archive to secondary Archive
Modbus protocol communication exception
[target tracking] | data set summary
Troubleshooting ideas that can solve 80% of faults
567.字符串中的排列
蓝牙技术|物联网的可穿戴设备新工作模式,蓝牙BLE助力新工作模式
Pfc232-sop8/14/16 should be wide-ranging and can be tape programmed with burning program
Many scenic spots are temporarily closed due to the typhoon. The provincial culture and tourism department reminds you to pay attention to safety!
Edgenext hit a mixed punch: a lightweight architecture integrating CNN and transformer
Yingguang single chip microcomputer development specification pmc131 with AD chip to detect battery voltage single chip microcomputer sop8/14
【Golang | gRPC】使用openssl生成证书
[how is the network connected] Chapter 4 explores access networks and network operators
Huimang micro IO MCU ft60f11f-mrb
如何下载微信支付证书(API证书)
Virtual lab basic experiment tutorial -7 Polarization (1)
辉芒微IO单片机FT60F010A-URT
好评率计算
Bluetooth technology | new working mode of wearable devices of the Internet of things, and Bluetooth ble helps the new working mode