赞
踩
创作人QQ:851301776,邮箱:lfr890207@163.com,欢迎大家一起技术交流,本博客主要是自己学习的心得体会,只为每天进步一点点!
个人座右铭:
1.没有横空出世,只要厚积一定发。
2.你可以学历不高,你可以不上学,但你不能不学习
所有的博客,最开始都是基础版,会不断的增加完善细节和内容,主要是为了自己在遇到类似项目可以快速解决
https采用RSA非对称加密,简单理解就是:通过公钥进行加密,通过私钥进行解密。https采用非对称加密。
备注:密码(123456)
首先创建域名文件夹,然后去拷贝对应的openssl.cnf文件,
在域名目录下创建demoCA目录
进入demoCA目录,并创建对应的文件,并写入。
输入指令,并按照提示输入密码
只有密码是和之前相同的,输入域名的两个输入域名,其他的自己随意输入,但是输入的需要记住,需要和生成CA证书的输入的一致。
这部只需要按照指令输入证书,主要是生成CA证书
- mrlee@mrlee-virtual-machine:~/https/www.lifurong.com$ openssl ca -in server.csr -out server.crt -cert ca.crt -keyfile ca.key -config openssl.cnf
- Using configuration from openssl.cnf
- Enter pass phrase for ca.key:
- Check that the request matches the signature
- Signature ok
- Certificate Details:
- Serial Number: 1 (0x1)
- Validity
- Not Before: May 16 15:31:58 2022 GMT
- Not After : May 16 15:31:58 2023 GMT
- Subject:
- countryName = CN
- stateOrProvinceName = mrlee
- organizationName = mrlee.Ltd
- organizationalUnitName = www.lifurong.com
- commonName = www.lifurong.com
- emailAddress = lifurong@163.com
- X509v3 extensions:
- X509v3 Basic Constraints:
- CA:FALSE
- Netscape Comment:
- OpenSSL Generated Certificate
- X509v3 Subject Key Identifier:
- 57:E2:79:84:AF:5D:84:4F:38:F1:11:7A:49:BF:EE:CC:B2:B6:18:F3
- X509v3 Authority Key Identifier:
- keyid:50:42:0C:FC:47:8D:51:33:0F:C8:83:7B:B2:E2:30:76:73:05:01:BB
-
- Certificate is to be certified until May 16 15:31:58 2023 GMT (365 days)
- Sign the certificate? [y/n]:y
-
-
- 1 out of 1 certificate requests certified, commit? [y/n]y
- Write out database with 1 new entries
- Data Base Updated
备注:第三步和第四步输入的不符,这块特别容易出错,错误提示如下:
红色框里面的指令
- mrlee@mrlee-virtual-machine:~/https/www.lifurong.com$ cat server.pem
- Certificate:
- Data:
- Version: 3 (0x2)
- Serial Number: 1 (0x1)
- Signature Algorithm: sha256WithRSAEncryption
- Issuer: C=CN, ST=mrlee, L=CS, O=mrlee.Ltd, OU=www.lifurong.com, CN=www.lifurong.com/emailAddress=lifurong@163.com
- Validity
- Not Before: May 16 15:31:58 2022 GMT
- Not After : May 16 15:31:58 2023 GMT
- Subject: C=CN, ST=mrlee, O=mrlee.Ltd, OU=www.lifurong.com, CN=www.lifurong.com/emailAddress=lifurong@163.com
- Subject Public Key Info:
- Public Key Algorithm: rsaEncryption
- RSA Public-Key: (1024 bit)
- Modulus:
- 00:cc:95:3e:bc:99:f9:f0:ed:b5:8b:e7:87:54:cc:
- 83:a9:21:cf:ec:63:79:21:0e:b0:8e:4a:1c:d4:25:
- 3d:e5:f0:c1:c8:0a:90:23:7a:b3:33:7f:95:1e:34:
- bf:86:74:49:4f:12:f9:97:e0:99:1a:48:42:d8:0d:
- 0b:d3:d5:88:c9:75:04:23:6b:91:73:5d:ee:e5:2b:
- 25:01:75:58:bf:1d:de:9d:a9:ec:c0:32:98:15:8b:
- 76:7c:eb:7a:d3:1a:e7:40:03:d1:4a:3a:4c:d0:0a:
- 81:02:47:51:a5:e9:34:98:40:56:4e:90:04:33:a0:
- fc:97:0c:51:fe:af:2e:43:db
- Exponent: 65537 (0x10001)
- X509v3 extensions:
- X509v3 Basic Constraints:
- CA:FALSE
- Netscape Comment:
- OpenSSL Generated Certificate
- X509v3 Subject Key Identifier:
- 57:E2:79:84:AF:5D:84:4F:38:F1:11:7A:49:BF:EE:CC:B2:B6:18:F3
- X509v3 Authority Key Identifier:
- keyid:50:42:0C:FC:47:8D:51:33:0F:C8:83:7B:B2:E2:30:76:73:05:01:BB
-
- Signature Algorithm: sha256WithRSAEncryption
- 82:e9:34:45:77:e0:c1:9a:be:d7:ef:20:dc:de:7d:9f:44:8e:
- f0:fb:5f:db:79:39:5c:f0:19:e0:f4:24:b0:f2:51:e4:df:40:
- 38:98:38:b1:c6:31:be:df:55:45:bc:45:13:7a:44:6b:06:bd:
- 7a:b3:54:19:7c:f7:1b:03:e6:af:9f:9b:aa:17:c9:4a:86:9d:
- c2:f8:a1:4a:2d:47:3f:64:5c:7c:07:09:cc:0b:6c:bf:0c:dd:
- ba:93:6d:c6:ca:75:22:0a:92:ad:ff:bb:22:a3:43:bf:c9:8c:
- ca:ec:b8:a6:11:43:ea:62:51:82:c1:7c:3d:72:8f:1b:f7:c5:
- 54:89:22:57:53:fa:16:6c:27:53:0e:2d:50:cb:22:e1:79:6e:
- a9:aa:94:b3:a5:29:ba:77:f8:2f:4b:9b:11:56:84:5d:99:30:
- 0c:e1:24:65:79:48:87:49:72:69:72:a2:ba:4a:48:9d:e0:82:
- 58:2c:4b:06:37:a2:0a:2e:1b:ce:df:ce:63:45:49:cc:cd:48:
- ed:5f:0b:f6:cd:62:f2:11:02:de:57:cc:e3:a8:62:20:c3:4f:
- c0:28:c3:fb:a1:00:cb:f5:7e:48:52:f7:95:78:71:a1:da:1a:
- cc:76:1d:ad:03:5c:6a:a0:6a:3c:0a:26:dd:d4:6d:4d:90:1f:
- 21:01:ea:5a
- -----BEGIN CERTIFICATE-----
- MIIDkTCCAnmgAwIBAgIBATANBgkqhkiG9w0BAQsFADCBlTELMAkGA1UEBhMCQ04x
- DjAMBgNVBAgMBW1ybGVlMQswCQYDVQQHDAJDUzESMBAGA1UECgwJbXJsZWUuTHRk
- MRkwFwYDVQQLDBB3d3cubGlmdXJvbmcuY29tMRkwFwYDVQQDDBB3d3cubGlmdXJv
- bmcuY29tMR8wHQYJKoZIhvcNAQkBFhBsaWZ1cm9uZ0AxNjMuY29tMB4XDTIyMDUx
- NjE1MzE1OFoXDTIzMDUxNjE1MzE1OFowgYgxCzAJBgNVBAYTAkNOMQ4wDAYDVQQI
- DAVtcmxlZTESMBAGA1UECgwJbXJsZWUuTHRkMRk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M8PX8qZYL8YvI1PzCd+X1VsAj52hb+fMUhEgnRb++bbYr2IT2+K1/oHcgBmg5
- NVqOd+VtTKJS45cpD1F4ubsqYBfGkGK9whQFGvJB3hZc6gWRcShtw0jsAx3VeOSl
- YjtxapdPrPT2StBQmS0xEgrz81A2ftTqvPmqD/1IthG4hemmRoDPcjnF/GoWzJax
- 7gGsi8VbYbCKYQHxxC5Wu95N3xAxz8bIfEsCuwJS0ZU1mK18MYeAzZMbS0AVis81
- G/tsaQVQUPk+qbxdUBAsMMpHdtSsWgPaRvftO29A6ga1ZhGTHdK7wpJx60biF8A9
- sVN904PHO0TOW3vKow5mN07BXgLZEUSlvnTeiWwE7WaLwFsWtpt467Seo45gGrOt
- 4vc3wLzcG/NAMGiAs4j+RHvrIus9WOiBjlEUFnt32MUnQ9htHoLhriw1eDGwkQFf
- XwOo3uBMI21QX6Qc6+fOtA6YY5a+RQBBZ/5DFSndSOMPXjXfdCJKHVzHOZc+Iy7O
- tj4h8ATpv+Bz3CPaAZqbig3EuMtJn9iOp1uqE7UdZhjDXQqq0DPFHa47aitKFp7b
- /V4KUfjWb0JldAJ0KFxPW3t9zKlBFihcd7/9sPbg6MI6ortrwFUMl3lN4v737oBz
- e8Ou01Sf0UCpZT3OQianCQj5ja6j3LRzUEkxoKXcjyXR/hF2Lu9kX7mramJPtMSG
- MK5F9AvFrHuKHZ2ahT+eZXncdF1OHal1ghZlBS1hgbqyI53mU3MOyA==
- -----END RSA PRIVATE KEY-----
主要是修改hosts文件,加入域名和IP相对应,这样设置的好处是,直接使用本地,不使用DNS。
ping一把试试
打开nginx.conf,在http模块中加入以下server,内容如下:
-
- # HTTPS server
- server {
- listen 443; //端口
- server_name www.lifurong.com; //域名
-
- ssl on; //开启ssl
- ssl_certificate /home/mrlee/https/www.lifurong.com/server.pem; //
- ssl_certificate_key /home/mrlee/https/www.lifurong.com/server.key;//解密使用的
-
- //测试使用
- location / {
- root /mnt/hgfs/project/visual_gateway/software/camera_lists;
- index camera_lists.txt;
- }
- }
注意:nginx配置,./configure --with-http_ssl_module,需要引入--with-http_ssl_module选项
启动nginx需要引入配置文件,但是需要输入密码,密码为:
在IE浏览器输入(注意使用IE浏览器):
主要原因是公钥CA证书没有认证,此步骤:
换句话说就是假的,就是CA证书一般不是自己提供,而是公司提供,通过认证的CA证书。
点击继续浏览此网站
虽然显示证书错误,但是已经可以拉取到内容
修改nginx配置如下:
- # HTTPS server
- server {
- listen 443;
- server_name www.lifurong.com;
-
- ssl on;
- ssl_certificate /home/mrlee/https/www.lifurong.com/server.pem;
- ssl_certificate_key /home/mrlee/https/www.lifurong.com/server.key;
-
- location / {
- root html;
- index index.html index.htm;
- }
- }
重启nginx
查看浏览器输入:
引入域名对应的IP
代码是按照此流程写的
编译:gcc -o xx xx.c -lssl -lcrypto
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。