|
Packit Service |
4684c1 |
/*
|
|
Packit Service |
4684c1 |
* Copyright (C) 2017 Red Hat, Inc.
|
|
Packit Service |
4684c1 |
*
|
|
Packit Service |
4684c1 |
* Author: Nikos Mavrogiannopoulos
|
|
Packit Service |
4684c1 |
*
|
|
Packit Service |
4684c1 |
* This file is part of GnuTLS.
|
|
Packit Service |
4684c1 |
*
|
|
Packit Service |
4684c1 |
* The GnuTLS is free software; you can redistribute it and/or
|
|
Packit Service |
4684c1 |
* modify it under the terms of the GNU Lesser General Public License
|
|
Packit Service |
4684c1 |
* as published by the Free Software Foundation; either version 2.1 of
|
|
Packit Service |
4684c1 |
* the License, or (at your option) any later version.
|
|
Packit Service |
4684c1 |
*
|
|
Packit Service |
4684c1 |
* This library is distributed in the hope that it will be useful, but
|
|
Packit Service |
4684c1 |
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit Service |
4684c1 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Packit Service |
4684c1 |
* Lesser General Public License for more details.
|
|
Packit Service |
4684c1 |
*
|
|
Packit Service |
4684c1 |
* You should have received a copy of the GNU Lesser General Public License
|
|
Packit Service |
4684c1 |
* along with this program. If not, see <https://www.gnu.org/licenses/>
|
|
Packit Service |
4684c1 |
*
|
|
Packit Service |
4684c1 |
*/
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
#ifndef GNUTLS_LIB_EXTV_H
|
|
Packit Service |
4684c1 |
#define GNUTLS_LIB_EXTV_H
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
#include <gnutls/gnutls.h>
|
|
Packit Service |
4684c1 |
#include "str.h"
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
/* Iterates through all TLS-type extensions in data, and
|
|
Packit Service |
4684c1 |
* calls the callback function for each of them. The ctx, flags
|
|
Packit Service |
4684c1 |
* and parse_type are passed verbatim to callback. */
|
|
Packit Service |
4684c1 |
int _gnutls_extv_parse(void *ctx,
|
|
Packit Service |
4684c1 |
gnutls_ext_raw_process_func cb,
|
|
Packit Service |
4684c1 |
const uint8_t * data, int data_size);
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
inline static
|
|
Packit Service |
4684c1 |
int _gnutls_extv_append_init(gnutls_buffer_st *buf)
|
|
Packit Service |
4684c1 |
{
|
|
Packit Service |
4684c1 |
unsigned pos;
|
|
Packit Service |
4684c1 |
int ret;
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
pos = buf->length;
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
ret = _gnutls_buffer_append_prefix(buf, 16, 0);
|
|
Packit Service |
4684c1 |
if (ret < 0)
|
|
Packit Service |
4684c1 |
return gnutls_assert_val(ret);
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
return pos;
|
|
Packit Service |
4684c1 |
}
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
/* its input is the buffer and the return value of _gnutls_extv_append_init()
|
|
Packit Service |
4684c1 |
* @is_hello: should be true for client and server hello messages.
|
|
Packit Service |
4684c1 |
*/
|
|
Packit Service |
4684c1 |
inline static
|
|
Packit Service |
4684c1 |
int _gnutls_extv_append_final(gnutls_buffer_st *buf, unsigned init, unsigned is_hello)
|
|
Packit Service |
4684c1 |
{
|
|
Packit Service |
4684c1 |
unsigned size = buf->length - init - 2;
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
if (size > UINT16_MAX) /* sent too many extensions */
|
|
Packit Service |
4684c1 |
return gnutls_assert_val(GNUTLS_E_HANDSHAKE_TOO_LARGE);
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
if (size > 0)
|
|
Packit Service |
4684c1 |
_gnutls_write_uint16(size, &buf->data[init]);
|
|
Packit Service |
4684c1 |
else if (is_hello && size == 0) {
|
|
Packit Service |
4684c1 |
/* there is no point to send empty extension bytes, and
|
|
Packit Service |
4684c1 |
* they are known to break certain clients */
|
|
Packit Service |
4684c1 |
buf->length -= 2;
|
|
Packit Service |
4684c1 |
}
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
return 0;
|
|
Packit Service |
4684c1 |
}
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
typedef int (*extv_append_func)(void *ctx, gnutls_buffer_st *buf);
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
int _gnutls_extv_append(gnutls_buffer_st *buf,
|
|
Packit Service |
4684c1 |
uint16_t tls_id,
|
|
Packit Service |
4684c1 |
void *ctx,
|
|
Packit Service |
4684c1 |
extv_append_func cb);
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
#endif /* GNUTLS_LIB_EXTV_H */
|