blob: d89708044e8ba87b802f5e1798278aa06e16b5e9 [file] [log] [blame]
Jacob Appelbaum8355d732012-07-30 01:29:05 -07001/* 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 Appelbaumad12a3a2012-08-05 17:47:17 -070016#include <string.h>
Jacob Appelbaum8355d732012-07-30 01:29:05 -070017#include <unistd.h>
Jacob Appelbaum12e15c92013-01-07 11:17:32 -080018#include <sys/stat.h>
Jacob Appelbaum8355d732012-07-30 01:29:05 -070019#include <sys/time.h>
20#include <sys/types.h>
21#include <sys/wait.h>
22#include <sys/mman.h>
23#include <time.h>
24#include <pwd.h>
25#include <grp.h>
26#include <arpa/inet.h>
Jacob Appelbaum5cc5ede2012-11-02 00:10:18 +000027#include <ctype.h>
Jacob Appelbaum8355d732012-07-30 01:29:05 -070028
29#include <openssl/bio.h>
30#include <openssl/ssl.h>
31#include <openssl/err.h>
32#include <openssl/evp.h>
33#include <openssl/x509.h>
34#include <openssl/conf.h>
35#include <openssl/x509v3.h>
36
Jacob Appelbaumb24f3422012-11-02 01:52:48 +000037int verbose;
38
Jacob Appelbaumc88a9f72012-11-02 01:28:30 +000039#include "src/util.h"
40
Jacob Appelbaum8355d732012-07-30 01:29:05 -070041/** Name of user that we feel safe to run SSL handshake with. */
42#ifndef UNPRIV_USER
43#define UNPRIV_USER "nobody"
44#endif
45#ifndef UNPRIV_GROUP
46#define UNPRIV_GROUP "nogroup"
47#endif
48
49// We should never accept a time before we were compiled
50// We measure in seconds since the epoch - eg: echo `date '+%s'`
51// We set this manually to ensure others can reproduce a build;
52// automation of this will make every build different!
53#ifndef RECENT_COMPILE_DATE
54#define RECENT_COMPILE_DATE (uint32_t) 1342323666
55#endif
56
57#ifndef MAX_REASONABLE_TIME
58#define MAX_REASONABLE_TIME (uint32_t) 1999991337
59#endif
60
61#ifndef MIN_PUB_KEY_LEN
62#define MIN_PUB_KEY_LEN (uint32_t) 1023
63#endif
64
65#ifndef MIN_ECC_PUB_KEY_LEN
66#define MIN_ECC_PUB_KEY_LEN (uint32_t) 160
67#endif
68
69#ifndef MAX_ECC_PUB_KEY_LEN
70#define MAX_ECC_PUB_KEY_LEN (uint32_t) 521
71#endif
72// After the duration of the TLS handshake exceeds this threshold
73// (in msec), a warning is printed.
74#define TLS_RTT_THRESHOLD 2000
75
Jacob Appelbaum6bb4b812012-07-30 02:27:37 -070076// RFC 5280 says...
77// ub-common-name-length INTEGER ::= 64
78#define MAX_CN_NAME_LENGTH 64
79
Jacob Appelbaum53a10582012-07-31 00:31:55 -070080// RFC 1034 and posix say...
Brian Aker95d9fd52012-10-15 22:44:03 -040081#define TLSDATE_HOST_NAME_MAX 255
Jacob Appelbaum53a10582012-07-31 00:31:55 -070082
Jacob Appelbaumad12a3a2012-08-05 17:47:17 -070083// To support our RFC 2595 wildcard verification
84#define RFC2595_MIN_LABEL_COUNT 3
85
Jacob Appelbaum8355d732012-07-30 01:29:05 -070086static int ca_racket;
87
88static const char *host;
89
Jacob Appelbaum5cc5ede2012-11-02 00:10:18 +000090static const char *hostname_to_verify;
91
Jacob Appelbaum8355d732012-07-30 01:29:05 -070092static const char *port;
93
94static const char *protocol;
95
Elly Fong-Jones4687c5d2012-10-03 17:34:48 -040096static char *proxy;
97
Jacob Appelbaum12e15c92013-01-07 11:17:32 -080098static const char *ca_cert_container;
Jacob Appelbaum8355d732012-07-30 01:29:05 -070099void openssl_time_callback (const SSL* ssl, int where, int ret);
100uint32_t get_certificate_keybits (EVP_PKEY *public_key);
101uint32_t check_cn (SSL *ssl, const char *hostname);
102uint32_t check_san (SSL *ssl, const char *hostname);
103long openssl_check_against_host_and_verify (SSL *ssl);
104uint32_t check_name (SSL *ssl, const char *hostname);
105uint32_t verify_signature (SSL *ssl, const char *hostname);
106void check_key_length (SSL *ssl);
107void inspect_key (SSL *ssl, const char *hostname);
108static void run_ssl (uint32_t *time_map, int time_is_an_illusion);
109static void become_nobody (void);
110void check_key_length (SSL *ssl);
Jacob Appelbaumad12a3a2012-08-05 17:47:17 -0700111uint32_t dns_label_count (char *label, char *delim);
112uint32_t check_wildcard_match_rfc2595 (const char *orig_hostname,
113 const char *orig_cert_wild_card);
Jacob Appelbaum8355d732012-07-30 01:29:05 -0700114void inspect_key (SSL *ssl, const char *hostname);
115static void run_ssl (uint32_t *time_map, int time_is_an_illusion);
116
117#endif