Skip to content

Commit a747fd5

Browse files
committed
Tests: test external account binding support.
1 parent 597b40d commit a747fd5

File tree

1 file changed

+179
-0
lines changed

1 file changed

+179
-0
lines changed

t/acme_external_account.t

Lines changed: 179 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,179 @@
1+
#!/usr/bin/perl
2+
3+
# Copyright (c) F5, Inc.
4+
#
5+
# This source code is licensed under the Apache License, Version 2.0 license
6+
# found in the LICENSE file in the root directory of this source tree.
7+
8+
# Tests for ACME client: External Account Binding support.
9+
10+
###############################################################################
11+
12+
use warnings;
13+
use strict;
14+
15+
use Test::More;
16+
17+
BEGIN { use FindBin; chdir($FindBin::Bin); }
18+
19+
use lib 'lib';
20+
use Test::Nginx;
21+
use Test::Nginx::ACME;
22+
use Test::Nginx::DNS;
23+
24+
###############################################################################
25+
26+
select STDERR; $| = 1;
27+
select STDOUT; $| = 1;
28+
29+
my $t = Test::Nginx->new()->has(qw/http http_ssl sni socket_ssl_sni/)
30+
->has_daemon('openssl');
31+
32+
$t->write_file_expand('nginx.conf', <<'EOF');
33+
34+
%%TEST_GLOBALS%%
35+
36+
daemon off;
37+
38+
events {
39+
}
40+
41+
http {
42+
%%TEST_GLOBALS_HTTP%%
43+
44+
resolver 127.0.0.1:%%PORT_8980_UDP%%;
45+
46+
acme_issuer eab-data {
47+
uri https://acme.test:%%PORT_9000%%/dir;
48+
external_account_key eab-data
49+
data:0Xl6zTksEz1MqVDw5dn680nma9vYwJoI30LjRdbrDSjTfRxtcX_6YOAYzVDImRQV;
50+
ssl_trusted_certificate acme.test.crt;
51+
state_path %%TESTDIR%%/eab-data;
52+
accept_terms_of_service;
53+
}
54+
55+
acme_issuer eab-file {
56+
uri https://acme.test:%%PORT_9000%%/dir;
57+
external_account_key eab-file eab-secret;
58+
ssl_trusted_certificate acme.test.crt;
59+
state_path %%TESTDIR%%/eab-file;
60+
accept_terms_of_service;
61+
}
62+
63+
server {
64+
listen 127.0.0.1:8080;
65+
server_name example.test;
66+
}
67+
68+
server {
69+
listen 127.0.0.1:8443 ssl;
70+
server_name data.example.test;
71+
72+
acme_certificate eab-data;
73+
74+
ssl_certificate $acme_certificate;
75+
ssl_certificate_key $acme_certificate_key;
76+
}
77+
78+
server {
79+
listen 127.0.0.1:8443 ssl;
80+
server_name file.example.test;
81+
82+
acme_certificate eab-file;
83+
84+
ssl_certificate $acme_certificate;
85+
ssl_certificate_key $acme_certificate_key;
86+
}
87+
}
88+
89+
EOF
90+
91+
$t->write_file('openssl.conf', <<EOF);
92+
[ req ]
93+
default_bits = 2048
94+
encrypt_key = no
95+
distinguished_name = req_distinguished_name
96+
[ req_distinguished_name ]
97+
EOF
98+
99+
my $d = $t->testdir();
100+
101+
foreach my $name ('acme.test') {
102+
system('openssl req -x509 -new '
103+
. "-config $d/openssl.conf -subj /CN=$name/ "
104+
. "-out $d/$name.crt -keyout $d/$name.key "
105+
. ">>$d/openssl.out 2>&1") == 0
106+
or die "Can't create certificate for $name: $!\n";
107+
}
108+
109+
my $dp = port(8980, udp=>1);
110+
my @dc = (
111+
{ name => 'acme.test', A => '127.0.0.1' },
112+
{ name => 'data.example.test', A => '127.0.0.1' },
113+
{ name => 'file.example.test', A => '127.0.0.1' }
114+
);
115+
116+
my $eab_secret = gen_hmac_secret(48);
117+
118+
my $acme = Test::Nginx::ACME->new($t, port(9000), port(9001),
119+
$t->testdir . '/acme.test.crt',
120+
$t->testdir . '/acme.test.key',
121+
http_port => port(8080),
122+
dns_port => $dp,
123+
conf => {
124+
externalAccountBindingRequired => \1,
125+
externalAccountMACKeys => {
126+
'eab-data' =>
127+
'0Xl6zTksEz1MqVDw5dn680nma9vYwJoI3'
128+
. '0LjRdbrDSjTfRxtcX_6YOAYzVDImRQV',
129+
'eab-file' => $eab_secret
130+
},
131+
}
132+
)->has(qw/eab/);
133+
134+
$t->run_daemon(\&Test::Nginx::DNS::dns_test_daemon, $t, $dp, \@dc);
135+
$t->waitforfile($t->testdir . '/' . $dp);
136+
137+
$t->run_daemon(\&Test::Nginx::ACME::acme_test_daemon, $t, $acme);
138+
$t->waitforsocket('127.0.0.1:' . $acme->port());
139+
$t->write_file('acme-root.crt', $acme->trusted_ca());
140+
$t->write_file('eab-secret', $eab_secret);
141+
142+
$t->write_file('index.html', 'SUCCESS');
143+
$t->plan(2)->run();
144+
145+
###############################################################################
146+
147+
$acme->wait_certificate('eab-data/data.example.test') or die "no certificate";
148+
$acme->wait_certificate('eab-file/file.example.test') or die "no certificate";
149+
150+
like(get(8443, 'data.example.test', 'acme-root'), qr/SUCCESS/, 'inline key');
151+
like(get(8443, 'file.example.test', 'acme-root'), qr/SUCCESS/, 'key file');
152+
153+
###############################################################################
154+
155+
sub get {
156+
my ($port, $host, $ca) = @_;
157+
158+
$ca = undef if $IO::Socket::SSL::VERSION < 2.062
159+
|| !eval { Net::SSLeay::X509_V_FLAG_PARTIAL_CHAIN() };
160+
161+
http_get('/',
162+
PeerAddr => '127.0.0.1:' . port($port),
163+
SSL => 1,
164+
SSL_hostname => $host,
165+
$ca ? (
166+
SSL_ca_file => "$d/$ca.crt",
167+
SSL_verifycn_name => $host,
168+
SSL_verify_mode => IO::Socket::SSL::SSL_VERIFY_PEER(),
169+
) : ()
170+
);
171+
}
172+
173+
sub gen_hmac_secret {
174+
my ($len) = @_;
175+
my @dict = ('A' .. 'Z', 'a' .. 'z', '0' .. '9', '-', '_');
176+
return join '' => map $dict[rand @dict], 1 .. ($len * 4 / 3);
177+
}
178+
179+
###############################################################################

0 commit comments

Comments
 (0)