1 | /* |
---|
2 | * Copyright 2016-2020 Fiona Klute |
---|
3 | * |
---|
4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
---|
5 | * you may not use this file except in compliance with the License. |
---|
6 | * You may obtain a copy of the License at |
---|
7 | * |
---|
8 | * http://www.apache.org/licenses/LICENSE-2.0 |
---|
9 | * |
---|
10 | * Unless required by applicable law or agreed to in writing, software |
---|
11 | * distributed under the License is distributed on an "AS IS" BASIS, |
---|
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
---|
13 | * See the License for the specific language governing permissions and |
---|
14 | * limitations under the License. |
---|
15 | */ |
---|
16 | |
---|
17 | #include <apr_buckets.h> |
---|
18 | #include <apr_lib.h> |
---|
19 | #include <apr_network_io.h> |
---|
20 | #include <apr_pools.h> |
---|
21 | #include <apr_uri.h> |
---|
22 | #include <gnutls/gnutls.h> |
---|
23 | #include "mod_gnutls.h" |
---|
24 | |
---|
25 | #ifndef __MOD_GNUTLS_UTIL_H__ |
---|
26 | #define __MOD_GNUTLS_UTIL_H__ |
---|
27 | |
---|
28 | /** Default GnuTLS priority string for mod_gnutls */ |
---|
29 | #define MGS_DEFAULT_PRIORITY "NORMAL:-RSA:-VERS-TLS1.0:-VERS-TLS1.1" |
---|
30 | |
---|
31 | /** maximum allowed length of one header line */ |
---|
32 | #define HTTP_HDR_LINE_MAX 1024 |
---|
33 | |
---|
34 | /** |
---|
35 | * Create an HTTP header to send a POST request with 'size' bytes of |
---|
36 | * data to 'uri'. |
---|
37 | */ |
---|
38 | const char* http_post_header(apr_pool_t *p, apr_uri_t *uri, |
---|
39 | const char *content_type, const char *accept, |
---|
40 | apr_size_t size) |
---|
41 | __attribute__((nonnull(1, 2, 3))); |
---|
42 | |
---|
43 | /** |
---|
44 | * Try to transfer one header line from 'sockb' into 'lineb', then |
---|
45 | * return it from there. The line may be no more than |
---|
46 | * HTTP_HDR_LINE_MAX bytes long, including the terminating CRLF. CR is |
---|
47 | * replaced with \0 so the line can be processed as a string without |
---|
48 | * breaks. 'lineb' is flushed before reading the line. Returns either |
---|
49 | * a pointer to the line (allocated from 'p'), or NULL in case of an |
---|
50 | * error. |
---|
51 | */ |
---|
52 | const char* read_line(apr_pool_t *p, apr_bucket_brigade *sockb, |
---|
53 | apr_bucket_brigade *lineb) |
---|
54 | __attribute__((nonnull)); |
---|
55 | |
---|
56 | /** |
---|
57 | * Send 'size' bytes from 'buf' over 'sock', using partial send |
---|
58 | * operations if necessary. Returns APR_SUCCESS or an APR error code |
---|
59 | * returned by apr_socket_send(). |
---|
60 | */ |
---|
61 | apr_status_t sock_send_buf(apr_socket_t *sock, const char *buf, |
---|
62 | const apr_size_t size) |
---|
63 | __attribute__((nonnull)); |
---|
64 | |
---|
65 | /** |
---|
66 | * Read a file into a gnutls_datum_t, allocate necessary memory from |
---|
67 | * the pool. |
---|
68 | */ |
---|
69 | apr_status_t datum_from_file(apr_pool_t *p, const char* filename, |
---|
70 | gnutls_datum_t *datum) |
---|
71 | __attribute__((nonnull)); |
---|
72 | |
---|
73 | /** |
---|
74 | * Allocate the connection configuration structure if necessary, set |
---|
75 | * some defaults. |
---|
76 | */ |
---|
77 | mgs_handle_t *init_gnutls_ctxt(conn_rec *c); |
---|
78 | |
---|
79 | /** |
---|
80 | * Initialize the global default priorities, must be called by the |
---|
81 | * pre_config hook |
---|
82 | * |
---|
83 | * @return `GNUTLS_E_SUCCESS` or a GnuTLS error code |
---|
84 | */ |
---|
85 | int mgs_default_priority_init(); |
---|
86 | |
---|
87 | /** |
---|
88 | * Get the global default priorities |
---|
89 | */ |
---|
90 | gnutls_priority_t mgs_get_default_prio(); |
---|
91 | |
---|
92 | /** |
---|
93 | * Deinitialize the global default priorities, must be in the cleanup |
---|
94 | * hook of the pre_config pool. |
---|
95 | */ |
---|
96 | void mgs_default_priority_deinit(); |
---|
97 | |
---|
98 | /** |
---|
99 | * Create a shallow copy of an APR array of `char *` into a new array |
---|
100 | * of gnutls_datum_t, filling `size` via `strlen()`. "Shallow copy" |
---|
101 | * means that the strings themselves are not copied, just the pointers |
---|
102 | * to them. |
---|
103 | * |
---|
104 | * @param src array to copy |
---|
105 | * @param pool allocate memory for the new array |
---|
106 | * @param min_elements allocate room for at least this many elements |
---|
107 | * |
---|
108 | * @return pointer to the first element of the new array |
---|
109 | */ |
---|
110 | gnutls_datum_t * mgs_str_array_to_datum_array(const apr_array_header_t *src, |
---|
111 | apr_pool_t *pool, |
---|
112 | const int min_elements); |
---|
113 | |
---|
114 | #endif /* __MOD_GNUTLS_UTIL_H__ */ |
---|