]>
git.proxmox.com Git - mirror_edk2.git/blob - CryptoPkg/Include/Library/TlsLib.h
2 Defines TLS Library APIs.
4 Copyright (c) 2016, Intel Corporation. All rights reserved.<BR>
5 This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
19 Initializes the OpenSSL library.
21 This function registers ciphers and digests used directly and indirectly
22 by SSL/TLS, and initializes the readable error messages.
23 This function must be called before any other action takes places.
33 Free an allocated SSL_CTX object.
35 @param[in] TlsCtx Pointer to the SSL_CTX object to be released.
45 Creates a new SSL_CTX object as framework to establish TLS/SSL enabled
48 @param[in] MajorVer Major Version of TLS/SSL Protocol.
49 @param[in] MinorVer Minor Version of TLS/SSL Protocol.
51 @return Pointer to an allocated SSL_CTX object.
52 If the creation failed, TlsCtxNew() returns NULL.
63 Free an allocated TLS object.
65 This function removes the TLS object pointed to by Tls and frees up the
66 allocated memory. If Tls is NULL, nothing is done.
68 @param[in] Tls Pointer to the TLS object to be freed.
78 Create a new TLS object for a connection.
80 This function creates a new TLS object for a connection. The new object
81 inherits the setting of the underlying context TlsCtx: connection method,
82 options, verification setting.
84 @param[in] TlsCtx Pointer to the SSL_CTX object.
86 @return Pointer to an allocated SSL object.
87 If the creation failed, TlsNew() returns NULL.
97 Checks if the TLS handshake was done.
99 This function will check if the specified TLS handshake was done.
101 @param[in] Tls Pointer to the TLS object for handshake state checking.
103 @retval TRUE The TLS handshake was done.
104 @retval FALSE The TLS handshake was not done.
114 Perform a TLS/SSL handshake.
116 This function will perform a TLS/SSL handshake.
118 @param[in] Tls Pointer to the TLS object for handshake operation.
119 @param[in] BufferIn Pointer to the most recently received TLS Handshake packet.
120 @param[in] BufferInSize Packet size in bytes for the most recently received TLS
122 @param[out] BufferOut Pointer to the buffer to hold the built packet.
123 @param[in, out] BufferOutSize Pointer to the buffer size in bytes. On input, it is
124 the buffer size provided by the caller. On output, it
125 is the buffer size in fact needed to contain the
128 @retval EFI_SUCCESS The required TLS packet is built successfully.
129 @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:
131 BufferIn is NULL but BufferInSize is NOT 0.
132 BufferInSize is 0 but BufferIn is NOT NULL.
133 BufferOutSize is NULL.
134 BufferOut is NULL if *BufferOutSize is not zero.
135 @retval EFI_BUFFER_TOO_SMALL BufferOutSize is too small to hold the response packet.
136 @retval EFI_ABORTED Something wrong during handshake.
143 IN UINT8
*BufferIn
, OPTIONAL
144 IN UINTN BufferInSize
, OPTIONAL
145 OUT UINT8
*BufferOut
, OPTIONAL
146 IN OUT UINTN
*BufferOutSize
150 Handle Alert message recorded in BufferIn. If BufferIn is NULL and BufferInSize is zero,
151 TLS session has errors and the response packet needs to be Alert message based on error type.
153 @param[in] Tls Pointer to the TLS object for state checking.
154 @param[in] BufferIn Pointer to the most recently received TLS Alert packet.
155 @param[in] BufferInSize Packet size in bytes for the most recently received TLS
157 @param[out] BufferOut Pointer to the buffer to hold the built packet.
158 @param[in, out] BufferOutSize Pointer to the buffer size in bytes. On input, it is
159 the buffer size provided by the caller. On output, it
160 is the buffer size in fact needed to contain the
163 @retval EFI_SUCCESS The required TLS packet is built successfully.
164 @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:
166 BufferIn is NULL but BufferInSize is NOT 0.
167 BufferInSize is 0 but BufferIn is NOT NULL.
168 BufferOutSize is NULL.
169 BufferOut is NULL if *BufferOutSize is not zero.
170 @retval EFI_ABORTED An error occurred.
171 @retval EFI_BUFFER_TOO_SMALL BufferOutSize is too small to hold the response packet.
178 IN UINT8
*BufferIn
, OPTIONAL
179 IN UINTN BufferInSize
, OPTIONAL
180 OUT UINT8
*BufferOut
, OPTIONAL
181 IN OUT UINTN
*BufferOutSize
185 Build the CloseNotify packet.
187 @param[in] Tls Pointer to the TLS object for state checking.
188 @param[in, out] Buffer Pointer to the buffer to hold the built packet.
189 @param[in, out] BufferSize Pointer to the buffer size in bytes. On input, it is
190 the buffer size provided by the caller. On output, it
191 is the buffer size in fact needed to contain the
194 @retval EFI_SUCCESS The required TLS packet is built successfully.
195 @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:
198 Buffer is NULL if *BufferSize is not zero.
199 @retval EFI_BUFFER_TOO_SMALL BufferSize is too small to hold the response packet.
206 IN OUT UINT8
*Buffer
,
207 IN OUT UINTN
*BufferSize
211 Attempts to read bytes from one TLS object and places the data in Buffer.
213 This function will attempt to read BufferSize bytes from the TLS object
214 and places the data in Buffer.
216 @param[in] Tls Pointer to the TLS object.
217 @param[in,out] Buffer Pointer to the buffer to store the data.
218 @param[in] BufferSize The size of Buffer in bytes.
220 @retval >0 The amount of data successfully read from the TLS object.
221 @retval <=0 No data was successfully read.
233 Attempts to write data from the buffer to TLS object.
235 This function will attempt to write BufferSize bytes data from the Buffer
238 @param[in] Tls Pointer to the TLS object.
239 @param[in] Buffer Pointer to the data buffer.
240 @param[in] BufferSize The size of Buffer in bytes.
242 @retval >0 The amount of data successfully written to the TLS object.
243 @retval <=0 No data was successfully written.
255 Attempts to read bytes from the specified TLS connection into the buffer.
257 This function tries to read BufferSize bytes data from the specified TLS
258 connection into the Buffer.
260 @param[in] Tls Pointer to the TLS connection for data reading.
261 @param[in,out] Buffer Pointer to the data buffer.
262 @param[in] BufferSize The size of Buffer in bytes.
264 @retval >0 The read operation was successful, and return value is the
265 number of bytes actually read from the TLS connection.
266 @retval <=0 The read operation was not successful.
278 Attempts to write data to a TLS connection.
280 This function tries to write BufferSize bytes data from the Buffer into the
281 specified TLS connection.
283 @param[in] Tls Pointer to the TLS connection for data writing.
284 @param[in] Buffer Pointer to the data buffer.
285 @param[in] BufferSize The size of Buffer in bytes.
287 @retval >0 The write operation was successful, and return value is the
288 number of bytes actually written to the TLS connection.
289 @retval <=0 The write operation was not successful.
301 Set a new TLS/SSL method for a particular TLS object.
303 This function sets a new TLS/SSL method for a particular TLS object.
305 @param[in] Tls Pointer to a TLS object.
306 @param[in] MajorVer Major Version of TLS/SSL Protocol.
307 @param[in] MinorVer Minor Version of TLS/SSL Protocol.
309 @retval EFI_SUCCESS The TLS/SSL method was set successfully.
310 @retval EFI_INVALID_PARAMETER The parameter is invalid.
311 @retval EFI_UNSUPPORTED Unsupported TLS/SSL method.
323 Set TLS object to work in client or server mode.
325 This function prepares a TLS object to work in client or server mode.
327 @param[in] Tls Pointer to a TLS object.
328 @param[in] IsServer Work in server mode.
330 @retval EFI_SUCCESS The TLS/SSL work mode was set successfully.
331 @retval EFI_INVALID_PARAMETER The parameter is invalid.
332 @retval EFI_UNSUPPORTED Unsupported TLS/SSL work mode.
337 TlsSetConnectionEnd (
343 Set the ciphers list to be used by the TLS object.
345 This function sets the ciphers for use by a specified TLS object.
347 @param[in] Tls Pointer to a TLS object.
348 @param[in] CipherId Pointer to a string that contains one or more
349 ciphers separated by a colon.
350 @param[in] CipherNum The number of cipher in the list.
352 @retval EFI_SUCCESS The ciphers list was set successfully.
353 @retval EFI_INVALID_PARAMETER The parameter is invalid.
354 @retval EFI_UNSUPPORTED Unsupported TLS cipher in the list.
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 Sets a TLS/SSL session ID to be used during TLS/SSL connect.
402 This function sets a session ID to be used when the TLS/SSL connection is
405 @param[in] Tls Pointer to the TLS object.
406 @param[in] SessionId Session ID data used for session resumption.
407 @param[in] SessionIdLen Length of Session ID in bytes.
409 @retval EFI_SUCCESS Session ID was set successfully.
410 @retval EFI_INVALID_PARAMETER The parameter is invalid.
411 @retval EFI_UNSUPPORTED No available session for ID setting.
419 IN UINT16 SessionIdLen
423 Adds the CA to the cert store when requesting Server or Client authentication.
425 This function adds the CA certificate to the list of CAs when requesting
426 Server or Client authentication for the chosen TLS connection.
428 @param[in] Tls Pointer to the TLS object.
429 @param[in] Data Pointer to the data buffer of a DER-encoded binary
430 X.509 certificate or PEM-encoded X.509 certificate.
431 @param[in] DataSize The size of data buffer in bytes.
433 @retval EFI_SUCCESS The operation succeeded.
434 @retval EFI_INVALID_PARAMETER The parameter is invalid.
435 @retval EFI_OUT_OF_RESOURCES Required resources could not be allocated.
436 @retval EFI_ABORTED Invalid X.509 certificate.
441 TlsSetCaCertificate (
448 Loads the local public certificate into the specified TLS object.
450 This function loads the X.509 certificate into the specified TLS object
453 @param[in] Tls Pointer to the TLS object.
454 @param[in] Data Pointer to the data buffer of a DER-encoded binary
455 X.509 certificate or PEM-encoded X.509 certificate.
456 @param[in] DataSize The size of data buffer in bytes.
458 @retval EFI_SUCCESS The operation succeeded.
459 @retval EFI_INVALID_PARAMETER The parameter is invalid.
460 @retval EFI_OUT_OF_RESOURCES Required resources could not be allocated.
461 @retval EFI_ABORTED Invalid X.509 certificate.
466 TlsSetHostPublicCert (
473 Adds the local private key to the specified TLS object.
475 This function adds the local private key (PEM-encoded RSA or PKCS#8 private
476 key) into the specified TLS object for TLS negotiation.
478 @param[in] Tls Pointer to the TLS object.
479 @param[in] Data Pointer to the data buffer of a PEM-encoded RSA
480 or PKCS#8 private key.
481 @param[in] DataSize The size of data buffer in bytes.
483 @retval EFI_SUCCESS The operation succeeded.
484 @retval EFI_UNSUPPORTED This function is not supported.
485 @retval EFI_ABORTED Invalid private key data.
490 TlsSetHostPrivateKey (
497 Adds the CA-supplied certificate revocation list for certificate validation.
499 This function adds the CA-supplied certificate revocation list data for
500 certificate validity checking.
502 @param[in] Data Pointer to the data buffer of a DER-encoded CRL data.
503 @param[in] DataSize The size of data buffer in bytes.
505 @retval EFI_SUCCESS The operation succeeded.
506 @retval EFI_UNSUPPORTED This function is not supported.
507 @retval EFI_ABORTED Invalid CRL data.
512 TlsSetCertRevocationList (
518 Gets the protocol version used by the specified TLS connection.
520 This function returns the protocol version used by the specified TLS
523 @param[in] Tls Pointer to the TLS object.
525 @return The protocol version of the specified TLS connection.
535 Gets the connection end of the specified TLS connection.
537 This function returns the connection end (as client or as server) used by
538 the specified TLS connection.
540 @param[in] Tls Pointer to the TLS object.
542 @return The connection end used by the specified TLS connection.
547 TlsGetConnectionEnd (
552 Gets the cipher suite used by the specified TLS connection.
554 This function returns current cipher suite used by the specified
557 @param[in] Tls Pointer to the TLS object.
558 @param[in,out] CipherId The cipher suite used by the TLS object.
560 @retval EFI_SUCCESS The cipher suite was returned successfully.
561 @retval EFI_INVALID_PARAMETER The parameter is invalid.
562 @retval EFI_UNSUPPORTED Unsupported cipher suite.
567 TlsGetCurrentCipher (
569 IN OUT UINT16
*CipherId
573 Gets the compression methods used by the specified TLS connection.
575 This function returns current integrated compression methods used by
576 the specified TLS connection.
578 @param[in] Tls Pointer to the TLS object.
579 @param[in,out] CompressionId The current compression method used by
582 @retval EFI_SUCCESS The compression method was returned successfully.
583 @retval EFI_INVALID_PARAMETER The parameter is invalid.
584 @retval EFI_ABORTED Invalid Compression method.
585 @retval EFI_UNSUPPORTED This function is not supported.
590 TlsGetCurrentCompressionId (
592 IN OUT UINT8
*CompressionId
596 Gets the verification mode currently set in the TLS connection.
598 This function returns the peer verification mode currently set in the
599 specified TLS connection.
601 @param[in] Tls Pointer to the TLS object.
603 @return The verification mode set in the specified TLS connection.
613 Gets the session ID used by the specified TLS connection.
615 This function returns the TLS/SSL session ID currently used by the
616 specified TLS connection.
618 @param[in] Tls Pointer to the TLS object.
619 @param[in,out] SessionId Buffer to contain the returned session ID.
620 @param[in,out] SessionIdLen The length of Session ID in bytes.
622 @retval EFI_SUCCESS The Session ID was returned successfully.
623 @retval EFI_INVALID_PARAMETER The parameter is invalid.
624 @retval EFI_UNSUPPORTED Invalid TLS/SSL session.
631 IN OUT UINT8
*SessionId
,
632 IN OUT UINT16
*SessionIdLen
636 Gets the client random data used in the specified TLS connection.
638 This function returns the TLS/SSL client random data currently used in
639 the specified TLS connection.
641 @param[in] Tls Pointer to the TLS object.
642 @param[in,out] ClientRandom Buffer to contain the returned client
643 random data (32 bytes).
650 IN OUT UINT8
*ClientRandom
654 Gets the server random data used in the specified TLS connection.
656 This function returns the TLS/SSL server random data currently used in
657 the specified TLS connection.
659 @param[in] Tls Pointer to the TLS object.
660 @param[in,out] ServerRandom Buffer to contain the returned server
661 random data (32 bytes).
668 IN OUT UINT8
*ServerRandom
672 Gets the master key data used in the specified TLS connection.
674 This function returns the TLS/SSL master key material currently used in
675 the specified TLS connection.
677 @param[in] Tls Pointer to the TLS object.
678 @param[in,out] KeyMaterial Buffer to contain the returned key material.
680 @retval EFI_SUCCESS Key material was returned successfully.
681 @retval EFI_INVALID_PARAMETER The parameter is invalid.
682 @retval EFI_UNSUPPORTED Invalid TLS/SSL session.
689 IN OUT UINT8
*KeyMaterial
693 Gets the CA Certificate from the cert store.
695 This function returns the CA certificate for the chosen
698 @param[in] Tls Pointer to the TLS object.
699 @param[out] Data Pointer to the data buffer to receive the CA
700 certificate data sent to the client.
701 @param[in,out] DataSize The size of data buffer in bytes.
703 @retval EFI_SUCCESS The operation succeeded.
704 @retval EFI_UNSUPPORTED This function is not supported.
705 @retval EFI_BUFFER_TOO_SMALL The Data is too small to hold the data.
710 TlsGetCaCertificate (
713 IN OUT UINTN
*DataSize
717 Gets the local public Certificate set in the specified TLS object.
719 This function returns the local public certificate which was currently set
720 in the specified TLS object.
722 @param[in] Tls Pointer to the TLS object.
723 @param[out] Data Pointer to the data buffer to receive the local
725 @param[in,out] DataSize The size of data buffer in bytes.
727 @retval EFI_SUCCESS The operation succeeded.
728 @retval EFI_INVALID_PARAMETER The parameter is invalid.
729 @retval EFI_NOT_FOUND The certificate is not found.
730 @retval EFI_BUFFER_TOO_SMALL The Data is too small to hold the data.
735 TlsGetHostPublicCert (
738 IN OUT UINTN
*DataSize
742 Gets the local private key set in the specified TLS object.
744 This function returns the local private key data which was currently set
745 in the specified TLS object.
747 @param[in] Tls Pointer to the TLS object.
748 @param[out] Data Pointer to the data buffer to receive the local
750 @param[in,out] DataSize The size of data buffer in bytes.
752 @retval EFI_SUCCESS The operation succeeded.
753 @retval EFI_UNSUPPORTED This function is not supported.
754 @retval EFI_BUFFER_TOO_SMALL The Data is too small to hold the data.
759 TlsGetHostPrivateKey (
762 IN OUT UINTN
*DataSize
766 Gets the CA-supplied certificate revocation list data set in the specified
769 This function returns the CA-supplied certificate revocation list data which
770 was currently set in the specified TLS object.
772 @param[out] Data Pointer to the data buffer to receive the CRL data.
773 @param[in,out] DataSize The size of data buffer in bytes.
775 @retval EFI_SUCCESS The operation succeeded.
776 @retval EFI_UNSUPPORTED This function is not supported.
777 @retval EFI_BUFFER_TOO_SMALL The Data is too small to hold the data.
782 TlsGetCertRevocationList (
784 IN OUT UINTN
*DataSize
787 #endif // __TLS_LIB_H__