@@ -50,28 +50,28 @@ mail {
50
50
ssl_certificate 1.example.com.crt;
51
51
52
52
server {
53
- listen 127.0.0.1:8142 ;
53
+ listen 127.0.0.1:8143 ;
54
54
protocol imap;
55
55
}
56
56
57
57
server {
58
- listen 127.0.0.1:8143 ssl;
58
+ listen 127.0.0.1:8993 ssl;
59
59
protocol imap;
60
60
61
61
ssl_verify_client on;
62
62
ssl_client_certificate 2.example.com.crt;
63
63
}
64
64
65
65
server {
66
- listen 127.0.0.1:8145 ssl;
66
+ listen 127.0.0.1:8994 ssl;
67
67
protocol imap;
68
68
69
69
ssl_verify_client optional;
70
70
ssl_client_certificate 2.example.com.crt;
71
71
}
72
72
73
73
server {
74
- listen 127.0.0.1:8146 ssl;
74
+ listen 127.0.0.1:8995 ssl;
75
75
protocol imap;
76
76
77
77
ssl_verify_client optional;
80
80
}
81
81
82
82
server {
83
- listen 127.0.0.1:8147 ssl;
83
+ listen 127.0.0.1:8996 ssl;
84
84
protocol imap;
85
85
86
86
ssl_verify_client optional_no_ca;
@@ -140,68 +140,63 @@ $t->run()->waitforsocket('127.0.0.1:' . port(8144));
140
140
# ##############################################################################
141
141
142
142
my $cred = sub { encode_base64(" \0 test\@ example.com\0 $_ [0]" , ' ' ) };
143
- my %ssl = (
144
- SSL => 1,
145
- SSL_verify_mode => IO::Socket::SSL::SSL_VERIFY_NONE(),
146
- SSL_error_trap => sub { die $_ [1] },
147
- );
148
143
149
144
# no ssl connection
150
145
151
- my $s = Test::Nginx::IMAP-> new(PeerAddr => ' 127.0.0.1: ' . port(8142) );
146
+ my $s = Test::Nginx::IMAP-> new();
152
147
$s -> ok(' plain connection' );
153
148
$s -> send (' 1 AUTHENTICATE PLAIN ' . $cred -> (" s1" ));
154
149
155
150
# no cert
156
151
157
- $s = Test::Nginx::IMAP-> new(PeerAddr => ' 127.0.0.1: ' . port(8143), %ssl );
152
+ $s = Test::Nginx::IMAP-> new(SSL => 1 );
158
153
$s -> check(qr / BYE No required SSL certificate/ , ' no cert' );
159
154
160
155
# no cert with ssl_verify_client optional
161
156
162
- $s = Test::Nginx::IMAP-> new(PeerAddr => ' 127.0.0.1:' . port(8145 ), %ssl );
157
+ $s = Test::Nginx::IMAP-> new(PeerAddr => ' 127.0.0.1:' . port(8994 ), SSL => 1 );
163
158
$s -> ok(' no optional cert' );
164
159
$s -> send (' 1 AUTHENTICATE PLAIN ' . $cred -> (" s2" ));
165
160
166
161
# wrong cert with ssl_verify_client optional
167
162
168
163
$s = Test::Nginx::IMAP-> new(
169
- PeerAddr => ' 127.0.0.1:' . port(8145),
164
+ PeerAddr => ' 127.0.0.1:' . port(8995),
165
+ SSL => 1,
170
166
SSL_cert_file => " $d /1.example.com.crt" ,
171
- SSL_key_file => " $d /1.example.com.key" ,
172
- %ssl ,
167
+ SSL_key_file => " $d /1.example.com.key"
173
168
);
174
169
$s -> check(qr / BYE SSL certificate error/ , ' bad optional cert' );
175
170
176
171
# wrong cert with ssl_verify_client optional_no_ca
177
172
178
173
$s = Test::Nginx::IMAP-> new(
179
- PeerAddr => ' 127.0.0.1:' . port(8147),
174
+ PeerAddr => ' 127.0.0.1:' . port(8996),
175
+ SSL => 1,
180
176
SSL_cert_file => " $d /1.example.com.crt" ,
181
- SSL_key_file => " $d /1.example.com.key" ,
182
- %ssl ,
177
+ SSL_key_file => " $d /1.example.com.key"
183
178
);
184
179
$s -> ok(' bad optional_no_ca cert' );
185
180
$s -> send (' 1 AUTHENTICATE PLAIN ' . $cred -> (" s3" ));
186
181
187
182
# matching cert with ssl_verify_client optional
188
183
189
184
$s = Test::Nginx::IMAP-> new(
190
- PeerAddr => ' 127.0.0.1:' . port(8145),
185
+ PeerAddr => ' 127.0.0.1:' . port(8995),
186
+ SSL => 1,
191
187
SSL_cert_file => " $d /2.example.com.crt" ,
192
- SSL_key_file => " $d /2.example.com.key" ,
193
- %ssl ,
188
+ SSL_key_file => " $d /2.example.com.key"
194
189
);
195
190
$s -> ok(' good cert' );
196
191
$s -> send (' 1 AUTHENTICATE PLAIN ' . $cred -> (" s4" ));
197
192
198
193
# trusted cert with ssl_verify_client optional
199
194
200
195
$s = Test::Nginx::IMAP-> new(
201
- PeerAddr => ' 127.0.0.1:' . port(8146),
196
+ PeerAddr => ' 127.0.0.1:' . port(8995),
197
+ SSL => 1,
202
198
SSL_cert_file => " $d /3.example.com.crt" ,
203
- SSL_key_file => " $d /3.example.com.key" ,
204
- %ssl ,
199
+ SSL_key_file => " $d /3.example.com.key"
205
200
);
206
201
$s -> ok(' trusted cert' );
207
202
$s -> send (' 1 AUTHENTICATE PLAIN ' . $cred -> (" s5" ));
@@ -211,9 +206,9 @@ $s->read();
211
206
212
207
my ($cipher , $sslversion );
213
208
214
- $s = get_ssl_socket(8143 );
215
- $cipher = $s -> get_cipher();
216
- $sslversion = $s -> get_sslversion();
209
+ $s = Test::Nginx::IMAP -> new( SSL => 1 );
210
+ $cipher = $s -> socket () -> get_cipher();
211
+ $sslversion = $s -> socket () -> get_sslversion();
217
212
$sslversion =~ s / _/ ./ ;
218
213
219
214
undef $s ;
@@ -242,31 +237,3 @@ like($f, qr|^$cipher:$sslversion$|m, 'log - cipher sslversion');
242
237
}
243
238
244
239
# ##############################################################################
245
-
246
- sub get_ssl_socket {
247
- my ($port ) = @_ ;
248
- my $s ;
249
-
250
- eval {
251
- local $SIG {ALRM } = sub { die " timeout\n " };
252
- local $SIG {PIPE } = sub { die " sigpipe\n " };
253
- alarm(8);
254
- $s = IO::Socket::SSL-> new(
255
- Proto => ' tcp' ,
256
- PeerAddr => ' 127.0.0.1:' . port($port ),
257
- SSL_verify_mode => IO::Socket::SSL::SSL_VERIFY_NONE(),
258
- SSL_error_trap => sub { die $_ [1] }
259
- );
260
- alarm(0);
261
- };
262
- alarm(0);
263
-
264
- if ($@ ) {
265
- log_in(" died: $@ " );
266
- return undef ;
267
- }
268
-
269
- return $s ;
270
- }
271
-
272
- # ##############################################################################
0 commit comments