Fix OCSP Stapling Issues with Nginx and LibreSSL on FreeBSD 12.0-STABLE

nginxocspSecurityssl

After hours of trying I have to get help for my issue.
I am trying to get OCSP stapling to work with my setup, but am not successful in doing so.

Here is my nginx configuration, without any non-relevant bits.

user www www;
worker_processes 5;
error_log /var/log/nginx/error.log;
events {
    worker_connections 1024;
}

http {
include mime.types;
index index.html index.htm;

log_format   main '$remote_addr - $remote_user [$time_local]  $status '
'"$request" $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';

aio on;

sendfile on;
autoindex on;
autoindex_exact_size off;

tcp_nopush on;
tcp_nodelay on;

ignore_invalid_headers on;

keepalive_timeout 70;

gzip on;
gzip_comp_level 5;
gzip_min_length 256;
gzip_proxied any;
gzip_types text/plain text/css application/xml application/javascript application/json font/opentype text/cache-manifest text/x-cross-domain-policy text/xml application/x-javascript;
gzip_vary on;

ssl_certificate fullchain.pem;
ssl_certificate_key server.key;
ssl_trusted_certificate trusted.pem;
ssl_protocols TLSv1.2 TLSv1.3;
ssl_ciphers 'ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA256';
ssl_ecdh_curve secp384r1;
ssl_prefer_server_ciphers on;
ssl_dhparam dh4096.pem;
ssl_session_timeout 10m;
ssl_session_cache shared:SSL:10m;
ssl_session_tickets off;
ssl_stapling on;
ssl_stapling_verify on;
resolver 1.1.1.1 1.0.0.1 valid=300s;
resolver_timeout 5s;
add_header Strict-Transport-Security "max-age=63072000";
add_header X-Frame-Options "DENY";
add_header X-Content-Type-Options nosniff;
add_header X-XSS-Protection "1, mode=block";
add_header Content-Security-Policy "upgrade-insecure-requests";
map "$scheme:$http_upgrade_insecure_requests" $shouldUpgrade {
    default 0;
    "http:1" 1;
}

map $http_accept $webp_suffix {
    default "";
    "~*webp" ".webp";
}

expires -1;
add_header Cache-Control "public";

server {
    listen 80;

    listen [::]:80;
    listen 443 ssl http2;

    server_name localhost ;
    access_log /var/log/nginx/access.log main;
    root /www/;
    error_page 404 /404.html;

    if ($shouldUpgrade) {
        return 307 https://$host$request_uri;
    }

}
}

I am getting an error in the log files:

2019/04/30 21:28:07 [error] 28718#100839: OCSP_basic_verify() failed (SSL: error:27FFF076:OCSP routines:CRYPTO_internal:signer certificate not found) while requesting certificate status, responder: ocsp.int-x3.letsencrypt.org, peer: 2.16.100.83:80, certificate: "/usr/local/etc/nginx/fullchain.pem"

No matter what I try to include in the file given to ssl_trusted_certificate, I could not fix this. I tried including the full chain, adding the root CA to it, only the CA, only the intermediary.
Adding the root CA into the fullchain.pem file given to ssl_certificate results in errors on SSL verification websites.

Despite all of that, I am still prompted by a OCSP Stapling not enabled. on https://ssldecoder.org and OCSP response: no response sent when using openssl s_client

Any help would be appreciated. I am using let's encrypt.

Best Answer

FreeBSD security/libressl was recently upgraded to 2.9.1. OCSP stapling has stopped working in nginx for me as well since the version change in LibreSSL, so I'm assuming there is an underlying issue in the library or nginx' interaction with it.

Edit: In the meantime, Elias Ohm has analyzed this in more detail on the FreeBSD bug tracker. TL;DR: It's an nginx bug, it's using the wrong function to access the certificate chain when using the newer OpenSSL API.