Index: configure ================================================================== --- configure +++ configure @@ -1,8 +1,8 @@ #! /bin/sh # Guess values for system-dependent variables and create Makefiles. -# Generated by GNU Autoconf 2.72 for tls 1.8.0. +# Generated by GNU Autoconf 2.72 for tls 2.0b1. # # # Copyright (C) 1992-1996, 1998-2017, 2020-2023 Free Software Foundation, # Inc. # @@ -599,12 +599,12 @@ MAKEFLAGS= # Identity of this package. PACKAGE_NAME='tls' PACKAGE_TARNAME='tls' -PACKAGE_VERSION='1.8.0' -PACKAGE_STRING='tls 1.8.0' +PACKAGE_VERSION='2.0b1' +PACKAGE_STRING='tls 2.0b1' PACKAGE_BUGREPORT='' PACKAGE_URL='' # Factoring default headers for most tests. ac_includes_default="\ @@ -1340,11 +1340,11 @@ # if test "$ac_init_help" = "long"; then # Omit some internal or obsolete options to make the list less imposing. # This message is too long to be a string in the A/UX 3.1 sh. cat <<_ACEOF -'configure' configures tls 1.8.0 to adapt to many kinds of systems. +'configure' configures tls 2.0b1 to adapt to many kinds of systems. Usage: $0 [OPTION]... [VAR=VALUE]... To assign environment variables (e.g., CC, CFLAGS...), specify them as VAR=VALUE. See below for descriptions of some of the useful variables. @@ -1402,11 +1402,11 @@ _ACEOF fi if test -n "$ac_init_help"; then case $ac_init_help in - short | recursive ) echo "Configuration of tls 1.8.0:";; + short | recursive ) echo "Configuration of tls 2.0b1:";; esac cat <<\_ACEOF Optional Features: --disable-option-checking ignore unrecognized --enable/--with options @@ -1528,11 +1528,11 @@ fi test -n "$ac_init_help" && exit $ac_status if $ac_init_version; then cat <<\_ACEOF -tls configure 1.8.0 +tls configure 2.0b1 generated by GNU Autoconf 2.72 Copyright (C) 2023 Free Software Foundation, Inc. This configure script is free software; the Free Software Foundation gives unlimited permission to copy, distribute and modify it. @@ -1835,11 +1835,11 @@ cat >config.log <<_ACEOF This file contains any messages produced by compilers while running configure, to aid debugging if configure makes a mistake. -It was created by tls $as_me 1.8.0, which was +It was created by tls $as_me 2.0b1, which was generated by GNU Autoconf 2.72. Invocation command line was $ $0$ac_configure_args_raw _ACEOF @@ -10291,11 +10291,11 @@ cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 # Save the log message, to keep $0 and so on meaningful, and to # report actual input values of CONFIG_FILES etc. instead of their # values after options handling. ac_log=" -This file was extended by tls $as_me 1.8.0, which was +This file was extended by tls $as_me 2.0b1, which was generated by GNU Autoconf 2.72. Invocation command line was CONFIG_FILES = $CONFIG_FILES CONFIG_HEADERS = $CONFIG_HEADERS CONFIG_LINKS = $CONFIG_LINKS @@ -10346,11 +10346,11 @@ ac_cs_config=`printf "%s\n" "$ac_configure_args" | sed "$ac_safe_unquote"` ac_cs_config_escaped=`printf "%s\n" "$ac_cs_config" | sed "s/^ //; s/'/'\\\\\\\\''/g"` cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 ac_cs_config='$ac_cs_config_escaped' ac_cs_version="\\ -tls config.status 1.8.0 +tls config.status 2.0b1 configured by $0, generated by GNU Autoconf 2.72, with options \\"\$ac_cs_config\\" Copyright (C) 2023 Free Software Foundation, Inc. This config.status script is free software; the Free Software Foundation Index: configure.ac ================================================================== --- configure.ac +++ configure.ac @@ -14,11 +14,11 @@ # so you can encode the package version directly into the source files. # This will also define a special symbol for Windows (BUILD_ # so that we create the export library with the dll. #----------------------------------------------------------------------- -AC_INIT([tls],[1.8.0]) +AC_INIT([tls],[2.0b1]) #-------------------------------------------------------------------- # Call TEA_INIT as the first TEA_ macro to set up initial vars. # This will define a ${TEA_PLATFORM} variable == "unix" or "windows" # as well as PKG_LIB_FILE and PKG_STUB_LIB_FILE. Index: doc/tls.html ================================================================== --- doc/tls.html +++ doc/tls.html @@ -98,37 +98,38 @@
-

tls(n) 1.8 tls "Tcl TLS extension"

+

tls(n) 2.0b1 tls "Tcl TLS extension"

Name

tls - binding to the OpenSSL library for encrypted socket and I/O channel communications

Synopsis

  • package require Tcl 8.5-
  • -
  • package require tls 1.8
  • +
  • package require tls 2.0b1
-

Commands

-

Typically one would use the tls::socket command to create a new encrypted -TCP socket. It is compatible with the native TCL ::socket command. -Alternatively for an existing TCP socket, the tls::import command can be -used to start TLS on the connection.

+

Compatibility

+

This extension is compatible with OpenSSL 1.1.1 or later. It requires Tcl +version 8.5 or later and will work with Tcl 9.0.

+
+

Commands

+

The following are the commands provided by the TcLTLS package. See the +Examples for example usage and the "demos" directory for +more example usage.

tls::init ?-option? ?value? ?-option value ...?

Optional function to set the default options used by tls::socket. If you -call tls::import directly, this command has no effect. This command -supports all of the same options as the tls::socket command, though you -should limit your options to only TLS related ones.

+call tls::import directly, the values set by this command have no effect. +This command supports all of the same options as the tls::socket command, +though you should limit your options to only TLS related ones.

tls::socket ?-option? ?value? ?-option value ...? host port

This is a helper function that utilizes the underlying commands socket and tls::import to create the connection. It behaves the same as the native TCL socket command, but also supports the tls:import command options with one additional option. It returns the channel handle id for the new socket.

-autoservername bool

If true, automatically set the -servername argument to the -host argument. Default is false.

+host argument. Prior to TclTLS 2.0, the default is false. +Starting in TclTLS 2.0, the default is true unless -servername +is also specified.

tls::socket -server command ?-option? ?value? ?-option value ...? port

Same as previous, but instead creates a server socket for clients to connect to just like the Tcl socket -server command. It returns the channel handle id for the new socket.

@@ -195,27 +201,28 @@ parameters for SSL handshake. Valid options are:

-alpn list

List of protocols to offer during Application-Layer Protocol Negotiation (ALPN). For example: h2 and http/1.1, but not h3 or -quic.

+quic. This option is new for TclTLS 1.8.

-cadir directory

Specifies the directory where the Certificate Authority (CA) certificates are stored. The default is platform specific and can be set at compile time. The default location can be overridden by the SSL_CERT_DIR environment -variable. See Certificate Validation for more details.

+variable. See Certificate Validation for more details.

-cafile filename

Specifies the file with the Certificate Authority (CA) certificates to use in PEM file format. The default is "cert.pem", in the OpenSSL directory. The default file can be overridden by the SSL_CERT_FILE environment -variable. See Certificate Validation for more details.

+variable. See Certificate Validation for more details.

-castore URI

Specifies the Uniform Resource Identifier (URI) for the Certificate Authority (CA) store, which may be a single container or a catalog of containers. Starting with OpenSSL 3.2 on MS Windows, set to "org.openssl.winstore://" -to use the built-in MS Windows Certificate Store. See -Certificate Validation for more details.

+to use the built-in MS Windows Certificate Store. +See Certificate Validation for more details. +This option is new for TclTLS 1.8.

-certfile filename

Specifies the name of the file with the certificate to use in PEM format as the local (client or server) certificate. It also contains the public key.

-cert string

Specifies the certificate to use as a DER encoded string (X.509 DER).

@@ -232,15 +239,16 @@ documentation for the full list of valid values.

-ciphersuites string

Specifies the list of cipher suites to use for TLS 1.3 as a colon ":" separated list of cipher suite names. See the OpenSSL -documentation for the full list of valid values.

+documentation for the full list of valid values. +This option is new for TclTLS 1.8.

-command callback

Specifies the callback command to be invoked at several points during the handshake to pass errors, tracing information, and protocol messages. -See Callback Options for more info.

+See Callback Options for more info.

-dhparams filename

Specifies the Diffie-Hellman (DH) parameters file.

-keyfile filename

Specifies the private key file. The default is to use the file specified by the -certfile option.

@@ -250,69 +258,76 @@

Force this channel to share the same SSL_CTX structure as the specified channel, and therefore share config, callbacks, etc.

-password callback

Specifies the callback command to invoke when OpenSSL needs to obtain a password. This is typically used to unlock the private key of a certificate. -The callback should return a password string. See Callback Options -for more info.

+The callback should return a password string. This option has changed for +TclTLS 1.8. See Callback Options for more info.

-post_handshake bool
-

Allow post-handshake session ticket updates.

+

Allow post-handshake session ticket updates. This option is new for TclTLS 1.8.

-request bool

Request a certificate from the peer during the SSL handshake. This is needed to do Certificate Validation. Starting in TclTLS 1.8, the default is -true. -See Certificate Validation for more details.

+true. Starting in TclTLS 2.0, If set to false and +-require is true, then this will be overridden to true. +See Certificate Validation for more details.

-require bool

Require a valid certificate from the peer during the SSL handshake. If this is set to true, then -request must also be set to true and a either -cadir, -cafile, -castore, or a platform default must be provided in order to validate against. The default in TclTLS 1.8 and earlier versions is false since not all platforms have certificates to -validate against in a form compatible with OpenSSL. -See Certificate Validation for more details.

+validate against in a form compatible with OpenSSL. Starting in TclTLS 2.0, +the default is true. +See Certificate Validation for more details.

-security_level integer

Specifies the security level (value from 0 to 5). The security level affects the allowed cipher suite encryption algorithms, supported ECC curves, supported signature algorithms, DH parameter sizes, certificate key sizes and signature algorithms. The default is 1 prior to OpenSSL 3.2 and 2 thereafter. Level 3 and higher disable support for session tickets and -only accept cipher suites that provide forward secrecy.

+only accept cipher suites that provide forward secrecy. +This option is new for TclTLS 1.8.

-server bool

Specifies whether to act as a server and respond with a server handshake when a client connects and provides a client handshake. The default is false.

-servername hostname
-

Specify the peer's hostname. This is used to set the TLS Server Name -Indication (SNI) extension. Set this to the expected servername in the -server's certificate or one of the Subject Alternate Names (SAN).

+

Specify the peer's hostname. This is used to set the TLS Server Name Indication +(SNI) extension. Set this to the expected servername in the server's certificate +or one of the Subject Alternate Names (SAN). Starting in TclTLS 2.0, this will +default to the host for the tls::socket command.

-session_id binary_string
-

Specifies the session id to resume a session. Not supported yet.

+

Specifies the session id to resume a session. Not supported yet. +This option is new for TclTLS 1.8.

-ssl2 bool
-

Enable use of SSL v2. The default is false. Note: Recent versions of -OpenSSL no longer support SSLv2, so this may not have any effect. See the -tls::protocols command for supported protocols.

+

Enable use of SSL v2.The default is false. +OpenSSL 1.1+ no longer supports SSL v2, so this may not have any effect. +See the tls::protocols command for supported protocols.

-ssl3 bool
-

Enable use of SSL v3. The default is false. Note: Recent versions -of OpenSSL may have this disabled at compile time, so this may not have any -effect. See the tls::protocols command for supported protocols.

+

Enable use of SSL v3. The default is false. Starting in TclTLS 1.8, +use of SSL v3 if only available via a compile time option. +See the tls::protocols command for supported protocols.

-tls1 bool
-

Enable use of TLS v1. The default is true. Note: TLS 1.0 needs -SHA1 to operate, which is only available in security level 0 for Open SSL 3.0+. -See the -security_level option.

+

Enable use of TLS v1. Starting in TclTLS 2.0, the default is false. +Note: TLS 1.0 needs SHA1 to operate, which is only available in security level +0 for Open SSL 3.0+. See the -security_level option.

-tls1.1 bool
-

Enable use of TLS v1.1. The default is true. Note: TLS 1.1 needs -SHA1 to operate, which is only available in security level 0 for Open SSL 3.0+. -See the -security_level option.

+

Enable use of TLS v1.1. Starting in TclTLS 2.0, the default is false. +Note: TLS 1.1 needs SHA1 to operate, which is only available in security level +0 for Open SSL 3.0+. See the -security_level option.

-tls1.2 bool

Enable use of TLS v1.2. The default is true.

-tls1.3 bool
-

Enable use of TLS v1.3. The default is true.

+

Enable use of TLS v1.3. The default is true. This is only available +starting with OpenSSL 1.1.1 and TclTLS 1.7.

-validatecommand callback

Specifies the callback command to invoke to validate the peer certificates and other config info during the protocol negotiation phase. This can be used by TCL scripts to perform their own Certificate Validation to supplement the default validation provided by OpenSSL. The script must return a boolean true -to continue the negotiation. See Callback Options for more info.

+to continue the negotiation. See Callback Options for more info. +This option is new for TclTLS 1.8.

tls::unimport channel

Compliment to tls::import. Used to remove the top level stacked channel from channel. This unstacks the encryption of a regular TCL channel. An error is thrown if TLS is not the top stacked channel type.

@@ -327,42 +342,54 @@ -local option is specified, then the local certificate is used. Returned values include:

SSL Status

alpn protocol
-

The protocol selected after Application-Layer Protocol Negotiation (ALPN).

+

The protocol selected after Application-Layer Protocol Negotiation (ALPN). +This value is new for TclTLS 1.8.

cipher cipher

The current cipher in use for the session.

peername name
-

The peername from the certificate.

+

The peername from the certificate. +This value is new for TclTLS 1.8.

protocol version
-

The protocol version used for the connection: SSL2, SSL3, TLS1, TLS1.1, TLS1.2, TLS1.3, or unknown.

+

The protocol version used for the connection: SSL2, SSL3, TLS1, TLS1.1, TLS1.2, +TLS1.3, or unknown. This value is new for TclTLS 1.8.

sbits n

The number of bits used for the session key.

signatureHashAlgorithm algorithm
-

The signature hash algorithm.

+

The signature hash algorithm. +This value is new for TclTLS 1.8.

signatureType type
-

The signature type value.

+

The signature type value. +This value is new for TclTLS 1.8.

verifyDepth n
-

Maximum depth for the certificate chain verification. Default is -1, to check all.

+

Maximum depth for the certificate chain verification. Default is -1, to check all. +This value is new for TclTLS 1.8.

verifyMode list
-

List of certificate verification modes.

+

List of certificate verification modes. +This value is new for TclTLS 1.8.

verifyResult result
-

Certificate verification result.

+

Certificate verification result. +This value is new for TclTLS 1.8.

ca_names list
-

List of the Certificate Authorities used to create the certificate.

+

List of the Certificate Authorities used to create the certificate. +This value is new for TclTLS 1.8.

Certificate Status

all string
-

Dump of all certificate info.

+

Dump of all certificate info. +This value is new for TclTLS 1.8.

version value

The certificate version.

serialNumber string
-

The serial number of the certificate as a hex string.

+

The serial number of the certificate as a hex string. +This value was changed from serial in TclTLS 1.8.

signature algorithm
-

Cipher algorithm used for certificate signature.

+

Cipher algorithm used for certificate signature. +This value is new for TclTLS 1.8.

issuer string

The distinguished name (DN) of the certificate issuer.

notBefore date

The beginning date of the certificate validity.

notAfter date
@@ -370,54 +397,72 @@
subject string

The distinguished name (DN) of the certificate subject. Fields include: Common Name (CN), Organization (O), Locality or City (L), State or Province (S), and Country Name (C).

issuerUniqueID string
-

The issuer unique id.

+

The issuer unique id. +This value is new for TclTLS 1.8.

subjectUniqueID string
-

The subject unique id.

+

The subject unique id. +This value is new for TclTLS 1.8.

num_extensions n
-

Number of certificate extensions.

+

Number of certificate extensions. +This value is new for TclTLS 1.8.

extensions list
-

List of certificate extension names.

+

List of certificate extension names. +This value is new for TclTLS 1.8.

authorityKeyIdentifier string

Authority Key Identifier (AKI) of the Issuing CA certificate that signed the SSL certificate as a hex string. This value matches the SKI value of the -Intermediate CA certificate.

+Intermediate CA certificate. +This value is new for TclTLS 1.8.

subjectKeyIdentifier string

Subject Key Identifier (SKI) hash of the public key inside the certificate as a -hex string. Used to identify certificates that contain a particular public key.

+hex string. Used to identify certificates that contain a particular public key. +This value is new for TclTLS 1.8.

subjectAltName list

List of all of the Subject Alternative Names (SAN) including domain names, sub -domains, and IP addresses that are secured by the certificate.

+domains, and IP addresses that are secured by the certificate. +This value is new for TclTLS 1.8.

ocsp list

List of all Online Certificate Status Protocol (OCSP) URLs that can be used to -check the validity of this certificate.

+check the validity of this certificate. +This value is new for TclTLS 1.8.

certificate cert

The PEM encoded certificate.

signatureAlgorithm algorithm
-

Cipher algorithm used for the certificate signature.

+

Cipher algorithm used for the certificate signature. +This value is new for TclTLS 1.8.

signatureValue string
-

Certificate signature as a hex string.

+

Certificate signature as a hex string. +This value is new for TclTLS 1.8.

signatureDigest version
-

Certificate signing digest as a hex string.

+

Certificate signing digest as a hex string. +This value is new for TclTLS 1.8.

publicKeyAlgorithm algorithm
-

Certificate signature public key algorithm.

+

Certificate signature public key algorithm. +This value is new for TclTLS 1.8.

publicKey string
-

Certificate signature public key as a hex string.

+

Certificate signature public key as a hex string. +This value is new for TclTLS 1.8.

bits n
-

Number of bits used for certificate signature key.

+

Number of bits used for certificate signature key. +This value is new for TclTLS 1.8.

self_signed boolean
-

Whether the certificate signature is self signed.

+

Whether the certificate signature is self signed. +This value is new for TclTLS 1.8.

sha1_hash hash
-

The SHA1 hash of the certificate as a hex string.

+

The SHA1 hash of the certificate as a hex string. +This value is new for TclTLS 1.8.

sha256_hash hash
-

The SHA256 hash of the certificate as a hex string.

+

The SHA256 hash of the certificate as a hex string. +This value is new for TclTLS 1.8.

tls::connection channel

Returns the current connection status of an SSL channel. The result is a list -of key-value pairs describing the connection. Returned values include:

+of key-value pairs describing the connection. +This command is new for TclTLS 1.8. Returned values include:

SSL Status

state state

State of the connection.

servername name
@@ -482,25 +527,27 @@

Unique session master key.

session_cache_mode mode

Server cache mode (client, server, or both).

tls::ciphers ?protocol? ?verbose? ?supported?
-

Without any args, returns a list of all symmetric ciphers for use with the +

Without any options, it returns a list of all symmetric ciphers for use with the -cipher option. With protocol, only the ciphers supported for that protocol are returned. See the tls::protocols command for the supported protocols. If verbose is specified as true then a verbose, human readable list is returned with additional information on the cipher. If supported -is specified as true, then only the ciphers supported for protocol will be listed.

+is specified as true, then only the ciphers supported for protocol will be listed. +The supported arg is new for TclTLS 1.8.

tls::protocols

Returns a list of the supported SSL/TLS protocols. Valid values are: ssl2, ssl3, tls1, tls1.1, tls1.2, and -tls1.3. Exact list depends on OpenSSL version and compile time flags.

+tls1.3. Exact list depends on OpenSSL version and compile time flags. +This command is new for TclTLS 1.8.

tls::version

Returns the OpenSSL version string.

-

Certificate Validation

+

Certificate Validation

PKI and Certificates

Using the Public Key Infrastructure (PKI), each user creates a private key that only they know about and a public key they can exchange with others for use in encrypting and decrypting data. The process is the sender encrypts their data using their private key and the receiver's public key. The data is then sent @@ -542,34 +589,39 @@ variable.

-castore URI

Specifies the Uniform Resource Identifier (URI) for the Certificate Authority (CA) store, which may be a single container or a catalog of containers. Starting with OpenSSL 3.2 on MS Windows, set to "org.openssl.winstore://" -to use the built-in MS Windows Certificate Store. -This store only supports root certificate stores. See -Certificate Validation for more details.

+to use the built-in MS Windows Certificate Store. Starting in TclTLS 2.0, this +is the default if -cadir, -cadir, and -castore are +not specified. This store only supports root certificate stores. See +Certificate Validation for more details.

-request bool

Request a certificate from the peer during the SSL handshake. This is needed to do Certificate Validation. Starting in TclTLS 1.8, the default is -true. In addition, the client can manually inspect and accept or reject +true. Starting in TclTLS 2.0, If set to false and +-require is true, then this will be overridden to true. +In addition, the client can manually inspect and accept or reject each certificate using the -validatecommand option.

-require bool

Require a valid certificate from the peer during the SSL handshake. If this is set to true, then -request must also be set to true and a either -cadir, -cafile, -castore, or a platform default must be provided in order to validate against. The default in TclTLS 1.8 and earlier versions is false since not all platforms have certificates to -validate against in a form compatible with OpenSSL.

+validate against in a form compatible with OpenSSL. Starting in TclTLS 2.0, +the default is true.

When are command line options needed?

In TclTLS 1.8 and earlier versions, certificate validation is NOT enabled by default. This limitation is due to the lack of a common cross platform database of Certificate Authority (CA) provided certificates to validate against. Many Linux systems natively support OpenSSL and thus have these certificates installed as part of the OS, but MacOS and MS Windows do not. -In order to use the -require option, one of the following +Staring in TclTLS 2.0, this has been changed to require certificate validation +by default. In order to use the -require option, one of the following must be true:

  • On Linux and Unix systems with OpenSSL already installed or if the CA certificates are available in PEM format, and if they are stored in the standard locations, or if the SSL_CERT_DIR or SSL_CERT_FILE @@ -579,11 +631,13 @@ or MS Windows and OpenSSL is installed, the SSL_CERT_DIR and/or SSL_CERT_FILE environment variables or the one of the -cadir, -cadir, or -castore options must be defined.

  • On MS Windows, starting in OpenSSL 3.2, it is now possible to access the built-in Windows Certificate Store from OpenSSL. This can utilized by -setting the -castore option to "org.openssl.winstore://".

  • +setting the -castore option to "org.openssl.winstore://". +In TclTLS 2.0, this is the default value if -cadir, +-cadir, and -castore are not specified.

  • If OpenSSL is not installed or the CA certificates are not available in PEM format, the CA certificates must be downloaded and installed with the user software. The CURL team makes them available at CA certificates extracted from Mozilla in the "cacert.pem" file. You must then either set the @@ -591,11 +645,11 @@ -cadir or -cafile options to the CA cert file's install location. It is your responsibility to keep this file up to date.

-

Callback Options

+

Callback Options

As previously described, each channel can be given their own callbacks to handle intermediate processing by the OpenSSL library, using the -command, -password, and -validate_command options passed to either of tls::socket or tls::import. Unlike previous versions of TclTLS, only if the callback generates an error, @@ -749,11 +803,11 @@ implementations.

The use of the reference callbacks tls::callback, tls::password, and tls::validate_command is not recommended. They may be removed from future releases.

-

Debug

+

Debug

For most debugging needs, the -callback option can be used to provide sufficient insight and information on the TLS handshake and progress. If further troubleshooting insight is needed, the compile time option --enable-debug can be used to get detailed execution flow status.

TLS key logging can be enabled by setting the environment variable @@ -768,15 +822,15 @@ certificate, even if it is invalid when the -validatecommand option is set to tls::validate_command.

The use of the variable tls::debug is not recommended. It may be removed from future releases.

-

HTTP Package Examples

+

Examples

The following are example scripts to download a webpage and file using the -http package. See Certificate Validation for whether the +http package. See Certificate Validation for when the -cadir, -cafile, and -castore options are also -needed. See the demos directory for more example scripts.

+needed. See the "demos" directory for more example scripts.

Example #1: Download a web page

 package require http
 package require tls
 set url "https://www.tcl.tk/"
@@ -812,11 +866,11 @@
 # Cleanup
 close $ch
 ::http::cleanup $token
 
-

Special Considerations

+

Special Considerations

The capabilities of this package can vary enormously based upon how the linked to OpenSSL library was configured and built. New versions may obsolete older protocol versions, add or remove ciphers, change default values, etc. Use the tls::protocols commands to obtain the supported protocol versions.

Index: doc/tls.man ================================================================== --- doc/tls.man +++ doc/tls.man @@ -1,46 +1,49 @@ [comment {-*- tcl -*- doctools manpage}] [comment {To convert this to another documentation format use the dtplite script from tcllib: dtplite -o tls.n nroff tls.man dtplite -o tls.html html tls.man }] -[manpage_begin tls n 1.8] +[manpage_begin tls n 2.0b1] [category tls] [copyright {1999 Matt Newman}] [copyright {2004 Starfish Systems}] [copyright {2024 Brian O'Hagan}] [keywords tls I/O "IP Address" OpenSSL SSL TCP TLS "asynchronous I/O" bind certificate channel connection "domain name" host "https" "network address" network socket TclTLS] [moddesc {Tcl TLS extension}] [see_also http socket [uri https://www.openssl.org/ OpenSSL]] [titledesc {binding to the OpenSSL library for encrypted socket and I/O channel communications}] [require Tcl 8.5-] -[require tls 1.8] +[require tls 2.0b1] [description] This extension provides TCL script access to secure socket communications using the Transport Layer Security (TLS) protocol. It provides a generic binding to [uri "https://www.openssl.org/" OpenSSL], utilizing the [syscmd Tcl_StackChannel] API in TCL 8.4 and higher. These sockets behave exactly the same as channels created using the built-in -[syscmd socket] command, along with additional options for controlling +[syscmd socket] command, but provide additional options for controlling the SSL/TLS session. +[section Compatibility] +This extension is compatible with OpenSSL 1.1.1 or later. It requires Tcl +version 8.5 or later and will work with Tcl 9.0. + [section Commands] -Typically one would use the [cmd tls::socket] command to create a new encrypted -TCP socket. It is compatible with the native TCL [syscmd ::socket] command. -Alternatively for an existing TCP socket, the [cmd tls::import] command can be -used to start TLS on the connection. +The following are the commands provided by the TcLTLS package. See the +[sectref Examples] for example usage and the [file demos] directory for +more example usage. [list_begin definitions] [call [cmd tls::init] [opt [arg -option]] [opt [arg value]] [opt [arg "-option value ..."]]] Optional function to set the default options used by [cmd tls::socket]. If you -call [cmd tls::import] directly, this command has no effect. This command -supports all of the same options as the [cmd tls::socket] command, though you -should limit your options to only TLS related ones. +call [cmd tls::import] directly, the values set by this command have no effect. +This command supports all of the same options as the [cmd tls::socket] command, +though you should limit your options to only TLS related ones. [call [cmd tls::socket] [opt [arg -option]] [opt [arg value]] [opt [arg "-option value ..."]] [arg host] [arg port]] This is a helper function that utilizes the underlying commands [syscmd socket] and [cmd tls::import] to create the connection. It behaves the same as the @@ -50,11 +53,13 @@ [list_begin options] [opt_def -autoservername [arg bool]] If [const true], automatically set the [option -servername] argument to the -[emph host] argument. Default is [const false]. +[emph host] argument. Prior to TclTLS 2.0, the default is [const false]. +Starting in TclTLS 2.0, the default is [const true] unless [option -servername] +is also specified. [list_end] [call [cmd tls::socket] [option -server] [arg command] [opt [arg -option]] [opt [arg value]] [opt [arg "-option value ..."]] [arg port]] @@ -71,11 +76,11 @@ [list_begin options] [opt_def -alpn [arg list]] List of protocols to offer during Application-Layer Protocol Negotiation (ALPN). For example: [const h2] and [const http/1.1], but not [const h3] or -[const quic]. +[const quic]. This option is new for TclTLS 1.8. [opt_def -cadir [arg directory]] Specifies the directory where the Certificate Authority (CA) certificates are stored. The default is platform specific and can be set at compile time. The default location can be overridden by the [var SSL_CERT_DIR] environment @@ -89,12 +94,13 @@ [opt_def -castore [arg URI]] Specifies the Uniform Resource Identifier (URI) for the Certificate Authority (CA) store, which may be a single container or a catalog of containers. Starting with OpenSSL 3.2 on MS Windows, set to "[const "org.openssl.winstore://"]" -to use the built-in MS Windows Certificate Store. See -[sectref "Certificate Validation"] for more details. +to use the built-in MS Windows Certificate Store. +See [sectref "Certificate Validation"] for more details. +This option is new for TclTLS 1.8. [opt_def -certfile [arg filename]] Specifies the name of the file with the certificate to use in PEM format as the local (client or server) certificate. It also contains the public key. @@ -116,10 +122,11 @@ [opt_def -ciphersuites [arg string]] Specifies the list of cipher suites to use for TLS 1.3 as a colon "[const :]" separated list of cipher suite names. See the [uri "https://docs.openssl.org/master/man1/openssl-ciphers/#options" OpenSSL] documentation for the full list of valid values. +This option is new for TclTLS 1.8. [opt_def -command [arg callback]] Specifies the callback command to be invoked at several points during the handshake to pass errors, tracing information, and protocol messages. See [sectref "Callback Options"] for more info. @@ -139,83 +146,90 @@ specified [arg channel], and therefore share config, callbacks, etc. [opt_def -password [arg callback]] Specifies the callback command to invoke when OpenSSL needs to obtain a password. This is typically used to unlock the private key of a certificate. -The callback should return a password string. See [sectref "Callback Options"] -for more info. +The callback should return a password string. This option has changed for +TclTLS 1.8. See [sectref "Callback Options"] for more info. [opt_def -post_handshake [arg bool]] -Allow post-handshake session ticket updates. +Allow post-handshake session ticket updates. This option is new for TclTLS 1.8. [opt_def -request [arg bool]] Request a certificate from the peer during the SSL handshake. This is needed to do Certificate Validation. Starting in TclTLS 1.8, the default is -[const true]. +[const true]. Starting in TclTLS 2.0, If set to [const false] and +[option -require] is [const true], then this will be overridden to [const true]. See [sectref "Certificate Validation"] for more details. [opt_def -require [arg bool]] Require a valid certificate from the peer during the SSL handshake. If this is set to true, then [option -request] must also be set to true and a either [option -cadir], [option -cafile], [option -castore], or a platform default must be provided in order to validate against. The default in TclTLS 1.8 and earlier versions is [const false] since not all platforms have certificates to -validate against in a form compatible with OpenSSL. +validate against in a form compatible with OpenSSL. Starting in TclTLS 2.0, +the default is [const true]. See [sectref "Certificate Validation"] for more details. [opt_def -security_level [arg integer]] Specifies the security level (value from 0 to 5). The security level affects the allowed cipher suite encryption algorithms, supported ECC curves, supported signature algorithms, DH parameter sizes, certificate key sizes and signature algorithms. The default is 1 prior to OpenSSL 3.2 and 2 thereafter. Level 3 and higher disable support for session tickets and only accept cipher suites that provide forward secrecy. +This option is new for TclTLS 1.8. [opt_def -server [arg bool]] Specifies whether to act as a server and respond with a server handshake when a client connects and provides a client handshake. The default is [const false]. [opt_def -servername [arg hostname]] -Specify the peer's hostname. This is used to set the TLS Server Name -Indication (SNI) extension. Set this to the expected servername in the -server's certificate or one of the Subject Alternate Names (SAN). +Specify the peer's hostname. This is used to set the TLS Server Name Indication +(SNI) extension. Set this to the expected servername in the server's certificate +or one of the Subject Alternate Names (SAN). Starting in TclTLS 2.0, this will +default to the host for the [cmd tls::socket] command. [opt_def -session_id [arg binary_string]] Specifies the session id to resume a session. Not supported yet. +This option is new for TclTLS 1.8. [opt_def -ssl2 [arg bool]] -Enable use of SSL v2. The default is [const false]. Note: Recent versions of -OpenSSL no longer support SSLv2, so this may not have any effect. See the -[cmd tls::protocols] command for supported protocols. +Enable use of SSL v2.The default is [const false]. +OpenSSL 1.1+ no longer supports SSL v2, so this may not have any effect. +See the [cmd tls::protocols] command for supported protocols. [opt_def -ssl3 [arg bool]] -Enable use of SSL v3. The default is [const false]. Note: Recent versions -of OpenSSL may have this disabled at compile time, so this may not have any -effect. See the [cmd tls::protocols] command for supported protocols. +Enable use of SSL v3. The default is [const false]. Starting in TclTLS 1.8, +use of SSL v3 if only available via a compile time option. +See the [cmd tls::protocols] command for supported protocols. [opt_def -tls1 [arg bool]] -Enable use of TLS v1. The default is [const true]. Note: TLS 1.0 needs -SHA1 to operate, which is only available in security level 0 for Open SSL 3.0+. -See the [arg -security_level] option. +Enable use of TLS v1. Starting in TclTLS 2.0, the default is [const false]. +Note: TLS 1.0 needs SHA1 to operate, which is only available in security level +0 for Open SSL 3.0+. See the [arg -security_level] option. [opt_def -tls1.1 [arg bool]] -Enable use of TLS v1.1. The default is [const true]. Note: TLS 1.1 needs -SHA1 to operate, which is only available in security level 0 for Open SSL 3.0+. -See the [arg -security_level] option. +Enable use of TLS v1.1. Starting in TclTLS 2.0, the default is [const false]. +Note: TLS 1.1 needs SHA1 to operate, which is only available in security level +0 for Open SSL 3.0+. See the [arg -security_level] option. [opt_def -tls1.2 [arg bool]] Enable use of TLS v1.2. The default is [const true]. [opt_def -tls1.3 [arg bool]] -Enable use of TLS v1.3. The default is [const true]. +Enable use of TLS v1.3. The default is [const true]. This is only available +starting with OpenSSL 1.1.1 and TclTLS 1.7. [opt_def -validatecommand [arg callback]] Specifies the callback command to invoke to validate the peer certificates and other config info during the protocol negotiation phase. This can be used by TCL scripts to perform their own Certificate Validation to supplement the default validation provided by OpenSSL. The script must return a boolean true to continue the negotiation. See [sectref "Callback Options"] for more info. +This option is new for TclTLS 1.8. [list_end] [call [cmd tls::unimport] [arg channel]] @@ -243,58 +257,70 @@ [list_begin definitions] [def "[var alpn] [arg protocol]"] The protocol selected after Application-Layer Protocol Negotiation (ALPN). +This value is new for TclTLS 1.8. [def "[var cipher] [arg cipher]"] The current cipher in use for the session. [def "[var peername] [arg name]"] The peername from the certificate. +This value is new for TclTLS 1.8. [def "[var protocol] [arg version]"] -The protocol version used for the connection: SSL2, SSL3, TLS1, TLS1.1, TLS1.2, TLS1.3, or unknown. +The protocol version used for the connection: SSL2, SSL3, TLS1, TLS1.1, TLS1.2, +TLS1.3, or unknown. This value is new for TclTLS 1.8. [def "[var sbits] [arg n]"] The number of bits used for the session key. [def "[var signatureHashAlgorithm] [arg algorithm]"] The signature hash algorithm. +This value is new for TclTLS 1.8. [def "[var signatureType] [arg type]"] The signature type value. +This value is new for TclTLS 1.8. [def "[var verifyDepth] [arg n]"] Maximum depth for the certificate chain verification. Default is -1, to check all. +This value is new for TclTLS 1.8. [def "[var verifyMode] [arg list]"] List of certificate verification modes. +This value is new for TclTLS 1.8. [def "[var verifyResult] [arg result]"] Certificate verification result. +This value is new for TclTLS 1.8. [def "[var ca_names] [arg list]"] List of the Certificate Authorities used to create the certificate. +This value is new for TclTLS 1.8. [list_end] Certificate Status [list_begin definitions] [def "[var all] [arg string]"] Dump of all certificate info. +This value is new for TclTLS 1.8. [def "[var version] [arg value]"] The certificate version. [def "[var serialNumber] [arg string]"] The serial number of the certificate as a hex string. +This value was changed from serial in TclTLS 1.8. [def "[var signature] [arg algorithm]"] Cipher algorithm used for certificate signature. +This value is new for TclTLS 1.8. [def "[var issuer] [arg string]"] The distinguished name (DN) of the certificate issuer. [def "[var notBefore] [arg date]"] @@ -308,73 +334,91 @@ Name (CN), Organization (O), Locality or City (L), State or Province (S), and Country Name (C). [def "[var issuerUniqueID] [arg string]"] The issuer unique id. +This value is new for TclTLS 1.8. [def "[var subjectUniqueID] [arg string]"] The subject unique id. +This value is new for TclTLS 1.8. [def "[var num_extensions] [arg n]"] Number of certificate extensions. +This value is new for TclTLS 1.8. [def "[var extensions] [arg list]"] List of certificate extension names. +This value is new for TclTLS 1.8. [def "[var authorityKeyIdentifier] [arg string]"] Authority Key Identifier (AKI) of the Issuing CA certificate that signed the SSL certificate as a hex string. This value matches the SKI value of the Intermediate CA certificate. +This value is new for TclTLS 1.8. [def "[var subjectKeyIdentifier] [arg string]"] Subject Key Identifier (SKI) hash of the public key inside the certificate as a hex string. Used to identify certificates that contain a particular public key. +This value is new for TclTLS 1.8. [def "[var subjectAltName] [arg list]"] List of all of the Subject Alternative Names (SAN) including domain names, sub domains, and IP addresses that are secured by the certificate. +This value is new for TclTLS 1.8. [def "[var ocsp] [arg list]"] List of all Online Certificate Status Protocol (OCSP) URLs that can be used to check the validity of this certificate. +This value is new for TclTLS 1.8. [def "[var certificate] [arg cert]"] The PEM encoded certificate. [def "[var signatureAlgorithm] [arg algorithm]"] Cipher algorithm used for the certificate signature. +This value is new for TclTLS 1.8. [def "[var signatureValue] [arg string]"] Certificate signature as a hex string. +This value is new for TclTLS 1.8. [def "[var signatureDigest] [arg version]"] Certificate signing digest as a hex string. +This value is new for TclTLS 1.8. [def "[var publicKeyAlgorithm] [arg algorithm]"] Certificate signature public key algorithm. +This value is new for TclTLS 1.8. [def "[var publicKey] [arg string]"] Certificate signature public key as a hex string. +This value is new for TclTLS 1.8. [def "[var bits] [arg n]"] Number of bits used for certificate signature key. +This value is new for TclTLS 1.8. [def "[var self_signed] [arg boolean]"] Whether the certificate signature is self signed. +This value is new for TclTLS 1.8. [def "[var sha1_hash] [arg hash]"] The SHA1 hash of the certificate as a hex string. +This value is new for TclTLS 1.8. [def "[var sha256_hash] [arg hash]"] The SHA256 hash of the certificate as a hex string. +This value is new for TclTLS 1.8. [list_end] [call [cmd tls::connection] [arg channel]] Returns the current connection status of an SSL channel. The result is a list -of key-value pairs describing the connection. Returned values include: +of key-value pairs describing the connection. +This command is new for TclTLS 1.8. Returned values include: [para] SSL Status @@ -481,22 +525,24 @@ [list_end] [call [cmd tls::ciphers] [opt [arg protocol]] [opt [arg verbose]] [opt [arg supported]]] -Without any args, returns a list of all symmetric ciphers for use with the +Without any options, it returns a list of all symmetric ciphers for use with the [arg -cipher] option. With [arg protocol], only the ciphers supported for that protocol are returned. See the [cmd tls::protocols] command for the supported protocols. If [arg verbose] is specified as true then a verbose, human readable list is returned with additional information on the cipher. If [arg supported] is specified as true, then only the ciphers supported for protocol will be listed. +The [arg supported] arg is new for TclTLS 1.8. [call [cmd tls::protocols]] Returns a list of the supported SSL/TLS protocols. Valid values are: [const ssl2], [const ssl3], [const tls1], [const tls1.1], [const tls1.2], and [const tls1.3]. Exact list depends on OpenSSL version and compile time flags. +This command is new for TclTLS 1.8. [call [cmd tls::version]] Returns the OpenSSL version string. @@ -542,11 +588,11 @@ [list_begin options] [opt_def -cadir [arg directory]] Specifies the directory where the Certificate Authority (CA) certificates are -stored. The default is platform specific, but is usually [file "/etc/ssl/certs"] on +stored. The default is platform specific, but is usually [file /etc/ssl/certs] on Linux/Unix systems. The default location can be overridden by the [var SSL_CERT_DIR] environment variable. [opt_def -cafile [arg filename]] Specifies the file with the Certificate Authority (CA) certificates to use in @@ -557,27 +603,31 @@ [opt_def -castore [arg URI]] Specifies the Uniform Resource Identifier (URI) for the Certificate Authority (CA) store, which may be a single container or a catalog of containers. Starting with OpenSSL 3.2 on MS Windows, set to "[const "org.openssl.winstore://"]" -to use the built-in MS Windows Certificate Store. -This store only supports root certificate stores. See +to use the built-in MS Windows Certificate Store. Starting in TclTLS 2.0, this +is the default if [option -cadir], [option -cadir], and [option -castore] are +not specified. This store only supports root certificate stores. See [sectref "Certificate Validation"] for more details. [opt_def -request [arg bool]] Request a certificate from the peer during the SSL handshake. This is needed to do Certificate Validation. Starting in TclTLS 1.8, the default is -[const true]. In addition, the client can manually inspect and accept or reject +[const true]. Starting in TclTLS 2.0, If set to [const false] and +[option -require] is [const true], then this will be overridden to [const true]. +In addition, the client can manually inspect and accept or reject each certificate using the [arg -validatecommand] option. [opt_def -require [arg bool]] Require a valid certificate from the peer during the SSL handshake. If this is set to true, then [option -request] must also be set to true and a either [option -cadir], [option -cafile], [option -castore], or a platform default must be provided in order to validate against. The default in TclTLS 1.8 and earlier versions is [const false] since not all platforms have certificates to -validate against in a form compatible with OpenSSL. +validate against in a form compatible with OpenSSL. Starting in TclTLS 2.0, +the default is [const true]. [list_end] [subsection "When are command line options needed?"] @@ -584,11 +634,12 @@ In TclTLS 1.8 and earlier versions, certificate validation is [emph NOT] enabled by default. This limitation is due to the lack of a common cross platform database of Certificate Authority (CA) provided certificates to validate against. Many Linux systems natively support OpenSSL and thus have these certificates installed as part of the OS, but MacOS and MS Windows do not. -In order to use the [option -require] option, one of the following +Staring in TclTLS 2.0, this has been changed to require certificate validation +by default. In order to use the [option -require] option, one of the following must be true: [list_begin itemized] [item] @@ -606,10 +657,12 @@ [item] On MS Windows, starting in OpenSSL 3.2, it is now possible to access the built-in Windows Certificate Store from OpenSSL. This can utilized by setting the [option -castore] option to "[const org.openssl.winstore://]". +In TclTLS 2.0, this is the default value if [option -cadir], +[option -cadir], and [option -castore] are not specified. [item] If OpenSSL is not installed or the CA certificates are not available in PEM format, the CA certificates must be downloaded and installed with the user software. The CURL team makes them available at @@ -860,16 +913,16 @@ [para] [emph "The use of the variable [var tls::debug] is not recommended. It may be removed from future releases."] -[section "HTTP Package Examples"] +[section "Examples"] The following are example scripts to download a webpage and file using the -http package. See [sectref "Certificate Validation"] for whether the +http package. See [sectref "Certificate Validation"] for when the [option -cadir], [option -cafile], and [option -castore] options are also -needed. See the demos directory for more example scripts. +needed. See the [file demos] directory for more example scripts. [para] Example #1: Download a web page Index: doc/tls.n ================================================================== --- doc/tls.n +++ doc/tls.n @@ -2,11 +2,11 @@ '\" Generated from file 'tls\&.man' by tcllib/doctools with format 'nroff' '\" Copyright (c) 1999 Matt Newman '\" Copyright (c) 2004 Starfish Systems '\" Copyright (c) 2024 Brian O'Hagan '\" -.TH "tls" n 1\&.8 tls "Tcl TLS extension" +.TH "tls" n 2\&.0b1 tls "Tcl TLS extension" .\" The -*- nroff -*- definitions below are for supplemental macros used .\" in Tcl/Tk manual entries. .\" .\" .AP type name in/out ?indent? .\" Start paragraph describing an argument to a library procedure. @@ -276,11 +276,11 @@ .SH NAME tls \- binding to the OpenSSL library for encrypted socket and I/O channel communications .SH SYNOPSIS package require \fBTcl 8\&.5-\fR .sp -package require \fBtls 1\&.8\fR +package require \fBtls 2\&.0b1\fR .sp \fBtls::init\fR ?\fI-option\fR? ?\fIvalue\fR? ?\fI-option value \&.\&.\&.\fR? .sp \fBtls::socket\fR ?\fI-option\fR? ?\fIvalue\fR? ?\fI-option value \&.\&.\&.\fR? \fIhost\fR \fIport\fR .sp @@ -307,23 +307,25 @@ This extension provides TCL script access to secure socket communications using the Transport Layer Security (TLS) protocol\&. It provides a generic binding to \fIOpenSSL\fR [https://www\&.openssl\&.org/], utilizing the \fBTcl_StackChannel\fR API in TCL 8\&.4 and higher\&. These sockets behave exactly the same as channels created using the built-in -\fBsocket\fR command, along with additional options for controlling +\fBsocket\fR command, but provide additional options for controlling the SSL/TLS session\&. +.SH COMPATIBILITY +This extension is compatible with OpenSSL 1\&.1\&.1 or later\&. It requires Tcl +version 8\&.5 or later and will work with Tcl 9\&.0\&. .SH COMMANDS -Typically one would use the \fBtls::socket\fR command to create a new encrypted -TCP socket\&. It is compatible with the native TCL \fB::socket\fR command\&. -Alternatively for an existing TCP socket, the \fBtls::import\fR command can be -used to start TLS on the connection\&. +The following are the commands provided by the TcLTLS package\&. See the +\fBExamples\fR for example usage and the "\fIdemos\fR" directory for +more example usage\&. .TP \fBtls::init\fR ?\fI-option\fR? ?\fIvalue\fR? ?\fI-option value \&.\&.\&.\fR? Optional function to set the default options used by \fBtls::socket\fR\&. If you -call \fBtls::import\fR directly, this command has no effect\&. This command -supports all of the same options as the \fBtls::socket\fR command, though you -should limit your options to only TLS related ones\&. +call \fBtls::import\fR directly, the values set by this command have no effect\&. +This command supports all of the same options as the \fBtls::socket\fR command, +though you should limit your options to only TLS related ones\&. .TP \fBtls::socket\fR ?\fI-option\fR? ?\fIvalue\fR? ?\fI-option value \&.\&.\&.\fR? \fIhost\fR \fIport\fR This is a helper function that utilizes the underlying commands \fBsocket\fR and \fBtls::import\fR to create the connection\&. It behaves the same as the native TCL \fBsocket\fR command, but also supports the \fBtls:import\fR @@ -331,11 +333,13 @@ for the new socket\&. .RS .TP \fB-autoservername\fR \fIbool\fR If \fBtrue\fR, automatically set the \fB-servername\fR argument to the -\fIhost\fR argument\&. Default is \fBfalse\fR\&. +\fIhost\fR argument\&. Prior to TclTLS 2\&.0, the default is \fBfalse\fR\&. +Starting in TclTLS 2\&.0, the default is \fBtrue\fR unless \fB-servername\fR +is also specified\&. .RE .TP \fBtls::socket\fR \fB-server\fR \fIcommand\fR ?\fI-option\fR? ?\fIvalue\fR? ?\fI-option value \&.\&.\&.\fR? \fIport\fR Same as previous, but instead creates a server socket for clients to connect to just like the Tcl \fBsocket -server\fR command\&. It returns the channel @@ -348,11 +352,11 @@ .RS .TP \fB-alpn\fR \fIlist\fR List of protocols to offer during Application-Layer Protocol Negotiation (ALPN)\&. For example: \fBh2\fR and \fBhttp/1\&.1\fR, but not \fBh3\fR or -\fBquic\fR\&. +\fBquic\fR\&. This option is new for TclTLS 1\&.8\&. .TP \fB-cadir\fR \fIdirectory\fR Specifies the directory where the Certificate Authority (CA) certificates are stored\&. The default is platform specific and can be set at compile time\&. The default location can be overridden by the \fBSSL_CERT_DIR\fR environment @@ -366,12 +370,13 @@ .TP \fB-castore\fR \fIURI\fR Specifies the Uniform Resource Identifier (URI) for the Certificate Authority (CA) store, which may be a single container or a catalog of containers\&. Starting with OpenSSL 3\&.2 on MS Windows, set to "\fBorg\&.openssl\&.winstore://\fR" -to use the built-in MS Windows Certificate Store\&. See -\fBCertificate Validation\fR for more details\&. +to use the built-in MS Windows Certificate Store\&. +See \fBCertificate Validation\fR for more details\&. +This option is new for TclTLS 1\&.8\&. .TP \fB-certfile\fR \fIfilename\fR Specifies the name of the file with the certificate to use in PEM format as the local (client or server) certificate\&. It also contains the public key\&. .TP @@ -393,10 +398,11 @@ \fB-ciphersuites\fR \fIstring\fR Specifies the list of cipher suites to use for TLS 1\&.3 as a colon "\fB:\fR" separated list of cipher suite names\&. See the \fIOpenSSL\fR [https://docs\&.openssl\&.org/master/man1/openssl-ciphers/#options] documentation for the full list of valid values\&. +This option is new for TclTLS 1\&.8\&. .TP \fB-command\fR \fIcallback\fR Specifies the callback command to be invoked at several points during the handshake to pass errors, tracing information, and protocol messages\&. See \fBCallback Options\fR for more info\&. @@ -416,83 +422,90 @@ specified \fIchannel\fR, and therefore share config, callbacks, etc\&. .TP \fB-password\fR \fIcallback\fR Specifies the callback command to invoke when OpenSSL needs to obtain a password\&. This is typically used to unlock the private key of a certificate\&. -The callback should return a password string\&. See \fBCallback Options\fR -for more info\&. +The callback should return a password string\&. This option has changed for +TclTLS 1\&.8\&. See \fBCallback Options\fR for more info\&. .TP \fB-post_handshake\fR \fIbool\fR -Allow post-handshake session ticket updates\&. +Allow post-handshake session ticket updates\&. This option is new for TclTLS 1\&.8\&. .TP \fB-request\fR \fIbool\fR Request a certificate from the peer during the SSL handshake\&. This is needed to do Certificate Validation\&. Starting in TclTLS 1\&.8, the default is -\fBtrue\fR\&. +\fBtrue\fR\&. Starting in TclTLS 2\&.0, If set to \fBfalse\fR and +\fB-require\fR is \fBtrue\fR, then this will be overridden to \fBtrue\fR\&. See \fBCertificate Validation\fR for more details\&. .TP \fB-require\fR \fIbool\fR Require a valid certificate from the peer during the SSL handshake\&. If this is set to true, then \fB-request\fR must also be set to true and a either \fB-cadir\fR, \fB-cafile\fR, \fB-castore\fR, or a platform default must be provided in order to validate against\&. The default in TclTLS 1\&.8 and earlier versions is \fBfalse\fR since not all platforms have certificates to -validate against in a form compatible with OpenSSL\&. +validate against in a form compatible with OpenSSL\&. Starting in TclTLS 2\&.0, +the default is \fBtrue\fR\&. See \fBCertificate Validation\fR for more details\&. .TP \fB-security_level\fR \fIinteger\fR Specifies the security level (value from 0 to 5)\&. The security level affects the allowed cipher suite encryption algorithms, supported ECC curves, supported signature algorithms, DH parameter sizes, certificate key sizes and signature algorithms\&. The default is 1 prior to OpenSSL 3\&.2 and 2 thereafter\&. Level 3 and higher disable support for session tickets and only accept cipher suites that provide forward secrecy\&. +This option is new for TclTLS 1\&.8\&. .TP \fB-server\fR \fIbool\fR Specifies whether to act as a server and respond with a server handshake when a client connects and provides a client handshake\&. The default is \fBfalse\fR\&. .TP \fB-servername\fR \fIhostname\fR -Specify the peer's hostname\&. This is used to set the TLS Server Name -Indication (SNI) extension\&. Set this to the expected servername in the -server's certificate or one of the Subject Alternate Names (SAN)\&. +Specify the peer's hostname\&. This is used to set the TLS Server Name Indication +(SNI) extension\&. Set this to the expected servername in the server's certificate +or one of the Subject Alternate Names (SAN)\&. Starting in TclTLS 2\&.0, this will +default to the host for the \fBtls::socket\fR command\&. .TP \fB-session_id\fR \fIbinary_string\fR Specifies the session id to resume a session\&. Not supported yet\&. +This option is new for TclTLS 1\&.8\&. .TP \fB-ssl2\fR \fIbool\fR -Enable use of SSL v2\&. The default is \fBfalse\fR\&. Note: Recent versions of -OpenSSL no longer support SSLv2, so this may not have any effect\&. See the -\fBtls::protocols\fR command for supported protocols\&. +Enable use of SSL v2\&.The default is \fBfalse\fR\&. +OpenSSL 1\&.1+ no longer supports SSL v2, so this may not have any effect\&. +See the \fBtls::protocols\fR command for supported protocols\&. .TP \fB-ssl3\fR \fIbool\fR -Enable use of SSL v3\&. The default is \fBfalse\fR\&. Note: Recent versions -of OpenSSL may have this disabled at compile time, so this may not have any -effect\&. See the \fBtls::protocols\fR command for supported protocols\&. +Enable use of SSL v3\&. The default is \fBfalse\fR\&. Starting in TclTLS 1\&.8, +use of SSL v3 if only available via a compile time option\&. +See the \fBtls::protocols\fR command for supported protocols\&. .TP \fB-tls1\fR \fIbool\fR -Enable use of TLS v1\&. The default is \fBtrue\fR\&. Note: TLS 1\&.0 needs -SHA1 to operate, which is only available in security level 0 for Open SSL 3\&.0+\&. -See the \fI-security_level\fR option\&. +Enable use of TLS v1\&. Starting in TclTLS 2\&.0, the default is \fBfalse\fR\&. +Note: TLS 1\&.0 needs SHA1 to operate, which is only available in security level +0 for Open SSL 3\&.0+\&. See the \fI-security_level\fR option\&. .TP \fB-tls1\&.1\fR \fIbool\fR -Enable use of TLS v1\&.1\&. The default is \fBtrue\fR\&. Note: TLS 1\&.1 needs -SHA1 to operate, which is only available in security level 0 for Open SSL 3\&.0+\&. -See the \fI-security_level\fR option\&. +Enable use of TLS v1\&.1\&. Starting in TclTLS 2\&.0, the default is \fBfalse\fR\&. +Note: TLS 1\&.1 needs SHA1 to operate, which is only available in security level +0 for Open SSL 3\&.0+\&. See the \fI-security_level\fR option\&. .TP \fB-tls1\&.2\fR \fIbool\fR Enable use of TLS v1\&.2\&. The default is \fBtrue\fR\&. .TP \fB-tls1\&.3\fR \fIbool\fR -Enable use of TLS v1\&.3\&. The default is \fBtrue\fR\&. +Enable use of TLS v1\&.3\&. The default is \fBtrue\fR\&. This is only available +starting with OpenSSL 1\&.1\&.1 and TclTLS 1\&.7\&. .TP \fB-validatecommand\fR \fIcallback\fR Specifies the callback command to invoke to validate the peer certificates and other config info during the protocol negotiation phase\&. This can be used by TCL scripts to perform their own Certificate Validation to supplement the default validation provided by OpenSSL\&. The script must return a boolean true to continue the negotiation\&. See \fBCallback Options\fR for more info\&. +This option is new for TclTLS 1\&.8\&. .RE .TP \fBtls::unimport\fR \fIchannel\fR Compliment to \fBtls::import\fR\&. Used to remove the top level stacked channel from \fIchannel\fR\&. This unstacks the encryption of a regular TCL channel\&. An @@ -513,56 +526,68 @@ SSL Status .RS .TP \fBalpn\fR \fIprotocol\fR The protocol selected after Application-Layer Protocol Negotiation (ALPN)\&. +This value is new for TclTLS 1\&.8\&. .TP \fBcipher\fR \fIcipher\fR The current cipher in use for the session\&. .TP \fBpeername\fR \fIname\fR The peername from the certificate\&. +This value is new for TclTLS 1\&.8\&. .TP \fBprotocol\fR \fIversion\fR -The protocol version used for the connection: SSL2, SSL3, TLS1, TLS1\&.1, TLS1\&.2, TLS1\&.3, or unknown\&. +The protocol version used for the connection: SSL2, SSL3, TLS1, TLS1\&.1, TLS1\&.2, +TLS1\&.3, or unknown\&. This value is new for TclTLS 1\&.8\&. .TP \fBsbits\fR \fIn\fR The number of bits used for the session key\&. .TP \fBsignatureHashAlgorithm\fR \fIalgorithm\fR The signature hash algorithm\&. +This value is new for TclTLS 1\&.8\&. .TP \fBsignatureType\fR \fItype\fR The signature type value\&. +This value is new for TclTLS 1\&.8\&. .TP \fBverifyDepth\fR \fIn\fR Maximum depth for the certificate chain verification\&. Default is -1, to check all\&. +This value is new for TclTLS 1\&.8\&. .TP \fBverifyMode\fR \fIlist\fR List of certificate verification modes\&. +This value is new for TclTLS 1\&.8\&. .TP \fBverifyResult\fR \fIresult\fR Certificate verification result\&. +This value is new for TclTLS 1\&.8\&. .TP \fBca_names\fR \fIlist\fR List of the Certificate Authorities used to create the certificate\&. +This value is new for TclTLS 1\&.8\&. .RE .IP Certificate Status .RS .TP \fBall\fR \fIstring\fR Dump of all certificate info\&. +This value is new for TclTLS 1\&.8\&. .TP \fBversion\fR \fIvalue\fR The certificate version\&. .TP \fBserialNumber\fR \fIstring\fR The serial number of the certificate as a hex string\&. +This value was changed from serial in TclTLS 1\&.8\&. .TP \fBsignature\fR \fIalgorithm\fR Cipher algorithm used for certificate signature\&. +This value is new for TclTLS 1\&.8\&. .TP \fBissuer\fR \fIstring\fR The distinguished name (DN) of the certificate issuer\&. .TP \fBnotBefore\fR \fIdate\fR @@ -576,71 +601,89 @@ Name (CN), Organization (O), Locality or City (L), State or Province (S), and Country Name (C)\&. .TP \fBissuerUniqueID\fR \fIstring\fR The issuer unique id\&. +This value is new for TclTLS 1\&.8\&. .TP \fBsubjectUniqueID\fR \fIstring\fR The subject unique id\&. +This value is new for TclTLS 1\&.8\&. .TP \fBnum_extensions\fR \fIn\fR Number of certificate extensions\&. +This value is new for TclTLS 1\&.8\&. .TP \fBextensions\fR \fIlist\fR List of certificate extension names\&. +This value is new for TclTLS 1\&.8\&. .TP \fBauthorityKeyIdentifier\fR \fIstring\fR Authority Key Identifier (AKI) of the Issuing CA certificate that signed the SSL certificate as a hex string\&. This value matches the SKI value of the Intermediate CA certificate\&. +This value is new for TclTLS 1\&.8\&. .TP \fBsubjectKeyIdentifier\fR \fIstring\fR Subject Key Identifier (SKI) hash of the public key inside the certificate as a hex string\&. Used to identify certificates that contain a particular public key\&. +This value is new for TclTLS 1\&.8\&. .TP \fBsubjectAltName\fR \fIlist\fR List of all of the Subject Alternative Names (SAN) including domain names, sub domains, and IP addresses that are secured by the certificate\&. +This value is new for TclTLS 1\&.8\&. .TP \fBocsp\fR \fIlist\fR List of all Online Certificate Status Protocol (OCSP) URLs that can be used to check the validity of this certificate\&. +This value is new for TclTLS 1\&.8\&. .TP \fBcertificate\fR \fIcert\fR The PEM encoded certificate\&. .TP \fBsignatureAlgorithm\fR \fIalgorithm\fR Cipher algorithm used for the certificate signature\&. +This value is new for TclTLS 1\&.8\&. .TP \fBsignatureValue\fR \fIstring\fR Certificate signature as a hex string\&. +This value is new for TclTLS 1\&.8\&. .TP \fBsignatureDigest\fR \fIversion\fR Certificate signing digest as a hex string\&. +This value is new for TclTLS 1\&.8\&. .TP \fBpublicKeyAlgorithm\fR \fIalgorithm\fR Certificate signature public key algorithm\&. +This value is new for TclTLS 1\&.8\&. .TP \fBpublicKey\fR \fIstring\fR Certificate signature public key as a hex string\&. +This value is new for TclTLS 1\&.8\&. .TP \fBbits\fR \fIn\fR Number of bits used for certificate signature key\&. +This value is new for TclTLS 1\&.8\&. .TP \fBself_signed\fR \fIboolean\fR Whether the certificate signature is self signed\&. +This value is new for TclTLS 1\&.8\&. .TP \fBsha1_hash\fR \fIhash\fR The SHA1 hash of the certificate as a hex string\&. +This value is new for TclTLS 1\&.8\&. .TP \fBsha256_hash\fR \fIhash\fR The SHA256 hash of the certificate as a hex string\&. +This value is new for TclTLS 1\&.8\&. .RE .TP \fBtls::connection\fR \fIchannel\fR Returns the current connection status of an SSL channel\&. The result is a list -of key-value pairs describing the connection\&. Returned values include: +of key-value pairs describing the connection\&. +This command is new for TclTLS 1\&.8\&. Returned values include: .sp SSL Status .RS .TP \fBstate\fR \fIstate\fR @@ -738,21 +781,23 @@ \fBsession_cache_mode\fR \fImode\fR Server cache mode (client, server, or both)\&. .RE .TP \fBtls::ciphers\fR ?\fIprotocol\fR? ?\fIverbose\fR? ?\fIsupported\fR? -Without any args, returns a list of all symmetric ciphers for use with the +Without any options, it returns a list of all symmetric ciphers for use with the \fI-cipher\fR option\&. With \fIprotocol\fR, only the ciphers supported for that protocol are returned\&. See the \fBtls::protocols\fR command for the supported protocols\&. If \fIverbose\fR is specified as true then a verbose, human readable list is returned with additional information on the cipher\&. If \fIsupported\fR is specified as true, then only the ciphers supported for protocol will be listed\&. +The \fIsupported\fR arg is new for TclTLS 1\&.8\&. .TP \fBtls::protocols\fR Returns a list of the supported SSL/TLS protocols\&. Valid values are: \fBssl2\fR, \fBssl3\fR, \fBtls1\fR, \fBtls1\&.1\fR, \fBtls1\&.2\fR, and \fBtls1\&.3\fR\&. Exact list depends on OpenSSL version and compile time flags\&. +This command is new for TclTLS 1\&.8\&. .TP \fBtls::version\fR Returns the OpenSSL version string\&. .PP .SH "CERTIFICATE VALIDATION" @@ -802,35 +847,40 @@ .TP \fB-castore\fR \fIURI\fR Specifies the Uniform Resource Identifier (URI) for the Certificate Authority (CA) store, which may be a single container or a catalog of containers\&. Starting with OpenSSL 3\&.2 on MS Windows, set to "\fBorg\&.openssl\&.winstore://\fR" -to use the built-in MS Windows Certificate Store\&. -This store only supports root certificate stores\&. See +to use the built-in MS Windows Certificate Store\&. Starting in TclTLS 2\&.0, this +is the default if \fB-cadir\fR, \fB-cadir\fR, and \fB-castore\fR are +not specified\&. This store only supports root certificate stores\&. See \fBCertificate Validation\fR for more details\&. .TP \fB-request\fR \fIbool\fR Request a certificate from the peer during the SSL handshake\&. This is needed to do Certificate Validation\&. Starting in TclTLS 1\&.8, the default is -\fBtrue\fR\&. In addition, the client can manually inspect and accept or reject +\fBtrue\fR\&. Starting in TclTLS 2\&.0, If set to \fBfalse\fR and +\fB-require\fR is \fBtrue\fR, then this will be overridden to \fBtrue\fR\&. +In addition, the client can manually inspect and accept or reject each certificate using the \fI-validatecommand\fR option\&. .TP \fB-require\fR \fIbool\fR Require a valid certificate from the peer during the SSL handshake\&. If this is set to true, then \fB-request\fR must also be set to true and a either \fB-cadir\fR, \fB-cafile\fR, \fB-castore\fR, or a platform default must be provided in order to validate against\&. The default in TclTLS 1\&.8 and earlier versions is \fBfalse\fR since not all platforms have certificates to -validate against in a form compatible with OpenSSL\&. +validate against in a form compatible with OpenSSL\&. Starting in TclTLS 2\&.0, +the default is \fBtrue\fR\&. .PP .SS "WHEN ARE COMMAND LINE OPTIONS NEEDED?" In TclTLS 1\&.8 and earlier versions, certificate validation is \fINOT\fR enabled by default\&. This limitation is due to the lack of a common cross platform database of Certificate Authority (CA) provided certificates to validate against\&. Many Linux systems natively support OpenSSL and thus have these certificates installed as part of the OS, but MacOS and MS Windows do not\&. -In order to use the \fB-require\fR option, one of the following +Staring in TclTLS 2\&.0, this has been changed to require certificate validation +by default\&. In order to use the \fB-require\fR option, one of the following must be true: .IP \(bu On Linux and Unix systems with OpenSSL already installed or if the CA certificates are available in PEM format, and if they are stored in the standard locations, or if the \fBSSL_CERT_DIR\fR or \fBSSL_CERT_FILE\fR @@ -843,10 +893,12 @@ \fB-cadir\fR, or \fB-castore\fR options must be defined\&. .IP \(bu On MS Windows, starting in OpenSSL 3\&.2, it is now possible to access the built-in Windows Certificate Store from OpenSSL\&. This can utilized by setting the \fB-castore\fR option to "\fBorg\&.openssl\&.winstore://\fR"\&. +In TclTLS 2\&.0, this is the default value if \fB-cadir\fR, +\fB-cadir\fR, and \fB-castore\fR are not specified\&. .IP \(bu If OpenSSL is not installed or the CA certificates are not available in PEM format, the CA certificates must be downloaded and installed with the user software\&. The CURL team makes them available at \fICA certificates extracted @@ -1054,15 +1106,15 @@ certificate, even if it is invalid when the \fB-validatecommand\fR option is set to \fBtls::validate_command\fR\&. .PP \fIThe use of the variable \fBtls::debug\fR is not recommended\&. It may be removed from future releases\&.\fR -.SH "HTTP PACKAGE EXAMPLES" +.SH EXAMPLES The following are example scripts to download a webpage and file using the -http package\&. See \fBCertificate Validation\fR for whether the +http package\&. See \fBCertificate Validation\fR for when the \fB-cadir\fR, \fB-cafile\fR, and \fB-castore\fR options are also -needed\&. See the demos directory for more example scripts\&. +needed\&. See the "\fIdemos\fR" directory for more example scripts\&. .PP Example #1: Download a web page .CS Index: generic/tls.c ================================================================== --- generic/tls.c +++ generic/tls.c @@ -1348,13 +1348,13 @@ char *model = NULL; char *servername = NULL; /* hostname for Server Name Indication */ char *session_id = NULL; Tcl_Obj *alpn = NULL; int ssl2 = 0, ssl3 = 0; - int tls1 = 1, tls1_1 = 1, tls1_2 = 1, tls1_3 = 1; + int tls1 = 0, tls1_1 = 0, tls1_2 = 1, tls1_3 = 1; int proto = 0, level = -1; - int verify = 0, require = 0, request = 1, post_handshake = 0; + int verify = 0, require = 1, request = 1, post_handshake = 0; dprintf("Called"); #if defined(NO_TLS1) || defined(OPENSSL_NO_TLS1) tls1 = 0; @@ -1423,13 +1423,14 @@ OPTBAD("option", "-alpn, -cadir, -cafile, -castore, -cert, -certfile, -cipher, -ciphersuites, -command, -dhparams, -key, -keyfile, -model, -password, -post_handshake, -request, -require, -security_level, -server, -servername, -session_id, -ssl2, -ssl3, -tls1, -tls1.1, -tls1.2, -tls1.3, or -validatecommand"); return TCL_ERROR; } + if (require) request = 1; if (request) verify |= SSL_VERIFY_CLIENT_ONCE | SSL_VERIFY_PEER; if (request && require) verify |= SSL_VERIFY_FAIL_IF_NO_PEER_CERT; - if (request && post_handshake) verify |= SSL_VERIFY_POST_HANDSHAKE; + if (request && post_handshake) verify |= SSL_VERIFY_POST_HANDSHAKE; if (verify == 0) verify = SSL_VERIFY_NONE; proto |= (ssl2 ? TLS_PROTO_SSL2 : 0); proto |= (ssl3 ? TLS_PROTO_SSL3 : 0); proto |= (tls1 ? TLS_PROTO_TLS1 : 0); Index: generic/tlsInt.h ================================================================== --- generic/tlsInt.h +++ generic/tlsInt.h @@ -35,11 +35,11 @@ /* Windows needs to know which symbols to export. */ #ifdef BUILD_tls #undef TCL_STORAGE_CLASS #define TCL_STORAGE_CLASS DLLEXPORT -#endif /* BUILD_udp */ +#endif /* BUILD_tls */ /* Handle TCL 8.6 CONST changes */ #ifndef CONST86 # if TCL_MAJOR_VERSION > 8 # define CONST86 const Index: library/tls.tcl ================================================================== --- library/tls.tcl +++ library/tls.tcl @@ -263,10 +263,17 @@ if {![info exists argsArray(-servername)]} { set argsArray(-servername) $host lappend iopts -servername $host } } + + # Use host as SNI server name without -autoservername and -servername args + if {![info exists argsArray(-autoservername)] && + ![info exists argsArray(-servername)]} { + set argsArray(-servername) $host + lappend iopts -servername $host + } lappend sopts $host $port } # # Create TCP/IP socket