1 ;;; GnuTLS --- Guile bindings for GnuTLS.
2 ;;; Copyright (C) 2007-2012 Free Software Foundation, Inc.
4 ;;; GnuTLS is free software; you can redistribute it and/or
5 ;;; modify it under the terms of the GNU Lesser General Public
6 ;;; License as published by the Free Software Foundation; either
7 ;;; version 2.1 of the License, or (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 GNU
12 ;;; Lesser General Public License for more details.
14 ;;; You should have received a copy of the GNU Lesser General Public
15 ;;; License along with GnuTLS; if not, write to the Free Software
16 ;;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 ;;; Written by Ludovic Courtès <ludo@chbouib.org>.
22 ;;; Exercise the X.509 certificate API.
30 (define %certificate-file
31 (search-path %load-path "x509-certificate.pem"))
33 (define %private-key-file
34 (search-path %load-path "x509-key.pem"))
37 ;; The certificate's first OID.
40 (define %signature-algorithm
41 ;; The certificate's signature algorithm.
42 sign-algorithm/rsa-sha1)
45 (define (file-size file)
46 (stat:size (stat file)))
51 (let ((raw-certificate (make-u8vector (file-size %certificate-file)))
52 (raw-privkey (make-u8vector (file-size %private-key-file))))
54 (uniform-vector-read! raw-certificate
55 (open-input-file %certificate-file))
56 (uniform-vector-read! raw-privkey
57 (open-input-file %private-key-file))
59 (let ((cert (import-x509-certificate raw-certificate
60 x509-certificate-format/pem))
61 (sec (import-x509-private-key raw-privkey
62 x509-certificate-format/pem)))
64 (and (x509-certificate? cert)
65 (x509-private-key? sec)
66 (string? (x509-certificate-dn cert))
67 (string? (x509-certificate-issuer-dn cert))
68 (string=? (x509-certificate-dn-oid cert 0) %first-oid)
69 (eq? (x509-certificate-signature-algorithm cert)
71 (x509-certificate-matches-hostname? cert "localhost")
72 (let-values (((type name)
73 (x509-certificate-subject-alternative-name
77 (x509-subject-alternative-name->string type)))))))))
79 ;;; arch-tag: eef09b52-30e8-472a-8b93-cb636434f6eb