1#! /usr/bin/env perl
2# Copyright 2015-2018 The OpenSSL Project Authors. All Rights Reserved.
3#
4# Licensed under the Apache License 2.0 (the "License").  You may not use
5# this file except in compliance with the License.  You can obtain a copy
6# in the file LICENSE in the source distribution or at
7# https://www.openssl.org/source/license.html
8
9use strict;
10use OpenSSL::Test qw/:DEFAULT cmdstr srctop_file bldtop_dir/;
11use OpenSSL::Test::Utils;
12use TLSProxy::Proxy;
13
14my $test_name = "test_sslcertstatus";
15setup($test_name);
16
17plan skip_all => "TLSProxy isn't usable on $^O"
18    if $^O =~ /^(VMS)$/;
19
20plan skip_all => "$test_name needs the dynamic engine feature enabled"
21    if disabled("engine") || disabled("dynamic-engine");
22
23plan skip_all => "$test_name needs the sock feature enabled"
24    if disabled("sock");
25
26plan skip_all => "$test_name needs the ocsp feature enabled"
27    if disabled("ocsp");
28
29plan skip_all => "$test_name needs TLS enabled"
30    if alldisabled(available_protocols("tls"))
31       || (!disabled("tls1_3") && disabled("tls1_2"));
32
33my $proxy = TLSProxy::Proxy->new(
34    \&certstatus_filter,
35    cmdstr(app(["openssl"]), display => 1),
36    srctop_file("apps", "server.pem"),
37    (!$ENV{HARNESS_ACTIVE} || $ENV{HARNESS_VERBOSE})
38);
39
40#Test 1: Sending a status_request extension in both ClientHello and
41#ServerHello but then omitting the CertificateStatus message is valid
42$proxy->clientflags("-status -no_tls1_3");
43$proxy->start() or plan skip_all => "Unable to start up Proxy for tests";
44plan tests => 1;
45ok(TLSProxy::Message->success, "Missing CertificateStatus message");
46
47sub certstatus_filter
48{
49    my $proxy = shift;
50
51    # We're only interested in the initial ServerHello
52    if ($proxy->flight != 1) {
53        return;
54    }
55
56    foreach my $message (@{$proxy->message_list}) {
57        if ($message->mt == TLSProxy::Message::MT_SERVER_HELLO) {
58            #Add the status_request to the ServerHello even though we are not
59            #going to send a CertificateStatus message
60            $message->set_extension(TLSProxy::Message::EXT_STATUS_REQUEST,
61                                    "");
62
63            $message->repack();
64        }
65    }
66}
67