| 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 |
;; server, for instance obtained by the "connect" function. |
| 21 |
|
| 22 |
(let ((client (make-session connection-end/client))) |
| 23 |
;; Use the default settings. |
| 24 |
(set-session-default-priority! client) |
| 25 |
|
| 26 |
;; Request the "anonymous Diffie-Hellman" key exchange method. |
| 27 |
(set-session-priorities! client "NORMAL:+ANON-DH") |
| 28 |
|
| 29 |
;; Specify the underlying socket. |
| 30 |
(set-session-transport-fd! client (fileno some-socket)) |
| 31 |
|
| 32 |
;; Create anonymous credentials. |
| 33 |
(set-session-credentials! client |
| 34 |
(make-anonymous-client-credentials)) |
| 35 |
|
| 36 |
;; Perform the TLS handshake with the server. |
| 37 |
(handshake client) |
| 38 |
|
| 39 |
;; Send data over the TLS record layer. |
| 40 |
(write "hello, world!" (session-record-port client)) |
| 41 |
|
| 42 |
;; Terminate the TLS session. |
| 43 |
(bye client close-request/rdwr)) |