Now with patch attached, thanks Fred :)
On 04/20/2017 03:05 PM, Sander Hoentjen wrote:
> A new patch, that puts the order like this:
> config:
> crt A crt B
>
> if A contains wildcard, but not exact match, then wildcard is used.
> if A contains exact match, exact match is used.
> (this also means that if A contains both wildcard and exact match, exact
> match is used.)
> If A contains wildcard, and B contains exact match, then wildcard is used.
>
> This last one is different behavior from what is implemented now.
>
>
>
>
>
> On 04/18/2017 12:09 PM, Sander Hoentjen wrote:
>> On 04/18/2017 11:52 AM, Willy Tarreau wrote:
>>> Hi Daniel,
>>>
>>> On Tue, Apr 18, 2017 at 11:25:43AM +0200, Daniel Schneller wrote:
>>>> Hi!
>>>>
>>>> Not being very familiar with the code, so I thought I'd ask before
>>>> something
>>>> changes unexpectedly :)
>>>> I asked about certificate ordering a while ago, too, and I seem to remember
>>>> (and we currently rely on this) that exact domain matches are "weighted
>>>> higher" than wildcard matches on purpose, so that if I just dump the
>>>> certificates in a directory, it will pick a more specific one over a
>>>> wildcard
>>>> that is also there as a "catchall".
>>>>
>>>> Not saying one or the other is right or wrong, but if this should be
>>>> merged,
>>>> it must be made very clear that people might have to change their setups.
>>> FQDN matches always have precedence over wildcards (fortunately). Sander,
>>> I'm a bit surprized by your motivation for this change. You always want
>>> foo.example.com to have precedence over *.example.com and this is not a
>>> matter of directory. By changing this you'd silently break some certs by
>>> presenting the wrong one (the wildcard one) instead of the fully qualified
>>> name. If you have any reason for wanting to do that anyway, I think this
>>> is the wrong approach and you should instead refuse to load domain certs
>>> when they conflict with a wildcard, or at least emit a warning indicating
>>> that there's overlapping. But that still seems very strange to me :-/
>> Hi Willy,
>>
>> In our case we always request Let's Encrypt certificates for all our
>> customers. We put those in a directory that is loaded last. When a
>> customer buys a certificate himself this certificate is put in a
>> directory that is loaded before the Let's Encrypt ones. If a customer
>> has bought a certificate he always wants that certificate to be used,
>> even if it is a wildcard. If and when a customer removes his own cert,
>> he will always still have working SSL.
>>
>> Regards,
>> Sander
>>
>
diff --git a/include/types/ssl_sock.h b/include/types/ssl_sock.h
index e71ba79..b382f0b 100644
--- a/include/types/ssl_sock.h
+++ b/include/types/ssl_sock.h
@@ -27,6 +27,7 @@
struct sni_ctx {
SSL_CTX *ctx; /* context associated to the certificate */
+ int dirorder; /* directive order for the certificate */
int order; /* load order for the certificate */
int neg; /* reject if match */
struct ebmb_node name; /* node holding the servername value */
diff --git a/src/ssl_sock.c b/src/ssl_sock.c
index a9a8f06..9344048 100644
--- a/src/ssl_sock.c
+++ b/src/ssl_sock.c
@@ -130,6 +130,7 @@ enum {
int sslconns = 0;
int totalsslconns = 0;
+int dirorder = 0;
#if (defined SSL_CTRL_SET_TLSEXT_TICKET_KEY_CB && TLS_TICKETS_NO > 0)
struct list tlskeys_reference = LIST_HEAD_INIT(tlskeys_reference);
@@ -1453,9 +1454,12 @@ static int ssl_sock_switchctx_cbk(SSL *ssl, int *al, struct bind_conf *s)
break;
}
}
- if (!node && wildp) {
+ if (wildp) {
/* lookup in wildcards names */
- node = ebst_lookup(&s->sni_w_ctx, wildp);
+ n = ebst_lookup(&s->sni_w_ctx, wildp);
+ if (!node || n && container_of(n, struct sni_ctx, name)->dirorder < container_of(node, struct sni_ctx, name)->dirorder) {
+ node = n;
+ }
}
if (!node || container_of(node, struct sni_ctx, name)->neg) {
SSL_CTX *ctx;
@@ -1785,6 +1789,7 @@ static int ssl_sock_add_cert_sni(SSL_CTX *ctx, struct bind_conf *s, char *name,
return order;
memcpy(sc->name.key, trash.str, len + 1);
sc->ctx = ctx;
+ sc->dirorder = dirorder;
sc->order = order++;
sc->neg = neg;
if (wild)
@@ -5208,6 +5213,7 @@ static int bind_parse_ciphers(char **args, int cur_arg, struct proxy *px, struct
static int bind_parse_crt(char **args, int cur_arg, struct proxy *px, struct bind_conf *conf, char **err)
{
char path[MAXPATHLEN];
+ dirorder += 1;
if (!*args[cur_arg + 1]) {
memprintf(err, "'%s' : missing certificate location", args[cur_arg]);
@@ -5235,6 +5241,7 @@ static int bind_parse_crt(char **args, int cur_arg, struct proxy *px, struct bin
/* parse the "crt-list" bind keyword */
static int bind_parse_crt_list(char **args, int cur_arg, struct proxy *px, struct bind_conf *conf, char **err)
{
+ dirorder += 1;
if (!*args[cur_arg + 1]) {
memprintf(err, "'%s' : missing certificate location", args[cur_arg]);
return ERR_ALERT | ERR_FATAL;