Importing starttls 0.4+.
[elisp/starttls.git] / starttls.el
1 ;;; starttls.el --- TLSv1 functions
2
3 ;; Copyright (C) 1999 Daiki Ueno
4
5 ;; Author: Daiki Ueno <ueno@ueda.info.waseda.ac.jp>
6 ;;      Kenichi OKADA <okada@opaopa.org>
7 ;; Created: 1999/11/20
8 ;; Keywords: TLS, SSL, OpenSSL
9
10 ;; This file is not part of any package.
11
12 ;; This program is free software; you can redistribute it and/or
13 ;; modify it under the terms of the GNU General Public License as
14 ;; published by the Free Software Foundation; either version 2, or (at
15 ;; your option) any later version.
16
17 ;; This program is distributed in the hope that it will be useful, but
18 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
20 ;; General Public License for more details.
21
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with GNU Emacs; see the file COPYING.  If not, write to the
24 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
25 ;; Boston, MA 02111-1307, USA.
26
27 ;;; Commentary:
28
29 ;; This module defines some utility functions for TLSv1 functions.
30
31 ;; [RFC 2246] "The TLS Protocol Version 1.0"
32 ;;      by Christopher Allen <callen@certicom.com> and 
33 ;;      Tim Dierks <tdierks@certicom.com> (1999/01)
34
35 ;; [RFC 2595] "Using TLS with IMAP, POP3 and ACAP"
36 ;;      by Chris Newman <chris.newman@innosoft.com> (1999/06)
37
38 ;;; Code:
39
40 (defgroup starttls nil
41   "Support for `Transport Layer Security' protocol."
42   :group 'ssl)
43
44 (defcustom starttls-program "starttls"
45   "The program to run in a subprocess to open an TLSv1 connection."
46   :group 'starttls)
47
48 (defcustom starttls-extra-args nil
49   "Extra arguments to `starttls-program'"
50   :group 'starttls)
51
52 (defun starttls-negotiate (process)
53   (signal-process (process-id process) 'SIGALRM))
54
55 (defun starttls-open-stream (name buffer host service)
56   "Open a TLS connection for a service to a host.
57 Returns a subprocess-object to represent the connection.
58 Input and output work as for subprocesses; `delete-process' closes it.
59 Args are NAME BUFFER HOST SERVICE.
60 NAME is name for process.  It is modified if necessary to make it unique.
61 BUFFER is the buffer (or `buffer-name') to associate with the process.
62  Process output goes at end of that buffer, unless you specify
63  an output stream or filter function to handle the output.
64  BUFFER may be also nil, meaning that this process is not associated
65  with any buffer
66 Third arg is name of the host to connect to, or its IP address.
67 Fourth arg SERVICE is name of the service desired, or an integer
68 specifying a port number to connect to."
69
70   (let* ((process-connection-type nil)
71          (process (apply #'start-process
72                          name buffer starttls-program
73                          host (format "%s" service)
74                          starttls-extra-args)))
75     (process-kill-without-query process)
76     process))
77
78 (defun starttls-open-ssl-stream (name buffer host service)
79   "This function is compatible with the function `open-ssl-stream'."
80   (let* ((starttls-extra-args
81           (cons "--force" starttls-extra-args)))
82     (starttls-open-stream name buffer host service)))
83
84 (provide 'starttls)
85
86 ;;; starttls.el ends here