Function: open-gnutls-stream

open-gnutls-stream is an autoloaded and byte-compiled function defined in gnutls.el.gz.

Signature

(open-gnutls-stream NAME BUFFER HOST SERVICE &optional PARAMETERS)

Documentation

Open a SSL/TLS connection for a service to a host.

Returns a subprocess-object to represent the connection. Input and output work as for subprocesses; delete-process closes it. Args are NAME BUFFER HOST SERVICE. NAME is name for process. It is modified if necessary to make it unique. BUFFER is the buffer (or buffer-name) to associate with the process.
 Process output goes at end of that buffer, unless you specify
 a filter function to handle the output.
 BUFFER may be also nil, meaning that this process is not associated
 with any buffer
Third arg HOST is the name of the host to connect to, or its IP address. Fourth arg SERVICE is the name of the service desired, or an integer specifying a port number to connect to. Fifth arg PARAMETERS is an optional list of keyword/value pairs. Only :client-certificate, :nowait, :noquery, and :coding keywords are recognized, and have the same meaning as for open-network-stream. For historical reasons PARAMETERS can also be a symbol, which is interpreted the same as passing a list containing :nowait and the value of that symbol.

Usage example:

  (with-temp-buffer
    (open-gnutls-stream "tls"
                        (current-buffer)
                        "your server goes here"
                        "imaps"))

This is a very simple wrapper around gnutls-negotiate. See its documentation for the specific parameters you can use to open a GnuTLS connection, including specifying the credential type, trust and key files, and priority string.

Probably introduced at or before Emacs version 24.1.

Source Code

;; Defined in /usr/src/emacs/lisp/net/gnutls.el.gz
(defun open-gnutls-stream (name buffer host service &optional parameters)
  "Open a SSL/TLS connection for a service to a host.
Returns a subprocess-object to represent the connection.
Input and output work as for subprocesses; `delete-process' closes it.
Args are NAME BUFFER HOST SERVICE.
NAME is name for process.  It is modified if necessary to make it unique.
BUFFER is the buffer (or `buffer-name') to associate with the process.
 Process output goes at end of that buffer, unless you specify
 a filter function to handle the output.
 BUFFER may be also nil, meaning that this process is not associated
 with any buffer
Third arg HOST is the name of the host to connect to, or its IP address.
Fourth arg SERVICE is the name of the service desired, or an integer
specifying a port number to connect to.
Fifth arg PARAMETERS is an optional list of keyword/value pairs.
Only :client-certificate, :nowait, :noquery, and :coding keywords are
recognized, and have the same meaning as for
`open-network-stream'.
For historical reasons PARAMETERS can also be a symbol, which is
interpreted the same as passing a list containing :nowait and the
value of that symbol.

Usage example:

  (with-temp-buffer
    (open-gnutls-stream \"tls\"
                        (current-buffer)
                        \"your server goes here\"
                        \"imaps\"))

This is a very simple wrapper around `gnutls-negotiate'.  See its
documentation for the specific parameters you can use to open a
GnuTLS connection, including specifying the credential type,
trust and key files, and priority string."
  (let* ((parameters
          (cond ((symbolp parameters)
                 (list :nowait parameters))
                ((not (evenp (length parameters)))
                 (error "Malformed keyword list"))
                ((consp parameters)
                 parameters)
                (t
                 (error "Unknown parameter type"))))
         (cert (network-stream-certificate host service parameters))
         (keylist (and cert (list cert)))
         (nowait (plist-get parameters :nowait))
         (noquery (plist-get parameters :noquery))
         (process (open-network-stream
                   name buffer host service
                   :nowait nowait
                   :noquery noquery
                   :tls-parameters
                   (and nowait
                        (cons 'gnutls-x509pki
                              (gnutls-boot-parameters
                               :type 'gnutls-x509pki
                               :keylist keylist
                               :hostname (puny-encode-domain host))))
                   :coding (plist-get parameters :coding))))
    (if nowait
        process
      (gnutls-negotiate :process process
                        :type 'gnutls-x509pki
                        :keylist keylist
                        :hostname (puny-encode-domain host)))))