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 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162
|
/*-
* Copyright (c) 2018 GANDI SAS
* All rights reserved.
*
* Author: Emmanuel Hocdet <manu@gandi.net>
*
* SPDX-License-Identifier: BSD-2-Clause
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#include "config.h"
#include <ctype.h>
#include <stdlib.h>
#include <string.h>
#include "cache/cache.h"
#include "vend.h"
#include "proxy/cache_proxy.h"
#include "vcc_proxy_if.h"
struct pp2_tlv_ssl {
uint8_t client;
uint32_t verify;
}__attribute__((packed));
#define PP2_CLIENT_SSL 0x01
#define PP2_CLIENT_CERT_CONN 0x02
#define PP2_CLIENT_CERT_SESS 0x04
static VCL_BOOL
tlv_ssl_flag(VRT_CTX, int flag)
{
const struct pp2_tlv_ssl *dst;
int len;
CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
if (VPX_tlv(ctx->req, PP2_TYPE_SSL, (const void **)&dst, &len))
return (0);
return ((dst->client & flag) == flag);
}
VCL_BOOL v_matchproto_(td_proxy_is_ssl)
vmod_is_ssl(VRT_CTX)
{
return (tlv_ssl_flag(ctx, PP2_CLIENT_SSL));
}
VCL_BOOL v_matchproto_(td_proxy_client_has_cert_sess)
vmod_client_has_cert_sess(VRT_CTX)
{
return (tlv_ssl_flag(ctx, PP2_CLIENT_CERT_SESS));
}
VCL_BOOL v_matchproto_(td_proxy_client_has_cert_conn)
vmod_client_has_cert_conn(VRT_CTX)
{
return (tlv_ssl_flag(ctx, PP2_CLIENT_CERT_CONN));
}
/* return come from SSL_get_verify_result */
VCL_INT v_matchproto_(td_proxy_ssl_verify_result)
vmod_ssl_verify_result(VRT_CTX)
{
const struct pp2_tlv_ssl *dst;
int len;
CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
if (VPX_tlv(ctx->req, PP2_TYPE_SSL, (const void **)&dst, &len))
return (0); /* X509_V_OK */
return (vbe32dec(&dst->verify));
}
static VCL_STRING
tlv_string(VRT_CTX, int tlv)
{
const char *ptr;
char *d;
int len;
CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
if (VPX_tlv(ctx->req, tlv, (const void **)&ptr, &len))
return (NULL);
d = WS_Alloc(ctx->ws, len+1);
if (d == NULL) {
VRT_fail(ctx, "proxy.TLV: out of workspace");
return (NULL);
}
AN(ptr);
memcpy(d, ptr, len);
d[len] = '\0';
return (d);
}
VCL_STRING v_matchproto_(td_proxy_alpn)
vmod_alpn(VRT_CTX)
{
return (tlv_string(ctx, PP2_TYPE_ALPN));
}
VCL_STRING v_matchproto_(td_proxy_authority)
vmod_authority(VRT_CTX)
{
return (tlv_string(ctx, PP2_TYPE_AUTHORITY));
}
VCL_STRING v_matchproto_(td_proxy_ssl_version)
vmod_ssl_version(VRT_CTX)
{
return (tlv_string(ctx, PP2_SUBTYPE_SSL_VERSION));
}
VCL_STRING v_matchproto_(td_proxy_ssl_cipher)
vmod_ssl_cipher(VRT_CTX)
{
return (tlv_string(ctx, PP2_SUBTYPE_SSL_CIPHER));
}
VCL_STRING v_matchproto_(td_proxy_cert_sign)
vmod_cert_sign(VRT_CTX)
{
return (tlv_string(ctx, PP2_SUBTYPE_SSL_SIG_ALG));
}
VCL_STRING v_matchproto_(td_proxy_cert_key)
vmod_cert_key(VRT_CTX)
{
return (tlv_string(ctx, PP2_SUBTYPE_SSL_KEY_ALG));
}
VCL_STRING v_matchproto_(td_proxy_client_cert_cn)
vmod_client_cert_cn(VRT_CTX)
{
return (tlv_string(ctx, PP2_SUBTYPE_SSL_CN));
}
|