1 /* srp-tls.h
2  *
3  * Copyright (c) 2019 Apple Computer, Inc. All rights reserved.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  *     http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  * TLS Shim definitions.   These entry points should in principle work for any TLS
18  * library, with the addition of a single shim file, for example tls-mbedtls.c.
19  */
20 
21 #ifndef __SRP_TLS_H
22 #define __SRP_TLS_H
23 // Anonymous key structure, depends on the target.
24 typedef struct srp_key srp_key_t;
25 
26 #ifdef SRP_CRYPTO_MBEDTLS_INTERNAL
27 #include <mbedtls/certs.h>
28 #include <mbedtls/x509.h>
29 #include <mbedtls/ssl.h>
30 
31 struct tls_context {
32     struct mbedtls_ssl_context context;
33     enum { handshake_in_progress, handshake_complete } state;
34 };
35 #endif // SRP_CRYPTO_MBEDTLS_INTERNAL
36 
37 // tls_*.c:
38 bool srp_tls_init(void);
39 bool srp_tls_client_init(void);
40 bool srp_tls_server_init(const char *NULLABLE cacert_file,
41 			 const char *NULLABLE srvcrt_file, const char *NULLABLE server_key_file);
42 bool srp_tls_accept_setup(comm_t *NONNULL comm);
43 bool srp_tls_listen_callback(comm_t *NONNULL comm);
44 bool srp_tls_connect_callback(comm_t *NONNULL comm);
45 ssize_t srp_tls_read(comm_t *NONNULL comm, unsigned char *NONNULL buf, size_t max);
46 void srp_tls_context_free(comm_t *NONNULL comm);
47 ssize_t srp_tls_write(comm_t *NONNULL comm, struct iovec *NONNULL iov, int iov_len);
48 
49 #endif // __SRP_TLS_H
50 
51 // Local Variables:
52 // mode: C
53 // tab-width: 4
54 // c-file-style: "bsd"
55 // c-basic-offset: 4
56 // fill-column: 108
57 // indent-tabs-mode: nil
58 // End:
59