| 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 |
;; Check that X509 certificates and private keys can be converted to abstract |
| 20 |
;; keys. |
| 21 |
|
| 22 |
(use-modules (gnutls) |
| 23 |
(gnutls build tests) |
| 24 |
(rnrs bytevectors) |
| 25 |
(ice-9 match) |
| 26 |
(ice-9 receive) |
| 27 |
(srfi srfi-1) |
| 28 |
(srfi srfi-26)) |
| 29 |
|
| 30 |
(run-test |
| 31 |
(lambda () |
| 32 |
;; Generate a X509 private key |
| 33 |
(receive (crt-private-key certificate) |
| 34 |
;; Stolen from x509-auth.scm |
| 35 |
(let ((import-key |
| 36 |
(lambda (import-proc file) |
| 37 |
(let* ((path (search-path %load-path file)) |
| 38 |
(size (stat:size (stat path))) |
| 39 |
(raw (make-u8vector size))) |
| 40 |
(uniform-vector-read! raw (open-input-file path)) |
| 41 |
(import-proc raw x509-certificate-format/pem))))) |
| 42 |
(values |
| 43 |
(import-key import-x509-private-key "x509-key.pem") |
| 44 |
(import-key import-x509-certificate "x509-certificate.pem"))) |
| 45 |
(receive (key pub) |
| 46 |
(values |
| 47 |
(x509-private-key->private-key crt-private-key '()) |
| 48 |
(x509-certificate->public-key certificate)) |
| 49 |
(unless (and key pub) |
| 50 |
(error "conversion failed")))))) |