diff options
Diffstat (limited to 'src/lib')
| -rw-r--r-- | src/lib/libtls/Makefile | 4 | ||||
| -rw-r--r-- | src/lib/libtls/tls.h | 7 | ||||
| -rw-r--r-- | src/lib/libtls/tls_client.c | 4 | ||||
| -rw-r--r-- | src/lib/libtls/tls_init.3 | 31 | ||||
| -rw-r--r-- | src/lib/libtls/tls_internal.h | 4 | ||||
| -rw-r--r-- | src/lib/libtls/tls_peer.c | 50 | ||||
| -rw-r--r-- | src/lib/libtls/tls_verify.c | 8 |
7 files changed, 95 insertions, 13 deletions
diff --git a/src/lib/libtls/Makefile b/src/lib/libtls/Makefile index 0e3329589e..2e03e247e4 100644 --- a/src/lib/libtls/Makefile +++ b/src/lib/libtls/Makefile | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | # $OpenBSD: Makefile,v 1.15 2015/09/11 11:28:01 jsing Exp $ | 1 | # $OpenBSD: Makefile,v 1.16 2015/09/11 12:56:55 beck Exp $ |
| 2 | 2 | ||
| 3 | CFLAGS+= -Wall -Werror -Wimplicit | 3 | CFLAGS+= -Wall -Werror -Wimplicit |
| 4 | CFLAGS+= -DLIBRESSL_INTERNAL | 4 | CFLAGS+= -DLIBRESSL_INTERNAL |
| @@ -46,6 +46,8 @@ MLINKS+=tls_init.3 tls_config_insecure_noverifyname.3 | |||
| 46 | MLINKS+=tls_init.3 tls_config_verify.3 | 46 | MLINKS+=tls_init.3 tls_config_verify.3 |
| 47 | MLINKS+=tls_init.3 tls_config_verify_client.3 | 47 | MLINKS+=tls_init.3 tls_config_verify_client.3 |
| 48 | MLINKS+=tls_init.3 tls_config_verify_client_optional.3 | 48 | MLINKS+=tls_init.3 tls_config_verify_client_optional.3 |
| 49 | MLINKS+=tls_init.3 tls_peer_cert_provided.3 | ||
| 50 | MLINKS+=tls_init.3 tls_peer_cert_contains_name.3 | ||
| 49 | MLINKS+=tls_init.3 tls_load_file.3 | 51 | MLINKS+=tls_init.3 tls_load_file.3 |
| 50 | MLINKS+=tls_init.3 tls_client.3 | 52 | MLINKS+=tls_init.3 tls_client.3 |
| 51 | MLINKS+=tls_init.3 tls_server.3 | 53 | MLINKS+=tls_init.3 tls_server.3 |
diff --git a/src/lib/libtls/tls.h b/src/lib/libtls/tls.h index 3cb24f0ee5..3d1682e2b6 100644 --- a/src/lib/libtls/tls.h +++ b/src/lib/libtls/tls.h | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | /* $OpenBSD: tls.h,v 1.19 2015/09/11 11:28:01 jsing Exp $ */ | 1 | /* $OpenBSD: tls.h,v 1.20 2015/09/11 12:56:55 beck Exp $ */ |
| 2 | /* | 2 | /* |
| 3 | * Copyright (c) 2014 Joel Sing <jsing@openbsd.org> | 3 | * Copyright (c) 2014 Joel Sing <jsing@openbsd.org> |
| 4 | * | 4 | * |
| @@ -76,6 +76,11 @@ void tls_config_verify(struct tls_config *_config); | |||
| 76 | void tls_config_verify_client(struct tls_config *_config); | 76 | void tls_config_verify_client(struct tls_config *_config); |
| 77 | void tls_config_verify_client_optional(struct tls_config *_config); | 77 | void tls_config_verify_client_optional(struct tls_config *_config); |
| 78 | 78 | ||
| 79 | int tls_peer_cert_provided(struct tls *ctx); | ||
| 80 | int tls_peer_cert_contains_name(struct tls *ctx, const char *name); | ||
| 81 | int tls_peer_cert_issuer(struct tls *ctx, char **name); | ||
| 82 | int tls_peer_cert_subject(struct tls *ctx, char **subject); | ||
| 83 | |||
| 79 | void tls_config_clear_keys(struct tls_config *_config); | 84 | void tls_config_clear_keys(struct tls_config *_config); |
| 80 | int tls_config_parse_protocols(uint32_t *_protocols, const char *_protostr); | 85 | int tls_config_parse_protocols(uint32_t *_protocols, const char *_protostr); |
| 81 | 86 | ||
diff --git a/src/lib/libtls/tls_client.c b/src/lib/libtls/tls_client.c index fb7f3a6f75..2aca519f8b 100644 --- a/src/lib/libtls/tls_client.c +++ b/src/lib/libtls/tls_client.c | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | /* $OpenBSD: tls_client.c,v 1.26 2015/09/10 10:14:20 jsing Exp $ */ | 1 | /* $OpenBSD: tls_client.c,v 1.27 2015/09/11 12:56:55 beck Exp $ */ |
| 2 | /* | 2 | /* |
| 3 | * Copyright (c) 2014 Joel Sing <jsing@openbsd.org> | 3 | * Copyright (c) 2014 Joel Sing <jsing@openbsd.org> |
| 4 | * | 4 | * |
| @@ -262,7 +262,7 @@ tls_handshake_client(struct tls *ctx) | |||
| 262 | tls_set_errorx(ctx, "no server certificate"); | 262 | tls_set_errorx(ctx, "no server certificate"); |
| 263 | goto err; | 263 | goto err; |
| 264 | } | 264 | } |
| 265 | if ((rv = tls_check_servername(ctx, cert, | 265 | if ((rv = tls_check_name(ctx, cert, |
| 266 | ctx->servername)) != 0) { | 266 | ctx->servername)) != 0) { |
| 267 | if (rv != -2) | 267 | if (rv != -2) |
| 268 | tls_set_errorx(ctx, "name `%s' not present in" | 268 | tls_set_errorx(ctx, "name `%s' not present in" |
diff --git a/src/lib/libtls/tls_init.3 b/src/lib/libtls/tls_init.3 index 6197817f6f..4066713603 100644 --- a/src/lib/libtls/tls_init.3 +++ b/src/lib/libtls/tls_init.3 | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | .\" $OpenBSD: tls_init.3,v 1.37 2015/09/11 09:02:10 beck Exp $ | 1 | .\" $OpenBSD: tls_init.3,v 1.38 2015/09/11 12:56:55 beck Exp $ |
| 2 | .\" | 2 | .\" |
| 3 | .\" Copyright (c) 2014 Ted Unangst <tedu@openbsd.org> | 3 | .\" Copyright (c) 2014 Ted Unangst <tedu@openbsd.org> |
| 4 | .\" | 4 | .\" |
| @@ -112,6 +112,10 @@ | |||
| 112 | .Fn tls_config_verify_client "struct tls_config *config" | 112 | .Fn tls_config_verify_client "struct tls_config *config" |
| 113 | .Ft "void" | 113 | .Ft "void" |
| 114 | .Fn tls_config_verify_client_optional "struct tls_config *config" | 114 | .Fn tls_config_verify_client_optional "struct tls_config *config" |
| 115 | .Ft "int" | ||
| 116 | .Fn tls_peer_cert_provided "struct tls *ctx" | ||
| 117 | .Ft "int" | ||
| 118 | .Fn tls_peer_cert_contains_name "struct tls *ctx" "const char *name" | ||
| 115 | .Ft "uint8_t *" | 119 | .Ft "uint8_t *" |
| 116 | .Fn tls_load_file "const char *file" "size_t *len" "char *password" | 120 | .Fn tls_load_file "const char *file" "size_t *len" "char *password" |
| 117 | .Ft "struct tls *" | 121 | .Ft "struct tls *" |
| @@ -354,6 +358,24 @@ enables client certificate verification, requiring the client to send | |||
| 354 | a certificate. | 358 | a certificate. |
| 355 | .Em (Server) | 359 | .Em (Server) |
| 356 | .It | 360 | .It |
| 361 | .Fn tls_peer_cert_provided | ||
| 362 | checks if the peer of | ||
| 363 | .Ar ctx | ||
| 364 | has provided a certificate. | ||
| 365 | .Fn tls_peer_cert_provided | ||
| 366 | will only succeed after the handshake is complete. | ||
| 367 | .Em (Server and client) | ||
| 368 | .It | ||
| 369 | .Fn tls_peer_cert_constains_name | ||
| 370 | checks if the peer of a tls | ||
| 371 | .Ar ctx | ||
| 372 | has povided a certificate that contains a | ||
| 373 | SAN or CN that matches | ||
| 374 | .Ar name | ||
| 375 | .Fn tls_peer_cert_contains_name | ||
| 376 | will only succeed after the handshake is complete. | ||
| 377 | .Em (Server and client) | ||
| 378 | .It | ||
| 357 | .Fn tls_config_verify_client_opional | 379 | .Fn tls_config_verify_client_opional |
| 358 | enables client certificate verification, without requiring the client | 380 | enables client certificate verification, without requiring the client |
| 359 | to send a certificate. | 381 | to send a certificate. |
| @@ -455,7 +477,12 @@ or | |||
| 455 | .Fn tls_connect_servername . | 477 | .Fn tls_connect_servername . |
| 456 | .El | 478 | .El |
| 457 | .Sh RETURN VALUES | 479 | .Sh RETURN VALUES |
| 458 | Functions that return | 480 | The |
| 481 | .Fn tls_peer_cert_provided | ||
| 482 | and | ||
| 483 | .Fn tls_peer_cert_contain_name | ||
| 484 | functions return 1 if the check succeeds, and 0 if it does not. | ||
| 485 | All other functions that return | ||
| 459 | .Vt int | 486 | .Vt int |
| 460 | or | 487 | or |
| 461 | .Vt ssize_t | 488 | .Vt ssize_t |
diff --git a/src/lib/libtls/tls_internal.h b/src/lib/libtls/tls_internal.h index b514847cfe..34af0fb48a 100644 --- a/src/lib/libtls/tls_internal.h +++ b/src/lib/libtls/tls_internal.h | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | /* $OpenBSD: tls_internal.h,v 1.19 2015/09/11 09:24:54 jsing Exp $ */ | 1 | /* $OpenBSD: tls_internal.h,v 1.20 2015/09/11 12:56:55 beck Exp $ */ |
| 2 | /* | 2 | /* |
| 3 | * Copyright (c) 2014 Jeremie Courreges-Anglas <jca@openbsd.org> | 3 | * Copyright (c) 2014 Jeremie Courreges-Anglas <jca@openbsd.org> |
| 4 | * Copyright (c) 2014 Joel Sing <jsing@openbsd.org> | 4 | * Copyright (c) 2014 Joel Sing <jsing@openbsd.org> |
| @@ -73,7 +73,7 @@ struct tls { | |||
| 73 | struct tls *tls_new(void); | 73 | struct tls *tls_new(void); |
| 74 | struct tls *tls_server_conn(struct tls *ctx); | 74 | struct tls *tls_server_conn(struct tls *ctx); |
| 75 | 75 | ||
| 76 | int tls_check_servername(struct tls *ctx, X509 *cert, const char *servername); | 76 | int tls_check_name(struct tls *ctx, X509 *cert, const char *servername); |
| 77 | int tls_configure_keypair(struct tls *ctx, int); | 77 | int tls_configure_keypair(struct tls *ctx, int); |
| 78 | int tls_configure_server(struct tls *ctx); | 78 | int tls_configure_server(struct tls *ctx); |
| 79 | int tls_configure_ssl(struct tls *ctx); | 79 | int tls_configure_ssl(struct tls *ctx); |
diff --git a/src/lib/libtls/tls_peer.c b/src/lib/libtls/tls_peer.c index e2a2c7b141..39a9d90cab 100644 --- a/src/lib/libtls/tls_peer.c +++ b/src/lib/libtls/tls_peer.c | |||
| @@ -1,6 +1,7 @@ | |||
| 1 | /* $OpenBSD: tls_peer.c,v 1.1 2015/09/11 11:28:01 jsing Exp $ */ | 1 | /* $OpenBSD: tls_peer.c,v 1.2 2015/09/11 12:56:55 beck Exp $ */ |
| 2 | /* | 2 | /* |
| 3 | * Copyright (c) 2015 Joel Sing <jsing@openbsd.org> | 3 | * Copyright (c) 2015 Joel Sing <jsing@openbsd.org> |
| 4 | * Copyright (c) 2015 Bob Beck <beck@openbsd.org> | ||
| 4 | * | 5 | * |
| 5 | * Permission to use, copy, modify, and distribute this software for any | 6 | * Permission to use, copy, modify, and distribute this software for any |
| 6 | * purpose with or without fee is hereby granted, provided that the above | 7 | * purpose with or without fee is hereby granted, provided that the above |
| @@ -85,3 +86,50 @@ err: | |||
| 85 | 86 | ||
| 86 | return (rv); | 87 | return (rv); |
| 87 | } | 88 | } |
| 89 | |||
| 90 | int | ||
| 91 | tls_peer_cert_provided(struct tls *ctx) | ||
| 92 | { | ||
| 93 | return (ctx->ssl_peer_cert != NULL); | ||
| 94 | } | ||
| 95 | |||
| 96 | int | ||
| 97 | tls_peer_cert_contains_name(struct tls *ctx, const char *name) | ||
| 98 | { | ||
| 99 | if (ctx->ssl_peer_cert == NULL) | ||
| 100 | return (0); | ||
| 101 | |||
| 102 | return (tls_check_name(ctx, ctx->ssl_peer_cert, name) == 0); | ||
| 103 | } | ||
| 104 | |||
| 105 | int | ||
| 106 | tls_peer_cert_issuer(struct tls *ctx, char **issuer) | ||
| 107 | { | ||
| 108 | X509_NAME *name = NULL; | ||
| 109 | |||
| 110 | *issuer = NULL; | ||
| 111 | if (ctx->ssl_peer_cert != NULL) | ||
| 112 | return (-1); | ||
| 113 | if ((name = X509_get_issuer_name(ctx->ssl_peer_cert)) == NULL) | ||
| 114 | return (-1); | ||
| 115 | *issuer = X509_NAME_oneline(name, 0, 0); | ||
| 116 | if (*issuer == NULL) | ||
| 117 | return (-1); | ||
| 118 | return (0); | ||
| 119 | } | ||
| 120 | |||
| 121 | int | ||
| 122 | tls_peer_cert_subject(struct tls *ctx, char **subject) | ||
| 123 | { | ||
| 124 | X509_NAME *name = NULL; | ||
| 125 | |||
| 126 | *subject = NULL; | ||
| 127 | if (ctx->ssl_peer_cert == NULL) | ||
| 128 | return (-1); | ||
| 129 | if ((name = X509_get_subject_name(ctx->ssl_peer_cert)) == NULL) | ||
| 130 | return (-1); | ||
| 131 | *subject = X509_NAME_oneline(name, 0, 0); | ||
| 132 | if (*subject == NULL) | ||
| 133 | return (-1); | ||
| 134 | return (0); | ||
| 135 | } | ||
diff --git a/src/lib/libtls/tls_verify.c b/src/lib/libtls/tls_verify.c index 7fd0b3d545..c6f29c897d 100644 --- a/src/lib/libtls/tls_verify.c +++ b/src/lib/libtls/tls_verify.c | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | /* $OpenBSD: tls_verify.c,v 1.11 2015/09/09 19:49:07 jsing Exp $ */ | 1 | /* $OpenBSD: tls_verify.c,v 1.12 2015/09/11 12:56:55 beck Exp $ */ |
| 2 | /* | 2 | /* |
| 3 | * Copyright (c) 2014 Jeremie Courreges-Anglas <jca@openbsd.org> | 3 | * Copyright (c) 2014 Jeremie Courreges-Anglas <jca@openbsd.org> |
| 4 | * | 4 | * |
| @@ -246,13 +246,13 @@ tls_check_common_name(struct tls *ctx, X509 *cert, const char *name) | |||
| 246 | } | 246 | } |
| 247 | 247 | ||
| 248 | int | 248 | int |
| 249 | tls_check_servername(struct tls *ctx, X509 *cert, const char *servername) | 249 | tls_check_name(struct tls *ctx, X509 *cert, const char *name) |
| 250 | { | 250 | { |
| 251 | int rv; | 251 | int rv; |
| 252 | 252 | ||
| 253 | rv = tls_check_subject_altname(ctx, cert, servername); | 253 | rv = tls_check_subject_altname(ctx, cert, name); |
| 254 | if (rv == 0 || rv == -2) | 254 | if (rv == 0 || rv == -2) |
| 255 | return rv; | 255 | return rv; |
| 256 | 256 | ||
| 257 | return tls_check_common_name(ctx, cert, servername); | 257 | return tls_check_common_name(ctx, cert, name); |
| 258 | } | 258 | } |
