Jacob Appelbaum | 8355d73 | 2012-07-30 01:29:05 -0700 | [diff] [blame] | 1 | /* Copyright (c) 2012, Jacob Appelbaum |
| 2 | * Copyright (c) 2012, The Tor Project, Inc. */ |
| 3 | /* See LICENSE for licensing information */ |
| 4 | |
| 5 | /** |
| 6 | * \file tlsdate-helper.h |
| 7 | * \brief The secondary header for our clock helper. |
| 8 | **/ |
| 9 | |
| 10 | #ifndef TLSDATEHELPER_H |
| 11 | #define TLSDATEHELPER_H |
| 12 | |
| 13 | #include <stdarg.h> |
| 14 | #include <stdint.h> |
| 15 | #include <stdio.h> |
Jacob Appelbaum | ad12a3a | 2012-08-05 17:47:17 -0700 | [diff] [blame] | 16 | #include <string.h> |
Jacob Appelbaum | 8355d73 | 2012-07-30 01:29:05 -0700 | [diff] [blame] | 17 | #include <unistd.h> |
| 18 | #include <sys/time.h> |
| 19 | #include <sys/types.h> |
| 20 | #include <sys/wait.h> |
| 21 | #include <sys/mman.h> |
| 22 | #include <time.h> |
| 23 | #include <pwd.h> |
| 24 | #include <grp.h> |
| 25 | #include <arpa/inet.h> |
Jacob Appelbaum | 5cc5ede | 2012-11-02 00:10:18 +0000 | [diff] [blame] | 26 | #include <ctype.h> |
Jacob Appelbaum | 8355d73 | 2012-07-30 01:29:05 -0700 | [diff] [blame] | 27 | |
| 28 | #include <openssl/bio.h> |
| 29 | #include <openssl/ssl.h> |
| 30 | #include <openssl/err.h> |
| 31 | #include <openssl/evp.h> |
| 32 | #include <openssl/x509.h> |
| 33 | #include <openssl/conf.h> |
| 34 | #include <openssl/x509v3.h> |
| 35 | |
Jacob Appelbaum | b24f342 | 2012-11-02 01:52:48 +0000 | [diff] [blame] | 36 | int verbose; |
| 37 | |
Jacob Appelbaum | c88a9f7 | 2012-11-02 01:28:30 +0000 | [diff] [blame] | 38 | #include "src/util.h" |
| 39 | |
Jacob Appelbaum | 8355d73 | 2012-07-30 01:29:05 -0700 | [diff] [blame] | 40 | /** Name of user that we feel safe to run SSL handshake with. */ |
| 41 | #ifndef UNPRIV_USER |
| 42 | #define UNPRIV_USER "nobody" |
| 43 | #endif |
| 44 | #ifndef UNPRIV_GROUP |
| 45 | #define UNPRIV_GROUP "nogroup" |
| 46 | #endif |
| 47 | |
| 48 | // We should never accept a time before we were compiled |
| 49 | // We measure in seconds since the epoch - eg: echo `date '+%s'` |
| 50 | // We set this manually to ensure others can reproduce a build; |
| 51 | // automation of this will make every build different! |
| 52 | #ifndef RECENT_COMPILE_DATE |
| 53 | #define RECENT_COMPILE_DATE (uint32_t) 1342323666 |
| 54 | #endif |
| 55 | |
| 56 | #ifndef MAX_REASONABLE_TIME |
| 57 | #define MAX_REASONABLE_TIME (uint32_t) 1999991337 |
| 58 | #endif |
| 59 | |
| 60 | #ifndef MIN_PUB_KEY_LEN |
| 61 | #define MIN_PUB_KEY_LEN (uint32_t) 1023 |
| 62 | #endif |
| 63 | |
| 64 | #ifndef MIN_ECC_PUB_KEY_LEN |
| 65 | #define MIN_ECC_PUB_KEY_LEN (uint32_t) 160 |
| 66 | #endif |
| 67 | |
| 68 | #ifndef MAX_ECC_PUB_KEY_LEN |
| 69 | #define MAX_ECC_PUB_KEY_LEN (uint32_t) 521 |
| 70 | #endif |
| 71 | // After the duration of the TLS handshake exceeds this threshold |
| 72 | // (in msec), a warning is printed. |
| 73 | #define TLS_RTT_THRESHOLD 2000 |
| 74 | |
Jacob Appelbaum | 6bb4b81 | 2012-07-30 02:27:37 -0700 | [diff] [blame] | 75 | // RFC 5280 says... |
| 76 | // ub-common-name-length INTEGER ::= 64 |
| 77 | #define MAX_CN_NAME_LENGTH 64 |
| 78 | |
Jacob Appelbaum | 53a1058 | 2012-07-31 00:31:55 -0700 | [diff] [blame] | 79 | // RFC 1034 and posix say... |
Brian Aker | 95d9fd5 | 2012-10-15 22:44:03 -0400 | [diff] [blame] | 80 | #define TLSDATE_HOST_NAME_MAX 255 |
Jacob Appelbaum | 53a1058 | 2012-07-31 00:31:55 -0700 | [diff] [blame] | 81 | |
Jacob Appelbaum | ad12a3a | 2012-08-05 17:47:17 -0700 | [diff] [blame] | 82 | // To support our RFC 2595 wildcard verification |
| 83 | #define RFC2595_MIN_LABEL_COUNT 3 |
| 84 | |
Jacob Appelbaum | 8355d73 | 2012-07-30 01:29:05 -0700 | [diff] [blame] | 85 | static int ca_racket; |
| 86 | |
| 87 | static const char *host; |
| 88 | |
Jacob Appelbaum | 5cc5ede | 2012-11-02 00:10:18 +0000 | [diff] [blame] | 89 | static const char *hostname_to_verify; |
| 90 | |
Jacob Appelbaum | 8355d73 | 2012-07-30 01:29:05 -0700 | [diff] [blame] | 91 | static const char *port; |
| 92 | |
| 93 | static const char *protocol; |
| 94 | |
Elly Fong-Jones | 4687c5d | 2012-10-03 17:34:48 -0400 | [diff] [blame] | 95 | static char *proxy; |
| 96 | |
Jacob Appelbaum | 8355d73 | 2012-07-30 01:29:05 -0700 | [diff] [blame] | 97 | static const char *certdir; |
Jacob Appelbaum | 8355d73 | 2012-07-30 01:29:05 -0700 | [diff] [blame] | 98 | void openssl_time_callback (const SSL* ssl, int where, int ret); |
| 99 | uint32_t get_certificate_keybits (EVP_PKEY *public_key); |
| 100 | uint32_t check_cn (SSL *ssl, const char *hostname); |
| 101 | uint32_t check_san (SSL *ssl, const char *hostname); |
| 102 | long openssl_check_against_host_and_verify (SSL *ssl); |
| 103 | uint32_t check_name (SSL *ssl, const char *hostname); |
| 104 | uint32_t verify_signature (SSL *ssl, const char *hostname); |
| 105 | void check_key_length (SSL *ssl); |
| 106 | void inspect_key (SSL *ssl, const char *hostname); |
| 107 | static void run_ssl (uint32_t *time_map, int time_is_an_illusion); |
| 108 | static void become_nobody (void); |
| 109 | void check_key_length (SSL *ssl); |
Jacob Appelbaum | ad12a3a | 2012-08-05 17:47:17 -0700 | [diff] [blame] | 110 | uint32_t dns_label_count (char *label, char *delim); |
| 111 | uint32_t check_wildcard_match_rfc2595 (const char *orig_hostname, |
| 112 | const char *orig_cert_wild_card); |
Jacob Appelbaum | 8355d73 | 2012-07-30 01:29:05 -0700 | [diff] [blame] | 113 | void inspect_key (SSL *ssl, const char *hostname); |
| 114 | static void run_ssl (uint32_t *time_map, int time_is_an_illusion); |
| 115 | |
| 116 | #endif |