|
20 | 20 |
|
21 | 21 | -export([peer_cert_issuer/1, peer_cert_subject/1, peer_cert_validity/1]).
|
22 | 22 | -export([peer_cert_subject_items/2, peer_cert_auth_name/1]).
|
| 23 | +-export([cipher_suites_erlang/2, cipher_suites_erlang/1, |
| 24 | + cipher_suites_openssl/2, cipher_suites_openssl/1, |
| 25 | + cipher_suites/1]). |
23 | 26 |
|
24 | 27 | %%--------------------------------------------------------------------------
|
25 | 28 |
|
26 | 29 | -export_type([certificate/0]).
|
27 | 30 |
|
28 | 31 | -type certificate() :: rabbit_cert_info:certificate().
|
29 | 32 |
|
| 33 | +-type cipher_suites_mode() :: default | all | anonymous. |
| 34 | + |
| 35 | +-spec cipher_suites(cipher_suites_mode()) -> ssl:ciphers(). |
| 36 | +cipher_suites(Mode) -> |
| 37 | + Version = get_highest_protocol_version(), |
| 38 | + ssl:cipher_suites(Mode, Version). |
| 39 | + |
| 40 | +-spec cipher_suites_erlang(cipher_suites_mode()) -> |
| 41 | + [ssl:old_cipher_suite()]. |
| 42 | +cipher_suites_erlang(Mode) -> |
| 43 | + Version = get_highest_protocol_version(), |
| 44 | + cipher_suites_erlang(Mode, Version). |
| 45 | + |
| 46 | +-spec cipher_suites_erlang(cipher_suites_mode(), |
| 47 | + ssl:protocol_version() | tls_record:tls_version()) -> |
| 48 | + [ssl:old_cipher_suite()]. |
| 49 | +cipher_suites_erlang(Mode, Version) -> |
| 50 | + [ format_cipher_erlang(C) |
| 51 | + || C <- ssl:cipher_suites(Mode, Version) ]. |
| 52 | + |
| 53 | +-spec cipher_suites_openssl(cipher_suites_mode()) -> |
| 54 | + [ssl:old_cipher_suite()]. |
| 55 | +cipher_suites_openssl(Mode) -> |
| 56 | + Version = get_highest_protocol_version(), |
| 57 | + cipher_suites_openssl(Mode, Version). |
| 58 | + |
| 59 | +-spec cipher_suites_openssl(cipher_suites_mode(), |
| 60 | + ssl:protocol_version() | tls_record:tls_version()) -> |
| 61 | + [ssl:old_cipher_suite()]. |
| 62 | +cipher_suites_openssl(Mode, Version) -> |
| 63 | + lists:filtermap(fun(C) -> |
| 64 | + OpenSSL = format_cipher_openssl(C), |
| 65 | + case is_list(OpenSSL) of |
| 66 | + true -> {true, OpenSSL}; |
| 67 | + false -> false |
| 68 | + end |
| 69 | + end, |
| 70 | + ssl:cipher_suites(Mode, Version)). |
| 71 | + |
| 72 | + |
| 73 | +%% OTP-20.3 and OTP-21 have different modules containing cipher format functions |
| 74 | +%% This is not a hot codepath and `function_exported` should not slow things down much. |
| 75 | +format_cipher_erlang(Cipher) -> |
| 76 | + case erlang:function_exported(ssl_cipher_format, suite, 1) of |
| 77 | + true -> |
| 78 | + ssl_cipher_format:erl_suite_definition(ssl_cipher_format:suite(Cipher)); |
| 79 | + false -> |
| 80 | + ssl_cipher:erl_suite_definition(ssl_cipher:suite(Cipher)) |
| 81 | + end. |
| 82 | + |
| 83 | +format_cipher_openssl(Cipher) -> |
| 84 | + case erlang:function_exported(ssl_cipher_format, suite, 1) of |
| 85 | + true -> |
| 86 | + ssl_cipher_format:openssl_suite_name(ssl_cipher_format:suite(Cipher)); |
| 87 | + false -> |
| 88 | + ssl_cipher:openssl_suite_name(ssl_cipher:suite(Cipher)) |
| 89 | + end. |
| 90 | + |
| 91 | +-spec get_highest_protocol_version() -> tls_record:tls_version(). |
| 92 | +get_highest_protocol_version() -> |
| 93 | + tls_record:highest_protocol_version([]). |
| 94 | + |
30 | 95 | %%--------------------------------------------------------------------------
|
31 | 96 | %% High-level functions used by reader
|
32 | 97 | %%--------------------------------------------------------------------------
|
|
0 commit comments