Skip to content

Commit a3312e0

Browse files
Merge pull request #7838 from rabbitmq/mergify/bp/v3.11.x/pr-7837
Update ct_helper (backport #7821) (backport #7837)
2 parents 8296864 + 122a127 commit a3312e0

File tree

4 files changed

+52
-44
lines changed

4 files changed

+52
-44
lines changed

MODULE.bazel

+1-1
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,7 @@ erlang_dev_package = use_extension(
370370
)
371371

372372
erlang_dev_package.git_package(
373-
commit = "478aa272708ed4ad282ca02bed41a5320330e8af",
373+
branch = "master",
374374
build_file = "@//:bazel/BUILD.ct_helper",
375375
repository = "ninenines/ct_helper",
376376
)

bazel/BUILD.ct_helper

+3-6
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,11 @@ erlang_bytecode(
2020
testonly = True,
2121
srcs = [
2222
"src/ct_helper.erl",
23-
"src/ct_helper_error_h.erl",
24-
"src/erl_make_certs.erl",
23+
"src/ct_helper_error_h.erl"
2524
],
2625
outs = [
2726
"ebin/ct_helper.beam",
28-
"ebin/ct_helper_error_h.beam",
29-
"ebin/erl_make_certs.beam",
27+
"ebin/ct_helper_error_h.beam"
3028
],
3129
app_name = "ct_helper",
3230
erlc_opts = "//:erlc_opts",
@@ -44,8 +42,7 @@ filegroup(
4442
srcs = [
4543
"src/ct_helper.app.src",
4644
"src/ct_helper.erl",
47-
"src/ct_helper_error_h.erl",
48-
"src/erl_make_certs.erl",
45+
"src/ct_helper_error_h.erl"
4946
],
5047
)
5148

deps/rabbitmq_trust_store/test/system_SUITE.erl

+48-36
Original file line numberDiff line numberDiff line change
@@ -201,9 +201,9 @@ validation_success_for_AMQP_client1(Config) ->
201201
%% Note that when this test is executed together with the HTTP provider group
202202
%% it runs into unexpected interference and fails, even if TLS app PEM cache is force
203203
%% cleared. That's why originally each group was made to use a separate node.
204-
AuthorityInfo = {Root, _AuthorityKey} = erl_make_certs:make_cert([]),
205-
{Certificate, Key} = chain(AuthorityInfo),
206-
{Certificate2, Key2} = chain(AuthorityInfo),
204+
RootCert = #{cert := Root} = public_key:pkix_test_root_cert("RootCA", []),
205+
{Certificate, Key} = chain(RootCert),
206+
{Certificate2, Key2} = chain(RootCert),
207207
Port = port(Config),
208208
Host = rabbit_ct_helpers:get_config(Config, rmq_hostname),
209209
%% When: Rabbit accepts just this one authority's certificate
@@ -293,7 +293,7 @@ validate_chain1(Config) ->
293293
Port = port(Config),
294294
Host = rabbit_ct_helpers:get_config(Config, rmq_hostname),
295295

296-
ok = whitelist(Config, "alice", CertTrusted, KeyTrusted),
296+
ok = whitelist(Config, "alice", CertTrusted),
297297
rabbit_trust_store:refresh(),
298298

299299
catch rabbit_networking:stop_tcp_listener(Port),
@@ -326,18 +326,30 @@ validate_longer_chain1(Config) ->
326326
%% AND a certificate `CertUntrusted` that is not whitelisted with the same root as `CertTrusted`
327327
%% AND `CertInter` intermediate CA
328328
%% AND `RootTrusted` CA
329-
AuthorityInfo = {RootCA, _AuthorityKey} = erl_make_certs:make_cert([]),
330-
Inter = {CertInter, {KindInter, KeyDataInter, _}} = erl_make_certs:make_cert([{issuer, AuthorityInfo}]),
331-
KeyInter = {KindInter, KeyDataInter},
332-
{CertUntrusted, {KindUntrusted, KeyDataUntrusted, _}} = erl_make_certs:make_cert([{issuer, Inter}]),
333-
KeyUntrusted = {KindUntrusted, KeyDataUntrusted},
334-
{CertTrusted, {Kind, KeyData, _}} = erl_make_certs:make_cert([{issuer, Inter}]),
335-
KeyTrusted = {Kind, KeyData},
329+
330+
KeyInterDec = public_key:generate_key({rsa, 2048, 17}),
331+
KeyInter = {'RSAPrivateKey', public_key:der_encode('RSAPrivateKey', KeyInterDec)},
332+
333+
TestDataTrusted = public_key:pkix_test_data(#{
334+
root => [],
335+
intermediates => [[{key, KeyInterDec}]],
336+
peer => []
337+
}),
338+
CertTrusted = proplists:get_value(cert, TestDataTrusted),
339+
KeyTrusted = proplists:get_value(key, TestDataTrusted),
340+
[RootCA, CertInter, RootCA] = proplists:get_value(cacerts, TestDataTrusted),
341+
342+
TestDataUntrusted = public_key:pkix_test_data(#{
343+
root => #{cert => CertInter, key => KeyInterDec},
344+
peer => []
345+
}),
346+
CertUntrusted = proplists:get_value(cert, TestDataUntrusted),
347+
KeyUntrusted = proplists:get_value(key, TestDataUntrusted),
336348

337349
Port = port(Config),
338350
Host = rabbit_ct_helpers:get_config(Config, rmq_hostname),
339351

340-
ok = whitelist(Config, "alice", CertTrusted, KeyTrusted),
352+
ok = whitelist(Config, "alice", CertTrusted),
341353
rabbit_trust_store:refresh(),
342354

343355
catch rabbit_networking:stop_tcp_listener(Port),
@@ -486,7 +498,7 @@ whitelisted_certificate_accepted_from_AMQP_client_regardless_of_validation_to_ro
486498
Port = port(Config),
487499
Host = rabbit_ct_helpers:get_config(Config, rmq_hostname),
488500

489-
ok = whitelist(Config, "alice", CertTrusted, KeyTrusted),
501+
ok = whitelist(Config, "alice", CertTrusted),
490502
rabbit_trust_store:refresh(),
491503

492504
%% When: Rabbit validates paths with a different root `R` than
@@ -520,7 +532,7 @@ removed_certificate_denied_from_AMQP_client1(Config) ->
520532

521533
Port = port(Config),
522534
Host = rabbit_ct_helpers:get_config(Config, rmq_hostname),
523-
ok = whitelist(Config, "bob", CertOther, KeyOther),
535+
ok = whitelist(Config, "bob", CertOther),
524536
rabbit_trust_store:refresh(),
525537

526538
%% When: we wait for at least one second (the accuracy of the
@@ -584,7 +596,7 @@ installed_certificate_accepted_from_AMQP_client1(Config) ->
584596
{key, Key} | cfg()], 1, 1),
585597

586598
wait_for_file_system_time(),
587-
ok = whitelist(Config, "charlie", CertOther, KeyOther),
599+
ok = whitelist(Config, "charlie", CertOther),
588600
wait_for_trust_store_refresh(),
589601

590602
%% Then: a client presenting the whitelisted certificate `CertOther`
@@ -618,8 +630,8 @@ whitelist_directory_DELTA1(Config) ->
618630
{_, CertRevoked, KeyRevoked} = ct_helper:make_certs(),
619631
{_, CertListed2, KeyListed2} = ct_helper:make_certs(),
620632

621-
ok = whitelist(Config, "foo", CertListed1, KeyListed1),
622-
ok = whitelist(Config, "bar", CertRevoked, KeyRevoked),
633+
ok = whitelist(Config, "foo", CertListed1),
634+
ok = whitelist(Config, "bar", CertRevoked),
623635
rabbit_trust_store:refresh(),
624636

625637
%% When: we wait for at least one second (the accuracy
@@ -633,7 +645,7 @@ whitelist_directory_DELTA1(Config) ->
633645

634646
wait_for_file_system_time(),
635647
ok = delete("bar.pem", Config),
636-
ok = whitelist(Config, "baz", CertListed2, KeyListed2),
648+
ok = whitelist(Config, "baz", CertListed2),
637649
wait_for_trust_store_refresh(),
638650

639651
%% Then: connectivity to Rabbit is as it should be.
@@ -695,7 +707,7 @@ replaced_whitelisted_certificate_should_be_accepted1(Config) ->
695707
{cert, Cert},
696708
{key, Key} | cfg()], 1, 1),
697709
%% And: the first certificate has been whitelisted
698-
ok = whitelist(Config, "bart", CertFirst, KeyFirst),
710+
ok = whitelist(Config, "bart", CertFirst),
699711
rabbit_trust_store:refresh(),
700712

701713
wait_for_trust_store_refresh(),
@@ -732,7 +744,7 @@ replaced_whitelisted_certificate_should_be_accepted1(Config) ->
732744
ok = amqp_connection:close(Con),
733745

734746
%% When: a whitelisted certicate is replaced with one with the same name
735-
ok = whitelist(Config, "bart", CertUpdated, KeyUpdated),
747+
ok = whitelist(Config, "bart", CertUpdated),
736748

737749
wait_for_trust_store_refresh(),
738750

@@ -797,10 +809,10 @@ ignore_corrupt_cert1(Config) ->
797809
{_, CertTrusted, KeyTrusted} = ct_helper:make_certs(),
798810

799811
rabbit_trust_store:refresh(),
800-
ok = whitelist(Config, "alice", CertTrusted, KeyTrusted),
812+
ok = whitelist(Config, "alice", CertTrusted),
801813

802814
%% When: Rabbit tries to whitelist the corrupt certificate.
803-
ok = whitelist(Config, "corrupt", <<48>>, KeyTrusted),
815+
ok = whitelist(Config, "corrupt", <<48>>),
804816
rabbit_trust_store:refresh(),
805817

806818
catch rabbit_networking:stop_tcp_listener(Port),
@@ -835,9 +847,9 @@ ignore_same_cert_with_different_name1(Config) ->
835847
{_, CertTrusted, KeyTrusted} = ct_helper:make_certs(),
836848

837849
rabbit_trust_store:refresh(),
838-
ok = whitelist(Config, "alice", CertTrusted, KeyTrusted),
850+
ok = whitelist(Config, "alice", CertTrusted),
839851
%% When: Rabbit tries to insert the duplicate certificate
840-
ok = whitelist(Config, "malice", CertTrusted, KeyTrusted),
852+
ok = whitelist(Config, "malice", CertTrusted),
841853
rabbit_trust_store:refresh(),
842854

843855
catch rabbit_networking:stop_tcp_listener(Port),
@@ -872,8 +884,8 @@ list(Config) ->
872884
ok = rabbit_ct_broker_helpers:rpc(Config, 0, rabbit_trust_store, refresh, []),
873885
timer:sleep(2000),
874886

875-
{_Root, Cert, Key} = ct_helper:make_certs(),
876-
ok = whitelist(Config, "alice", Cert, Key),
887+
{_Root, Cert, _Key} = ct_helper:make_certs(),
888+
ok = whitelist(Config, "alice", Cert),
877889
% wait_for_trust_store_refresh(),
878890
ok = rabbit_ct_broker_helpers:rpc(Config, 0, rabbit_trust_store, refresh, []),
879891
Certs = rabbit_ct_broker_helpers:rpc(Config, 0,
@@ -882,8 +894,8 @@ list(Config) ->
882894
{match, _} = re:run(Certs, ".*alice\.pem.*").
883895

884896
disabled_provider_removes_certificates(Config) ->
885-
{_Root, Cert, Key} = ct_helper:make_certs(),
886-
ok = whitelist(Config, "alice", Cert, Key),
897+
{_Root, Cert, _Key} = ct_helper:make_certs(),
898+
ok = whitelist(Config, "alice", Cert),
887899
ok = rabbit_ct_broker_helpers:rpc(Config, 0, rabbit_trust_store, refresh, []),
888900

889901
%% Certificate is there
@@ -902,8 +914,8 @@ disabled_provider_removes_certificates(Config) ->
902914
nomatch = re:run(CertsAfterDelete, ".*alice\.pem.*").
903915

904916
enabled_provider_adds_cerificates(Config) ->
905-
{_Root, Cert, Key} = ct_helper:make_certs(),
906-
ok = whitelist(Config, "alice", Cert, Key),
917+
{_Root, Cert, _Key} = ct_helper:make_certs(),
918+
ok = whitelist(Config, "alice", Cert),
907919
ok = rabbit_ct_broker_helpers:rpc(Config, 0,
908920
?MODULE, change_configuration,
909921
[rabbitmq_trust_store, [{directory, whitelist_dir(Config)},
@@ -949,9 +961,9 @@ cfg() ->
949961
%% Ancillary
950962

951963
chain(Issuer) ->
952-
%% Theses are DER encoded.
953-
{Certificate, {Kind, Key, _}} = erl_make_certs:make_cert([{issuer, Issuer}]),
954-
{Certificate, {Kind, Key}}.
964+
%% These are DER encoded.
965+
TestData = public_key:pkix_test_data(#{root => Issuer, peer => [{key, {rsa, 2048, 17}}]}),
966+
{proplists:get_value(cert, TestData), proplists:get_value(key, TestData)}.
955967

956968
change_configuration(App, Props) ->
957969
ok = application:stop(App),
@@ -964,10 +976,10 @@ change_cfg(App, [{Name,Value}|Rest]) ->
964976
ok = application:set_env(App, Name, Value),
965977
change_cfg(App, Rest).
966978

967-
whitelist(Config, Filename, Certificate, {A, B} = _Key) ->
979+
whitelist(Config, Filename, Certificate) ->
968980
Path = whitelist_dir(Config),
969-
ok = erl_make_certs:write_pem(Path, Filename, {Certificate, {A, B, not_encrypted}}),
970-
[file:delete(filename:join(Path, K)) || K <- filelib:wildcard("*_key.pem", Path)],
981+
ok = file:write_file(filename:join(Path, Filename ++ ".pem"),
982+
public_key:pem_encode([{'Certificate', Certificate, not_encrypted}])),
971983
ok.
972984

973985
delete(Name, Config) ->

moduleindex.yaml

-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@ credentials_obfuscation:
6969
ct_helper:
7070
- ct_helper
7171
- ct_helper_error_h
72-
- erl_make_certs
7372
cuttlefish:
7473
- conf_parse
7574
- cuttlefish

0 commit comments

Comments
 (0)