FUNCS += functions/gnutls_random_art.short
FUNCS += functions/gnutls_record_check_pending
FUNCS += functions/gnutls_record_check_pending.short
-FUNCS += functions/gnutls_record_disable_padding
-FUNCS += functions/gnutls_record_disable_padding.short
+FUNCS += functions/gnutls_range_can_use_length_hiding
+FUNCS += functions/gnutls_range_can_use_length_hiding.short
+FUNCS += functions/gnutls_range_send_message
+FUNCS += functions/gnutls_range_send_message.short
+FUNCS += functions/gnutls_record_max_empty_records
+FUNCS += functions/gnutls_record_max_empty_records.short
FUNCS += functions/gnutls_record_get_direction
FUNCS += functions/gnutls_record_get_direction.short
FUNCS += functions/gnutls_record_get_discarded
@item %LATEST_RECORD_VERSION @tab
will use the latest TLS version record version in client hello.
-@item %RANDOM_PADDING @tab
-will use random padding to all sent TLS records. This is negotiated
-using an extension. Use @funcref{gnutls_record_get_random_padding_status}
-to check whether this has been negotiated in the current session.
+@item %NEW_PADDING @tab
+will enable the new padding extension negotiation. If the new padding extension
+is negotiated, GnuTLS will use a more efficient length-hiding mechanism.
+Use @funcref{gnutls_range_can_use_length_hiding} to check whether length-hiding
+can be used in the current session.
@end multitable
@caption{Special priority string keywords.}
@cindex record padding
@cindex bad_record_mac
-The TLS protocol allows for random padding of records in CBC ciphers, to prevent
+The TLS protocol allows for extra padding of records in CBC ciphers, to prevent
statistical analysis based on the length of exchanged messages (see @xcite{RFC5246} section 6.2.3.2).
-GnuTLS appears to be one of few implementation that take advantage of this text,
-and pad records by a random length.
+GnuTLS appears to be one of few implementations that take advantage of this feature:
+the user can provide some plaintext data with a range of lengths she wishes to hide,
+and GnuTLS adds extra padding to make sure the attacker cannot tell the real plaintext
+length is in a range smaller than the user-provided one.
+Use @funcref{gnutls_range_send_message} to send length-hidden messages and
+@funcref{gnutls_range_can_use_length_hiding} to check whether the current
+session supports length hiding. Using the standard @funcref{gnutls_record_send}
+will only add minimal padding.
The TLS implementation in the Symbian operating system, frequently
used by Nokia and Sony-Ericsson mobile phones, cannot handle
in error messages such as 'A TLS fatal alert has been received', 'Bad
record MAC', or both, on the GnuTLS server side.
-GnuTLS implements a work around for this problem. However, it has to
-be enabled specifically. It can be enabled by using
-@funcref{gnutls_record_disable_padding}, or @funcref{gnutls_priority_set} with
-the @code{%COMPAT} priority string (see @ref{Priority Strings}).
+If compatibility with such devices is a concern, not sending length-hidden messages
+solves the problem by using minimal padding.
If you implement an application that have a configuration file, we
recommend that you make it possible for users or administrators to
#
# DO NOT EDIT THIS FILE (invoke-gnutls-cli.texi)
#
-# It has been AutoGen-ed January 1, 2013 at 09:07:50 PM by AutoGen 5.16
+# It has been AutoGen-ed January 22, 2013 at 05:28:22 PM by AutoGen 5.15
# From the definitions ../src/cli-args.def
# and the template file agtexi-cmd.tpl
@end ignore
@anchor{gnutls-cli usage}
-@subheading gnutls-cli help/usage (-h)
-@cindex gnutls-cli help
+@subheading gnutls-cli usage (-h)
-This is the automatically generated usage text for gnutls-cli.
-The text printed is the same whether for the @code{help} option (-h) or the @code{more-help} option (-!). @code{more-help} will print
-the usage text by passing it through a pager program.
-@code{more-help} is disabled on platforms without a working
-@code{fork(2)} function. The @code{PAGER} environment variable is
-used to select the program, defaulting to @file{more}. Both will exit
-with a status code of 0.
+This is the automatically generated usage text for gnutls-cli:
@exampleindent 0
@example
--pskkey=str PSK key (in hex) to use
-p, --port=str The port or service to connect to
--insecure Don't abort program if server certificate can't be validated
+ --ranges When possible, use length-hiding padding to prevent traffic analysis
--benchmark-ciphers Benchmark individual ciphers
--benchmark-soft-ciphers Benchmark individual software ciphers (no hw acceleration)
--benchmark-tls-kx Benchmark TLS key exchange methods
-Simple client program to set up a TLS connection to some other computer. It
-sets up a TLS connection and forwards data from the standard input to the
-secured socket and vice versa.
+Simple client program to set up a TLS connection to some other computer.
+It sets up a TLS connection and forwards data from the standard input to
+the secured socket and vice versa.
please send bug reports to: bug-gnutls@@gnu.org
@end example
@exampleindent 4
-@anchor{gnutls-cli debug}
-@subheading debug option (-d)
+@anchor{gnutls-cli benchmark-ciphers}
+@subheading benchmark-ciphers option
+
+This is the ``benchmark individual ciphers'' option.
+
+
+@anchor{gnutls-cli benchmark-soft-ciphers}
+@subheading benchmark-soft-ciphers option
+
+This is the ``benchmark individual software ciphers (no hw acceleration)'' option.
+
+
+@anchor{gnutls-cli benchmark-tls-ciphers}
+@subheading benchmark-tls-ciphers option
+
+This is the ``benchmark tls ciphers'' option.
+
+
+@anchor{gnutls-cli benchmark-tls-kx}
+@subheading benchmark-tls-kx option
+
+This is the ``benchmark tls key exchange methods'' option.
+
+
+@anchor{gnutls-cli ca-verification}
+@subheading ca-verification option
+
+This is the ``disable ca certificate verification'' option.
+
+This option has some usage constraints. It:
+@itemize @bullet
+@item
+is enabled by default.
+@end itemize
+
+This option will disable CA certificate verification. It is to be used with the --dane or --tofu options.
+
+@anchor{gnutls-cli crlf}
+@subheading crlf option
+
+This is the ``send cr lf instead of lf'' option.
-This is the ``enable debugging.'' option.
-This option takes an argument number.
-Specifies the debug level.
-@anchor{gnutls-cli tofu}
-@subheading tofu option
-This is the ``enable trust on first use authentication'' option.
-This option will, in addition to certificate authentication, perform authentication based on previously seen public keys, a model similar to SSH authentication.
@anchor{gnutls-cli dane}
@subheading dane option
This option will, in addition to certificate authentication using
the trusted CAs, verify the server certificates using on the DANE information
available via DNSSEC.
+
+@anchor{gnutls-cli debug}
+@subheading debug option (-d)
+
+This is the ``enable debugging.'' option.
+Specifies the debug level.
+
+@anchor{gnutls-cli dh-bits}
+@subheading dh-bits option
+
+This is the ``the minimum number of bits allowed for dh'' option.
+This option sets the minimum number of bits allowed for a Diffie-Hellman key exchange. You may want to lower the default value if the peer sends a weak prime and you get an connection error with unacceptable prime.
+
+@anchor{gnutls-cli disable-extensions}
+@subheading disable-extensions option
+
+This is the ``disable all the tls extensions'' option.
+This option disables all TLS extensions. Deprecated option. Use the priority string.
+
+@anchor{gnutls-cli fingerprint}
+@subheading fingerprint option (-f)
+
+This is the ``send the openpgp fingerprint, instead of the key'' option.
+
+
+@anchor{gnutls-cli heartbeat}
+@subheading heartbeat option (-b)
+
+This is the ``activate heartbeat support'' option.
+
+
+@anchor{gnutls-cli insecure}
+@subheading insecure option
+
+This is the ``don't abort program if server certificate can't be validated'' option.
+
+
+@anchor{gnutls-cli list}
+@subheading list option (-l)
+
+This is the ``print a list of the supported algorithms and modes'' option.
+Print a list of the supported algorithms and modes. If a priority string is given then only the enabled ciphersuites are shown.
+
@anchor{gnutls-cli local-dns}
@subheading local-dns option
This is the ``use the local dns server for dnssec resolving.'' option.
This option will use the local DNS server for DNSSEC.
This is disabled by default due to many servers not allowing DNSSEC.
-@anchor{gnutls-cli ca-verification}
-@subheading ca-verification option
-This is the ``disable ca certificate verification'' option.
+@anchor{gnutls-cli mtu}
+@subheading mtu option
+
+This is the ``set mtu for datagram tls'' option.
+
+
+@anchor{gnutls-cli noticket}
+@subheading noticket option
+
+This is the ``don't accept session tickets'' option.
-@noindent
-This option has some usage constraints. It:
-@itemize @bullet
-@item
-is enabled by default.
-@end itemize
-This option will disable CA certificate verification. It is to be used with the --dane or --tofu options.
@anchor{gnutls-cli ocsp}
@subheading ocsp option
This is the ``enable ocsp certificate verification'' option.
This option will enable verification of the peer's certificate using ocsp
-@anchor{gnutls-cli resume}
-@subheading resume option (-r)
-This is the ``establish a session and resume'' option.
-Connect, establish a session, reconnect and resume.
-@anchor{gnutls-cli rehandshake}
-@subheading rehandshake option (-e)
+@anchor{gnutls-cli pgpcertfile}
+@subheading pgpcertfile option
-This is the ``establish a session and rehandshake'' option.
-Connect, establish a session and rehandshake immediately.
-@anchor{gnutls-cli starttls}
-@subheading starttls option (-s)
+This is the ``pgp public key (certificate) file to use'' option.
-This is the ``connect, establish a plain session and start tls.'' option.
-The TLS session will be initiated when EOF or a SIGALRM is received.
-@anchor{gnutls-cli disable-extensions}
-@subheading disable-extensions option
-This is the ``disable all the tls extensions'' option.
-This option disables all TLS extensions. Deprecated option. Use the priority string.
-@anchor{gnutls-cli dh-bits}
-@subheading dh-bits option
+@anchor{gnutls-cli pgpkeyfile}
+@subheading pgpkeyfile option
+
+This is the ``pgp key file to use'' option.
+
+
+@anchor{gnutls-cli pgpkeyring}
+@subheading pgpkeyring option
+
+This is the ``pgp key ring file to use'' option.
+
+
+@anchor{gnutls-cli pgpsubkey}
+@subheading pgpsubkey option
+
+This is the ``pgp subkey to use (hex or auto)'' option.
+
+
+@anchor{gnutls-cli port}
+@subheading port option (-p)
+
+This is the ``the port or service to connect to'' option.
+
+
+@anchor{gnutls-cli print-cert}
+@subheading print-cert option
+
+This is the ``print peer's certificate in pem format'' option.
+
-This is the ``the minimum number of bits allowed for dh'' option.
-This option takes an argument number.
-This option sets the minimum number of bits allowed for a Diffie-Hellman key exchange. You may want to lower the default value if the peer sends a weak prime and you get an connection error with unacceptable prime.
@anchor{gnutls-cli priority}
@subheading priority option
This is the ``priorities string'' option.
-This option takes an argument string.
TLS algorithms and protocols to enable. You can
use predefined sets of ciphersuites such as PERFORMANCE,
NORMAL, SECURE128, SECURE256.
Check the GnuTLS manual on section ``Priority strings'' for more
information on allowed keywords
-@anchor{gnutls-cli list}
-@subheading list option (-l)
-This is the ``print a list of the supported algorithms and modes'' option.
-Print a list of the supported algorithms and modes. If a priority string is given then only the enabled ciphersuites are shown.
+@anchor{gnutls-cli pskkey}
+@subheading pskkey option
+
+This is the ``psk key (in hex) to use'' option.
+
+
+@anchor{gnutls-cli pskusername}
+@subheading pskusername option
+
+This is the ``psk username to use'' option.
+
+
+@anchor{gnutls-cli ranges}
+@subheading ranges option
+
+This is the ``when possible, use length-hiding padding to prevent traffic analysis'' option.
+
+
+@anchor{gnutls-cli recordsize}
+@subheading recordsize option
+
+This is the ``the maximum record size to advertize'' option.
+
+
+@anchor{gnutls-cli rehandshake}
+@subheading rehandshake option (-e)
+
+This is the ``establish a session and rehandshake'' option.
+Connect, establish a session and rehandshake immediately.
+
+@anchor{gnutls-cli resume}
+@subheading resume option (-r)
+
+This is the ``establish a session and resume'' option.
+Connect, establish a session, reconnect and resume.
+
+@anchor{gnutls-cli srppasswd}
+@subheading srppasswd option
+
+This is the ``srp password to use'' option.
+
+
+@anchor{gnutls-cli srpusername}
+@subheading srpusername option
+
+This is the ``srp username to use'' option.
+
+
+@anchor{gnutls-cli srtp-profiles}
+@subheading srtp-profiles option
+
+This is the ``offer srtp profiles'' option.
+
+
+@anchor{gnutls-cli starttls}
+@subheading starttls option (-s)
+
+This is the ``connect, establish a plain session and start tls.'' option.
+The TLS session will be initiated when EOF or a SIGALRM is received.
+
+@anchor{gnutls-cli tofu}
+@subheading tofu option
+
+This is the ``enable trust on first use authentication'' option.
+This option will, in addition to certificate authentication, perform authentication based on previously seen public keys, a model similar to SSH authentication.
+
+@anchor{gnutls-cli udp}
+@subheading udp option (-u)
+
+This is the ``use dtls (datagram tls) over udp'' option.
+
+
+@anchor{gnutls-cli verbose}
+@subheading verbose option (-V)
+
+This is the ``more verbose output'' option.
+
+This option has some usage constraints. It:
+@itemize @bullet
+@item
+may appear an unlimited number of times.
+@end itemize
+
+
+
+@anchor{gnutls-cli x509cafile}
+@subheading x509cafile option
+
+This is the ``certificate file or pkcs #11 url to use'' option.
+
+
+@anchor{gnutls-cli x509certfile}
+@subheading x509certfile option
+
+This is the ``x.509 certificate file or pkcs #11 url to use'' option.
+
+
+@anchor{gnutls-cli x509crlfile}
+@subheading x509crlfile option
+
+This is the ``crl file to use'' option.
+
+
+@anchor{gnutls-cli x509fmtder}
+@subheading x509fmtder option
+
+This is the ``use der format for certificates to read from'' option.
+
+
+@anchor{gnutls-cli x509keyfile}
+@subheading x509keyfile option
+
+This is the ``x.509 key file or pkcs #11 url to use'' option.
+
@anchor{gnutls-cli exit status}
@subheading gnutls-cli exit status
One of the following exit values will be returned:
@table @samp
-@item 0 (EXIT_SUCCESS)
+@item 0
Successful program execution.
-@item 1 (EXIT_FAILURE)
+@item 1
The operation failed or the command syntax was not valid.
@end table
+
+
@anchor{gnutls-cli See Also}
@subheading gnutls-cli See Also
+
gnutls-cli-debug(1), gnutls-serv(1)
+
@anchor{gnutls-cli Examples}
@subheading gnutls-cli Examples
+
@subheading Connecting using PSK authentication
To connect to a server using PSK authentication, you need to enable the choice of PSK by using a cipher priority parameter such as in the example below.
@example
PSK_COBJECTS = gnutls_psk.c
-COBJECTS = gnutls_record.c gnutls_compress.c debug.c gnutls_cipher.c \
+COBJECTS = gnutls_range.c gnutls_record.c \
+ gnutls_compress.c debug.c gnutls_cipher.c \
gnutls_mbuffers.c gnutls_buffers.c gnutls_handshake.c \
gnutls_num.c gnutls_errors.c gnutls_dh.c gnutls_kx.c \
gnutls_priority.c gnutls_hash_int.c gnutls_cipher_int.c \
}
-/**
- * gnutls_record_get_random_padding_status:
- * @session: is a #gnutls_session_t structure.
- *
- * Returns: non-zero if the new padding scheme is enabled.
- *
- **/
-int
-gnutls_record_get_random_padding_status (gnutls_session_t session)
-{
- return session->security_parameters.new_record_padding;
-}
-
static int compressed_to_ciphertext (gnutls_session_t session,
uint8_t * cipher_data, int cipher_size,
gnutls_datum_t *compressed,
+ size_t target_size,
content_type_t _type,
record_parameters_st * params);
static int ciphertext_to_compressed (gnutls_session_t session,
compressed_to_ciphertext_new (gnutls_session_t session,
uint8_t * cipher_data, int cipher_size,
gnutls_datum_t *compressed,
+ size_t target_size,
content_type_t type,
record_parameters_st * params);
/* returns ciphertext which contains the headers too. This also
* calculates the size in the header field.
*
- * If random pad != 0 then the random pad data will be appended.
*/
int
_gnutls_encrypt (gnutls_session_t session, const uint8_t * headers,
size_t headers_size, const uint8_t * data,
- size_t data_size, uint8_t * ciphertext,
+ size_t data_size, size_t target_size, uint8_t * ciphertext,
size_t ciphertext_size, content_type_t type,
record_parameters_st * params)
{
if (session->security_parameters.new_record_padding != 0)
ret = compressed_to_ciphertext_new (session, &ciphertext[headers_size],
ciphertext_size - headers_size,
- &comp, type, params);
+ &comp, target_size, type, params);
else
ret = compressed_to_ciphertext (session, &ciphertext[headers_size],
ciphertext_size - headers_size,
- &comp, type, params);
+ &comp, target_size, type, params);
if (free_comp)
gnutls_free(comp.data);
int hash_size, uint8_t * pad,
unsigned auth_cipher, uint16_t blocksize)
{
- uint8_t rnd = *pad;
- unsigned int length;
-
- *pad = 0;
-
- /* make rnd a multiple of blocksize */
- if (session->security_parameters.version == GNUTLS_SSL3)
- {
- rnd = 0;
- }
-
- if (rnd > 0)
- {
- rnd = (rnd / blocksize) * blocksize;
- /* added to avoid the case of pad calculated 0
- * seen below for pad calculation.
- */
- if (rnd > blocksize)
- rnd -= blocksize;
- }
+ /* pad is the LH pad the user wants us to add. Besides
+ * this LH pad, we only add minimal padding
+ */
+ unsigned int pre_length = data_size + hash_size + *pad;
- length = data_size + hash_size;
+ *pad = (uint8_t) (blocksize - (pre_length % blocksize)) + *pad;
- *pad = (uint8_t) (blocksize - (length % blocksize)) + rnd;
+ unsigned int length = data_size + hash_size + *pad;
- length += *pad;
if (_gnutls_version_has_explicit_iv
(session->security_parameters.version))
length += blocksize; /* for the IV */
compressed_to_ciphertext (gnutls_session_t session,
uint8_t * cipher_data, int cipher_size,
gnutls_datum_t *compressed,
+ size_t target_size,
content_type_t type,
record_parameters_st * params)
{
uint8_t * tag_ptr = NULL;
- uint8_t pad = 0;
+ uint8_t pad = target_size - compressed->size;
int length, length_to_encrypt, ret;
uint8_t preamble[MAX_PREAMBLE_SIZE];
int preamble_size;
int ver = gnutls_protocol_get_version (session);
int explicit_iv = _gnutls_version_has_explicit_iv (session->security_parameters.version);
int auth_cipher = _gnutls_auth_cipher_is_aead(¶ms->write.cipher_state);
- uint8_t nonce[MAX_CIPHER_BLOCK_SIZE+1];
+ uint8_t nonce[MAX_CIPHER_BLOCK_SIZE];
_gnutls_hard_log("ENC[%p]: cipher: %s, MAC: %s, Epoch: %u\n",
*/
if (block_algo == CIPHER_BLOCK)
{
- /* Call _gnutls_rnd() once. Get data used for the IV + 1 for
- * the random padding.
+ /* Call _gnutls_rnd() once. Get data used for the IV
*/
- ret = _gnutls_rnd (GNUTLS_RND_NONCE, nonce, blocksize+1);
+ ret = _gnutls_rnd (GNUTLS_RND_NONCE, nonce, blocksize);
if (ret < 0)
return gnutls_assert_val(ret);
- /* We don't use long padding if requested or if we are in DTLS.
- */
- if (session->internals.priorities.no_padding == 0 && !IS_DTLS(session))
- pad = nonce[blocksize];
-
length_to_encrypt = length =
calc_enc_length_block (session, compressed->size, tag_size, &pad,
auth_cipher, blocksize);
compressed_to_ciphertext_new (gnutls_session_t session,
uint8_t * cipher_data, int cipher_size,
gnutls_datum_t *compressed,
+ size_t target_size,
content_type_t type,
record_parameters_st * params)
{
uint8_t * tag_ptr = NULL;
- uint16_t pad = 0;
+ uint16_t pad = target_size - compressed->size;
int length, length_to_encrypt, ret;
uint8_t preamble[MAX_PREAMBLE_SIZE];
int preamble_size;
int ver = gnutls_protocol_get_version (session);
int explicit_iv = _gnutls_version_has_explicit_iv (session->security_parameters.version);
int auth_cipher = _gnutls_auth_cipher_is_aead(¶ms->write.cipher_state);
- uint8_t nonce[MAX_CIPHER_BLOCK_SIZE+2];
+ uint8_t nonce[MAX_CIPHER_BLOCK_SIZE];
_gnutls_hard_log("ENC[%p]: cipher: %s, MAC: %s, Epoch: %u\n",
session, gnutls_cipher_get_name(params->cipher_algorithm), gnutls_mac_get_name(params->mac_algorithm),
(unsigned int)params->epoch);
- /* Call _gnutls_rnd() once. Get data used for the IV + 2 for
- * the random padding.
+ /* Call _gnutls_rnd() once. Get data used for the IV
*/
- ret = _gnutls_rnd (GNUTLS_RND_NONCE, nonce, blocksize+2);
+ ret = _gnutls_rnd (GNUTLS_RND_NONCE, nonce, blocksize);
if (ret < 0)
return gnutls_assert_val(ret);
- /* We don't use long padding if requested.
- */
- if (session->internals.priorities.no_padding == 0)
- memcpy(&pad, &nonce[blocksize], 2);
-
/* cipher_data points to the start of data to be encrypted */
data_ptr = cipher_data;
DECR_LEN(cipher_size, 2);
- pad %= (cipher_size - (compressed->size + tag_size));
-
if (block_algo == CIPHER_BLOCK) /* make pad a multiple of blocksize */
{
unsigned t = (2 + pad + compressed->size + tag_size) % blocksize;
-
- if (pad > t)
- pad -= t;
- else
- pad += blocksize - t;
+ if (t > 0)
+ {
+ pad += blocksize - t;
+ }
}
_gnutls_write_uint16 (pad, data_ptr);
int _gnutls_encrypt (gnutls_session_t session, const uint8_t * headers,
size_t headers_size, const uint8_t * data,
- size_t data_size, uint8_t * ciphertext,
+ size_t data_size, size_t target_size, uint8_t * ciphertext,
size_t ciphertext_size, content_type_t type,
record_parameters_st * params);
/* to disable record padding */
unsigned int no_extensions:1;
- unsigned int no_padding:1;
unsigned int allow_large_records:1;
unsigned int new_record_padding:1;
+ unsigned int max_empty_records;
safe_renegotiation_t sr;
unsigned int ssl3_record_version:1;
unsigned int server_precedence:1;
unsigned int additional_verify_flags;
};
+/* Allow around 50KB of length-hiding padding
+ * when using legacy padding,
+ * or around 3.2MB when using new padding. */
+#define DEFAULT_MAX_EMPTY_RECORDS 200
+
#define ENABLE_COMPAT(x) \
- (x)->no_padding = 1; \
(x)->allow_large_records = 1; \
(x)->allow_weak_keys = 1
(*priority_cache)->sr = SR_PARTIAL;
(*priority_cache)->ssl3_record_version = 1;
+ (*priority_cache)->max_empty_records = DEFAULT_MAX_EMPTY_RECORDS;
+
if (priorities == NULL)
priorities = LEVEL_NORMAL;
(*priority_cache)->server_precedence = 1;
}
else if (strcasecmp (&broken_list[i][1],
- "RANDOM_PADDING") == 0)
+ "NEW_PADDING") == 0)
{
(*priority_cache)->new_record_padding = 1;
}
--- /dev/null
+/*
+ * Copyright (C) 2012 INRIA Paris-Rocquencourt
+ *
+ * Author: Alfredo Pironti
+ *
+ * This file is part of GnuTLS.
+ *
+ * The GnuTLS is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>
+ *
+ */
+
+#include "gnutls_int.h"
+#include "gnutls_errors.h"
+#include "algorithms.h"
+#include "gnutls_constate.h"
+#include "gnutls_record.h"
+
+ssize_t
+min (ssize_t a, ssize_t b)
+{
+ if (a < b)
+ return a;
+ else
+ return b;
+}
+
+void
+_gnutls_set_range (gnutls_range_st * dst, const size_t low, const size_t high)
+{
+ dst->low = low;
+ dst->high = high;
+ return;
+}
+
+/*
+ * Returns how much LH pad we can put in this fragment, given we'll
+ * put at least data_length bytes of user data.
+ */
+ssize_t
+_gnutls_range_max_lh_pad (gnutls_session_t session, ssize_t data_length, ssize_t max_frag)
+{
+ int ret;
+ record_parameters_st *record_params;
+
+ ret = _gnutls_epoch_get (session, EPOCH_WRITE_CURRENT, &record_params);
+ if (ret < 0)
+ {
+ return gnutls_assert_val (GNUTLS_E_INVALID_REQUEST);
+ }
+
+ ssize_t max_pad;
+ unsigned int fixed_pad;
+
+ if (session->security_parameters.new_record_padding != 0)
+ {
+ max_pad = MAX_USER_SEND_SIZE (session);
+ fixed_pad = 2;
+ }
+ else
+ {
+ max_pad = MAX_PAD_SIZE;
+ fixed_pad = 1;
+ }
+
+ ssize_t this_pad = min(max_pad,max_frag - data_length);
+
+ ssize_t block_size =
+ gnutls_cipher_get_block_size (record_params->cipher_algorithm);
+ ssize_t tag_size =
+ _gnutls_auth_cipher_tag_len (&record_params->write.cipher_state);
+ ssize_t overflow;
+ switch (_gnutls_cipher_is_block (record_params->cipher_algorithm))
+ {
+ case CIPHER_STREAM:
+ return this_pad;
+
+ case CIPHER_BLOCK:
+ overflow = (data_length + this_pad + tag_size + fixed_pad) % block_size;
+ if (overflow > this_pad)
+ {
+ return this_pad;
+ }
+ else
+ {
+ return this_pad - overflow;
+ }
+ default:
+ return gnutls_assert_val (GNUTLS_E_INTERNAL_ERROR);
+ }
+}
+
+/**
+ * gnutls_range_can_use_length_hiding:
+ * @session: is a #gnutls_session_t structure.
+ *
+ * Returns true (1) if the current session supports length-hiding
+ * padding, false (0) if the current session does not. Returns
+ * a negative value in case of error.
+ * If the session supports length-hiding padding, you can
+ * invoke #gnutls_range_send_message to send a message whose
+ * length is hidden in the given range. If the session does not
+ * support length hiding padding, you can use the standard
+ * #gnutls_record_send function, or #gnutls_range_send_message
+ * making sure that the range is the same as the length of the
+ * message you are trying to send.
+ **/
+int
+gnutls_range_can_use_length_hiding (gnutls_session_t session)
+{
+ int ret;
+ record_parameters_st *record_params;
+
+ ret = _gnutls_epoch_get (session, EPOCH_WRITE_CURRENT, &record_params);
+ if (ret < 0)
+ {
+ return gnutls_assert_val (GNUTLS_E_INVALID_REQUEST);
+ }
+
+ if (session->security_parameters.new_record_padding != 0)
+ {
+ return 1;
+ }
+
+ if (session->security_parameters.version == GNUTLS_SSL3)
+ {
+ return 0;
+ }
+
+ switch (_gnutls_cipher_is_block (record_params->cipher_algorithm))
+ {
+ case CIPHER_STREAM:
+ return 0;
+ case CIPHER_BLOCK:
+ return 1;
+ default:
+ return gnutls_assert_val (GNUTLS_E_INTERNAL_ERROR);
+ }
+}
+
+ssize_t
+_gnutls_range_split (gnutls_session_t session,
+ const gnutls_range_st orig,
+ gnutls_range_st * small_range,
+ gnutls_range_st * rem_range)
+{
+ int ret;
+ ssize_t max_frag = MAX_USER_SEND_SIZE (session);
+ ssize_t orig_low = (ssize_t) orig.low;
+ ssize_t orig_high = (ssize_t) orig.high;
+
+ if (orig_high == orig_low)
+ {
+ int length = min (orig_high, max_frag);
+ int rem = orig_high - length;
+ _gnutls_set_range (small_range, length, length);
+ _gnutls_set_range (rem_range, rem, rem);
+ return 0;
+ }
+ else
+ {
+ if (orig_low >= max_frag)
+ {
+ _gnutls_set_range (small_range, max_frag, max_frag);
+ _gnutls_set_range (rem_range, orig_low - max_frag,
+ orig_high - max_frag);
+ }
+ else
+ {
+ ret = _gnutls_range_max_lh_pad(session,orig_low,max_frag);
+ if (ret < 0) {
+ return ret; // already gnutls_assert_val'd
+ }
+ ssize_t this_pad = min(ret,orig_high - orig_low);
+
+ _gnutls_set_range(small_range, orig_low, orig_low + this_pad);
+ _gnutls_set_range(rem_range, 0, orig_high - (orig_low + this_pad));
+ }
+ return 0;
+ }
+}
+
+size_t
+_gnutls_range_fragment (size_t data_size, gnutls_range_st cur,
+ gnutls_range_st next)
+{
+ return min (cur.high, data_size - next.low);
+}
+
+/**
+ * gnutls_range_send_message:
+ * @session: is a #gnutls_session_t structure.
+ * @data: contains the data to send.
+ * @data_size: is the length of the data.
+ * @range: is the range of lengths in which the real data length must be hidden.
+ *
+ * This function operates like #gnutls_record_send but, while
+ * #gnutls_record_send adds minimal padding to each TLS record,
+ * this function uses the TLS extra-padding feature to conceal the real
+ * data size within the range of lengths provided.
+ * Some TLS sessions do not support extra padding (e.g. stream ciphers in standard
+ * TLS or SSL3 sessions). To know whether the current session supports extra
+ * padding, and hence length hiding, use the #gnutls_range_can_use_length_hiding
+ * function.
+ *
+ * Returns: The number of bytes sent (that is data_size in a successful invocation),
+ * or a negative error code.
+ **/
+ssize_t
+gnutls_range_send_message (gnutls_session_t session, const void *data,
+ size_t data_size, const gnutls_range_st range)
+{
+ size_t sent = 0;
+ size_t next_fragment_length;
+ ssize_t ret;
+ gnutls_range_st cur_range, next_range;
+
+ // sanity check on range and data size
+ if (range.low > range.high ||
+ data_size < range.low || data_size > range.high)
+ {
+ return gnutls_assert_val (GNUTLS_E_INVALID_REQUEST);
+ }
+
+ ret = gnutls_range_can_use_length_hiding(session);
+ if (ret < 0)
+ {
+ return ret; // already gnutls_assert_val'd
+ }
+
+ if (ret == 0 && range.low != range.high)
+ {
+ // Cannot use LH, but a range was given
+ return gnutls_assert_val (GNUTLS_E_INVALID_REQUEST);
+ }
+
+ _gnutls_set_range (&cur_range, range.low, range.high);
+
+ _gnutls_record_log
+ ("RANGE: Preparing message with size %d, range (%d,%d)\n",
+ (int) data_size, (int) range.low, (int) range.high);
+
+ while (cur_range.high != 0)
+ {
+ ret =
+ _gnutls_range_split (session, cur_range, &cur_range,
+ &next_range);
+ if (ret < 0)
+ {
+ return ret; // already gnutls_assert_val'd
+ }
+
+ next_fragment_length =
+ _gnutls_range_fragment (data_size, cur_range, next_range);
+
+ _gnutls_record_log
+ ("RANGE: Next fragment size: %d (%d,%d); remaining range: (%d,%d)\n",
+ (int) next_fragment_length, (int) cur_range.low,
+ (int) cur_range.high, (int) next_range.low, (int) next_range.high);
+
+ ret = _gnutls_send_tlen_int (session, GNUTLS_APPLICATION_DATA, -1,
+ EPOCH_WRITE_CURRENT,
+ &(((char *) data)[sent]),
+ next_fragment_length, MBUFFER_FLUSH,
+ cur_range.high);
+ if (ret < 0)
+ {
+ return ret; // already gnutls_assert_val'd
+ }
+ if (ret != (ssize_t) next_fragment_length)
+ {
+ _gnutls_record_log
+ ("RANGE: ERROR: ret = %d; next_fragment_length = %d\n", (int) ret,
+ (int) next_fragment_length);
+ return gnutls_assert_val (GNUTLS_E_INTERNAL_ERROR);
+ }
+ sent += next_fragment_length;
+ data_size -= next_fragment_length;
+ _gnutls_set_range (&cur_range, next_range.low, next_range.high);
+ }
+
+ return sent;
+}
};
/**
- * gnutls_record_disable_padding:
+ * gnutls_record_max_empty_records:
* @session: is a #gnutls_session_t structure.
+ * @i: is the desired value of maximum empty records that can be accepted in a row.
*
- * Used to disabled padding in TLS 1.0 and above. Normally you do not
- * need to use this function, but there are buggy clients that
- * complain if a server pads the encrypted data. This of course will
- * disable protection against statistical attacks on the data.
- *
- * Normally only servers that require maximum compatibility with everything
- * out there, need to call this function.
+ * Used to set the maximum number of empty fragments that can be accepted
+ * in a row. Accepting many empty fragments is useful for receiving length-hidden
+ * content, where empty fragments filled with pad are sent to hide the real
+ * length of a message. However, a malicious peer could send empty fragments to
+ * mount a DoS attack, so as a safety measure, a maximum number of empty fragments
+ * is accepted by default. If you know your application must accept a given number
+ * of empty fragments in a row, you can use this function to set the desired value.
**/
void
-gnutls_record_disable_padding (gnutls_session_t session)
+gnutls_record_max_empty_records (gnutls_session_t session, const unsigned int i)
{
- session->internals.priorities.no_padding = 1;
+ session->internals.priorities.max_empty_records = i;
}
+
/**
* gnutls_transport_set_ptr:
* @session: is a #gnutls_session_t structure.
gnutls_handshake_description_t htype,
unsigned int epoch_rel, const void *_data,
size_t data_size, unsigned int mflags)
+{
+ return _gnutls_send_tlen_int(session,type,htype,epoch_rel,_data,data_size,mflags,data_size);
+}
+
+ssize_t
+_gnutls_send_tlen_int (gnutls_session_t session, content_type_t type,
+ gnutls_handshake_description_t htype,
+ unsigned int epoch_rel, const void *_data,
+ size_t data_size, unsigned int mflags, size_t target_length)
{
mbuffer_st *bufel;
ssize_t cipher_size;
memcpy(&headers[3], &record_state->sequence_number.i, 8);
_gnutls_record_log
- ("REC[%p]: Preparing Packet %s(%d) with length: %d\n", session,
- _gnutls_packet2str (type), type, (int) data_size);
+ ("REC[%p]: Preparing Packet %s(%d) with length: %d and target length: %d\n", session,
+ _gnutls_packet2str (type), type, (int) data_size, (int) target_length);
if (data_size > MAX_USER_SEND_SIZE(session))
{
ret =
_gnutls_encrypt (session, headers, header_size, data,
- send_data_size, _mbuffer_get_udata_ptr (bufel),
+ send_data_size, target_length, _mbuffer_get_udata_ptr (bufel),
cipher_size, type, record_params);
if (ret <= 0)
{
return 0;
}
-#define MAX_EMPTY_PACKETS_SEQUENCE 4
-
/* @ms: is the number of milliseconds to wait for data. Use zero for indefinite.
*
* This will receive record layer packets and add them to
mbuffer_st* bufel = NULL, *decrypted = NULL;
gnutls_datum_t t;
int ret;
- int empty_packet = 0;
+ unsigned int empty_fragments = 0;
record_parameters_st *record_params;
record_state_st *record_state;
struct tls_record_st record;
begin:
- if (empty_packet > MAX_EMPTY_PACKETS_SEQUENCE)
+ if (empty_fragments > session->internals.priorities.max_empty_records)
{
gnutls_assert ();
return GNUTLS_E_TOO_MANY_EMPTY_PACKETS;
if (_mbuffer_get_udata_size(decrypted) == 0)
{
_mbuffer_xfree(&decrypted);
- empty_packet++;
+ empty_fragments++;
goto begin;
}
#include <gnutls/gnutls.h>
#include <gnutls_buffers.h>
+ssize_t _gnutls_send_tlen_int (gnutls_session_t session, content_type_t type,
+ gnutls_handshake_description_t htype,
+ unsigned int epoch_rel, const void *data,
+ size_t sizeofdata, unsigned int mflags,
+ size_t targetlength);
ssize_t _gnutls_send_int (gnutls_session_t session, content_type_t type,
gnutls_handshake_description_t htype,
unsigned int epoch_rel, const void *data,
int gnutls_heartbeat_pong (gnutls_session_t session, unsigned int flags);
void gnutls_record_set_timeout (gnutls_session_t session, unsigned int ms);
+
+ typedef struct {
+ size_t low;
+ size_t high;
+ } gnutls_range_st;
+
ssize_t gnutls_record_send (gnutls_session_t session, const void *data,
size_t data_size);
+ ssize_t gnutls_range_send_message (gnutls_session_t session, const void *data,
+ size_t data_size, gnutls_range_st range);
ssize_t gnutls_record_recv (gnutls_session_t session, void *data,
size_t data_size);
#define gnutls_read gnutls_record_recv
void gnutls_session_enable_compatibility_mode (gnutls_session_t session);
- void gnutls_record_disable_padding (gnutls_session_t session);
+ void gnutls_record_max_empty_records (gnutls_session_t session, const unsigned int i);
+
+ int gnutls_range_can_use_length_hiding (gnutls_session_t session);
int gnutls_record_get_direction (gnutls_session_t session);
size_t gnutls_record_get_max_size (gnutls_session_t session);
ssize_t gnutls_record_set_max_size (gnutls_session_t session, size_t size);
- int gnutls_record_get_random_padding_status (gnutls_session_t session);
size_t gnutls_record_check_pending (gnutls_session_t session);
*
* DO NOT EDIT THIS FILE (cli-args.c)
*
- * It has been AutoGen-ed November 9, 2012 at 05:12:10 PM by AutoGen 5.16
+ * It has been AutoGen-ed January 22, 2013 at 05:25:25 PM by AutoGen 5.15
* From the definitions cli-args.def
* and the template file options
*
- * Generated from AutoOpts 36:4:11 templates.
+ * Generated from AutoOpts 36:3:11 templates.
*
* AutoOpts is a copyrighted work. This source file is not encumbered
* by AutoOpts licensing, but is provided under the licensing terms chosen
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-#ifndef __doxygen__
#define OPTION_CODE_COMPILE 1
#include "cli-args.h"
#include <sys/types.h>
#define zCopyright (gnutls_cli_opt_strs+0)
#define zLicenseDescrip (gnutls_cli_opt_strs+281)
+extern tUsageProc optionUsage;
#ifndef NULL
# define NULL 0
/*
* gnutls-cli option static const strings
*/
-static char const gnutls_cli_opt_strs[3786] =
+static char const gnutls_cli_opt_strs[3868] =
/* 0 */ "gnutls-cli @VERSION@\n"
"Copyright (C) 2000-2012 Free Software Foundation, all rights reserved.\n"
"This is free software. It is licensed for use, modification and\n"
/* 2762 */ "Don't abort program if server certificate can't be validated\0"
/* 2823 */ "INSECURE\0"
/* 2832 */ "insecure\0"
-/* 2841 */ "Benchmark individual ciphers\0"
-/* 2870 */ "BENCHMARK_CIPHERS\0"
-/* 2888 */ "benchmark-ciphers\0"
-/* 2906 */ "Benchmark individual software ciphers (no hw acceleration)\0"
-/* 2965 */ "BENCHMARK_SOFT_CIPHERS\0"
-/* 2988 */ "benchmark-soft-ciphers\0"
-/* 3011 */ "Benchmark TLS key exchange methods\0"
-/* 3046 */ "BENCHMARK_TLS_KX\0"
-/* 3063 */ "benchmark-tls-kx\0"
-/* 3080 */ "Benchmark TLS ciphers\0"
-/* 3102 */ "BENCHMARK_TLS_CIPHERS\0"
-/* 3124 */ "benchmark-tls-ciphers\0"
-/* 3146 */ "Print a list of the supported algorithms and modes\0"
-/* 3197 */ "LIST\0"
-/* 3202 */ "list\0"
-/* 3207 */ "Display extended usage information and exit\0"
-/* 3251 */ "help\0"
-/* 3256 */ "Extended usage information passed thru pager\0"
-/* 3301 */ "more-help\0"
-/* 3311 */ "Output version information and exit\0"
-/* 3347 */ "version\0"
-/* 3355 */ "GNUTLS_CLI\0"
-/* 3366 */ "gnutls-cli - GnuTLS client - Ver. @VERSION@\n"
+/* 2841 */ "When possible, use length-hiding padding to prevent traffic analysis\0"
+/* 2910 */ "RANGES\0"
+/* 2917 */ "ranges\0"
+/* 2924 */ "Benchmark individual ciphers\0"
+/* 2953 */ "BENCHMARK_CIPHERS\0"
+/* 2971 */ "benchmark-ciphers\0"
+/* 2989 */ "Benchmark individual software ciphers (no hw acceleration)\0"
+/* 3048 */ "BENCHMARK_SOFT_CIPHERS\0"
+/* 3071 */ "benchmark-soft-ciphers\0"
+/* 3094 */ "Benchmark TLS key exchange methods\0"
+/* 3129 */ "BENCHMARK_TLS_KX\0"
+/* 3146 */ "benchmark-tls-kx\0"
+/* 3163 */ "Benchmark TLS ciphers\0"
+/* 3185 */ "BENCHMARK_TLS_CIPHERS\0"
+/* 3207 */ "benchmark-tls-ciphers\0"
+/* 3229 */ "Print a list of the supported algorithms and modes\0"
+/* 3280 */ "LIST\0"
+/* 3285 */ "list\0"
+/* 3290 */ "Display extended usage information and exit\0"
+/* 3334 */ "help\0"
+/* 3339 */ "Extended usage information passed thru pager\0"
+/* 3384 */ "more-help\0"
+/* 3394 */ "Output version information and exit\0"
+/* 3430 */ "version\0"
+/* 3438 */ "GNUTLS_CLI\0"
+/* 3449 */ "gnutls-cli - GnuTLS client - Ver. @VERSION@\n"
"USAGE: %s [ -<flag> [<val>] | --<name>[{=| }<val>] ]... [hostname]\n\0"
-/* 3479 */ "bug-gnutls@gnu.org\0"
-/* 3498 */ "\n\n\0"
-/* 3501 */ "\n"
- "Simple client program to set up a TLS connection to some other computer. It\n"
- "sets up a TLS connection and forwards data from the standard input to the\n"
- "secured socket and vice versa.\n\0"
-/* 3685 */ "gnutls-cli @VERSION@\0"
-/* 3706 */ "Usage: gnutls-cli [options] hostname\n"
+/* 3562 */ "bug-gnutls@gnu.org\0"
+/* 3581 */ "\n\n\0"
+/* 3584 */ "\n"
+ "Simple client program to set up a TLS connection to some other computer.\n"
+ "It sets up a TLS connection and forwards data from the standard input to\n"
+ "the secured socket and vice versa.\n\0"
+/* 3767 */ "gnutls-cli @VERSION@\0"
+/* 3788 */ "Usage: gnutls-cli [options] hostname\n"
"gnutls-cli --help for usage instructions.\n";
/*
#define INSECURE_name (gnutls_cli_opt_strs+2832)
#define INSECURE_FLAGS (OPTST_DISABLED)
+/*
+ * ranges option description:
+ */
+#define RANGES_DESC (gnutls_cli_opt_strs+2841)
+#define RANGES_NAME (gnutls_cli_opt_strs+2910)
+#define RANGES_name (gnutls_cli_opt_strs+2917)
+#define RANGES_FLAGS (OPTST_DISABLED)
+
/*
* benchmark-ciphers option description:
*/
-#define BENCHMARK_CIPHERS_DESC (gnutls_cli_opt_strs+2841)
-#define BENCHMARK_CIPHERS_NAME (gnutls_cli_opt_strs+2870)
-#define BENCHMARK_CIPHERS_name (gnutls_cli_opt_strs+2888)
+#define BENCHMARK_CIPHERS_DESC (gnutls_cli_opt_strs+2924)
+#define BENCHMARK_CIPHERS_NAME (gnutls_cli_opt_strs+2953)
+#define BENCHMARK_CIPHERS_name (gnutls_cli_opt_strs+2971)
#define BENCHMARK_CIPHERS_FLAGS (OPTST_DISABLED)
/*
* benchmark-soft-ciphers option description:
*/
-#define BENCHMARK_SOFT_CIPHERS_DESC (gnutls_cli_opt_strs+2906)
-#define BENCHMARK_SOFT_CIPHERS_NAME (gnutls_cli_opt_strs+2965)
-#define BENCHMARK_SOFT_CIPHERS_name (gnutls_cli_opt_strs+2988)
+#define BENCHMARK_SOFT_CIPHERS_DESC (gnutls_cli_opt_strs+2989)
+#define BENCHMARK_SOFT_CIPHERS_NAME (gnutls_cli_opt_strs+3048)
+#define BENCHMARK_SOFT_CIPHERS_name (gnutls_cli_opt_strs+3071)
#define BENCHMARK_SOFT_CIPHERS_FLAGS (OPTST_DISABLED)
/*
* benchmark-tls-kx option description:
*/
-#define BENCHMARK_TLS_KX_DESC (gnutls_cli_opt_strs+3011)
-#define BENCHMARK_TLS_KX_NAME (gnutls_cli_opt_strs+3046)
-#define BENCHMARK_TLS_KX_name (gnutls_cli_opt_strs+3063)
+#define BENCHMARK_TLS_KX_DESC (gnutls_cli_opt_strs+3094)
+#define BENCHMARK_TLS_KX_NAME (gnutls_cli_opt_strs+3129)
+#define BENCHMARK_TLS_KX_name (gnutls_cli_opt_strs+3146)
#define BENCHMARK_TLS_KX_FLAGS (OPTST_DISABLED)
/*
* benchmark-tls-ciphers option description:
*/
-#define BENCHMARK_TLS_CIPHERS_DESC (gnutls_cli_opt_strs+3080)
-#define BENCHMARK_TLS_CIPHERS_NAME (gnutls_cli_opt_strs+3102)
-#define BENCHMARK_TLS_CIPHERS_name (gnutls_cli_opt_strs+3124)
+#define BENCHMARK_TLS_CIPHERS_DESC (gnutls_cli_opt_strs+3163)
+#define BENCHMARK_TLS_CIPHERS_NAME (gnutls_cli_opt_strs+3185)
+#define BENCHMARK_TLS_CIPHERS_name (gnutls_cli_opt_strs+3207)
#define BENCHMARK_TLS_CIPHERS_FLAGS (OPTST_DISABLED)
/*
* list option description:
*/
-#define LIST_DESC (gnutls_cli_opt_strs+3146)
-#define LIST_NAME (gnutls_cli_opt_strs+3197)
-#define LIST_name (gnutls_cli_opt_strs+3202)
+#define LIST_DESC (gnutls_cli_opt_strs+3229)
+#define LIST_NAME (gnutls_cli_opt_strs+3280)
+#define LIST_name (gnutls_cli_opt_strs+3285)
#define LIST_FLAGS (OPTST_DISABLED)
/*
* Help/More_Help/Version option descriptions:
*/
-#define HELP_DESC (gnutls_cli_opt_strs+3207)
-#define HELP_name (gnutls_cli_opt_strs+3251)
+#define HELP_DESC (gnutls_cli_opt_strs+3290)
+#define HELP_name (gnutls_cli_opt_strs+3334)
#ifdef HAVE_WORKING_FORK
-#define MORE_HELP_DESC (gnutls_cli_opt_strs+3256)
-#define MORE_HELP_name (gnutls_cli_opt_strs+3301)
+#define MORE_HELP_DESC (gnutls_cli_opt_strs+3339)
+#define MORE_HELP_name (gnutls_cli_opt_strs+3384)
#define MORE_HELP_FLAGS (OPTST_IMM | OPTST_NO_INIT)
#else
#define MORE_HELP_DESC NULL
# define VER_FLAGS (OPTST_SET_ARGTYPE(OPARG_TYPE_STRING) | \
OPTST_ARG_OPTIONAL | OPTST_IMM | OPTST_NO_INIT)
#endif
-#define VER_DESC (gnutls_cli_opt_strs+3311)
-#define VER_name (gnutls_cli_opt_strs+3347)
+#define VER_DESC (gnutls_cli_opt_strs+3394)
+#define VER_name (gnutls_cli_opt_strs+3430)
/*
* Declare option callback procedures
*/
doOptPgpkeyring, doOptRecordsize, doOptX509crlfile, doUsageOpt;
#define VER_PROC optionPrintVersion
-/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
-/**
- * Define the gnutls-cli Option Descriptions.
- * This is an array of OPTION_CT entries, one for each
- * option that the gnutls-cli program responds to.
+/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
+ *
+ * Define the Gnutls_Cli Option Descriptions.
*/
static tOptDesc optDesc[OPTION_CT] = {
{ /* entry idx, value */ 0, VALUE_OPT_DEBUG,
/* desc, NAME, name */ INSECURE_DESC, INSECURE_NAME, INSECURE_name,
/* disablement strs */ NULL, NULL },
- { /* entry idx, value */ 37, VALUE_OPT_BENCHMARK_CIPHERS,
- /* equiv idx, value */ 37, VALUE_OPT_BENCHMARK_CIPHERS,
+ { /* entry idx, value */ 37, VALUE_OPT_RANGES,
+ /* equiv idx, value */ 37, VALUE_OPT_RANGES,
+ /* equivalenced to */ NO_EQUIVALENT,
+ /* min, max, act ct */ 0, 1, 0,
+ /* opt state flags */ RANGES_FLAGS, 0,
+ /* last opt argumnt */ { NULL }, /* --ranges */
+ /* arg list/cookie */ NULL,
+ /* must/cannot opts */ NULL, NULL,
+ /* option proc */ NULL,
+ /* desc, NAME, name */ RANGES_DESC, RANGES_NAME, RANGES_name,
+ /* disablement strs */ NULL, NULL },
+
+ { /* entry idx, value */ 38, VALUE_OPT_BENCHMARK_CIPHERS,
+ /* equiv idx, value */ 38, VALUE_OPT_BENCHMARK_CIPHERS,
/* equivalenced to */ NO_EQUIVALENT,
/* min, max, act ct */ 0, 1, 0,
/* opt state flags */ BENCHMARK_CIPHERS_FLAGS, 0,
/* desc, NAME, name */ BENCHMARK_CIPHERS_DESC, BENCHMARK_CIPHERS_NAME, BENCHMARK_CIPHERS_name,
/* disablement strs */ NULL, NULL },
- { /* entry idx, value */ 38, VALUE_OPT_BENCHMARK_SOFT_CIPHERS,
- /* equiv idx, value */ 38, VALUE_OPT_BENCHMARK_SOFT_CIPHERS,
+ { /* entry idx, value */ 39, VALUE_OPT_BENCHMARK_SOFT_CIPHERS,
+ /* equiv idx, value */ 39, VALUE_OPT_BENCHMARK_SOFT_CIPHERS,
/* equivalenced to */ NO_EQUIVALENT,
/* min, max, act ct */ 0, 1, 0,
/* opt state flags */ BENCHMARK_SOFT_CIPHERS_FLAGS, 0,
/* desc, NAME, name */ BENCHMARK_SOFT_CIPHERS_DESC, BENCHMARK_SOFT_CIPHERS_NAME, BENCHMARK_SOFT_CIPHERS_name,
/* disablement strs */ NULL, NULL },
- { /* entry idx, value */ 39, VALUE_OPT_BENCHMARK_TLS_KX,
- /* equiv idx, value */ 39, VALUE_OPT_BENCHMARK_TLS_KX,
+ { /* entry idx, value */ 40, VALUE_OPT_BENCHMARK_TLS_KX,
+ /* equiv idx, value */ 40, VALUE_OPT_BENCHMARK_TLS_KX,
/* equivalenced to */ NO_EQUIVALENT,
/* min, max, act ct */ 0, 1, 0,
/* opt state flags */ BENCHMARK_TLS_KX_FLAGS, 0,
/* desc, NAME, name */ BENCHMARK_TLS_KX_DESC, BENCHMARK_TLS_KX_NAME, BENCHMARK_TLS_KX_name,
/* disablement strs */ NULL, NULL },
- { /* entry idx, value */ 40, VALUE_OPT_BENCHMARK_TLS_CIPHERS,
- /* equiv idx, value */ 40, VALUE_OPT_BENCHMARK_TLS_CIPHERS,
+ { /* entry idx, value */ 41, VALUE_OPT_BENCHMARK_TLS_CIPHERS,
+ /* equiv idx, value */ 41, VALUE_OPT_BENCHMARK_TLS_CIPHERS,
/* equivalenced to */ NO_EQUIVALENT,
/* min, max, act ct */ 0, 1, 0,
/* opt state flags */ BENCHMARK_TLS_CIPHERS_FLAGS, 0,
/* desc, NAME, name */ BENCHMARK_TLS_CIPHERS_DESC, BENCHMARK_TLS_CIPHERS_NAME, BENCHMARK_TLS_CIPHERS_name,
/* disablement strs */ NULL, NULL },
- { /* entry idx, value */ 41, VALUE_OPT_LIST,
- /* equiv idx, value */ 41, VALUE_OPT_LIST,
+ { /* entry idx, value */ 42, VALUE_OPT_LIST,
+ /* equiv idx, value */ 42, VALUE_OPT_LIST,
/* equivalenced to */ NO_EQUIVALENT,
/* min, max, act ct */ 0, 1, 0,
/* opt state flags */ LIST_FLAGS, 0,
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
- * Define the gnutls-cli Option Environment
+ * Define the Gnutls_Cli Option Environment
*/
-#define zPROGNAME (gnutls_cli_opt_strs+3355)
-#define zUsageTitle (gnutls_cli_opt_strs+3366)
+#define zPROGNAME (gnutls_cli_opt_strs+3438)
+#define zUsageTitle (gnutls_cli_opt_strs+3449)
#define zRcName NULL
#define apzHomeList NULL
-#define zBugsAddr (gnutls_cli_opt_strs+3479)
-#define zExplain (gnutls_cli_opt_strs+3498)
-#define zDetail (gnutls_cli_opt_strs+3501)
-#define zFullVersion (gnutls_cli_opt_strs+3685)
-/* extracted from optcode.tlib near line 350 */
+#define zBugsAddr (gnutls_cli_opt_strs+3562)
+#define zExplain (gnutls_cli_opt_strs+3581)
+#define zDetail (gnutls_cli_opt_strs+3584)
+#define zFullVersion (gnutls_cli_opt_strs+3767)
+/* extracted from optcode.tlib near line 349 */
#if defined(ENABLE_NLS)
# define OPTPROC_BASE OPTPROC_TRANSLATE | OPTPROC_NXLAT_OPT
#define gnutls_cli_full_usage (NULL)
-#define gnutls_cli_short_usage (gnutls_cli_opt_strs+3706)
-
-#endif /* not defined __doxygen__ */
+#define gnutls_cli_short_usage (gnutls_cli_opt_strs+3788)
/*
* Create the static procedure(s) declared above.
*/
/**
- * The callout function that invokes the optionUsage function.
+ * The callout function that invokes the USAGE() macro.
*
* @param pOptions the AutoOpts option description structure
* @param pOptDesc the descriptor for the "help" (usage) option.
- * @noreturn
*/
static void
doUsageOpt(tOptions * pOptions, tOptDesc * pOptDesc)
{
- optionUsage(&gnutls_cliOptions, GNUTLS_CLI_EXIT_SUCCESS);
- /* NOTREACHED */
- (void)pOptDesc;
(void)pOptions;
+ USAGE(GNUTLS_CLI_EXIT_SUCCESS);
}
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
optionFileCheck(pOptions, pOptDesc, type, mode);
}
-/* extracted from optmain.tlib near line 1113 */
+/* extracted from optmain.tlib near line 1093 */
-/**
- * The directory containing the data associated with gnutls-cli.
- */
#ifndef PKGDATADIR
# define PKGDATADIR ""
#endif
-/**
- * Information about the person or institution that packaged gnutls-cli
- * for the current distribution.
- */
#ifndef WITH_PACKAGER
# define gnutls_cli_packager_info NULL
#else
# endif
"\n";
#endif
-#ifndef __doxygen__
-#endif /* __doxygen__ */
-/**
- * The option definitions for gnutls-cli. The one structure that
- * binds them all.
- */
tOptions gnutls_cliOptions = {
OPTIONS_STRUCT_VERSION,
0, NULL, /* original argc + argv */
NO_EQUIVALENT, /* '-#' option index */
NO_EQUIVALENT /* index of default opt */
},
- 45 /* full option count */, 42 /* user option count */,
+ 46 /* full option count */, 43 /* user option count */,
gnutls_cli_full_usage, gnutls_cli_short_usage,
NULL, NULL,
PKGDATADIR, gnutls_cli_packager_info
static char* AO_gettext(char const* pz);
static void coerce_it(void** s);
-/**
- * AutoGen specific wrapper function for gettext.
- * It relies on the macro _() to convert from English to the target
- * language, then strdup-duplicates the result string.
- *
- * @param[in] pz the input text used as a lookup key.
- * @returns the translated text (if there is one),
- * or the original text (if not).
- */
-static char *
+static char*
AO_gettext(char const* pz)
{
char* pzRes;
static void coerce_it(void** s) { *s = AO_gettext(*s);
}
-/**
- * Translate all the translatable strings in the gnutls_cliOptions
- * structure defined above. This is done only once.
+/*
+ * This invokes the translation code (e.g. gettext(3)).
*/
static void
translate_option_strings(void)
doc = "";
};
+flag = {
+ name = ranges;
+ descrip = "When possible, use length-hiding padding to prevent traffic analysis";
+ doc = "";
+};
+
flag = {
name = benchmark-ciphers;
descrip = "Benchmark individual ciphers";
*
* DO NOT EDIT THIS FILE (cli-args.h)
*
- * It has been AutoGen-ed November 9, 2012 at 05:12:09 PM by AutoGen 5.16
+ * It has been AutoGen-ed January 22, 2013 at 05:25:25 PM by AutoGen 5.15
* From the definitions cli-args.def
* and the template file options
*
- * Generated from AutoOpts 36:4:11 templates.
+ * Generated from AutoOpts 36:3:11 templates.
*
* AutoOpts is a copyrighted work. This header file is not encumbered
* by AutoOpts licensing, but is provided under the licensing terms chosen
* tolerable version is at least as old as what was current when the header
* template was released.
*/
-#define AO_TEMPLATE_VERSION 147460
+#define AO_TEMPLATE_VERSION 147459
#if (AO_TEMPLATE_VERSION < OPTIONS_MINIMUM_VERSION) \
|| (AO_TEMPLATE_VERSION > OPTIONS_STRUCT_VERSION)
# error option template version mismatches autoopts/options.h header
INDEX_OPT_PSKKEY = 34,
INDEX_OPT_PORT = 35,
INDEX_OPT_INSECURE = 36,
- INDEX_OPT_BENCHMARK_CIPHERS = 37,
- INDEX_OPT_BENCHMARK_SOFT_CIPHERS = 38,
- INDEX_OPT_BENCHMARK_TLS_KX = 39,
- INDEX_OPT_BENCHMARK_TLS_CIPHERS = 40,
- INDEX_OPT_LIST = 41,
- INDEX_OPT_VERSION = 42,
- INDEX_OPT_HELP = 43,
- INDEX_OPT_MORE_HELP = 44
+ INDEX_OPT_RANGES = 37,
+ INDEX_OPT_BENCHMARK_CIPHERS = 38,
+ INDEX_OPT_BENCHMARK_SOFT_CIPHERS = 39,
+ INDEX_OPT_BENCHMARK_TLS_KX = 40,
+ INDEX_OPT_BENCHMARK_TLS_CIPHERS = 41,
+ INDEX_OPT_LIST = 42,
+ INDEX_OPT_VERSION = 43,
+ INDEX_OPT_HELP = 44,
+ INDEX_OPT_MORE_HELP = 45
} teOptIndex;
-#define OPTION_CT 45
+#define OPTION_CT 46
#define GNUTLS_CLI_VERSION "@VERSION@"
#define GNUTLS_CLI_FULL_VERSION "gnutls-cli @VERSION@"
*/
typedef enum {
GNUTLS_CLI_EXIT_SUCCESS = 0,
- GNUTLS_CLI_EXIT_FAILURE = 1,
- GNUTLS_CLI_EXIT_LIBOPTS_FAILURE = 70
+ GNUTLS_CLI_EXIT_FAILURE = 1
} gnutls_cli_exit_code_t;
/* * * * * *
*
#define VALUE_OPT_PSKKEY 130
#define VALUE_OPT_PORT 'p'
#define VALUE_OPT_INSECURE 132
-#define VALUE_OPT_BENCHMARK_CIPHERS 133
-#define VALUE_OPT_BENCHMARK_SOFT_CIPHERS 134
-#define VALUE_OPT_BENCHMARK_TLS_KX 135
-#define VALUE_OPT_BENCHMARK_TLS_CIPHERS 136
+#define VALUE_OPT_RANGES 133
+#define VALUE_OPT_BENCHMARK_CIPHERS 134
+#define VALUE_OPT_BENCHMARK_SOFT_CIPHERS 135
+#define VALUE_OPT_BENCHMARK_TLS_KX 136
+#define VALUE_OPT_BENCHMARK_TLS_CIPHERS 137
#define VALUE_OPT_LIST 'l'
#define VALUE_OPT_HELP 'h'
#define VALUE_OPT_MORE_HELP '!'
gnutls_cliOptions.pzCurOpt = NULL)
#define START_OPT RESTART_OPT(1)
#define USAGE(c) (*gnutls_cliOptions.pUsageProc)(&gnutls_cliOptions, c)
-/* extracted from opthead.tlib near line 484 */
+/* extracted from opthead.tlib near line 469 */
#ifdef __cplusplus
extern "C" {
#define MAX_BUF 4096
/* global stuff here */
-int resume, starttls, insecure, rehandshake, udp, mtu;
+int resume, starttls, insecure, ranges, rehandshake, udp, mtu;
const char *hostname = NULL;
const char *service = NULL;
int record_max_size;
bytes++;
}
}
-
- ret = socket_send (&hd, buffer, bytes);
+ if (ranges && gnutls_range_can_use_length_hiding(hd.session)) {
+ gnutls_range_st range;
+ range.low = 0;
+ range.high = MAX_BUF;
+ ret = socket_send_range (&hd, buffer, bytes, &range);
+ } else {
+ ret = socket_send(&hd, buffer, bytes);
+ }
if (ret > 0)
{
resume = HAVE_OPT(RESUME);
rehandshake = HAVE_OPT(REHANDSHAKE);
insecure = HAVE_OPT(INSECURE);
+ ranges = HAVE_OPT(RANGES);
udp = HAVE_OPT(UDP);
mtu = OPT_VALUE_MTU;
ssize_t
socket_send (const socket_st * socket, const void *buffer, int buffer_size)
+{
+ return socket_send_range(socket, buffer, buffer_size, NULL);
+}
+
+
+ssize_t
+socket_send_range (const socket_st * socket, const void *buffer, int buffer_size, gnutls_range_st *range)
{
int ret;
if (socket->secure)
do
{
- ret = gnutls_record_send (socket->session, buffer, buffer_size);
+ if (range == NULL) {
+ ret = gnutls_record_send (socket->session, buffer, buffer_size);
+ } else {
+ ret = gnutls_range_send_message(socket->session, buffer, buffer_size, *range);
+ }
}
while (ret == GNUTLS_E_AGAIN || ret == GNUTLS_E_INTERRUPTED);
else
ssize_t socket_recv (const socket_st * socket, void *buffer, int buffer_size);
ssize_t socket_send (const socket_st * socket, const void *buffer,
int buffer_size);
+ssize_t socket_send_range(const socket_st * socket, const void *buffer,
+ int buffer_size, gnutls_range_st *range);
void socket_open (socket_st * hd, const char *hostname, const char *service, int udp);
void socket_bye (socket_st * socket);
#define AES_CBC_SHA256 "NONE:+VERS-DTLS1.0:-CIPHER-ALL:+RSA:+AES-128-CBC:+AES-256-CBC:+SHA256:+SIGN-ALL:+COMP-ALL:+ANON-ECDH:+CURVE-ALL"
#define AES_GCM "NONE:+VERS-DTLS1.0:-CIPHER-ALL:+RSA:+AES-128-GCM:+MAC-ALL:+SIGN-ALL:+COMP-ALL:+ANON-ECDH:+CURVE-ALL"
-#define NEW_AES_CBC "NONE:+VERS-DTLS1.0:-CIPHER-ALL:+AES-128-CBC:+SHA1:+SIGN-ALL:+COMP-ALL:+ANON-ECDH:+CURVE-ALL:%RANDOM_PADDING"
-#define NEW_AES_CBC_SHA256 "NONE:+VERS-DTLS1.0:-CIPHER-ALL:+RSA:+AES-128-CBC:+AES-256-CBC:+SHA256:+SIGN-ALL:+COMP-ALL:+ANON-ECDH:+CURVE-ALL:%RANDOM_PADDING"
-#define NEW_AES_GCM "NONE:+VERS-DTLS1.0:-CIPHER-ALL:+RSA:+AES-128-GCM:+MAC-ALL:+SIGN-ALL:+COMP-ALL:+ANON-ECDH:+CURVE-ALL:%RANDOM_PADDING"
+#define NEW_AES_CBC "NONE:+VERS-DTLS1.0:-CIPHER-ALL:+AES-128-CBC:+SHA1:+SIGN-ALL:+COMP-ALL:+ANON-ECDH:+CURVE-ALL:%NEW_PADDING"
+#define NEW_AES_CBC_SHA256 "NONE:+VERS-DTLS1.0:-CIPHER-ALL:+RSA:+AES-128-CBC:+AES-256-CBC:+SHA256:+SIGN-ALL:+COMP-ALL:+ANON-ECDH:+CURVE-ALL:%NEW_PADDING"
+#define NEW_AES_GCM "NONE:+VERS-DTLS1.0:-CIPHER-ALL:+RSA:+AES-128-GCM:+MAC-ALL:+SIGN-ALL:+COMP-ALL:+ANON-ECDH:+CURVE-ALL:%NEW_PADDING"
static void ch_handler(int sig)
{