1.\" $OpenBSD: tls_load_file.3,v 1.11 2018/11/29 14:24:23 tedu Exp $ 2.\" 3.\" Copyright (c) 2014 Ted Unangst <tedu@openbsd.org> 4.\" Copyright (c) 2015 Reyk Floeter <reyk@openbsd.org> 5.\" Copyright (c) 2015 Bob Beck <beck@openbsd.org> 6.\" Copyright (c) 2016, 2017 Joel Sing <jsing@openbsd.org> 7.\" 8.\" Permission to use, copy, modify, and distribute this software for any 9.\" purpose with or without fee is hereby granted, provided that the above 10.\" copyright notice and this permission notice appear in all copies. 11.\" 12.\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 13.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 14.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 15.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 16.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 17.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 18.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 19.\" 20.Dd $Mdocdate: November 29 2018 $ 21.Dt TLS_LOAD_FILE 3 22.Os 23.Sh NAME 24.Nm tls_load_file , 25.Nm tls_unload_file , 26.Nm tls_config_set_ca_file , 27.Nm tls_config_set_ca_path , 28.Nm tls_config_set_ca_mem , 29.Nm tls_config_set_cert_file , 30.Nm tls_config_set_cert_mem , 31.Nm tls_config_set_crl_file , 32.Nm tls_config_set_crl_mem , 33.Nm tls_config_set_key_file , 34.Nm tls_config_set_key_mem , 35.Nm tls_config_set_ocsp_staple_mem , 36.Nm tls_config_set_ocsp_staple_file , 37.Nm tls_config_set_keypair_file , 38.Nm tls_config_set_keypair_mem , 39.Nm tls_config_set_keypair_ocsp_file , 40.Nm tls_config_set_keypair_ocsp_mem , 41.Nm tls_config_add_keypair_file , 42.Nm tls_config_add_keypair_ocsp_mem , 43.Nm tls_config_add_keypair_ocsp_file , 44.Nm tls_config_add_keypair_mem , 45.Nm tls_config_clear_keys , 46.Nm tls_config_set_verify_depth , 47.Nm tls_config_verify_client , 48.Nm tls_config_verify_client_optional , 49.Nm tls_default_ca_cert_file 50.Nd TLS certificate and key configuration 51.Sh SYNOPSIS 52.In tls.h 53.Ft uint8_t * 54.Fo tls_load_file 55.Fa "const char *file" 56.Fa "size_t *len" 57.Fa "char *password" 58.Fc 59.Ft void 60.Fo tls_unload_file 61.Fa "uint8_t *buf" 62.Fa "size_t len" 63.Fc 64.Ft int 65.Fo tls_config_set_ca_file 66.Fa "struct tls_config *config" 67.Fa "const char *ca_file" 68.Fc 69.Ft int 70.Fo tls_config_set_ca_path 71.Fa "struct tls_config *config" 72.Fa "const char *ca_path" 73.Fc 74.Ft int 75.Fo tls_config_set_ca_mem 76.Fa "struct tls_config *config" 77.Fa "const uint8_t *cert" 78.Fa "size_t len" 79.Fc 80.Ft int 81.Fo tls_config_set_cert_file 82.Fa "struct tls_config *config" 83.Fa "const char *cert_file" 84.Fc 85.Ft int 86.Fo tls_config_set_cert_mem 87.Fa "struct tls_config *config" 88.Fa "const uint8_t *cert" 89.Fa "size_t len" 90.Fc 91.Ft int 92.Fo tls_config_set_crl_file 93.Fa "struct tls_config *config" 94.Fa "const char *crl_file" 95.Fc 96.Ft int 97.Fo tls_config_set_crl_mem 98.Fa "struct tls_config *config" 99.Fa "const uint8_t *crl" 100.Fa "size_t len" 101.Fc 102.Ft int 103.Fo tls_config_set_key_file 104.Fa "struct tls_config *config" 105.Fa "const char *key_file" 106.Fc 107.Ft int 108.Fo tls_config_set_key_mem 109.Fa "struct tls_config *config" 110.Fa "const uint8_t *key" 111.Fa "size_t len" 112.Fc 113.Ft int 114.Fo tls_config_set_ocsp_staple_mem 115.Fa "struct tls_config *config" 116.Fa "const uint8_t *staple" 117.Fa "size_t len" 118.Fc 119.Ft int 120.Fo tls_config_set_ocsp_staple_file 121.Fa "struct tls_config *config" 122.Fa "const char *staple_file" 123.Fc 124.Ft int 125.Fo tls_config_set_keypair_file 126.Fa "struct tls_config *config" 127.Fa "const char *cert_file" 128.Fa "const char *key_file" 129.Fc 130.Ft int 131.Fo tls_config_set_keypair_mem 132.Fa "struct tls_config *config" 133.Fa "const uint8_t *cert" 134.Fa "size_t cert_len" 135.Fa "const uint8_t *key" 136.Fa "size_t key_len" 137.Fc 138.Ft int 139.Fo tls_config_set_keypair_ocsp_file 140.Fa "struct tls_config *config" 141.Fa "const char *cert_file" 142.Fa "const char *key_file" 143.Fa "const char *staple_file" 144.Fc 145.Ft int 146.Fo tls_config_set_keypair_ocsp_mem 147.Fa "struct tls_config *config" 148.Fa "const uint8_t *cert" 149.Fa "size_t cert_len" 150.Fa "const uint8_t *key" 151.Fa "size_t key_len" 152.Fa "const uint8_t *staple" 153.Fa "size_t staple_len" 154.Fc 155.Ft int 156.Fo tls_config_add_keypair_file 157.Fa "struct tls_config *config" 158.Fa "const char *cert_file" 159.Fa "const char *key_file" 160.Fc 161.Ft int 162.Fo tls_config_add_keypair_mem 163.Fa "struct tls_config *config" 164.Fa "const uint8_t *cert" 165.Fa "size_t cert_len" 166.Fa "const uint8_t *key" 167.Fa "size_t key_len" 168.Fc 169.Ft int 170.Fo tls_config_add_keypair_ocsp_file 171.Fa "struct tls_config *config" 172.Fa "const char *cert_file" 173.Fa "const char *key_file" 174.Fa "const char *staple_file" 175.Fc 176.Ft int 177.Fo tls_config_add_keypair_ocsp_mem 178.Fa "struct tls_config *config" 179.Fa "const uint8_t *cert" 180.Fa "size_t cert_len" 181.Fa "const uint8_t *key" 182.Fa "size_t key_len" 183.Fa "const uint8_t *staple" 184.Fa "size_t staple_len" 185.Fc 186.Ft void 187.Fn tls_config_clear_keys "struct tls_config *config" 188.Ft int 189.Fo tls_config_set_verify_depth 190.Fa "struct tls_config *config" 191.Fa "int verify_depth" 192.Fc 193.Ft void 194.Fn tls_config_verify_client "struct tls_config *config" 195.Ft void 196.Fn tls_config_verify_client_optional "struct tls_config *config" 197.Ft const char * 198.Fn tls_default_ca_cert_file "void" 199.Sh DESCRIPTION 200.Fn tls_load_file 201loads a certificate or key from disk into memory to be used with 202.Fn tls_config_set_ca_mem , 203.Fn tls_config_set_cert_mem , 204.Fn tls_config_set_crl_mem 205or 206.Fn tls_config_set_key_mem . 207A private key will be decrypted if the optional 208.Ar password 209argument is specified. 210.Pp 211.Fn tls_unload_file 212unloads the memory that was returned from an earlier 213.Fn tls_load_file 214call, ensuring that the memory contents is discarded. 215.Pp 216.Fn tls_default_ca_cert_file 217returns the path of the file that contains the default root certificates. 218.Pp 219.Fn tls_config_set_ca_file 220sets the filename used to load a file 221containing the root certificates. 222.Pp 223.Fn tls_config_set_ca_path 224sets the path (directory) which should be searched for root 225certificates. 226.Pp 227.Fn tls_config_set_ca_mem 228sets the root certificates directly from memory. 229.Pp 230.Fn tls_config_set_cert_file 231sets file from which the public certificate will be read. 232.Pp 233.Fn tls_config_set_cert_mem 234sets the public certificate directly from memory. 235.Pp 236.Fn tls_config_set_crl_file 237sets the filename used to load a file containing the 238Certificate Revocation List (CRL). 239.Pp 240.Fn tls_config_set_crl_mem 241sets the CRL directly from memory. 242.Pp 243.Fn tls_config_set_key_file 244sets the file from which the private key will be read. 245.Pp 246.Fn tls_config_set_key_mem 247directly sets the private key from memory. 248.Pp 249.Fn tls_config_set_ocsp_staple_file 250sets a DER-encoded OCSP response to be stapled during the TLS handshake from 251the specified file. 252.Pp 253.Fn tls_config_set_ocsp_staple_mem 254sets a DER-encoded OCSP response to be stapled during the TLS handshake from 255memory. 256.Pp 257.Fn tls_config_set_keypair_file 258sets the files from which the public certificate, and private key will be read. 259.Pp 260.Fn tls_config_set_keypair_mem 261directly sets the public certificate, and private key from memory. 262.Pp 263.Fn tls_config_set_keypair_ocsp_file 264sets the files from which the public certificate, private key, and DER-encoded 265OCSP staple will be read. 266.Pp 267.Fn tls_config_set_keypair_ocsp_mem 268directly sets the public certificate, private key, and DER-encoded OCSP staple 269from memory. 270.Pp 271.Fn tls_config_add_keypair_file 272adds an additional public certificate, and private key from the specified files, 273used as an alternative certificate for Server Name Indication (server only). 274.Pp 275.Fn tls_config_add_keypair_mem 276adds an additional public certificate, and private key from memory, used as an 277alternative certificate for Server Name Indication (server only). 278.Pp 279.Fn tls_config_add_keypair_ocsp_file 280adds an additional public certificate, private key, and DER-encoded OCSP staple 281from the specified files, used as an alternative certificate for Server Name 282Indication (server only). 283.Pp 284.Fn tls_config_add_keypair_ocsp_mem 285adds an additional public certificate, private key, and DER-encoded OCSP staple 286from memory, used as an alternative certificate for Server Name Indication 287(server only). 288.Pp 289.Fn tls_config_clear_keys 290clears any secret keys from memory. 291.Pp 292.Fn tls_config_set_verify_depth 293limits the number of intermediate certificates that will be followed during 294certificate validation. 295.Pp 296.Fn tls_config_verify_client 297enables client certificate verification, requiring the client to send 298a certificate (server only). 299.Pp 300.Fn tls_config_verify_client_optional 301enables client certificate verification, without requiring the client 302to send a certificate (server only). 303.Sh RETURN VALUES 304.Fn tls_load_file 305returns 306.Dv NULL 307on error or an out of memory condition. 308.Pp 309The other functions return 0 on success or -1 on error. 310.Sh SEE ALSO 311.Xr tls_config_ocsp_require_stapling 3 , 312.Xr tls_config_set_protocols 3 , 313.Xr tls_config_set_session_id 3 , 314.Xr tls_configure 3 , 315.Xr tls_init 3 316.Sh HISTORY 317.Fn tls_config_set_ca_file , 318.Fn tls_config_set_ca_path , 319.Fn tls_config_set_cert_file , 320.Fn tls_config_set_cert_mem , 321.Fn tls_config_set_key_file , 322.Fn tls_config_set_key_mem , 323and 324.Fn tls_config_set_verify_depth 325appeared in 326.Ox 5.6 327and got their final names in 328.Ox 5.7 . 329.Pp 330.Fn tls_load_file , 331.Fn tls_config_set_ca_mem , 332and 333.Fn tls_config_clear_keys 334appeared in 335.Ox 5.7 . 336.Pp 337.Fn tls_config_verify_client 338and 339.Fn tls_config_verify_client_optional 340appeared in 341.Ox 5.9 . 342.Pp 343.Fn tls_config_set_keypair_file 344and 345.Fn tls_config_set_keypair_mem 346appeared in 347.Ox 6.0 , 348and 349.Fn tls_config_add_keypair_file 350and 351.Fn tls_config_add_keypair_mem 352in 353.Ox 6.1 . 354.Pp 355.Fn tls_config_set_crl_file 356and 357.Fn tls_config_set_crl_mem 358appeared in 359.Ox 6.2 . 360.Sh AUTHORS 361.An Joel Sing Aq Mt jsing@openbsd.org 362with contibutions from 363.An Ted Unangst Aq Mt tedu@openbsd.org 364and 365.An Bob Beck Aq Mt beck@openbsd.org . 366.Pp 367.Fn tls_load_file 368and 369.Fn tls_config_set_ca_mem 370were written by 371.An Reyk Floeter Aq Mt reyk@openbsd.org . 372