1 ;;; GnuTLS --- Guile bindings for GnuTLS
2 ;;; Copyright (C) 2011-2012 Free Software Foundation, Inc.
4 ;;; GnuTLS is free software; you can redistribute it and/or modify
5 ;;; it under the terms of the GNU General Public License as published by
6 ;;; the Free Software Foundation; either version 3 of the License, or
7 ;;; (at your option) any later version.
9 ;;; GnuTLS is distributed in the hope that it will be useful,
10 ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
11 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 ;;; GNU General Public License for more details.
14 ;;; You should have received a copy of the GNU General Public License
15 ;;; along with GnuTLS-EXTRA; if not, write to the Free Software
16 ;;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
19 ;;; Written by Ludovic Courtès <ludo@gnu.org>.
23 ;;; Exercise the priority API of GnuTLS.
31 (define %valid-priority-strings
32 ;; Valid priority strings (from the manual).
33 '("NONE:+VERS-TLS-ALL:+MAC-ALL:+RSA:+AES-128-CBC:+SIGN-ALL:+COMP-NULL"
35 "SECURE:-VERS-SSL3.0:+COMP-DEFLATE"
36 "NONE:+VERS-TLS-ALL:+AES-128-CBC:+RSA:+SHA1:+COMP-NULL:+SIGN-RSA-SHA1"))
38 (define %invalid-priority-strings
39 ;; Invalid strings: the prefix and the suffix that leads to a parse error.
40 '(("" . "THIS-DOES-NOT-WORK")
41 ("NORMAL:" . "FAIL-HERE")
42 ("SECURE:-VERS-SSL3.0:" . "+FAIL-HERE")
43 ("NONE:+VERS-TLS-ALL:+AES-128-CBC:"
44 . "+FAIL-HERE:+SHA1:+COMP-NULL:+SIGN-RSA-SHA1")))
49 (let ((s (make-session connection-end/client)))
50 ;; We shouldn't have any exception with the valid priority strings.
51 (for-each (cut set-session-priorities! s <>)
52 %valid-priority-strings)
54 (every (lambda (prefix+suffix)
55 (let* ((prefix (car prefix+suffix))
56 (suffix (cdr prefix+suffix))
57 (pos (string-length prefix))
58 (string (string-append prefix suffix)))
61 (let ((s (make-session connection-end/client)))
62 ;; The following call should raise an exception.
63 (set-session-priorities! s string)
65 (lambda (key err function error-location . unused)
66 (and (eq? key 'gnutls-error)
67 (eq? err error/invalid-request)
68 (eq? function 'set-session-priorities!)
69 (= error-location pos))))))
70 %invalid-priority-strings))))