@node gnutls-cli Invocation
@section Invoking gnutls-cli
@pindex gnutls-cli
@ignore
#  -*- buffer-read-only: t -*- vi: set ro:
#
# DO NOT EDIT THIS FILE   (invoke-gnutls-cli.texi)
#
# It has been AutoGen-ed
# From the definitions    ../src/cli-args.def
# and the template file   agtexi-cmd.tpl
@end ignore


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.

This section was generated by @strong{AutoGen},
using the @code{agtexi-cmd} template and the option descriptions for the @code{gnutls-cli} program.
This software is released under the GNU General Public License, version 3 or later.


@anchor{gnutls-cli usage}
@subheading gnutls-cli help/usage (@option{--help})
@cindex gnutls-cli help

This is the automatically generated usage text for gnutls-cli.

The text printed is the same whether selected with the @code{help} option
(@option{--help}) or the @code{more-help} option (@option{--more-help}).  @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.

@exampleindent 0
@example
gnutls-cli is unavailable - no --help
@end example
@exampleindent 4

@anchor{gnutls-cli debug}
@subheading debug option (-d)

This is the ``enable debugging'' option.
This option takes a number argument.
Specifies the debug level.
@anchor{gnutls-cli tofu}
@subheading tofu option

This is the ``enable trust on first use authentication'' option.

@noindent
This option has some usage constraints.  It:
@itemize @bullet
@item
can be disabled with --no-tofu.
@end itemize

This option will, in addition to certificate authentication, perform authentication
based on previously seen public keys, a model similar to SSH authentication. Note that when tofu 
is specified (PKI) and DANE authentication will become advisory to assist the public key acceptance
process.
@anchor{gnutls-cli strict-tofu}
@subheading strict-tofu option

This is the ``fail to connect if a known certificate has changed'' option.

@noindent
This option has some usage constraints.  It:
@itemize @bullet
@item
can be disabled with --no-strict-tofu.
@end itemize

This option will perform authentication as with option --tofu; however, while --tofu asks whether to trust a changed public key, this option will fail in case of public key changes.
@anchor{gnutls-cli dane}
@subheading dane option

This is the ``enable dane certificate verification (dnssec)'' option.

@noindent
This option has some usage constraints.  It:
@itemize @bullet
@item
can be disabled with --no-dane.
@end itemize

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 local-dns}
@subheading local-dns option

This is the ``use the local dns server for dnssec resolving'' option.

@noindent
This option has some usage constraints.  It:
@itemize @bullet
@item
can be disabled with --no-local-dns.
@end itemize

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 ``enable ca certificate verification'' option.

@noindent
This option has some usage constraints.  It:
@itemize @bullet
@item
can be disabled with --no-ca-verification.
@item
It is enabled by default.
@end itemize

This option can be used to enable or 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.

@noindent
This option has some usage constraints.  It:
@itemize @bullet
@item
can be disabled with --no-ocsp.
@end itemize

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)

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 ``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 app-proto}
@subheading app-proto option

This is an alias for the @code{starttls-proto} option,
@pxref{gnutls-cli starttls-proto, the starttls-proto option documentation}.

@anchor{gnutls-cli starttls-proto}
@subheading starttls-proto option

This is the ``the application protocol to be used to obtain the server's certificate (https, ftp, smtp, imap)'' option.
This option takes a string argument.

@noindent
This option has some usage constraints.  It:
@itemize @bullet
@item
must not appear in combination with any of the following options:
starttls.
@end itemize

Specify the application layer protocol for STARTTLS. If the protocol is supported, gnutls-cli will proceed to the TLS negotiation.
@anchor{gnutls-cli dh-bits}
@subheading dh-bits option

This is the ``the minimum number of bits allowed for dh'' option.
This option takes a number argument.
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 a string argument.
TLS algorithms and protocols to enable. You can
use predefined sets of ciphersuites such as PERFORMANCE,
NORMAL, PFS, SECURE128, SECURE256. The default is NORMAL.

Check  the  GnuTLS  manual  on  section  ``Priority strings'' for more
information on the allowed keywords
@anchor{gnutls-cli ranges}
@subheading ranges option

This is the ``use length-hiding padding to prevent traffic analysis'' option.
When possible (e.g., when using CBC ciphersuites), use length-hiding padding to prevent traffic analysis.
@anchor{gnutls-cli benchmark-ciphers}
@subheading benchmark-ciphers option

This is the ``benchmark individual ciphers'' option.
By default the benchmarked ciphers will utilize any capabilities of the local CPU to improve performance. To test against the raw software implementation set the environment variable GNUTLS_CPUID_OVERRIDE to 0x1.
@anchor{gnutls-cli benchmark-tls-ciphers}
@subheading benchmark-tls-ciphers option

This is the ``benchmark tls ciphers'' option.
By default the benchmarked ciphers will utilize any capabilities of the local CPU to improve performance. To test against the raw software implementation set the environment variable GNUTLS_CPUID_OVERRIDE to 0x1.
@anchor{gnutls-cli list}
@subheading list option (-l)

This is the ``print a list of the supported algorithms and modes'' option.

@noindent
This option has some usage constraints.  It:
@itemize @bullet
@item
must not appear in combination with any of the following options:
port.
@end itemize

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 priority-list}
@subheading priority-list option

This is the ``print a list of the supported priority strings'' option.
Print a list of the supported priority strings. The ciphersuites corresponding to each priority string can be examined using -l -p.
@anchor{gnutls-cli alpn}
@subheading alpn option

This is the ``application layer protocol'' option.
This option takes a string argument.

@noindent
This option has some usage constraints.  It:
@itemize @bullet
@item
may appear an unlimited number of times.
@end itemize

This option will set and enable the Application Layer Protocol Negotiation  (ALPN) in the TLS protocol.
@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 inline-commands}
@subheading inline-commands option

This is the ``inline commands of the form ^<cmd>^'' option.
Enable inline commands of the form ^<cmd>^. The inline commands are expected to be in a line by themselves. The available commands are: resume and renegotiate.
@anchor{gnutls-cli inline-commands-prefix}
@subheading inline-commands-prefix option

This is the ``change the default delimiter for inline commands.'' option.
This option takes a string argument.
Change the default delimiter (^) used for inline commands. The delimiter is expected to be a single US-ASCII character (octets 0 - 127). This option is only relevant if inline commands are enabled via the inline-commands option
@anchor{gnutls-cli provider}
@subheading provider option

This is the ``specify the pkcs #11 provider library'' option.
This option takes a file argument.
This will override the default options in /etc/gnutls/pkcs11.conf
@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)
Successful program execution.
@item 1 (EXIT_FAILURE)
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
$ ./gnutls-cli -p 5556 localhost --pskusername psk_identity \
    --pskkey 88f3824b3e5659f52d00e959bacab954b6540344 \
    --priority NORMAL:-KX-ALL:+ECDHE-PSK:+DHE-PSK:+PSK
Resolving 'localhost'...
Connecting to '127.0.0.1:5556'...
- PSK authentication.
- Version: TLS1.1
- Key Exchange: PSK
- Cipher: AES-128-CBC
- MAC: SHA1
- Compression: NULL
- Handshake was completed
    
- Simple Client Mode:
@end example
By keeping the --pskusername parameter and removing the --pskkey parameter, it will query only for the password during the handshake. 

@subheading Listing ciphersuites in a priority string
To list the ciphersuites in a priority string:
@example
$ ./gnutls-cli --priority SECURE192 -l
Cipher suites for SECURE192
TLS_ECDHE_ECDSA_AES_256_CBC_SHA384         0xc0, 0x24	TLS1.2
TLS_ECDHE_ECDSA_AES_256_GCM_SHA384         0xc0, 0x2e	TLS1.2
TLS_ECDHE_RSA_AES_256_GCM_SHA384           0xc0, 0x30	TLS1.2
TLS_DHE_RSA_AES_256_CBC_SHA256             0x00, 0x6b	TLS1.2
TLS_DHE_DSS_AES_256_CBC_SHA256             0x00, 0x6a	TLS1.2
TLS_RSA_AES_256_CBC_SHA256                 0x00, 0x3d	TLS1.2

Certificate types: CTYPE-X.509
Protocols: VERS-TLS1.2, VERS-TLS1.1, VERS-TLS1.0, VERS-SSL3.0, VERS-DTLS1.0
Compression: COMP-NULL
Elliptic curves: CURVE-SECP384R1, CURVE-SECP521R1
PK-signatures: SIGN-RSA-SHA384, SIGN-ECDSA-SHA384, SIGN-RSA-SHA512, SIGN-ECDSA-SHA512
@end example

@subheading Connecting using a PKCS #11 token
To connect to a server using a certificate and a private key present in a PKCS #11 token you 
need to substitute the PKCS 11 URLs in the x509certfile and x509keyfile parameters.

Those can be found using "p11tool --list-tokens" and then listing all the objects in the
needed token, and using the appropriate.
@example
$ p11tool --list-tokens

Token 0:
URL: pkcs11:model=PKCS15;manufacturer=MyMan;serial=1234;token=Test
Label: Test
Manufacturer: EnterSafe
Model: PKCS15
Serial: 1234

$ p11tool --login --list-certs "pkcs11:model=PKCS15;manufacturer=MyMan;serial=1234;token=Test"

Object 0:
URL: pkcs11:model=PKCS15;manufacturer=MyMan;serial=1234;token=Test;object=client;type=cert
Type: X.509 Certificate
Label: client
ID: 2a:97:0d:58:d1:51:3c:23:07:ae:4e:0d:72:26:03:7d:99:06:02:6a

$ MYCERT="pkcs11:model=PKCS15;manufacturer=MyMan;serial=1234;token=Test;object=client;type=cert"
$ MYKEY="pkcs11:model=PKCS15;manufacturer=MyMan;serial=1234;token=Test;object=client;type=private"
$ export MYCERT MYKEY

$ gnutls-cli www.example.com --x509keyfile $MYKEY --x509certfile $MYCERT
@end example
Notice that the private key only differs from the certificate in the type.
