← Back to Pull requests

Spot certificate rejections reported by BoringSSL (Electron) #231

Closed
unknown closed this pull request without merging on Nov 11, 2026 16:53 UTC
View on GitHub
unknown unknown commented on Nov 09, 2026 12:59 UTC
Author

getCauseFromError spots a client rejecting the certificate by OpenSSL's wording of the TLS alert, such as "tls alert certificate unknown". When Mockttp runs on BoringSSL, as it does inside Electron, the same alerts are worded only in upper case (...:SSL routines:OPENSSL_internal:SSLV3_ALERT_CERTIFICATE_UNKNOWN:...). So they become 'unknown' and are logged as "Unknown TLS error". Only bad_certificate is already caught, by its error code (ERR_SSL_SSLV3_ALERT_BAD_CERTIFICATE).

Repro

A plain Mockttp server, with a client that answers the server's certificate with each alert:

// Run with `node repro.js`, then `ELECTRON_RUN_AS_NODE=1 electron repro.js`.
const net = require('net'), tls = require('tls'), { Duplex } = require('stream');
const { getLocal, generateCACertificate } = require('mockttp');

// Starts a TLS 1.2 handshake and answers the server's certificate with a fatal alert.
const refuse = (port, alert) => new Promise((resolve) => {
    const raw = net.connect(port, '127.0.0.1');
    const relay = new Duplex({ read() {}, write(c, _e, done) { raw.write(c, () => done()); } });
    raw.once('data', () => raw.end(Buffer.from([0x15, 3, 3, 0, 2, 2, alert])));
    raw.on('data', (d) => relay.push(d)).on('close', resolve).on('error', () => {});
    tls.connect({ socket: relay, servername: 'example.com', maxVersion: 'TLSv1.2' }).on('error', () => {});
});

(async () => {
    const server = getLocal({ https: await generateCACertificate() });
    let cause;
    await server.on('tls-client-error', (e) => { cause = e.failureCause; });
    await server.start();
    for (const alert of [42, 44, 45, 46, 48, 116, 40, 43]) {
        cause = undefined;
        await refuse(server.port, alert);
        await new Promise((r) => setTimeout(r, 100));
        console.log(`alert ${alert}: ${cause}`);
    }
    await server.stop();
})();

Results with Mockttp 4.6.4:

| Alert | Node 26 (OpenSSL 4.1) | Electron 45 (BoringSSL) |
|---|---|---|
| bad_certificate (42) | cert-rejected | cert-rejected |
| certificate_revoked (44) | cert-rejected | unknown |
| certificate_expired (45) | cert-rejected | unknown |
| certificate_unknown (46), Chrome's | cert-rejected | unknown |
| unknown_ca (48) | cert-rejected | unknown |
| certificate_required (116) | cert-rejected | unknown |
| handshake_failure (40) | unknown | unknown |
| unsupported_certificate (43) | unknown | unknown |

Fix

The single error-code check becomes a pattern covering the alerts the message checks already catch: bad certificate, certificate unknown, expired, revoked or required, and unknown CA. It matches the codes of both libraries, such as ERR_SSL_SSLV3_ALERT_CERTIFICATE_UNKNOWN, ERR_SSL_TLS_ALERT_CERTIFICATE_UNKNOWN and ERR_SSL_SSL/TLS_ALERT_CERTIFICATE_UNKNOWN. With the fix, both runtimes give the Node column above for all eight alerts. Other alerts are unchanged, including unsupported_certificate, which OpenSSL doesn't count either.

Test

test/tls-error-cause.spec.ts checks getCauseFromError (now exported) with errors copied from real runs. It covers OpenSSL and BoringSSL rejections, and other alerts that aren't rejections. The BoringSSL case fails without the fix. I didn't add an integration test, because the Node test runs can't produce BoringSSL's wording.

Found while running Mockttp inside an Electron app, where Chrome on an Android device refusing the certificate always showed as 'unknown'.

The Node test suite passes locally (mocha test/*/.spec.ts: 854 passing, 2 pending). I haven't run the browser tests, but this code is server-side only.

🤖 Generated with Claude Code

Diff: 458 lines (+343 / -115) across 5 files Reviewer: pimterry Review duration: 3113m
All Vouch review confidence checks passed
Residual risk 0.18 = Change Risk (0.46) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.46 · 458 lines diff across 5 files
0.46
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
0.17
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
60%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size diff_size
0.367
Shallow Review Depth shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #231"
general weight: 0.35
Reviewers
Assignees
Unassigned
Labels
risk: low confidence: 60.5% reviewed
Vouch Risk Breakdown
AI-powered review risk analysis
Change Risk
Change Risk · Model 1 (XGBoost)
Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
Score: 45.5% (MEDIUM) · Higher = larger blast radius
45.5%
Review Confidence
Review Confidence · Models 2 & 3
Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
Score: 60.5% · Lower = rushed or shallow review
60.5%
Residual Risk
Residual Risk · Core Equation
Residual = Change × (1 − Confidence)
Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
Score: 18.0% · Safe to merge
18.0%