Skip to content

Commit d12fe1e

Browse files
committed
ssl: Do not use undocumented crypto function
Clean up white space errors
1 parent c8fca7e commit d12fe1e

14 files changed

Lines changed: 577 additions & 532 deletions

lib/ssl/src/dtls_record.erl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -623,6 +623,5 @@ start_additional_data(Type, Version, Epoch, SeqNo) ->
623623

624624

625625
sufficient_dtlsv1_2_crypto_support() ->
626-
CryptoSupport = crypto:supports(),
627-
proplists:get_bool(sha256, proplists:get_value(hashs, CryptoSupport)).
626+
proplists:get_bool(sha256, crypto:supports(hashs)).
628627

lib/ssl/src/ssl_cipher.erl

Lines changed: 70 additions & 68 deletions
Large diffs are not rendered by default.

lib/ssl/src/ssl_handshake.erl

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,12 @@
4343

4444
-type oid() :: tuple().
4545
-type public_key_params() :: #'Dss-Parms'{} | {namedCurve, oid()} | #'ECParameters'{} | term().
46-
-type public_key_info() :: {oid(), #'RSAPublicKey'{} | integer() | #'ECPoint'{}, public_key_params()}.
46+
-type public_key_info() :: {oid(), #'RSAPublicKey'{} | integer() |
47+
#'ECPoint'{}, public_key_params()}.
4748
-type ssl_handshake_history() :: {iodata(), iodata()}.
4849

49-
-type ssl_handshake() :: #server_hello{} | #server_hello_done{} | #certificate{} | #certificate_request{} |
50+
-type ssl_handshake() :: #server_hello{} | #server_hello_done{} | #certificate{} |
51+
#certificate_request{} |
5052
#client_key_exchange{} | #finished{} | #certificate_verify{} |
5153
#hello_request{} | #next_protocol{} | #end_of_early_data{}.
5254

@@ -2066,9 +2068,7 @@ certificate_types(Version) when ?TLS_LTE(Version, ?TLS_1_2) ->
20662068

20672069
%% Returns encoded certificate_type if algorithm is supported
20682070
supported_cert_type_or_empty(Algo, Type) ->
2069-
case proplists:get_bool(
2070-
Algo,
2071-
proplists:get_value(public_keys, crypto:supports())) of
2071+
case proplists:get_bool(Algo, crypto:supports(public_keys)) of
20722072
true ->
20732073
<<?BYTE(Type)>>;
20742074
false ->
@@ -3752,8 +3752,7 @@ convert_hostname(SNI) ->
37523752
SNI.
37533753

37543754
client_ecc_extensions(SupportedECCs) ->
3755-
CryptoSupport = proplists:get_value(public_keys, crypto:supports()),
3756-
case proplists:get_bool(ecdh, CryptoSupport) of
3755+
case proplists:get_bool(ecdh, crypto:supports(public_keys)) of
37573756
true ->
37583757
%% RFC 8422 - 5.1. Client Hello Extensions
37593758
%% Clients SHOULD send both the Supported Elliptic Curves Extension and the
@@ -3768,8 +3767,7 @@ client_ecc_extensions(SupportedECCs) ->
37683767
end.
37693768

37703769
server_ecc_extension(_Version, EcPointFormats) ->
3771-
CryptoSupport = proplists:get_value(public_keys, crypto:supports()),
3772-
case proplists:get_bool(ecdh, CryptoSupport) of
3770+
case proplists:get_bool(ecdh, crypto:supports(public_keys)) of
37733771
true ->
37743772
handle_ecc_point_fmt_extension(EcPointFormats);
37753773
false ->

lib/ssl/src/tls_record.erl

Lines changed: 26 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ is_higher(_, _) ->
349349

350350

351351
%%--------------------------------------------------------------------
352-
-spec supported_protocol_versions() -> [tls_version()].
352+
-spec supported_protocol_versions() -> [tls_version()].
353353
%%
354354
%% Description: Protocol versions supported
355355
%%--------------------------------------------------------------------
@@ -378,32 +378,31 @@ supported_protocol_versions([]) ->
378378
supported_protocol_versions([_|_] = Vsns) ->
379379
sufficient_support(Vsns).
380380

381-
sufficient_crypto_support(Version) ->
382-
sufficient_crypto_support(crypto:supports(), Version).
383-
384-
sufficient_crypto_support(CryptoSupport, Version) when Version == 'tlsv1';
385-
Version == 'tlsv1.1' ->
386-
Hashes = proplists:get_value(hashs, CryptoSupport),
387-
PKeys = proplists:get_value(public_keys, CryptoSupport),
388-
proplists:get_bool(sha, Hashes)
381+
sufficient_crypto_support(Version) when Version == 'tlsv1';
382+
Version == 'tlsv1.1' ->
383+
Hashes = crypto:supports(hashs),
384+
PKeys = crypto:supports(public_keys),
385+
proplists:get_bool(sha, Hashes)
386+
andalso
387+
proplists:get_bool(md5, Hashes)
389388
andalso
390-
proplists:get_bool(md5, Hashes)
391-
andalso
392-
proplists:get_bool(aes_cbc, proplists:get_value(ciphers, CryptoSupport))
389+
proplists:get_bool(aes_cbc, crypto:supports(ciphers))
393390
andalso
394-
(proplists:get_bool(ecdsa, PKeys) orelse proplists:get_bool(rsa, PKeys) orelse proplists:get_bool(dss, PKeys))
391+
(proplists:get_bool(ecdsa, PKeys) orelse proplists:get_bool(rsa, PKeys) orelse
392+
proplists:get_bool(dss, PKeys))
395393
andalso
396394
(proplists:get_bool(ecdh, PKeys) orelse proplists:get_bool(dh, PKeys));
397395

398-
sufficient_crypto_support(CryptoSupport, 'tlsv1.2') ->
399-
PKeys = proplists:get_value(public_keys, CryptoSupport),
400-
(proplists:get_bool(sha256, proplists:get_value(hashs, CryptoSupport)))
401-
andalso
402-
(proplists:get_bool(aes_cbc, proplists:get_value(ciphers, CryptoSupport)))
396+
sufficient_crypto_support('tlsv1.2') ->
397+
PKeys = crypto:supports(public_keys),
398+
(proplists:get_bool(sha256, crypto:supports(hashs)))
403399
andalso
404-
(proplists:get_bool(ecdsa, PKeys) orelse proplists:get_bool(rsa, PKeys) orelse proplists:get_bool(dss, PKeys))
400+
(proplists:get_bool(aes_cbc, crypto:supports(ciphers))
405401
andalso
406-
(proplists:get_bool(ecdh, PKeys) orelse proplists:get_bool(dh, PKeys));
402+
(proplists:get_bool(ecdsa, PKeys) orelse proplists:get_bool(rsa, PKeys) orelse
403+
proplists:get_bool(dss, PKeys))
404+
andalso
405+
(proplists:get_bool(ecdh, PKeys) orelse proplists:get_bool(dh, PKeys)));
407406

408407
%% A TLS-compliant application MUST implement the TLS_AES_128_GCM_SHA256
409408
%% [GCM] cipher suite and SHOULD implement the TLS_AES_256_GCM_SHA384
@@ -415,9 +414,9 @@ sufficient_crypto_support(CryptoSupport, 'tlsv1.2') ->
415414
%% CertificateVerify and certificates), and ecdsa_secp256r1_sha256. A
416415
%% TLS-compliant application MUST support key exchange with secp256r1
417416
%% (NIST P-256) and SHOULD support key exchange with X25519 [RFC7748].
418-
sufficient_crypto_support(CryptoSupport, 'tlsv1.3') ->
417+
sufficient_crypto_support('tlsv1.3') ->
419418
Fun = fun({Group, Algorithm}) ->
420-
is_algorithm_supported(CryptoSupport, Group, Algorithm)
419+
is_algorithm_supported(crypto:supports(Group), Algorithm)
421420
end,
422421
%% Minimum requirement check
423422
L = [{ciphers, aes_gcm}, %% TLS_AES_*_GCM_*
@@ -430,12 +429,12 @@ sufficient_crypto_support(CryptoSupport, 'tlsv1.3') ->
430429
{curves, secp256r1} %% key exchange with secp256r1
431430
],
432431
lists:all(Fun, L);
433-
sufficient_crypto_support(CryptoSupport, Version) ->
434-
sufficient_crypto_support(CryptoSupport, protocol_version(Version)).
432+
sufficient_crypto_support(Version) ->
433+
sufficient_crypto_support(protocol_version(Version)).
435434

436435

437-
is_algorithm_supported(CryptoSupport, Group, Algorithm) ->
438-
proplists:get_bool(Algorithm, proplists:get_value(Group, CryptoSupport)).
436+
is_algorithm_supported(CryptoSupport, Algorithm) ->
437+
proplists:get_bool(Algorithm, CryptoSupport).
439438

440439
-spec is_acceptable_version(tls_version()) -> boolean().
441440
is_acceptable_version(Version)
@@ -726,6 +725,5 @@ max_len(_) ->
726725
?MAX_CIPHER_TEXT_LENGTH.
727726

728727
sufficient_support(Versions) ->
729-
CryptoSupport = crypto:supports(),
730-
[Ver || Ver <- Versions, sufficient_crypto_support(CryptoSupport, Ver)].
728+
[Ver || Ver <- Versions, sufficient_crypto_support(Ver)].
731729

lib/ssl/src/tls_v1.erl

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -884,9 +884,8 @@ rsa_exclusive(_) ->
884884
signature_algs(?TLS_1_3, HashSigns) ->
885885
signature_algs(?TLS_1_2, HashSigns);
886886
signature_algs(?TLS_1_2, HashSigns) ->
887-
CryptoSupports = crypto:supports(),
888-
Hashes = proplists:get_value(hashs, CryptoSupports),
889-
PubKeys = proplists:get_value(public_keys, CryptoSupports),
887+
Hashes = crypto:supports(hashs),
888+
PubKeys = crypto:supports(public_keys),
890889
Schemes = rsa_schemes(),
891890
Supported = lists:foldl(fun({Hash, dsa = Sign} = Alg, Acc) ->
892891
case proplists:get_bool(dss, PubKeys)
@@ -922,7 +921,7 @@ signature_algs(?TLS_1_2, HashSigns) ->
922921
default_signature_algs([?TLS_1_3]) ->
923922
default_signature_schemes(?TLS_1_3) ++ legacy_signature_schemes(?TLS_1_3);
924923
default_signature_algs([?TLS_1_3, ?TLS_1_2 | _]) ->
925-
default_signature_schemes(?TLS_1_3) ++ legacy_signature_schemes(?TLS_1_3)
924+
default_signature_schemes(?TLS_1_3) ++ legacy_signature_schemes(?TLS_1_3)
926925
++ default_pre_1_3_signature_algs_only();
927926
default_signature_algs([?TLS_1_2 = Version |_]) ->
928927
Default = [%% SHA2 ++ PSS
@@ -956,12 +955,11 @@ legacy_signature_algs_pre_13() ->
956955

957956
signature_schemes(Version, [_|_] =SignatureSchemes) when is_tuple(Version)
958957
andalso ?TLS_GTE(Version, ?TLS_1_2) ->
959-
CryptoSupports = crypto:supports(),
960-
Hashes = proplists:get_value(hashs, CryptoSupports),
961-
PubKeys = proplists:get_value(public_keys, CryptoSupports),
962-
Curves = proplists:get_value(curves, CryptoSupports),
963-
RSAPSSSupported = lists:member(rsa_pkcs1_pss_padding,
964-
proplists:get_value(rsa_opts, CryptoSupports)),
958+
Hashes = crypto:supports(hashs),
959+
PubKeys = crypto:supports(public_keys),
960+
Curves = crypto:supports(curves),
961+
RSAOpts = crypto:supports(rsa_opts),
962+
RSAPSSSupported = lists:member(rsa_pkcs1_pss_padding, RSAOpts),
965963
Fun = fun(mldsa44 = Scheme, Acc)->
966964
[Scheme | Acc];
967965
(mldsa65 = Scheme, Acc)->
@@ -1081,9 +1079,7 @@ legacy_signature_schemes(Version) ->
10811079
signature_schemes(Version, LegacySchemes).
10821080

10831081
rsa_schemes() ->
1084-
Supports = crypto:supports(),
1085-
RSAOpts = proplists:get_value(rsa_opts, Supports),
1086-
1082+
RSAOpts = crypto:supports(rsa_opts),
10871083
case lists:member(rsa_pkcs1_pss_padding, RSAOpts)
10881084
andalso lists:member(rsa_pss_saltlen, RSAOpts)
10891085
andalso lists:member(rsa_mgf1_md, RSAOpts) of
@@ -1120,7 +1116,8 @@ hkdf_expand(Algo, PseudoRandKey, ContextInfo, Length, N, N, Prev, Acc) ->
11201116
binary:part(<<Acc/binary, Keyingmaterial/binary>>, {0, Length});
11211117
hkdf_expand(Algo, PseudoRandKey, ContextInfo, Length, M, N, Prev, Acc) ->
11221118
Keyingmaterial = hmac_hash(Algo, PseudoRandKey, <<Prev/binary, ContextInfo/binary, ?BYTE(M)>>),
1123-
hkdf_expand(Algo, PseudoRandKey, ContextInfo, Length, M + 1, N, Keyingmaterial, <<Acc/binary, Keyingmaterial/binary>>).
1119+
hkdf_expand(Algo, PseudoRandKey, ContextInfo, Length, M + 1, N,
1120+
Keyingmaterial, <<Acc/binary, Keyingmaterial/binary>>).
11241121

11251122
%%%% HMAC and the Pseudorandom Functions RFC 2246 & 4346 - 5.%%%%
11261123
hmac_hash(?NULL, _, _) ->

0 commit comments

Comments
 (0)