From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.emacs.gnus.general/70649 Path: news.gmane.org!not-for-mail From: Ted Zlatanov Newsgroups: gmane.emacs.gnus.general Subject: Re: TLS and stuff Date: Tue, 07 Sep 2010 12:09:35 -0500 Organization: =?utf-8?B?0KLQtdC+0LTQvtGAINCX0LvQsNGC0LDQvdC+0LI=?= @ Cienfuegos Message-ID: <8739tltr8w.fsf@lifelogs.com> References: NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: dough.gmane.org 1283879397 15321 80.91.229.12 (7 Sep 2010 17:09:57 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Tue, 7 Sep 2010 17:09:57 +0000 (UTC) To: ding@gnus.org Original-X-From: ding-owner+M19022@lists.math.uh.edu Tue Sep 07 19:09:55 2010 Return-path: Envelope-to: ding-account@gmane.org Original-Received: from util0.math.uh.edu ([129.7.128.18]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1Ot1gA-0005hp-7D for ding-account@gmane.org; Tue, 07 Sep 2010 19:09:54 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.math.uh.edu) by util0.math.uh.edu with smtp (Exim 4.63) (envelope-from ) id 1Ot1g9-0001yP-29; Tue, 07 Sep 2010 12:09:53 -0500 Original-Received: from mx2.math.uh.edu ([129.7.128.33]) by util0.math.uh.edu with esmtps (TLSv1:AES256-SHA:256) (Exim 4.63) (envelope-from ) id 1Ot1g7-0001y7-Fk for ding@lists.math.uh.edu; Tue, 07 Sep 2010 12:09:51 -0500 Original-Received: from quimby.gnus.org ([80.91.231.51]) by mx2.math.uh.edu with esmtp (Exim 4.72) (envelope-from ) id 1Ot1g2-0003j9-QK for ding@lists.math.uh.edu; Tue, 07 Sep 2010 12:09:51 -0500 Original-Received: from lo.gmane.org ([80.91.229.12]) by quimby.gnus.org with esmtp (Exim 3.36 #1 (Debian)) id 1Ot1g2-0005yQ-00 for ; Tue, 07 Sep 2010 19:09:46 +0200 Original-Received: from list by lo.gmane.org with local (Exim 4.69) (envelope-from ) id 1Ot1g1-0005e8-9R for ding@gnus.org; Tue, 07 Sep 2010 19:09:45 +0200 Original-Received: from 38.98.147.130 ([38.98.147.130]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Tue, 07 Sep 2010 19:09:45 +0200 Original-Received: from tzz by 38.98.147.130 with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Tue, 07 Sep 2010 19:09:45 +0200 X-Injected-Via-Gmane: http://gmane.org/ Original-Lines: 175 Original-X-Complaints-To: usenet@dough.gmane.org X-Gmane-NNTP-Posting-Host: 38.98.147.130 X-Face: bd.DQ~'29fIs`T_%O%C\g%6jW)yi[zuz6;d4V0`@y-~$#3P_Ng{@m+e4o<4P'#(_GJQ%TT= D}[Ep*b!\e,fBZ'j_+#"Ps?s2!4H2-Y"sx" User-Agent: Gnus/5.110011 (No Gnus v0.11) Emacs/24.0.50 (gnu/linux) Cancel-Lock: sha1:yPyJooUWrSrwXh97v5SvTxHM2Dw= X-Spam-Score: -0.7 (/) List-ID: Precedence: bulk Xref: news.gmane.org gmane.emacs.gnus.general:70649 Archived-At: --=-=-= Content-Type: text/plain On Tue, 07 Sep 2010 18:10:01 +0200 Lars Magne Ingebrigtsen wrote: LMI> I saw over on the Emacs list that Emacs 24 now has native TLS support, LMI> which would be nice for many Gnus things. The patch is not yet ready but I'm getting close to anonymous and x509 authentication. In fact I started work on this patch (which Simon Josefsson wrote originally) exactly for the benefit of Gnus. LMI> Is there a simple how-to on how to use that, but still fall back on LMI> using, er, "openssl s_client" if the built-in support doesn't exist? LMI> I'm thinking about how to use that for imaps servers... See lisp/net/gnutls.el below (this version is revised from the posted one with the patch to fix some stupid message bugs). Simon wanted gnutls.el to be a drop-in replacement for starttls.el so I'll probably adapt it a little but keep the interface. I posted the latest patch last night. All I can say is "it compiles." But you can try this after eval-ing gnutls.el: (open-ssl-stream "tls" "tls-buffer" "yourserver.com" "imaps") Right now it errors out with progn: (err=-28) handshake: nil Ouch, error return -28 so I need to fix the error handling that's supposed to return 'gnutls-e-again in this case. I'll get to it tonight, I hope. Ted --=-=-= Content-Type: application/emacs-lisp Content-Disposition: attachment; filename=gnutls.el Content-Transfer-Encoding: quoted-printable ;;; gnutls.el --- Support SSL and TLS connections through GnuTLS ;; Copyright (C) 2010 Free Software Foundation, Inc. ;; Author: Ted Zlatanov ;; Keywords: comm, tls, ssl, encryption ;; Originally-By: Simon Josefsson (See http://josefsson.org/emacs-security/) ;; This file is part of GNU Emacs. ;; GNU Emacs is free software: you can redistribute it and/or modify ;; it under the terms of the GNU General Public License as published by ;; the Free Software Foundation, either version 3 of the License, or ;; (at your option) any later version. ;; GNU Emacs is distributed in the hope that it will be useful, ;; but WITHOUT ANY WARRANTY; without even the implied warranty of ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ;; GNU General Public License for more details. ;; You should have received a copy of the GNU General Public License ;; along with GNU Emacs. If not, see . ;;; Commentary: ;; This package provides language bindings for the GnuTLS library ;; using the corresponding core functions in gnutls.c. ;; Simple test: ;; ;; (setq jas (open-ssl-stream "ssl" (current-buffer) "www.pdc.kth.se" 443)) ;; (process-send-string jas "GET /\r\n\r\n") ;;; Code: (defconst gnutls-version "0.3.1") (defun open-ssl-stream (name buffer host service) "Open a SSL 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 an output stream or filter function to handle the output. BUFFER may be also nil, meaning that this process is not associated with any buffer Third arg is name of the host to connect to, or its IP address. Fourth arg SERVICE is name of the service desired, or an integer specifying a port number to connect to." (let ((proc (open-network-stream name buffer host service))) (starttls-negotiate proc))) (defun starttls-negotiate (proc &optional priority-string credentials credentials-file) "Negotiate a SSL or TLS connection. PROC is the process returned by `starttls-open-stream'. PRIORITY-STRING is as per the GnuTLS docs. CREDENTIALS is `gnutls-x509pki', `gnutls-anon', or `gnutls-srp'. CREDENTIALS-FILE is a filename with meaning dependent on CREDENTIALS." (let* ((credentials (or credentials 'gnutls-anon)) (priority-string (or priority-string (cond ((eq credentials 'gnutls-anon) "PERFORMANCE:+ANON-DH:!ARCFOUR-128") ((eq credentials 'gnutls-x509pki) "PERFORMANCE"))))) (gnutls-message-maybe (gnutls-global-init) "global_init: %s") (gnutls-message-maybe (gnutls-init proc) "init: %s") (gnutls-message-maybe (gnutls-priority-set-direct proc priority-string) "priority_set: %s") (gnutls-message-maybe (gnutls-cred-set proc credentials) "credential_set: %s") (cond ((eq credentials 'gnutls-x509pki) (gnutls-message-maybe (gnutls-cert-set-x509-trust-file proc credentials-file) "x509_trustfile: %s"))) (let ((ret 'gnutls-e-again)) (while (or (eq ret 'gnutls-e-again) (eq ret 'gnutls-e-interrupted)) (gnutls-message-maybe (setq ret (gnutls-handshake proc)) "handshake: %s")) (if (gnutls-errorp ret) (progn (message "Ouch, error return %d" ret) (setq proc nil)) (message "Handshake complete %d." ret))) proc)) (defun starttls-open-stream (name buffer host service) "Open a 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 an output stream or filter function to handle the output. BUFFER may be also nil, meaning that this process is not associated with any buffer Third arg is name of the host to connect to, or its IP address. Fourth arg SERVICE is name of the service desired, or an integer specifying a port number to connect to." (open-network-stream name buffer host service)) (defun gnutls-message-maybe (doit format &rest params) "When DOIT, message with the caller name followed by FORMAT on PARAMS." (when (gnutls-errorp doit) (message "%s: (err=3D%s) %s" "gnutls.el" doit (apply 'format format (or params '(nil)))))) (provide 'ssl) (provide 'gnutls) (provide 'starttls) ;;; gnutls.el ends here --=-=-=--