Debian Codegraph @

c/include/proton/tls.h

raw
1 #ifndef PROTON_TLS_H
2 #define PROTON_TLS_H 1
3
4 /*
5 *
6 * Licensed to the Apache Software Foundation (ASF) under one
7 * or more contributor license agreements. See the NOTICE file
8 * distributed with this work for additional information
9 * regarding copyright ownership. The ASF licenses this file
10 * to you under the Apache License, Version 2.0 (the
11 * "License"); you may not use this file except in compliance
12 * with the License. You may obtain a copy of the License at
13 *
14 * http://www.apache.org/licenses/LICENSE-2.0
15 *
16 * Unless required by applicable law or agreed to in writing,
17 * software distributed under the License is distributed on an
18 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
19 * KIND, either express or implied. See the License for the
20 * specific language governing permissions and limitations
21 * under the License.
22 *
23 */
24
25 #include <proton/import_export.h>
26 #include <proton/raw_connection.h>
27
28 #ifdef __cplusplus
29 extern "C" {
30 #endif
31
32 /**
33 * @file
34 *
35 * @copybrief tls
36 *
37 * @addtogroup tls
38 * @{
39 */
40
41 /**
42 * API for using TLS separate from AMQP connections.
43 *
44 * This API is currently unsettled and subject to significant change and improvement.
45 *
46 * Based heavily on the original Proton SSL API for configuring TLS over AMQP connections,
47 * this implementation separates the encryption/decryption of data from the network IO
48 * operations.
49 *
50 * A Transport can be configured as either an "TLS client" or an "TLS server". An TLS
51 * client is the party that proactively establishes a connection to an TLS server. An TLS
52 * server is the party that accepts a connection request from a remote TLS client.
53 *
54 * This TLS implementation defines the following objects:
55
56 * @li A top-level object that stores the configuration used by one or more TLS
57 * sessions (pn_tls_config_t).
58 * @li A per-connection TLS session object that performs the encryption/authentication
59 * associated with the transport (pn_tls_t).
60 *
61 * The pn_tls_config_t is used to construct an TLS session (pn_tls_t). The
62 * session "adopts" its configuration from the pn_tls_config_t that was used to create it.
63 * For example, pn_tls_config_t can be configured as either a "client" or a "server". TLS
64 * sessions constructed from this domain will perform the corresponding role (either
65 * client or server).
66 *
67 * If an TLS session is created without a pn_tls_config_t object then a default will be used
68 * (see ::pn_tls_init()).
69 *
70 * If either an TLS server or client needs to identify itself with the remote node, it
71 * must have its TLS certificate configured (see ::pn_tls_config_set_credentials()).
72 *
73 * If either an TLS server or client needs to verify the identity of the remote node, it
74 * must have its database of trusted CAs configured. By default this will be set up to use
75 * the default system database of trusted CA. But this can be changed
76 * (see ::pn_tls_config_set_trusted_certs()).
77 *
78 * The level of verification required of the remote may be configured (see
79 * ::pn_tls_config_set_peer_authentication)
80 */
81 typedef struct pn_tls_config_t pn_tls_config_t;
82
83 /**
84 * @see pn_tls
85 */
86 typedef struct pn_tls_t pn_tls_t;
87
88 /**
89 * Determines the type of TLS endpoint.
90 */
91 typedef enum {
92 PN_TLS_MODE_CLIENT = 1, /**< Local connection endpoint is an TLS client */
93 PN_TLS_MODE_SERVER /**< Local connection endpoint is an TLS server */
94 } pn_tls_mode_t;
95
96 /**
97 * Error codes
98 */
99
100 #define PN_TLS_OK (0) /**< No error */
101 #define PN_TLS_INIT_ERR (-1) /**< Failure in initialization, unrelated to activity with the peer */
102 #define PN_TLS_PROTOCOL_ERR (-2) /**< Failure in the TLS protocol between peers */
103 #define PN_TLS_AUTHENTICATION_ERR (-3) /**< Peer authentication failure */
104 #define PN_TLS_STATE_ERR (-4) /**< Requested action not possible due to session state */
105
106
107 /**
108 * Create an TLS configuration domain
109 *
110 * This method allocates an TLS domain object. This object is used to hold the TLS
111 * configuration for one or more TLS sessions. The TLS session object (pn_tls_t) is
112 * allocated from this object.
113 *
114 * @param[in] mode the role, client or server, assumed by all TLS sessions created
115 * with this domain.
116 * @return a pointer to the TLS domain, if TLS support is present.
117 */
118 PN_TLS_EXTERN pn_tls_config_t *pn_tls_config(pn_tls_mode_t mode);
119
120 /**
121 * Release an TLS configuration domain
122 *
123 * This method frees an TLS domain object allocated by ::pn_tls_config.
124 * @param[in] domain the domain to destroy.
125 */
126 PN_TLS_EXTERN void pn_tls_config_free(pn_tls_config_t *domain);
127
128 /**
129 * Set the certificate that identifies the local node to the remote.
130 *
131 * This certificate establishes the identity for the local node for all TLS sessions
132 * created from this domain. It will be sent to the remote if the remote needs to verify
133 * the identity of this node. This may be used for both TLS servers and TLS clients (if
134 * client authentication is required by the server).
135 *
136 * @note This setting effects only those pn_tls_t objects created after this call
137 * returns. pn_tls_t objects created before invoking this method will use the domain's
138 * previous setting.
139 *
140 * @param[in] domain the tls domain that will use this certificate.
141 * @param[in] credential_1 specifier for the file/database containing the identifying
142 * certificate. For Openssl users, this is a PEM file. For Windows SChannel users, this is
143 * the PKCS#12 file or system store.
144 * @param[in] credential_2 an optional key to access the identifying certificate. For
145 * Openssl users, this is an optional PEM file containing the private key used to sign the
146 * certificate. For Windows SChannel users, this is the friendly name of the
147 * self-identifying certificate if there are multiple certificates in the store.
148 * @param[in] password the password used to sign the key, else NULL if key is not
149 * protected.
150 * @return 0 on success
151 */
152 PN_TLS_EXTERN int pn_tls_config_set_credentials(pn_tls_config_t *domain,
153 const char *credential_1,
154 const char *credential_2,
155 const char *password);
156
157 /**
158 * Configure the set of trusted CA certificates used by this domain to verify peers.
159 *
160 * If the local TLS client/server needs to verify the identity of the remote, it must
161 * validate the signature of the remote's certificate. This function sets the database of
162 * trusted CAs that will be used to verify the signature of the remote's certificate.
163 *
164 * @note This setting effects only those pn_tls_t objects created after this call
165 * returns. pn_tls_t objects created before invoking this method will use the domain's
166 * previous setting.
167 *
168 * @note By default the list of trusted CA certificates will be set to the system default.
169 * What this is is depends on the OS and the TLS implementation used: For OpenTLS the default
170 * will depend on how the OS is set up. When using the Windows SChannel implementation the default
171 * will be the users default trusted certificate store.
172 *
173 * @param[in] domain the tls domain that will use the database.
174 * @param[in] certificate_db database of trusted CAs, used to authenticate the peer.
175 * @return 0 on success
176 */
177 PN_TLS_EXTERN int pn_tls_config_set_trusted_certs(pn_tls_config_t *domain,
178 const char *certificate_db);
179
180 /**
181 * Determines the level of peer validation.
182 *
183 * ANONYMOUS_PEER does not require a valid certificate, and permits
184 * use of ciphers that do not provide authentication.
185 *
186 * VERIFY_PEER will only connect to those peers that provide a valid
187 * identifying certificate signed by a trusted CA and are using an
188 * authenticated cipher.
189 *
190 * VERIFY_PEER_NAME is like VERIFY_PEER, but also requires the peer's
191 * identity as contained in the certificate to be valid (see
192 * ::pn_tls_set_peer_hostname).
193 *
194 * VERIFY_PEER_NAME is configured by default.
195 */
196 typedef enum {
197 PN_TLS_VERIFY_NULL = 0, /**< internal use only */
198 PN_TLS_VERIFY_PEER, /**< require peer to provide a valid identifying certificate */
199 PN_TLS_ANONYMOUS_PEER, /**< do not require a certificate nor cipher authorization */
200 PN_TLS_VERIFY_PEER_NAME /**< require valid certificate and matching name */
201 } pn_tls_verify_mode_t;
202
203 /**
204 * Configure the level of verification used on the peer certificate.
205 *
206 * This method controls how the peer's certificate is validated, if at all. By default,
207 * servers do not attempt to verify their peers (PN_TLS_ANONYMOUS_PEER) but
208 * clients attempt to verify both the certificate and peer name (PN_TLS_VERIFY_PEER_NAME).
209 * Once certificates and trusted CAs are configured, peer verification can be enabled.
210 *
211 * @note In order to verify a peer, a trusted CA must be configured. See
212 * ::pn_tls_config_set_trusted_certs().
213 *
214 * @note Servers must provide their own certificate when verifying a peer. See
215 * ::pn_tls_config_set_credentials().
216 *
217 * @note This setting effects only those pn_tls_t objects created after this call
218 * returns. pn_tls_t objects created before invoking this method will use the domain's
219 * previous setting.
220 *
221 * @param[in] domain the tls domain to configure.
222 * @param[in] mode the level of validation to apply to the peer
223 * @param[in] trusted_CAs path to a database of trusted CAs that the server will advertise
224 * to the peer client if the server has been configured to verify its peer.
225 * @return 0 on success
226 */
227 PN_TLS_EXTERN int pn_tls_config_set_peer_authentication(pn_tls_config_t *domain,
228 const pn_tls_verify_mode_t mode,
229 const char *trusted_CAs);
230
231 /**
232 * Configure the list of permitted ciphers
233 *
234 * @note The syntax of the permitted list is undefined and will depend on the
235 * underlying TLS implementation.
236 *
237 * @param[in] domain the tls domain to configure.
238 * @param[in] ciphers string representing the cipher list
239 * @return 0 on success
240 */
241 PN_TLS_EXTERN int pn_tls_config_set_impl_ciphers(pn_tls_config_t *domain, const char *ciphers);
242
243 /**
244 * Create a new TLS session object derived from a domain.
245 *
246 * @param[in] domain the domain that configures the TLS session.
247 * @return a pointer to the TLS object. Returns NULL if memory allocation fails or if domain is NULL.
248 */
249 PN_TLS_EXTERN pn_tls_t *pn_tls(pn_tls_config_t *domain);
250
251 /**
252 * Start a TLS session.
253 *
254 * This method starts the operation of a TLS session based on the object's
255 * configuration. Subsequent configuration steps will have no effect. A client
256 * TLS session will generate one or more result buffers for the clienthello
257 * handshake.
258 * @param[in] tls the tls session to configured.
259 * @return 0 on success, else an error code.
260 */
261 PN_TLS_EXTERN int pn_tls_start(pn_tls_t *tls);
262
263
264 PN_TLS_EXTERN void pn_tls_free(pn_tls_t *tls);
265
266 /**
267 * Get the name of the Cipher that is currently in use.
268 *
269 * Gets a text description of the cipher that is currently active, or
270 * returns FALSE if TLS is not active (no cipher). Note that the
271 * cipher in use may change over time due to renegotiation or other
272 * changes to the TLS state. The cipher is not null terminated.
273 *
274 * @param[in] tls the tls client/server to query.
275 * @param[out] cipher set to a pointer to the current cipher description or NULL if no cipher.
276 * @param[out] size set to the cipher or 0 if no cipher.
277 * @return True if cipher is non-null and size is not zero.
278 */
279 PN_TLS_EXTERN bool pn_tls_get_cipher(pn_tls_t *tls, const char **cipher, size_t *size);
280
281 /**
282 * Get the SSF (security strength factor) of the Cipher that is currently in use.
283 *
284 * @param[in] tls the tls client/server to query.
285 * @return the ssf, note that 0 means no security.
286 */
287 PN_TLS_EXTERN int pn_tls_get_ssf(pn_tls_t *tls);
288
289 /**
290 * Get the name of the TLS protocol that is currently in use.
291 *
292 * Gets a text description of the TLS protocol that is currently active, or returns FALSE if TLS
293 * is not active. Note that the protocol may change over time due to renegotiation.
294 *
295 * @param[in] tls the tls client/server to query.
296 * @param[out] version set to a pointer to the current protocol version or NULL if not active.
297 * @param[out] size set to the length of the version or zero if not active.
298 * @return True if version is non-null and size is not zero.
299 * not ready.
300 */
301 PN_TLS_EXTERN bool pn_tls_get_protocol_version(pn_tls_t *tls, const char **version, size_t *size);
302
303 /**
304 * Set the expected identity of the remote peer.
305 *
306 * By default, TLS will use the hostname associated with the connection that
307 * the transport is bound to (see ::pn_connection_set_hostname). This method
308 * allows the caller to override that default.
309 *
310 * The hostname is used for two purposes: 1) when set on an TLS client, it is sent to the
311 * server during the handshake (if Server Name Indication is supported), and 2) it is used
312 * to check against the identifying name provided in the peer's certificate. If the
313 * supplied name does not exactly match a SubjectAltName (type DNS name), or the
314 * CommonName entry in the peer's certificate, the peer is considered unauthenticated
315 * (potential imposter), and the TLS connection is aborted.
316 *
317 * @note Verification of the hostname is only done if PN_TLS_VERIFY_PEER_NAME is enabled.
318 * See ::pn_tls_config_set_peer_authentication.
319 *
320 * @param[in] tls the tls session.
321 * @param[in] hostname the expected identity of the remote. Must conform to the syntax as
322 * given in RFC1034, Section 3.5.
323 * @return 0 on success.
324 */
325 PN_TLS_EXTERN int pn_tls_set_peer_hostname(pn_tls_t *tls, const char *hostname);
326
327 /**
328 * Access the configured peer identity.
329 *
330 * Return the expected identity of the remote peer, as set by ::pn_tls_set_peer_hostname.
331 *
332 * @param[in] tls the tls session.
333 * @param[out] hostname buffer to hold the null-terminated name string. If null, no string
334 * is written.
335 * @param[in,out] bufsize on input set to the number of octets in hostname. On output, set
336 * to the number of octets needed to hold the value of hostname plus a null byte. Zero if
337 * no hostname set.
338 * @return 0 on success.
339 */
340 PN_TLS_EXTERN int pn_tls_get_peer_hostname(pn_tls_t *tls, char *hostname, size_t *bufsize);
341
342 /**
343 * Get the subject from the peers certificate.
344 *
345 * @param[in] tls the tls client/server to query.
346 * @return A null terminated string representing the full subject,
347 * which is valid until the tls object is destroyed.
348 */
349 PN_TLS_EXTERN const char* pn_tls_get_remote_subject(pn_tls_t *tls);
350
351 /**
352 * Enumeration identifying the sub fields of the subject field in the tls certificate.
353 */
354 typedef enum {
355 PN_TLS_CERT_SUBJECT_COUNTRY_NAME,
356 PN_TLS_CERT_SUBJECT_STATE_OR_PROVINCE,
357 PN_TLS_CERT_SUBJECT_CITY_OR_LOCALITY,
358 PN_TLS_CERT_SUBJECT_ORGANIZATION_NAME,
359 PN_TLS_CERT_SUBJECT_ORGANIZATION_UNIT,
360 PN_TLS_CERT_SUBJECT_COMMON_NAME
361 } pn_tls_cert_subject_subfield;
362
363 /**
364 * Enumeration identifying hashing algorithm.
365 */
366 typedef enum {
367 PN_TLS_SHA1, /* Produces hash that is 20 bytes long */
368 PN_TLS_SHA256, /* Produces hash that is 32 bytes long */
369 PN_TLS_SHA512, /* Produces hash that is 64 bytes long */
370 PN_TLS_MD5 /* Produces hash that is 16 bytes long */
371 } pn_tls_hash_alg;
372
373 /**
374 * Get the fingerprint of the certificate. The certificate fingerprint (as displayed in the Fingerprints section when
375 * looking at a certificate with say the Firefox browser) is the hexadecimal hash of the entire certificate.
376 * The fingerprint is not part of the certificate, rather it is computed from the certificate and can be used to uniquely identify a certificate.
377 * @param[in] tls0 the tls client/server to query
378 * @param[in] fingerprint char pointer. The certificate fingerprint (in hex format) will be populated in this array.
379 * If sha1 is the digest name, the fingerprint is 41 characters long (40 + 1 '\0' character), 65 characters long for
380 * sha256 and 129 characters long for sha512 and 33 characters for md5.
381 * @param[in] fingerprint_length - Must be at >= 33 for md5, >= 41 for sha1, >= 65 for sha256 and >=129 for sha512.
382 * @param[in] hash_alg the hash algorithm to use. Must be of type pn_tls_hash_alg (currently supports sha1, sha256, sha512 and md5)
383 * @return error code - Returns 0 on success. Return a value less than zero if there were any errors. Upon execution of this function,
384 * char *fingerprint will contain the appropriate null terminated hex fingerprint
385 */
386 PN_TLS_EXTERN int pn_tls_get_cert_fingerprint(pn_tls_t *tls0,
387 char *fingerprint,
388 size_t fingerprint_length,
389 pn_tls_hash_alg hash_alg);
390
391 /**
392 * Returns a char pointer that contains the value of the sub field of the subject field in the tls certificate. The subject field usually contains the following sub fields -
393 * C = ISO3166 two character country code
394 * ST = state or province
395 * L = Locality; generally means city
396 * O = Organization - Company Name
397 * OU = Organization Unit - division or unit
398 * CN = CommonName
399 * @param[in] tls0 the tls client/server to query
400 * @param[in] field The enumeration pn_tls_cert_subject_subfield representing the required sub field.
401 * @return A null terminated string which contains the requested sub field value which is valid until the tls object is destroyed.
402 */
403 PN_TLS_EXTERN const char* pn_tls_get_remote_subject_subfield(pn_tls_t *tls, pn_tls_cert_subject_subfield field);
404
405 PN_TLS_EXTERN bool pn_tls_is_encrypt_output_pending(pn_tls_t *tls);
406 PN_TLS_EXTERN bool pn_tls_is_decrypt_output_pending(pn_tls_t *tls);
407
408
409 // True if peers have negotiated a TLS session. False indicates handshake in progress or protocol error.
410 PN_TLS_EXTERN bool pn_tls_is_secure(pn_tls_t *tls);
411
412
413 // ----------------------------------------------------------------------------------------------------------------------
414
415 // A common pool of buffers to put both encrypted and decrypted bytes in:
416 // - this could easily just be split into 2 result buffer sets if preferred.
417
418 // Give buffers to store encryption/decryption results
419 // returns the number of buffers taken - it's possible that we don't have space
420 // to record all of them
421 PN_TLS_EXTERN size_t pn_tls_give_encrypt_output_buffers(pn_tls_t*, pn_raw_buffer_t const*, size_t count);
422 PN_TLS_EXTERN size_t pn_tls_give_decrypt_output_buffers(pn_tls_t*, pn_raw_buffer_t const*, size_t count);
423
424
425 // Take result buffers back into app ownership, return the actual number of buffers returned
426 // keep calling these until the number returned is 0 to make sure you get all buffers currently available
427 // Gives only buffers with encrypted/decrypted content before pn_tls_stop() and all buffers afterwards.
428 PN_TLS_EXTERN size_t pn_tls_take_decrypt_output_buffers(pn_tls_t*, pn_raw_buffer_t*, size_t count);
429 PN_TLS_EXTERN size_t pn_tls_take_encrypt_output_buffers(pn_tls_t*, pn_raw_buffer_t*, size_t count);
430
431 // Stage data to be encrypted by the engine at a future pn_tls_process() step.
432 // returned value is number of buffers taken (ownership transfer)
433 // i.e. held by the tls code - governed by capacity.
434 PN_TLS_EXTERN size_t pn_tls_give_encrypt_input_buffers(pn_tls_t*, pn_raw_buffer_t const* bufs, size_t count_bufs);
435
436 // returned value is number of buffers taken
437 PN_TLS_EXTERN size_t pn_tls_give_decrypt_input_buffers(pn_tls_t*, pn_raw_buffer_t const* bufs, size_t count_bufs);
438
439 // Take input buffers back into app ownership, return the actual number of buffers returned
440 // Returns buffers whose data is fully processed (or pn_tls_stop() called).
441 // keep calling these until the number returned is 0 to make sure you get all buffers currently available
442 PN_TLS_EXTERN size_t pn_tls_take_encrypt_input_buffers(pn_tls_t*, pn_raw_buffer_t*, size_t count);
443 PN_TLS_EXTERN size_t pn_tls_take_decrypt_input_buffers(pn_tls_t*, pn_raw_buffer_t*, size_t count);
444
445 // Return the max number of additional input buffers we can hold
446 PN_TLS_EXTERN size_t pn_tls_get_encrypt_input_buffer_capacity(pn_tls_t*);
447 PN_TLS_EXTERN size_t pn_tls_get_decrypt_input_buffer_capacity(pn_tls_t*);
448
449 // True if there is no remaining space in the XXcrypt result buffers owned by the
450 // engine and there is XXcryped data available to put in a result buffer since
451 // the last pn_tls_process()
452 PN_TLS_EXTERN bool pn_tls_need_encrypt_output_buffers(pn_tls_t*);
453 PN_TLS_EXTERN bool pn_tls_need_decrypt_output_buffers(pn_tls_t*);
454
455 PN_TLS_EXTERN size_t pn_tls_get_encrypt_output_buffer_capacity(pn_tls_t*);
456 PN_TLS_EXTERN size_t pn_tls_get_decrypt_output_buffer_capacity(pn_tls_t*);
457
458 // Number of buffers ready to be returned by take operation since last pn_tls_process() or pn_tls_stop()
459 PN_TLS_EXTERN size_t pn_tls_get_decrypt_output_buffer_count(pn_tls_t*);
460 PN_TLS_EXTERN size_t pn_tls_get_encrypt_output_buffer_count(pn_tls_t*);
461
462 PN_TLS_EXTERN uint32_t pn_tls_get_last_decrypt_output_buffer_size(pn_tls_t*);
463 PN_TLS_EXTERN uint32_t pn_tls_get_last_encrypt_output_buffer_size(pn_tls_t*);
464
465
466 // Configurable. Zero implies "use default". No effect after pn_tls_start().
467 PN_TLS_EXTERN void pn_tls_set_encrypt_input_buffer_max_capacity(pn_tls_t*, size_t s);
468 PN_TLS_EXTERN void pn_tls_set_decrypt_input_buffer_max_capacity(pn_tls_t*, size_t s);
469 PN_TLS_EXTERN void pn_tls_set_encrypt_output_buffer_max_capacity(pn_tls_t*, size_t s);
470 PN_TLS_EXTERN void pn_tls_set_decrypt_output_buffer_max_capacity(pn_tls_t*, size_t s);
471
472 // Process as much unencrypted data to encrypted result data as possible.
473 // Also process as much undecrypted data to decryptedcrypted result data as possible.
474 // Check for TLS engine errors here.
475 // Always returns an error if called before pn_tls_start() or after pn_tls_stop().
476 PN_TLS_EXTERN int pn_tls_process(pn_tls_t* tls);
477
478 // Future pn_tls_process() or pn_tls_give_xxx() are no-ops.
479 // Unused encrypt/decrypt result buffers become zero length encrypted/decrypted result
480 // buffers and can be reclaimed.
481 // Future: If no closure from peer or self closure not written to result buffer, session resume cancelled.
482 PN_TLS_EXTERN int pn_tls_stop(pn_tls_t* tls);
483
484 // Confirms receipt of the peer's TLS closure record. This confirms clean shutdown and
485 // the absence of a truncation attack.
486 PN_TLS_EXTERN bool pn_tls_is_input_closed(pn_tls_t* tls);
487
488 // Closes the encrypt side and appends the TLS closure record to the pending encypted
489 // output. pn_tls_give_encrypt_input_buffers() will no longer take any supplied buffers.
490 PN_TLS_EXTERN void pn_tls_close_output(pn_tls_t* tls);
491
492 // If non-zero the TLS session was unable to start or was aborted.
493 // The application should stop all read activity, and take all
494 // remaining encrypted content and write it onto the connection
495 // (i.e. until pn_tls_is_encrypt_output_pending() is false), then
496 // close the associated connection. This will allow the error to be
497 // propagated to the peer if expected by the TLS protocol. Specific return values TBD (INIT_FAILED,
498 // BAD_AUTH, TLS_PROTOCOL_ERROR, ...).
499 PN_TLS_EXTERN int pn_tls_get_session_error(pn_tls_t* tls);
500
501 // Error string associated with the fatal TLS session error. zero if no error, buf is null or buf_len is 0.
502 PN_TLS_EXTERN size_t pn_tls_get_session_error_string(pn_tls_t* tls, char *buf, size_t buf_len);
503
504 /**
505 * Provide an ordered list of application protols for RFC 7301 negotiation.
506 * List ordered in descending preference for the caller.
507 *
508 * Each protocol name must be provided as its well known octet sequence in UTF-8, null
509 * terminated. For the client, the order is preserved in the client_hello to the server, but
510 * the server will not usually take that ordering into account.
511 *
512 * For the server, protocol selection follows the standard mechanism in RFC 7301: the first item in the server list that matches an item in the client list is selected. No match will result in a failed TLS handshake.
513 *
514 * ALPN processing can be turned off by setting protocols to NULL and protocol_count to zero.
515 *
516 * @note This setting effects only those pn_tls_t objects created after this call
517 * returns. pn_tls_t objects created before invoking this method will use the domain's
518 * previous setting.
519 *
520 * @param[in] tls the tls client/server to query.
521 * @param[in] protocols the array of pointers the protocol names in the list.
522 * @param[in] count the size of the protocols array.
523 * @return 0 on success, PN_ARG_ERROR if any array pointers are null or any protocol names exceed 255 bytes in length. PN_OUT_OF_MEMORY if memory allocation fails.
524 */
525 PN_TLS_EXTERN int pn_tls_config_set_alpn_protocols(pn_tls_config_t *domain, const char **protocols, size_t protocol_count);
526
527 /**
528 * Get the name of the negotiated application protocol.
529 *
530 * Gets the name of the negotiated application protocol or returns FALSE if the negotiation
531 * failed, is not yet complete, or was never requested by the client. The protocol name is not
532 * a null terminated string.
533 *
534 * @param[in] tls the tls client/server to query.
535 * @param[out] protocol_name set to a pointer to the application protocol name or NULL if not negotiated.
536 * @param[out] size set to the length of the protocol name or zero if not negotiated.
537 * @return True if the protocol_name is non-null and size is not zero.
538 */
539 PN_TLS_EXTERN bool pn_tls_get_alpn_protocol(pn_tls_t *tls, const char **protocol_name, size_t *size);
540
541 // TODO: Tracing. Session tickets.
542
543 /**
544 * @}
545 */
546
547 #ifdef __cplusplus
548 }
549 #endif
550
551 #endif /* tls.h */