]>
git.proxmox.com Git - mirror_edk2.git/blob - CryptoPkg/Include/Library/TlsLib.h
2 Defines TLS Library APIs.
4 Copyright (c) 2016 - 2017, Intel Corporation. All rights reserved.<BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
13 Initializes the OpenSSL library.
15 This function registers ciphers and digests used directly and indirectly
16 by SSL/TLS, and initializes the readable error messages.
17 This function must be called before any other action takes places.
19 @retval TRUE The OpenSSL library has been initialized.
20 @retval FALSE Failed to initialize the OpenSSL library.
30 Free an allocated SSL_CTX object.
32 @param[in] TlsCtx Pointer to the SSL_CTX object to be released.
42 Creates a new SSL_CTX object as framework to establish TLS/SSL enabled
45 @param[in] MajorVer Major Version of TLS/SSL Protocol.
46 @param[in] MinorVer Minor Version of TLS/SSL Protocol.
48 @return Pointer to an allocated SSL_CTX object.
49 If the creation failed, TlsCtxNew() returns NULL.
60 Free an allocated TLS object.
62 This function removes the TLS object pointed to by Tls and frees up the
63 allocated memory. If Tls is NULL, nothing is done.
65 @param[in] Tls Pointer to the TLS object to be freed.
75 Create a new TLS object for a connection.
77 This function creates a new TLS object for a connection. The new object
78 inherits the setting of the underlying context TlsCtx: connection method,
79 options, verification setting.
81 @param[in] TlsCtx Pointer to the SSL_CTX object.
83 @return Pointer to an allocated SSL object.
84 If the creation failed, TlsNew() returns NULL.
94 Checks if the TLS handshake was done.
96 This function will check if the specified TLS handshake was done.
98 @param[in] Tls Pointer to the TLS object for handshake state checking.
100 @retval TRUE The TLS handshake was done.
101 @retval FALSE The TLS handshake was not done.
111 Perform a TLS/SSL handshake.
113 This function will perform a TLS/SSL handshake.
115 @param[in] Tls Pointer to the TLS object for handshake operation.
116 @param[in] BufferIn Pointer to the most recently received TLS Handshake packet.
117 @param[in] BufferInSize Packet size in bytes for the most recently received TLS
119 @param[out] BufferOut Pointer to the buffer to hold the built packet.
120 @param[in, out] BufferOutSize Pointer to the buffer size in bytes. On input, it is
121 the buffer size provided by the caller. On output, it
122 is the buffer size in fact needed to contain the
125 @retval EFI_SUCCESS The required TLS packet is built successfully.
126 @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:
128 BufferIn is NULL but BufferInSize is NOT 0.
129 BufferInSize is 0 but BufferIn is NOT NULL.
130 BufferOutSize is NULL.
131 BufferOut is NULL if *BufferOutSize is not zero.
132 @retval EFI_BUFFER_TOO_SMALL BufferOutSize is too small to hold the response packet.
133 @retval EFI_ABORTED Something wrong during handshake.
140 IN UINT8
*BufferIn
, OPTIONAL
141 IN UINTN BufferInSize
, OPTIONAL
142 OUT UINT8
*BufferOut
, OPTIONAL
143 IN OUT UINTN
*BufferOutSize
147 Handle Alert message recorded in BufferIn. If BufferIn is NULL and BufferInSize is zero,
148 TLS session has errors and the response packet needs to be Alert message based on error type.
150 @param[in] Tls Pointer to the TLS object for state checking.
151 @param[in] BufferIn Pointer to the most recently received TLS Alert packet.
152 @param[in] BufferInSize Packet size in bytes for the most recently received TLS
154 @param[out] BufferOut Pointer to the buffer to hold the built packet.
155 @param[in, out] BufferOutSize Pointer to the buffer size in bytes. On input, it is
156 the buffer size provided by the caller. On output, it
157 is the buffer size in fact needed to contain the
160 @retval EFI_SUCCESS The required TLS packet is built successfully.
161 @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:
163 BufferIn is NULL but BufferInSize is NOT 0.
164 BufferInSize is 0 but BufferIn is NOT NULL.
165 BufferOutSize is NULL.
166 BufferOut is NULL if *BufferOutSize is not zero.
167 @retval EFI_ABORTED An error occurred.
168 @retval EFI_BUFFER_TOO_SMALL BufferOutSize is too small to hold the response packet.
175 IN UINT8
*BufferIn
, OPTIONAL
176 IN UINTN BufferInSize
, OPTIONAL
177 OUT UINT8
*BufferOut
, OPTIONAL
178 IN OUT UINTN
*BufferOutSize
182 Build the CloseNotify packet.
184 @param[in] Tls Pointer to the TLS object for state checking.
185 @param[in, out] Buffer Pointer to the buffer to hold the built packet.
186 @param[in, out] BufferSize Pointer to the buffer size in bytes. On input, it is
187 the buffer size provided by the caller. On output, it
188 is the buffer size in fact needed to contain the
191 @retval EFI_SUCCESS The required TLS packet is built successfully.
192 @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:
195 Buffer is NULL if *BufferSize is not zero.
196 @retval EFI_BUFFER_TOO_SMALL BufferSize is too small to hold the response packet.
203 IN OUT UINT8
*Buffer
,
204 IN OUT UINTN
*BufferSize
208 Attempts to read bytes from one TLS object and places the data in Buffer.
210 This function will attempt to read BufferSize bytes from the TLS object
211 and places the data in Buffer.
213 @param[in] Tls Pointer to the TLS object.
214 @param[in,out] Buffer Pointer to the buffer to store the data.
215 @param[in] BufferSize The size of Buffer in bytes.
217 @retval >0 The amount of data successfully read from the TLS object.
218 @retval <=0 No data was successfully read.
230 Attempts to write data from the buffer to TLS object.
232 This function will attempt to write BufferSize bytes data from the Buffer
235 @param[in] Tls Pointer to the TLS object.
236 @param[in] Buffer Pointer to the data buffer.
237 @param[in] BufferSize The size of Buffer in bytes.
239 @retval >0 The amount of data successfully written to the TLS object.
240 @retval <=0 No data was successfully written.
252 Attempts to read bytes from the specified TLS connection into the buffer.
254 This function tries to read BufferSize bytes data from the specified TLS
255 connection into the Buffer.
257 @param[in] Tls Pointer to the TLS connection for data reading.
258 @param[in,out] Buffer Pointer to the data buffer.
259 @param[in] BufferSize The size of Buffer in bytes.
261 @retval >0 The read operation was successful, and return value is the
262 number of bytes actually read from the TLS connection.
263 @retval <=0 The read operation was not successful.
275 Attempts to write data to a TLS connection.
277 This function tries to write BufferSize bytes data from the Buffer into the
278 specified TLS connection.
280 @param[in] Tls Pointer to the TLS connection for data writing.
281 @param[in] Buffer Pointer to the data buffer.
282 @param[in] BufferSize The size of Buffer in bytes.
284 @retval >0 The write operation was successful, and return value is the
285 number of bytes actually written to the TLS connection.
286 @retval <=0 The write operation was not successful.
298 Set a new TLS/SSL method for a particular TLS object.
300 This function sets a new TLS/SSL method for a particular TLS object.
302 @param[in] Tls Pointer to a TLS object.
303 @param[in] MajorVer Major Version of TLS/SSL Protocol.
304 @param[in] MinorVer Minor Version of TLS/SSL Protocol.
306 @retval EFI_SUCCESS The TLS/SSL method was set successfully.
307 @retval EFI_INVALID_PARAMETER The parameter is invalid.
308 @retval EFI_UNSUPPORTED Unsupported TLS/SSL method.
320 Set TLS object to work in client or server mode.
322 This function prepares a TLS object to work in client or server mode.
324 @param[in] Tls Pointer to a TLS object.
325 @param[in] IsServer Work in server mode.
327 @retval EFI_SUCCESS The TLS/SSL work mode was set successfully.
328 @retval EFI_INVALID_PARAMETER The parameter is invalid.
329 @retval EFI_UNSUPPORTED Unsupported TLS/SSL work mode.
334 TlsSetConnectionEnd (
340 Set the ciphers list to be used by the TLS object.
342 This function sets the ciphers for use by a specified TLS object.
344 @param[in] Tls Pointer to a TLS object.
345 @param[in] CipherId Array of UINT16 cipher identifiers. Each UINT16
346 cipher identifier comes from the TLS Cipher Suite
347 Registry of the IANA, interpreting Byte1 and Byte2
348 in network (big endian) byte order.
349 @param[in] CipherNum The number of cipher in the list.
351 @retval EFI_SUCCESS The ciphers list was set successfully.
352 @retval EFI_INVALID_PARAMETER The parameter is invalid.
353 @retval EFI_UNSUPPORTED No supported TLS cipher was found in CipherId.
354 @retval EFI_OUT_OF_RESOURCES Memory allocation failed.
366 Set the compression method for TLS/SSL operations.
368 This function handles TLS/SSL integrated compression methods.
370 @param[in] CompMethod The compression method ID.
372 @retval EFI_SUCCESS The compression method for the communication was
374 @retval EFI_UNSUPPORTED Unsupported compression method.
379 TlsSetCompressionMethod (
384 Set peer certificate verification mode for the TLS connection.
386 This function sets the verification mode flags for the TLS connection.
388 @param[in] Tls Pointer to the TLS object.
389 @param[in] VerifyMode A set of logically or'ed verification mode flags.
400 Set the specified host name to be verified.
402 @param[in] Tls Pointer to the TLS object.
403 @param[in] Flags The setting flags during the validation.
404 @param[in] HostName The specified host name to be verified.
406 @retval EFI_SUCCESS The HostName setting was set successfully.
407 @retval EFI_INVALID_PARAMETER The parameter is invalid.
408 @retval EFI_ABORTED Invalid HostName setting.
420 Sets a TLS/SSL session ID to be used during TLS/SSL connect.
422 This function sets a session ID to be used when the TLS/SSL connection is
425 @param[in] Tls Pointer to the TLS object.
426 @param[in] SessionId Session ID data used for session resumption.
427 @param[in] SessionIdLen Length of Session ID in bytes.
429 @retval EFI_SUCCESS Session ID was set successfully.
430 @retval EFI_INVALID_PARAMETER The parameter is invalid.
431 @retval EFI_UNSUPPORTED No available session for ID setting.
439 IN UINT16 SessionIdLen
443 Adds the CA to the cert store when requesting Server or Client authentication.
445 This function adds the CA certificate to the list of CAs when requesting
446 Server or Client authentication for the chosen TLS connection.
448 @param[in] Tls Pointer to the TLS object.
449 @param[in] Data Pointer to the data buffer of a DER-encoded binary
450 X.509 certificate or PEM-encoded X.509 certificate.
451 @param[in] DataSize The size of data buffer in bytes.
453 @retval EFI_SUCCESS The operation succeeded.
454 @retval EFI_INVALID_PARAMETER The parameter is invalid.
455 @retval EFI_OUT_OF_RESOURCES Required resources could not be allocated.
456 @retval EFI_ABORTED Invalid X.509 certificate.
461 TlsSetCaCertificate (
468 Loads the local public certificate into the specified TLS object.
470 This function loads the X.509 certificate into the specified TLS object
473 @param[in] Tls Pointer to the TLS object.
474 @param[in] Data Pointer to the data buffer of a DER-encoded binary
475 X.509 certificate or PEM-encoded X.509 certificate.
476 @param[in] DataSize The size of data buffer in bytes.
478 @retval EFI_SUCCESS The operation succeeded.
479 @retval EFI_INVALID_PARAMETER The parameter is invalid.
480 @retval EFI_OUT_OF_RESOURCES Required resources could not be allocated.
481 @retval EFI_ABORTED Invalid X.509 certificate.
486 TlsSetHostPublicCert (
493 Adds the local private key to the specified TLS object.
495 This function adds the local private key (PEM-encoded RSA or PKCS#8 private
496 key) into the specified TLS object for TLS negotiation.
498 @param[in] Tls Pointer to the TLS object.
499 @param[in] Data Pointer to the data buffer of a PEM-encoded RSA
500 or PKCS#8 private key.
501 @param[in] DataSize The size of data buffer in bytes.
503 @retval EFI_SUCCESS The operation succeeded.
504 @retval EFI_UNSUPPORTED This function is not supported.
505 @retval EFI_ABORTED Invalid private key data.
510 TlsSetHostPrivateKey (
517 Adds the CA-supplied certificate revocation list for certificate validation.
519 This function adds the CA-supplied certificate revocation list data for
520 certificate validity checking.
522 @param[in] Data Pointer to the data buffer of a DER-encoded CRL data.
523 @param[in] DataSize The size of data buffer in bytes.
525 @retval EFI_SUCCESS The operation succeeded.
526 @retval EFI_UNSUPPORTED This function is not supported.
527 @retval EFI_ABORTED Invalid CRL data.
532 TlsSetCertRevocationList (
538 Gets the protocol version used by the specified TLS connection.
540 This function returns the protocol version used by the specified TLS
543 If Tls is NULL, then ASSERT().
545 @param[in] Tls Pointer to the TLS object.
547 @return The protocol version of the specified TLS connection.
557 Gets the connection end of the specified TLS connection.
559 This function returns the connection end (as client or as server) used by
560 the specified TLS connection.
562 If Tls is NULL, then ASSERT().
564 @param[in] Tls Pointer to the TLS object.
566 @return The connection end used by the specified TLS connection.
571 TlsGetConnectionEnd (
576 Gets the cipher suite used by the specified TLS connection.
578 This function returns current cipher suite used by the specified
581 @param[in] Tls Pointer to the TLS object.
582 @param[in,out] CipherId The cipher suite used by the TLS object.
584 @retval EFI_SUCCESS The cipher suite was returned successfully.
585 @retval EFI_INVALID_PARAMETER The parameter is invalid.
586 @retval EFI_UNSUPPORTED Unsupported cipher suite.
591 TlsGetCurrentCipher (
593 IN OUT UINT16
*CipherId
597 Gets the compression methods used by the specified TLS connection.
599 This function returns current integrated compression methods used by
600 the specified TLS connection.
602 @param[in] Tls Pointer to the TLS object.
603 @param[in,out] CompressionId The current compression method used by
606 @retval EFI_SUCCESS The compression method was returned successfully.
607 @retval EFI_INVALID_PARAMETER The parameter is invalid.
608 @retval EFI_ABORTED Invalid Compression method.
609 @retval EFI_UNSUPPORTED This function is not supported.
614 TlsGetCurrentCompressionId (
616 IN OUT UINT8
*CompressionId
620 Gets the verification mode currently set in the TLS connection.
622 This function returns the peer verification mode currently set in the
623 specified TLS connection.
625 If Tls is NULL, then ASSERT().
627 @param[in] Tls Pointer to the TLS object.
629 @return The verification mode set in the specified TLS connection.
639 Gets the session ID used by the specified TLS connection.
641 This function returns the TLS/SSL session ID currently used by the
642 specified TLS connection.
644 @param[in] Tls Pointer to the TLS object.
645 @param[in,out] SessionId Buffer to contain the returned session ID.
646 @param[in,out] SessionIdLen The length of Session ID in bytes.
648 @retval EFI_SUCCESS The Session ID was returned successfully.
649 @retval EFI_INVALID_PARAMETER The parameter is invalid.
650 @retval EFI_UNSUPPORTED Invalid TLS/SSL session.
657 IN OUT UINT8
*SessionId
,
658 IN OUT UINT16
*SessionIdLen
662 Gets the client random data used in the specified TLS connection.
664 This function returns the TLS/SSL client random data currently used in
665 the specified TLS connection.
667 @param[in] Tls Pointer to the TLS object.
668 @param[in,out] ClientRandom Buffer to contain the returned client
669 random data (32 bytes).
676 IN OUT UINT8
*ClientRandom
680 Gets the server random data used in the specified TLS connection.
682 This function returns the TLS/SSL server random data currently used in
683 the specified TLS connection.
685 @param[in] Tls Pointer to the TLS object.
686 @param[in,out] ServerRandom Buffer to contain the returned server
687 random data (32 bytes).
694 IN OUT UINT8
*ServerRandom
698 Gets the master key data used in the specified TLS connection.
700 This function returns the TLS/SSL master key material currently used in
701 the specified TLS connection.
703 @param[in] Tls Pointer to the TLS object.
704 @param[in,out] KeyMaterial Buffer to contain the returned key material.
706 @retval EFI_SUCCESS Key material was returned successfully.
707 @retval EFI_INVALID_PARAMETER The parameter is invalid.
708 @retval EFI_UNSUPPORTED Invalid TLS/SSL session.
715 IN OUT UINT8
*KeyMaterial
719 Gets the CA Certificate from the cert store.
721 This function returns the CA certificate for the chosen
724 @param[in] Tls Pointer to the TLS object.
725 @param[out] Data Pointer to the data buffer to receive the CA
726 certificate data sent to the client.
727 @param[in,out] DataSize The size of data buffer in bytes.
729 @retval EFI_SUCCESS The operation succeeded.
730 @retval EFI_UNSUPPORTED This function is not supported.
731 @retval EFI_BUFFER_TOO_SMALL The Data is too small to hold the data.
736 TlsGetCaCertificate (
739 IN OUT UINTN
*DataSize
743 Gets the local public Certificate set in the specified TLS object.
745 This function returns the local public certificate which was currently set
746 in the specified TLS object.
748 @param[in] Tls Pointer to the TLS object.
749 @param[out] Data Pointer to the data buffer to receive the local
751 @param[in,out] DataSize The size of data buffer in bytes.
753 @retval EFI_SUCCESS The operation succeeded.
754 @retval EFI_INVALID_PARAMETER The parameter is invalid.
755 @retval EFI_NOT_FOUND The certificate is not found.
756 @retval EFI_BUFFER_TOO_SMALL The Data is too small to hold the data.
761 TlsGetHostPublicCert (
764 IN OUT UINTN
*DataSize
768 Gets the local private key set in the specified TLS object.
770 This function returns the local private key data which was currently set
771 in the specified TLS object.
773 @param[in] Tls Pointer to the TLS object.
774 @param[out] Data Pointer to the data buffer to receive the local
776 @param[in,out] DataSize The size of data buffer in bytes.
778 @retval EFI_SUCCESS The operation succeeded.
779 @retval EFI_UNSUPPORTED This function is not supported.
780 @retval EFI_BUFFER_TOO_SMALL The Data is too small to hold the data.
785 TlsGetHostPrivateKey (
788 IN OUT UINTN
*DataSize
792 Gets the CA-supplied certificate revocation list data set in the specified
795 This function returns the CA-supplied certificate revocation list data which
796 was currently set in the specified TLS object.
798 @param[out] Data Pointer to the data buffer to receive the CRL data.
799 @param[in,out] DataSize The size of data buffer in bytes.
801 @retval EFI_SUCCESS The operation succeeded.
802 @retval EFI_UNSUPPORTED This function is not supported.
803 @retval EFI_BUFFER_TOO_SMALL The Data is too small to hold the data.
808 TlsGetCertRevocationList (
810 IN OUT UINTN
*DataSize
813 #endif // __TLS_LIB_H__