ssl的原理和大概

    xiaoxiao2024-11-03  90

    ssl原理

    SSL(Secure Sockets Layer 安全套接层)协议,及其继任者TLS(Transport Layer Security传输层安全)协议,是为网络通信提供安全及数据完整性的一种安全协议。

    2ab9f28b753922d68d21abc0e7faf465.png-wh_

    浏览器发送一个https的请求给服务器;

    服务器要有一套数字证书,可以自己制作,也可以向组织申请,区别就是自己颁发的证书需要客户端验证通过,才可以继续访问,而使用受信任的公司申请的证书则不会弹出>提示页面,这套证书其实就是一对公钥和私钥;

    服务器会把公钥传输给客户端;

    客户端(浏览器)收到公钥后,会验证其是否合法有效,无效会有警告提醒,有效则会生成一串随机数,并用收到的公钥加密;

    客户端把加密后的随机字符串传输给服务器;

    服务器收到加密随机字符串后,先用私钥解密(公钥加密,私钥解密),获取到这一串随机数后,再用这串随机字符串加密传输的数据(该加密为对称加密,所谓对称加密,就是将数据和私钥也就是这个随机字符串>通过某种算法混合在一起,这样除非知道私钥,否则无法获取数据内容);

    服务器把加密后的数据传输给客户端;

    客户端收到数据后,再用自己的私钥也就是那个随机字符串解密;

    颁发的 证书必须得浏览器厂商认可的。

    生成ssl密钥对

    首先对让nginx支持ssl模块

    、[root@centos7 nginx-1.12.1]# cd /data/package/nginx-1.12.1 2、[root@centos7 nginx-1.12.1]# ./configure --prefix=/usr/local/nginx --with-http_ssl_module 3、make 4、make install

    正式操作:

    、[root@centos7 vhost]# cd /usr/local/nginx/conf/

    输入密码

    [root@centos7 conf]# openssl genrsa -des3 -out tmp.key 2048

    3、转换key,取消密码:

    [root@centos7 conf]# openssl rsa -in tmp.key -out testssl.key Enter pass phrase for tmp.key: 输入第2步的密码

    4、删除密钥文件:

    [root@centos7 conf]# rm -f tmp.key

    5、生成证书请求文件

    需要拿这个文件和私钥一起生产公钥文件:

    [root@centos7 conf]# openssl req -new -key testssl.key -out testssl.csr Country Name (2 letter code) [XX]:CN State or Province Name (full name) []:GD Locality Name (eg, city) [Default City]:GZ Organization Name (eg, company) [Default Company Ltd]:FC Organizational Unit Name (eg, section) []:FC Common Name (eg, your name or your server’s hostname) []:testssl Email Address []:admin@admin.com Please enter the following ‘extra’ attributes to be sent with your certificate request A challenge password []:123456 An optional company name []:123456

    6、

    [root@centos7 conf]# ls testssl.* testssl.csr testssl.key

    7、创建公钥

    [root@centos7 conf]# openssl x509 -req -days 365 -in testssl.csr -signkey testssl.key -out testssl.crt Signature ok subject=/C=CN/ST=GD/L=GZ/O=FC/OU=FC/CN=testssl/emailAddress=admin@admin.com Getting Private key You have new mail in /var/spool/mail/root [root@centos7 conf]# ls testssl.* testssl.crt testssl.csr testssl.key
    最新回复(0)