概述

  • SSL/TLS握手时,客户端与服务端协商加密套件是很重要的一个步骤,协商出加密套件后才能继续完成后续的握手和加密通信。而现在SSL/TLS协议通信的实现,基本都是通过OpenSSL开源库,本文章就主要介绍下加密套件的含义以及如何在OpenSSL中指定加密套件。

加密套件介绍

  • SSL/TLS协议的加密套件是定义了在一次连接中所使用的各种加密算法的组合。它包括以下几个主要部分
    • 密钥交换算法:用于协商会话密钥,如RSA、DH、ECDH等。
    • 对称加密算法:用于实际数据传输的加解密,例如AES、3DES等。
    • 消息认证码(MAC)或伪随机函数(PRF):用于验证数据完整性及防止篡改,如SHA256等。
      在这里插入图片描述

如何指定加密套件

  • 使用OpenSSL或者Nginx实现SSL/TLS协议时,都需要指定加密套件。

  • 一般如下指定就可以,表示指定加密套件为任意算法,但身份认证算法和加密算法不能为空。这样客户端和服务端就会自动协商一个加密套件进行通信。

  •   	ssl_ciphers ALL:!aNULL;  #Nginx配置加密套件
      	SSL_CTX_set_cipher_list(ServerCTX, "ALL:!aNULL");  #openssl接口配置加密套件
    
  • 但如果想自己指定加密套件,就可以使用以下列表中的一种。

    序号加密套件(完整名称)加密套件(openssl接口指定名称)版本密钥协商算法身份验证算法加密算法MAC
    1TLS_AES_256_GCM_SHA384TLS_AES_256_GCM_SHA384TLSv1.3anyanyAESGCM(256)AEAD
    2TLS_CHACHA20_POLY1305_SHA256TLS_CHACHA20_POLY1305_SHA256TLSv1.3anyanyCHACHA20/POLY1305(256)AEAD
    3TLS_AES_128_GCM_SHA256TLS_AES_128_GCM_SHA256TLSv1.3anyanyAESGCM(128)AEAD
    4TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384ECDHE-ECDSA-AES256-GCM-SHA384TLSv1.2ECDHECDSAAESGCM(256)AEAD
    5TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384ECDHE-RSA-AES256-GCM-SHA384TLSv1.2ECDHRSAAESGCM(256)AEAD
    6TLS_DHE_RSA_WITH_AES_256_GCM_SHA384DHE-RSA-AES256-GCM-SHA384TLSv1.2DHRSAAESGCM(256)AEAD
    7TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256ECDHE-ECDSA-CHACHA20-POLY1305TLSv1.2ECDHECDSACHACHA20/POLY1305(256)AEAD
    8TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256ECDHE-RSA-CHACHA20-POLY1305TLSv1.2ECDHRSACHACHA20/POLY1305(256)AEAD
    9TLS_DHE_RSA_WITH_CHACHA20_POLY1305_SHA256DHE-RSA-CHACHA20-POLY1305TLSv1.2DHRSACHACHA20/POLY1305(256)AEAD
    10TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256ECDHE-ECDSA-AES128-GCM-SHA256TLSv1.2ECDHECDSAAESGCM(128)AEAD
    11TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256ECDHE-RSA-AES128-GCM-SHA256TLSv1.2ECDHRSAAESGCM(128)AEAD
    12TLS_DHE_RSA_WITH_AES_128_GCM_SHA256DHE-RSA-AES128-GCM-SHA256TLSv1.2DHRSAAESGCM(128)AEAD
    13TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384ECDHE-ECDSA-AES256-SHA384TLSv1.2ECDHECDSAAES(256)SHA384
    14TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384ECDHE-RSA-AES256-SHA384TLSv1.2ECDHRSAAES(256)SHA384
    15TLS_DHE_RSA_WITH_AES_256_CBC_SHA256DHE-RSA-AES256-SHA256TLSv1.2DHRSAAES(256)SHA256
    16TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256ECDHE-ECDSA-AES128-SHA256TLSv1.2ECDHECDSAAES(128)SHA256
    17TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256ECDHE-RSA-AES128-SHA256TLSv1.2ECDHRSAAES(128)SHA256
    18TLS_DHE_RSA_WITH_AES_128_CBC_SHA256DHE-RSA-AES128-SHA256TLSv1.2DHRSAAES(128)SHA256
    19TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHAECDHE-ECDSA-AES256-SHATLSv1ECDHECDSAAES(256)SHA1
    20TLS_ECDHE_RSA_WITH_AES_256_CBC_SHAECDHE-RSA-AES256-SHATLSv1ECDHRSAAES(256)SHA1
    21TLS_DHE_RSA_WITH_AES_256_CBC_SHADHE-RSA-AES256-SHASSLv3DHRSAAES(256)SHA1
    22TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHAECDHE-ECDSA-AES128-SHATLSv1ECDHECDSAAES(128)SHA1
    23TLS_ECDHE_RSA_WITH_AES_128_CBC_SHAECDHE-RSA-AES128-SHATLSv1ECDHRSAAES(128)SHA1
    24TLS_DHE_RSA_WITH_AES_128_CBC_SHADHE-RSA-AES128-SHASSLv3DHRSAAES(128)SHA1
    25RSA_PSK_WITH_AES_256_GCM_SHA384RSA-PSK-AES256-GCM-SHA384TLSv1.2RSAPSKRSAAESGCM(256)AEAD
    26DHE_PSK_WITH_AES_256_GCM_SHA384DHE-PSK-AES256-GCM-SHA384TLSv1.2DHEPSKPSKAESGCM(256)AEAD
    27TLS_RSA_PSK_WITH_CHACHA20_POLY1305_SHA256RSA-PSK-CHACHA20-POLY1305TLSv1.2RSAPSKRSACHACHA20/POLY1305(256)AEAD
    28TLS_DHE_PSK_WITH_CHACHA20_POLY1305_SHA256DHE-PSK-CHACHA20-POLY1305TLSv1.2DHEPSKPSKCHACHA20/POLY1305(256)AEAD
    29TLS_ECDHE_PSK_WITH_CHACHA20_POLY1305_SHA256ECDHE-PSK-CHACHA20-POLY1305TLSv1.2ECDHEPSKPSKCHACHA20/POLY1305(256)AEAD
    30TLS_RSA_WITH_AES_256_GCM_SHA384AES256-GCM-SHA384TLSv1.2RSARSAAESGCM(256)AEAD
    31PSK_WITH_AES_256_GCM_SHA384PSK-AES256-GCM-SHA384TLSv1.2PSKPSKAESGCM(256)AEAD
    32TLS_PSK_WITH_CHACHA20_POLY1305_SHA256PSK-CHACHA20-POLY1305TLSv1.2PSKPSKCHACHA20/POLY1305(256)AEAD
    33RSA_PSK_WITH_AES_128_GCM_SHA256RSA-PSK-AES128-GCM-SHA256TLSv1.2RSAPSKRSAAESGCM(128)AEAD
    34DHE_PSK_WITH_AES_128_GCM_SHA256DHE-PSK-AES128-GCM-SHA256TLSv1.2DHEPSKPSKAESGCM(128)AEAD
    35TLS_RSA_WITH_AES_128_GCM_SHA256AES128-GCM-SHA256TLSv1.2RSARSAAESGCM(128)AEAD
    36PSK_WITH_AES_128_GCM_SHA256PSK-AES128-GCM-SHA256TLSv1.2PSKPSKAESGCM(128)AEAD
    37TLS_RSA_WITH_AES_256_CBC_SHA256AES256-SHA256TLSv1.2RSARSAAES(256)SHA256
    38TLS_RSA_WITH_AES_128_CBC_SHA256AES128-SHA256TLSv1.2RSARSAAES(128)SHA256
    39ECDHE_PSK_WITH_AES_256_CBC_SHA384ECDHE-PSK-AES256-CBC-SHA384TLSv1ECDHEPSKPSKAES(256)SHA384
    40ECDHE_PSK_WITH_AES_256_CBC_SHAECDHE-PSK-AES256-CBC-SHATLSv1ECDHEPSKPSKAES(256)SHA1
    41RSA_PSK_WITH_AES_256_CBC_SHA384RSA-PSK-AES256-CBC-SHA384TLSv1RSAPSKRSAAES(256)SHA384
    42DHE_PSK_WITH_AES_256_CBC_SHA384DHE-PSK-AES256-CBC-SHA384TLSv1DHEPSKPSKAES(256)SHA384
    43RSA_PSK_WITH_AES_256_CBC_SHARSA-PSK-AES256-CBC-SHASSLv3RSAPSKRSAAES(256)SHA1
    44DHE_PSK_WITH_AES_256_CBC_SHADHE-PSK-AES256-CBC-SHASSLv3DHEPSKPSKAES(256)SHA1
    45TLS_RSA_WITH_AES_256_CBC_SHAAES256-SHASSLv3RSARSAAES(256)SHA1
    46PSK_WITH_AES_256_CBC_SHA384PSK-AES256-CBC-SHA384TLSv1PSKPSKAES(256)SHA384
    47PSK_WITH_AES_256_CBC_SHAPSK-AES256-CBC-SHASSLv3PSKPSKAES(256)SHA1
    48ECDHE_PSK_WITH_AES_128_CBC_SHA256ECDHE-PSK-AES128-CBC-SHA256TLSv1ECDHEPSKPSKAES(128)SHA256
    49ECDHE_PSK_WITH_AES_128_CBC_SHAECDHE-PSK-AES128-CBC-SHATLSv1ECDHEPSKPSKAES(128)SHA1
    50RSA_PSK_WITH_AES_128_CBC_SHA256RSA-PSK-AES128-CBC-SHA256TLSv1RSAPSKRSAAES(128)SHA256
    51DHE_PSK_WITH_AES_128_CBC_SHA256DHE-PSK-AES128-CBC-SHA256TLSv1DHEPSKPSKAES(128)SHA256
    52RSA_PSK_WITH_AES_128_CBC_SHARSA-PSK-AES128-CBC-SHASSLv3RSAPSKRSAAES(128)SHA1
    53DHE_PSK_WITH_AES_128_CBC_SHADHE-PSK-AES128-CBC-SHASSLv3DHEPSKPSKAES(128)SHA1
    54TLS_RSA_WITH_AES_128_CBC_SHAAES128-SHASSLv3RSARSAAES(128)SHA1
    55PSK_WITH_AES_128_CBC_SHA256PSK-AES128-CBC-SHA256TLSv1PSKPSKAES(128)SHA256
    56PSK_WITH_AES_128_CBC_SHAPSK-AES128-CBC-SHASSLv3PSKPSKAES(128)SHA1
  • 当然也不能任意指定,指定时要看客户端是否支持。比如使用谷歌浏览器访问Nginx服务,抓包可以看到客户端支持的所有加密套件。那么服务端指定加密套件时,就只能从以下支持的加密套件中选择一个。
    在这里插入图片描述

命令行工具

  • OpenSSL提供了命令行工具,可以查看加密套件
  • 1、查看OpenSSL支持的所有加密套件
    • openssl ciphers -v
  • 2、查看OpenSSL支持的所有加密套件,但身份验证和加密算法不能为空
    • openssl ciphers -v ‘ALL:!aNULL’

参考

GitHub 加速计划 / ope / openssl
25.13 K
9.99 K
下载
传输层安全性/安全套接层及其加密库
最近提交(Master分支:1 个月前 )
fd39d1c8 Reviewed-by: Tomas Mraz <tomas@openssl.org> Reviewed-by: Shane Lontis <shane.lontis@oracle.com> (Merged from https://github.com/openssl/openssl/pull/25095) 2 个月前
ae87c488 Reviewed-by: Tomas Mraz <tomas@openssl.org> Reviewed-by: Shane Lontis <shane.lontis@oracle.com> (Merged from https://github.com/openssl/openssl/pull/25095) 2 个月前
Logo

旨在为数千万中国开发者提供一个无缝且高效的云端环境,以支持学习、使用和贡献开源项目。

更多推荐