summaryrefslogtreecommitdiff
path: root/jstests/ssl/ssl_alert_reporting.js
blob: f5ca56508960b25b7141f1498d7305e36d3a9984 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
// Ensure that TLS version alerts are correctly propagated

load('jstests/ssl/libs/ssl_helpers.js');

(function() {
    'use strict';

    const clientOptions = [
        "--ssl",
        "--sslPEMKeyFile",
        "jstests/libs/client.pem",
        "--sslCAFile",
        "jstests/libs/ca.pem",
        "--eval",
        ";"
    ];

    function runTest(serverDisabledProtos, clientDisabledProtos) {
        let expectedRegex = /tlsv1 alert protocol version/;

        var md = MongoRunner.runMongod({
            nopreallocj: "",
            sslMode: "requireSSL",
            sslCAFile: "jstests/libs/ca.pem",
            sslPEMKeyFile: "jstests/libs/server.pem",
            sslDisabledProtocols: serverDisabledProtos,
            waitForConnect: false,
        });

        assert.soon(function() {
            clearRawMongoProgramOutput();
            let shell = runMongoProgram("mongo",
                                        "--port",
                                        md.port,
                                        ...clientOptions,
                                        "--sslDisabledProtocols",
                                        clientDisabledProtos);
            let mongoOutput = rawMongoProgramOutput();
            return mongoOutput.match(expectedRegex);
        });

        MongoRunner.stopMongod(md);
    }

    // Client recieves and reports a protocol version alert if it advertises a protocol older than
    // the server's oldest supported protocol
    runTest("TLS1_0", "TLS1_1,TLS1_2");
}());