Mercurial > hg > nginx
annotate src/core/ngx_rwlock.c @ 7360:8f25a44d9add
SSL: logging level of "no suitable key share".
The "no suitable key share" errors are reported by OpenSSL 1.1.1 when
using TLSv1.3 if there are no shared groups (that is, elliptic curves).
In particular, it is easy enough to trigger by using only a single
curve in ssl_ecdh_curve:
ssl_ecdh_curve secp384r1;
and using a different curve in the client:
openssl s_client -connect 127.0.0.1:443 -curves prime256v1
On the client side it is seen as "sslv3 alert handshake failure",
"SSL alert number 40":
0:error:14094410:SSL routines:ssl3_read_bytes:sslv3 alert handshake failure:ssl/record/rec_layer_s3.c:1528:SSL alert number 40
It can be also triggered with default ssl_ecdh_curve by using a curve
which is not in the default list (X25519, prime256v1, X448, secp521r1,
secp384r1):
openssl s_client -connect 127.0.0.1:8443 -curves brainpoolP512r1
Given that many clients hardcode prime256v1, these errors might become
a common problem with TLSv1.3 if ssl_ecdh_curve is redefined. Previously
this resulted in not using ECDH with such clients, but with TLSv1.3 it
is no longer possible and will result in a handshake failure.
The SSL_R_NO_SHARED_GROUP error is what BoringSSL returns in the same
situation.
Seen at:
https://serverfault.com/questions/932102/nginx-ssl-handshake-error-no-suitable-key-share
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Tue, 25 Sep 2018 13:59:53 +0300 |
parents | d1816a2696de |
children | 7752d8523066 |
rev | line source |
---|---|
6101 | 1 |
2 /* | |
3 * Copyright (C) Ruslan Ermilov | |
4 * Copyright (C) Nginx, Inc. | |
5 */ | |
6 | |
7 | |
8 #include <ngx_config.h> | |
9 #include <ngx_core.h> | |
10 | |
11 | |
12 #if (NGX_HAVE_ATOMIC_OPS) | |
13 | |
14 | |
15 #define NGX_RWLOCK_SPIN 2048 | |
16 #define NGX_RWLOCK_WLOCK ((ngx_atomic_uint_t) -1) | |
17 | |
18 | |
19 void | |
20 ngx_rwlock_wlock(ngx_atomic_t *lock) | |
21 { | |
22 ngx_uint_t i, n; | |
23 | |
24 for ( ;; ) { | |
25 | |
26 if (*lock == 0 && ngx_atomic_cmp_set(lock, 0, NGX_RWLOCK_WLOCK)) { | |
27 return; | |
28 } | |
29 | |
30 if (ngx_ncpu > 1) { | |
31 | |
32 for (n = 1; n < NGX_RWLOCK_SPIN; n <<= 1) { | |
33 | |
34 for (i = 0; i < n; i++) { | |
35 ngx_cpu_pause(); | |
36 } | |
37 | |
38 if (*lock == 0 | |
39 && ngx_atomic_cmp_set(lock, 0, NGX_RWLOCK_WLOCK)) | |
40 { | |
41 return; | |
42 } | |
43 } | |
44 } | |
45 | |
46 ngx_sched_yield(); | |
47 } | |
48 } | |
49 | |
50 | |
51 void | |
52 ngx_rwlock_rlock(ngx_atomic_t *lock) | |
53 { | |
54 ngx_uint_t i, n; | |
55 ngx_atomic_uint_t readers; | |
56 | |
57 for ( ;; ) { | |
58 readers = *lock; | |
59 | |
60 if (readers != NGX_RWLOCK_WLOCK | |
61 && ngx_atomic_cmp_set(lock, readers, readers + 1)) | |
62 { | |
63 return; | |
64 } | |
65 | |
66 if (ngx_ncpu > 1) { | |
67 | |
68 for (n = 1; n < NGX_RWLOCK_SPIN; n <<= 1) { | |
69 | |
70 for (i = 0; i < n; i++) { | |
71 ngx_cpu_pause(); | |
72 } | |
73 | |
74 readers = *lock; | |
75 | |
76 if (readers != NGX_RWLOCK_WLOCK | |
77 && ngx_atomic_cmp_set(lock, readers, readers + 1)) | |
78 { | |
79 return; | |
80 } | |
81 } | |
82 } | |
83 | |
84 ngx_sched_yield(); | |
85 } | |
86 } | |
87 | |
88 | |
89 void | |
90 ngx_rwlock_unlock(ngx_atomic_t *lock) | |
91 { | |
92 ngx_atomic_uint_t readers; | |
93 | |
94 readers = *lock; | |
95 | |
96 if (readers == NGX_RWLOCK_WLOCK) { | |
7037
12efcdcb8a4b
Added memory barrier semantics to ngx_rwlock_unlock().
Ruslan Ermilov <ru@nginx.com>
parents:
6270
diff
changeset
|
97 (void) ngx_atomic_cmp_set(lock, NGX_RWLOCK_WLOCK, 0); |
6101 | 98 return; |
99 } | |
100 | |
101 for ( ;; ) { | |
102 | |
103 if (ngx_atomic_cmp_set(lock, readers, readers - 1)) { | |
104 return; | |
105 } | |
106 | |
107 readers = *lock; | |
108 } | |
109 } | |
110 | |
111 | |
7038
d1816a2696de
Introduced ngx_rwlock_downgrade().
Ruslan Ermilov <ru@nginx.com>
parents:
7037
diff
changeset
|
112 void |
d1816a2696de
Introduced ngx_rwlock_downgrade().
Ruslan Ermilov <ru@nginx.com>
parents:
7037
diff
changeset
|
113 ngx_rwlock_downgrade(ngx_atomic_t *lock) |
d1816a2696de
Introduced ngx_rwlock_downgrade().
Ruslan Ermilov <ru@nginx.com>
parents:
7037
diff
changeset
|
114 { |
d1816a2696de
Introduced ngx_rwlock_downgrade().
Ruslan Ermilov <ru@nginx.com>
parents:
7037
diff
changeset
|
115 if (*lock == NGX_RWLOCK_WLOCK) { |
d1816a2696de
Introduced ngx_rwlock_downgrade().
Ruslan Ermilov <ru@nginx.com>
parents:
7037
diff
changeset
|
116 *lock = 1; |
d1816a2696de
Introduced ngx_rwlock_downgrade().
Ruslan Ermilov <ru@nginx.com>
parents:
7037
diff
changeset
|
117 } |
d1816a2696de
Introduced ngx_rwlock_downgrade().
Ruslan Ermilov <ru@nginx.com>
parents:
7037
diff
changeset
|
118 } |
d1816a2696de
Introduced ngx_rwlock_downgrade().
Ruslan Ermilov <ru@nginx.com>
parents:
7037
diff
changeset
|
119 |
d1816a2696de
Introduced ngx_rwlock_downgrade().
Ruslan Ermilov <ru@nginx.com>
parents:
7037
diff
changeset
|
120 |
6103
79ddb0bdb273
Upstream: the "zone" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
6101
diff
changeset
|
121 #else |
79ddb0bdb273
Upstream: the "zone" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
6101
diff
changeset
|
122 |
6270
e769cc88f996
Core: read/write locks are also required by the Stream module.
Piotr Sikora <piotrsikora@google.com>
parents:
6103
diff
changeset
|
123 #if (NGX_HTTP_UPSTREAM_ZONE || NGX_STREAM_UPSTREAM_ZONE) |
6103
79ddb0bdb273
Upstream: the "zone" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
6101
diff
changeset
|
124 |
79ddb0bdb273
Upstream: the "zone" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
6101
diff
changeset
|
125 #error ngx_atomic_cmp_set() is not defined! |
79ddb0bdb273
Upstream: the "zone" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
6101
diff
changeset
|
126 |
6101 | 127 #endif |
6103
79ddb0bdb273
Upstream: the "zone" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
6101
diff
changeset
|
128 |
79ddb0bdb273
Upstream: the "zone" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
6101
diff
changeset
|
129 #endif |