networking · beginner · ~15 min

Is the TLS version acceptable?

Gate on a minimum protocol version.

Challenge

TLS versions are encoded as a (major, minor) pair on the wire: TLS 1.2 is (3,3) and TLS 1.3 is (3,4). Modern servers reject the deprecated TLS 1.0/1.1. Gate a version against a minimum of TLS 1.2.

Task

Implement int tls_version_ok(int major, int minor) that returns 1 if the version is TLS 1.2 or newer (major == 3 and minor >= 3), otherwise 0.

Input

  • major, minor: the wire version pair.

Output

Returns 1 if the version is acceptable (TLS 1.2+), else 0.

Example

tls_version_ok(3, 3)   ->   1   (TLS 1.2)
tls_version_ok(3, 4)   ->   1   (TLS 1.3)
tls_version_ok(3, 1)   ->   0   (TLS 1.0, too old)

Edge cases

  • A non-3 major version is not acceptable.

Input format

Two integers: the wire major and minor TLS version.

Output format

1 if major == 3 and minor >= 3 (TLS 1.2+), else 0.

Constraints

TLS 1.2 is (3,3) and TLS 1.3 is (3,4); accept major 3 with minor >= 3.

Starter code

int tls_version_ok(int major, int minor) {
    /* TODO */
    return 0;
}

Solve this exercise in the browser editor — compile and run against the test harness, no setup required.