blob: 8c692d6925ec42056e648ca9120da4d63bdff1ae [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>
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 Appelbaum5cc5ede2012-11-02 00:10:18 +000026#include <ctype.h>
Jacob Appelbaum8355d732012-07-30 01:29:05 -070027
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 Appelbaumb24f3422012-11-02 01:52:48 +000036int verbose;
37
Jacob Appelbaumc88a9f72012-11-02 01:28:30 +000038#include "src/util.h"
39
Jacob Appelbaum8355d732012-07-30 01:29:05 -070040/** 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 Appelbaum6bb4b812012-07-30 02:27:37 -070075// RFC 5280 says...
76// ub-common-name-length INTEGER ::= 64
77#define MAX_CN_NAME_LENGTH 64
78
Jacob Appelbaum53a10582012-07-31 00:31:55 -070079// RFC 1034 and posix say...
Brian Aker95d9fd52012-10-15 22:44:03 -040080#define TLSDATE_HOST_NAME_MAX 255
Jacob Appelbaum53a10582012-07-31 00:31:55 -070081
Jacob Appelbaumad12a3a2012-08-05 17:47:17 -070082// To support our RFC 2595 wildcard verification
83#define RFC2595_MIN_LABEL_COUNT 3
84
Jacob Appelbaum8355d732012-07-30 01:29:05 -070085static int ca_racket;
86
87static const char *host;
88
Jacob Appelbaum5cc5ede2012-11-02 00:10:18 +000089static const char *hostname_to_verify;
90
Jacob Appelbaum8355d732012-07-30 01:29:05 -070091static const char *port;
92
93static const char *protocol;
94
Elly Fong-Jones4687c5d2012-10-03 17:34:48 -040095static char *proxy;
96
Jacob Appelbaum8355d732012-07-30 01:29:05 -070097static const char *certdir;
Jacob Appelbaum8355d732012-07-30 01:29:05 -070098void openssl_time_callback (const SSL* ssl, int where, int ret);
99uint32_t get_certificate_keybits (EVP_PKEY *public_key);
100uint32_t check_cn (SSL *ssl, const char *hostname);
101uint32_t check_san (SSL *ssl, const char *hostname);
102long openssl_check_against_host_and_verify (SSL *ssl);
103uint32_t check_name (SSL *ssl, const char *hostname);
104uint32_t verify_signature (SSL *ssl, const char *hostname);
105void check_key_length (SSL *ssl);
106void inspect_key (SSL *ssl, const char *hostname);
107static void run_ssl (uint32_t *time_map, int time_is_an_illusion);
108static void become_nobody (void);
109void check_key_length (SSL *ssl);
Jacob Appelbaumad12a3a2012-08-05 17:47:17 -0700110uint32_t dns_label_count (char *label, char *delim);
111uint32_t check_wildcard_match_rfc2595 (const char *orig_hostname,
112 const char *orig_cert_wild_card);
Jacob Appelbaum8355d732012-07-30 01:29:05 -0700113void inspect_key (SSL *ssl, const char *hostname);
114static void run_ssl (uint32_t *time_map, int time_is_an_illusion);
115
116#endif