]> git.ipfire.org Git - thirdparty/hostap.git/blobdiff - src/crypto/tls.h
OpenSSL: Allow two server certificates/keys to be configured on server
[thirdparty/hostap.git] / src / crypto / tls.h
index e60efc8cdb73be2cf5241be22d9823f811176b30..c8b1a824ed54d830b11b022ae18cc8428c5d4560 100644 (file)
@@ -42,11 +42,24 @@ enum tls_fail_reason {
        TLS_FAIL_DOMAIN_SUFFIX_MISMATCH = 9,
        TLS_FAIL_DOMAIN_MISMATCH = 10,
        TLS_FAIL_INSUFFICIENT_KEY_LEN = 11,
+       TLS_FAIL_DN_MISMATCH = 12,
 };
 
 
 #define TLS_MAX_ALT_SUBJECT 10
 
+struct tls_cert_data {
+       int depth;
+       const char *subject;
+       const struct wpabuf *cert;
+       const u8 *hash;
+       size_t hash_len;
+       const char *altsubject[TLS_MAX_ALT_SUBJECT];
+       int num_altsubject;
+       const char *serial_num;
+       int tod;
+};
+
 union tls_event_data {
        struct {
                int depth;
@@ -56,15 +69,7 @@ union tls_event_data {
                const struct wpabuf *cert;
        } cert_fail;
 
-       struct {
-               int depth;
-               const char *subject;
-               const struct wpabuf *cert;
-               const u8 *hash;
-               size_t hash_len;
-               const char *altsubject[TLS_MAX_ALT_SUBJECT];
-               int num_altsubject;
-       } peer_cert;
+       struct tls_cert_data peer_cert;
 
        struct {
                int is_local;
@@ -81,6 +86,7 @@ struct tls_config {
        int cert_in_cb;
        const char *openssl_ciphers;
        unsigned int tls_session_lifetime;
+       unsigned int crl_reload_interval;
        unsigned int tls_flags;
 
        void (*event_cb)(void *ctx, enum tls_event ev,
@@ -100,6 +106,12 @@ struct tls_config {
 #define TLS_CONN_EXT_CERT_CHECK BIT(9)
 #define TLS_CONN_REQUIRE_OCSP_ALL BIT(10)
 #define TLS_CONN_SUITEB BIT(11)
+#define TLS_CONN_SUITEB_NO_ECDH BIT(12)
+#define TLS_CONN_DISABLE_TLSv1_3 BIT(13)
+#define TLS_CONN_ENABLE_TLSv1_0 BIT(14)
+#define TLS_CONN_ENABLE_TLSv1_1 BIT(15)
+#define TLS_CONN_ENABLE_TLSv1_2 BIT(16)
+#define TLS_CONN_TEAP_ANON_DH BIT(17)
 
 /**
  * struct tls_connection_params - Parameters for TLS connection
@@ -112,12 +124,19 @@ struct tls_config {
  * %NULL to allow all subjects
  * @altsubject_match: String to match in the alternative subject of the peer
  * certificate or %NULL to allow all alternative subjects
- * @suffix_match: String to suffix match in the dNSName or CN of the peer
- * certificate or %NULL to allow all domain names. This may allow subdomains an
- * wildcard certificates. Each domain name label must have a full match.
+ * @suffix_match: Semicolon deliminated string of values to suffix match against
+ * the dNSName or CN of the peer certificate or %NULL to allow all domain names.
+ * This may allow subdomains and wildcard certificates. Each domain name label
+ * must have a full case-insensitive match.
  * @domain_match: String to match in the dNSName or CN of the peer
  * certificate or %NULL to allow all domain names. This requires a full,
  * case-insensitive match.
+ *
+ * More than one match string can be provided by using semicolons to
+ * separate the strings (e.g., example.org;example.com). When multiple
+ * strings are specified, a match with any one of the values is
+ * considered a sufficient match for the certificate, i.e., the
+ * conditions are ORed together.
  * @client_cert: File or reference name for client X.509 certificate in PEM or
  * DER format
  * @client_cert_blob: client_cert as inlined data or %NULL if not used
@@ -141,12 +160,15 @@ struct tls_config {
  * @cert_id: the certificate's id when using engine
  * @ca_cert_id: the CA certificate's id when using engine
  * @openssl_ciphers: OpenSSL cipher configuration
+ * @openssl_ecdh_curves: OpenSSL ECDH curve configuration. %NULL for auto if
+ *     supported, empty string to disable, or a colon-separated curve list.
  * @flags: Parameter options (TLS_CONN_*)
  * @ocsp_stapling_response: DER encoded file with cached OCSP stapling response
  *     or %NULL if OCSP is not enabled
  * @ocsp_stapling_response_multi: DER encoded file with cached OCSP stapling
  *     response list (OCSPResponseList for ocsp_multi in RFC 6961) or %NULL if
  *     ocsp_multi is not enabled
+ * @check_cert_subject: Client certificate subject name matching string
  *
  * TLS connection parameters to be configured with tls_connection_set_params()
  * and tls_global_set_params().
@@ -166,12 +188,15 @@ struct tls_connection_params {
        const char *suffix_match;
        const char *domain_match;
        const char *client_cert;
+       const char *client_cert2;
        const u8 *client_cert_blob;
        size_t client_cert_blob_len;
        const char *private_key;
+       const char *private_key2;
        const u8 *private_key_blob;
        size_t private_key_blob_len;
        const char *private_key_passwd;
+       const char *private_key_passwd2;
        const char *dh_file;
        const u8 *dh_blob;
        size_t dh_blob_len;
@@ -184,10 +209,12 @@ struct tls_connection_params {
        const char *cert_id;
        const char *ca_cert_id;
        const char *openssl_ciphers;
+       const char *openssl_ecdh_curves;
 
        unsigned int flags;
        const char *ocsp_stapling_response;
        const char *ocsp_stapling_response_multi;
+       const char *check_cert_subject;
 };
 
 
@@ -250,6 +277,18 @@ void tls_connection_deinit(void *tls_ctx, struct tls_connection *conn);
  */
 int tls_connection_established(void *tls_ctx, struct tls_connection *conn);
 
+/**
+ * tls_connection_peer_serial_num - Fetch peer certificate serial number
+ * @tls_ctx: TLS context data from tls_init()
+ * @conn: Connection context data from tls_connection_init()
+ * Returns: Allocated string buffer containing the peer certificate serial
+ * number or %NULL on error.
+ *
+ * The caller is responsible for freeing the returned buffer with os_free().
+ */
+char * tls_connection_peer_serial_num(void *tls_ctx,
+                                     struct tls_connection *conn);
+
 /**
  * tls_connection_shutdown - Shutdown TLS connection
  * @tls_ctx: TLS context data from tls_init()
@@ -306,9 +345,11 @@ int __must_check tls_global_set_params(
  * @tls_ctx: TLS context data from tls_init()
  * @check_crl: 0 = do not verify CRLs, 1 = verify CRL for the user certificate,
  * 2 = verify CRL for all certificates
+ * @strict: 0 = allow CRL time errors, 1 = do not allow CRL time errors
  * Returns: 0 on success, -1 on failure
  */
-int __must_check tls_global_set_verify(void *tls_ctx, int check_crl);
+int __must_check tls_global_set_verify(void *tls_ctx, int check_crl,
+                                      int strict);
 
 /**
  * tls_connection_set_verify - Set certificate verification options
@@ -343,15 +384,21 @@ int __must_check tls_connection_get_random(void *tls_ctx,
  * @tls_ctx: TLS context data from tls_init()
  * @conn: Connection context data from tls_connection_init()
  * @label: Label (e.g., description of the key) for PRF
+ * @context: Optional extra upper-layer context (max len 2^16)
+ * @context_len: The length of the context value
  * @out: Buffer for output data from TLS-PRF
  * @out_len: Length of the output buffer
  * Returns: 0 on success, -1 on failure
  *
- * Exports keying material using the mechanism described in RFC 5705.
+ * Exports keying material using the mechanism described in RFC 5705. If
+ * context is %NULL, context is not provided; otherwise, context is provided
+ * (including the case of empty context with context_len == 0).
  */
 int __must_check tls_connection_export_key(void *tls_ctx,
                                           struct tls_connection *conn,
                                           const char *label,
+                                          const u8 *context,
+                                          size_t context_len,
                                           u8 *out, size_t out_len);
 
 /**
@@ -603,4 +650,24 @@ tls_connection_get_success_data(struct tls_connection *conn);
 
 void tls_connection_remove_session(struct tls_connection *conn);
 
+/**
+ * tls_get_tls_unique - Fetch "tls-unique" for channel binding
+ * @conn: Connection context data from tls_connection_init()
+ * @buf: Buffer for returning the value
+ * @max_len: Maximum length of the buffer in bytes
+ * Returns: Number of bytes written to buf or -1 on error
+ *
+ * This function can be used to fetch "tls-unique" (RFC 5929, Section 3) which
+ * is the first TLS Finished message sent in the most recent TLS handshake of
+ * the TLS connection.
+ */
+int tls_get_tls_unique(struct tls_connection *conn, u8 *buf, size_t max_len);
+
+/**
+ * tls_connection_get_cipher_suite - Get current TLS cipher suite
+ * @conn: Connection context data from tls_connection_init()
+ * Returns: TLS cipher suite of the current connection or 0 on error
+ */
+u16 tls_connection_get_cipher_suite(struct tls_connection *conn);
+
 #endif /* TLS_H */