| 1 |
;;; GnuTLS --- Guile bindings for GnuTLS. |
| 2 |
;;; Copyright (C) 2023-2025 Free Software Foundation, Inc. |
| 3 |
;;; |
| 4 |
;;; This file is part of Guile-GnuTLS. |
| 5 |
;;; |
| 6 |
;;; This library is free software; you can redistribute it and/or |
| 7 |
;;; modify it under the terms of the GNU Lesser General Public |
| 8 |
;;; License as published by the Free Software Foundation; either |
| 9 |
;;; version 2.1 of the License, or (at your option) any later version. |
| 10 |
;;; |
| 11 |
;;; This library 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 GNU |
| 14 |
;;; Lesser General Public License for more details. |
| 15 |
;;; |
| 16 |
;;; You should have received a copy of the GNU Lesser General Public |
| 17 |
;;; License along with this library; if not, see <https://www.gnu.org/licenses/>. |
| 18 |
|
| 19 |
;; Suppose that we have "some-socket", a socket object connected to the |
| 20 |
;; client, for instance obtained by the "accept" function. |
| 21 |
|
| 22 |
(let ((server (make-session connection-end/server))) |
| 23 |
(set-session-default-priority! server) |
| 24 |
|
| 25 |
;; Request the "anonymous Diffie-Hellman" key exchange method. |
| 26 |
(set-session-priorities! server "NORMAL:+ANON-DH") |
| 27 |
|
| 28 |
;; Specify the underlying transport socket. |
| 29 |
(set-session-transport-fd! server (fileno some-socket)) |
| 30 |
|
| 31 |
;; Create anonymous credentials. |
| 32 |
(let ((cred (make-anonymous-server-credentials)) |
| 33 |
(dh-params (make-dh-parameters 1024))) |
| 34 |
;; Note: DH parameter generation can take some time. |
| 35 |
(set-anonymous-server-dh-parameters! cred dh-params) |
| 36 |
(set-session-credentials! server cred)) |
| 37 |
|
| 38 |
;; Perform the TLS handshake with the client. |
| 39 |
(handshake server) |
| 40 |
|
| 41 |
;; Receive data over the TLS record layer. |
| 42 |
(let ((message (read (session-record-port server)))) |
| 43 |
(format #t "received the following message: ~a~%" |
| 44 |
message) |
| 45 |
|
| 46 |
(bye server close-request/rdwr))) |