Debian Codegraph @

guile/tests/priorities.scm

raw
1 ;;; GnuTLS --- Guile bindings for GnuTLS
2 ;;; Copyright (C) 2011-2025 Free Software Foundation, Inc.
3 ;;;
4 ;;; This file is part of Guile-GnuTLS.
5 ;;;
6 ;;; This program is free software: you can redistribute it and/or modify
7 ;;; it under the terms of the GNU General Public License as published by
8 ;;; the Free Software Foundation, either version 3 of the License, or
9 ;;; (at your option) any later version.
10 ;;;
11 ;;; This program is distributed in the hope that it will be useful,
12 ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
13 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 ;;; GNU General Public License for more details.
15 ;;;
16 ;;; You should have received a copy of the GNU General Public License
17 ;;; along with this program. If not, see <https://www.gnu.org/licenses/>.
18
19 ;;; Written by Ludovic Courtès <[email protected]>.
20
21
22 ;;;
23 ;;; Exercise the priority API of GnuTLS.
24 ;;;
25
26 (use-modules (gnutls)
27 (gnutls build tests)
28 (srfi srfi-1)
29 (srfi srfi-26))
30
31 (define %valid-priority-strings
32 ;; Valid priority strings (from the manual).
33 '("NONE:+VERS-TLS1.2:+MAC-ALL:+RSA:+AES-128-CBC:+SIGN-ALL:+COMP-NULL"
34 "NORMAL:-ARCFOUR-128"
35 "SECURE128:-VERS-SSL3.0:+COMP-NULL"
36 "NONE:+VERS-TLS1.2:+AES-128-CBC:+RSA:+SHA1:+COMP-NULL:+SIGN-RSA-SHA1"))
37
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 ("SECURE128:-VERS-SSL3.0:" . "+FAIL-HERE")
43 ("NONE:+VERS-TLS1.2:+AES-128-CBC:"
44 . "+FAIL-HERE:+SHA1:+COMP-NULL:+SIGN-RSA-SHA1")))
45
46 (run-test
47
48 (lambda ()
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)
53
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)))
59 (catch 'gnutls-error
60 (lambda ()
61 (let ((s (make-session connection-end/client)))
62 ;; The following call should raise an exception.
63 (set-session-priorities! s string)
64 #f))
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))))