]>
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 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.
25 @retval TRUE The OpenSSL library has been initialized.
26 @retval FALSE Failed to initialize the OpenSSL library.
36 Free an allocated SSL_CTX object.
38 @param[in] TlsCtx Pointer to the SSL_CTX object to be released.
48 Creates a new SSL_CTX object as framework to establish TLS/SSL enabled
51 @param[in] MajorVer Major Version of TLS/SSL Protocol.
52 @param[in] MinorVer Minor Version of TLS/SSL Protocol.
54 @return Pointer to an allocated SSL_CTX object.
55 If the creation failed, TlsCtxNew() returns NULL.
66 Free an allocated TLS object.
68 This function removes the TLS object pointed to by Tls and frees up the
69 allocated memory. If Tls is NULL, nothing is done.
71 @param[in] Tls Pointer to the TLS object to be freed.
81 Create a new TLS object for a connection.
83 This function creates a new TLS object for a connection. The new object
84 inherits the setting of the underlying context TlsCtx: connection method,
85 options, verification setting.
87 @param[in] TlsCtx Pointer to the SSL_CTX object.
89 @return Pointer to an allocated SSL object.
90 If the creation failed, TlsNew() returns NULL.
100 Checks if the TLS handshake was done.
102 This function will check if the specified TLS handshake was done.
104 @param[in] Tls Pointer to the TLS object for handshake state checking.
106 @retval TRUE The TLS handshake was done.
107 @retval FALSE The TLS handshake was not done.
117 Perform a TLS/SSL handshake.
119 This function will perform a TLS/SSL handshake.
121 @param[in] Tls Pointer to the TLS object for handshake operation.
122 @param[in] BufferIn Pointer to the most recently received TLS Handshake packet.
123 @param[in] BufferInSize Packet size in bytes for the most recently received TLS
125 @param[out] BufferOut Pointer to the buffer to hold the built packet.
126 @param[in, out] BufferOutSize Pointer to the buffer size in bytes. On input, it is
127 the buffer size provided by the caller. On output, it
128 is the buffer size in fact needed to contain the
131 @retval EFI_SUCCESS The required TLS packet is built successfully.
132 @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:
134 BufferIn is NULL but BufferInSize is NOT 0.
135 BufferInSize is 0 but BufferIn is NOT NULL.
136 BufferOutSize is NULL.
137 BufferOut is NULL if *BufferOutSize is not zero.
138 @retval EFI_BUFFER_TOO_SMALL BufferOutSize is too small to hold the response packet.
139 @retval EFI_ABORTED Something wrong during handshake.
146 IN UINT8
*BufferIn
, OPTIONAL
147 IN UINTN BufferInSize
, OPTIONAL
148 OUT UINT8
*BufferOut
, OPTIONAL
149 IN OUT UINTN
*BufferOutSize
153 Handle Alert message recorded in BufferIn. If BufferIn is NULL and BufferInSize is zero,
154 TLS session has errors and the response packet needs to be Alert message based on error type.
156 @param[in] Tls Pointer to the TLS object for state checking.
157 @param[in] BufferIn Pointer to the most recently received TLS Alert packet.
158 @param[in] BufferInSize Packet size in bytes for the most recently received TLS
160 @param[out] BufferOut Pointer to the buffer to hold the built packet.
161 @param[in, out] BufferOutSize Pointer to the buffer size in bytes. On input, it is
162 the buffer size provided by the caller. On output, it
163 is the buffer size in fact needed to contain the
166 @retval EFI_SUCCESS The required TLS packet is built successfully.
167 @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:
169 BufferIn is NULL but BufferInSize is NOT 0.
170 BufferInSize is 0 but BufferIn is NOT NULL.
171 BufferOutSize is NULL.
172 BufferOut is NULL if *BufferOutSize is not zero.
173 @retval EFI_ABORTED An error occurred.
174 @retval EFI_BUFFER_TOO_SMALL BufferOutSize is too small to hold the response packet.
181 IN UINT8
*BufferIn
, OPTIONAL
182 IN UINTN BufferInSize
, OPTIONAL
183 OUT UINT8
*BufferOut
, OPTIONAL
184 IN OUT UINTN
*BufferOutSize
188 Build the CloseNotify packet.
190 @param[in] Tls Pointer to the TLS object for state checking.
191 @param[in, out] Buffer Pointer to the buffer to hold the built packet.
192 @param[in, out] BufferSize Pointer to the buffer size in bytes. On input, it is
193 the buffer size provided by the caller. On output, it
194 is the buffer size in fact needed to contain the
197 @retval EFI_SUCCESS The required TLS packet is built successfully.
198 @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:
201 Buffer is NULL if *BufferSize is not zero.
202 @retval EFI_BUFFER_TOO_SMALL BufferSize is too small to hold the response packet.
209 IN OUT UINT8
*Buffer
,
210 IN OUT UINTN
*BufferSize
214 Attempts to read bytes from one TLS object and places the data in Buffer.
216 This function will attempt to read BufferSize bytes from the TLS object
217 and places the data in Buffer.
219 @param[in] Tls Pointer to the TLS object.
220 @param[in,out] Buffer Pointer to the buffer to store the data.
221 @param[in] BufferSize The size of Buffer in bytes.
223 @retval >0 The amount of data successfully read from the TLS object.
224 @retval <=0 No data was successfully read.
236 Attempts to write data from the buffer to TLS object.
238 This function will attempt to write BufferSize bytes data from the Buffer
241 @param[in] Tls Pointer to the TLS object.
242 @param[in] Buffer Pointer to the data buffer.
243 @param[in] BufferSize The size of Buffer in bytes.
245 @retval >0 The amount of data successfully written to the TLS object.
246 @retval <=0 No data was successfully written.
258 Attempts to read bytes from the specified TLS connection into the buffer.
260 This function tries to read BufferSize bytes data from the specified TLS
261 connection into the Buffer.
263 @param[in] Tls Pointer to the TLS connection for data reading.
264 @param[in,out] Buffer Pointer to the data buffer.
265 @param[in] BufferSize The size of Buffer in bytes.
267 @retval >0 The read operation was successful, and return value is the
268 number of bytes actually read from the TLS connection.
269 @retval <=0 The read operation was not successful.
281 Attempts to write data to a TLS connection.
283 This function tries to write BufferSize bytes data from the Buffer into the
284 specified TLS connection.
286 @param[in] Tls Pointer to the TLS connection for data writing.
287 @param[in] Buffer Pointer to the data buffer.
288 @param[in] BufferSize The size of Buffer in bytes.
290 @retval >0 The write operation was successful, and return value is the
291 number of bytes actually written to the TLS connection.
292 @retval <=0 The write operation was not successful.
304 Set a new TLS/SSL method for a particular TLS object.
306 This function sets a new TLS/SSL method for a particular TLS object.
308 @param[in] Tls Pointer to a TLS object.
309 @param[in] MajorVer Major Version of TLS/SSL Protocol.
310 @param[in] MinorVer Minor Version of TLS/SSL Protocol.
312 @retval EFI_SUCCESS The TLS/SSL method was set successfully.
313 @retval EFI_INVALID_PARAMETER The parameter is invalid.
314 @retval EFI_UNSUPPORTED Unsupported TLS/SSL method.
326 Set TLS object to work in client or server mode.
328 This function prepares a TLS object to work in client or server mode.
330 @param[in] Tls Pointer to a TLS object.
331 @param[in] IsServer Work in server mode.
333 @retval EFI_SUCCESS The TLS/SSL work mode was set successfully.
334 @retval EFI_INVALID_PARAMETER The parameter is invalid.
335 @retval EFI_UNSUPPORTED Unsupported TLS/SSL work mode.
340 TlsSetConnectionEnd (
346 Set the ciphers list to be used by the TLS object.
348 This function sets the ciphers for use by a specified TLS object.
350 @param[in] Tls Pointer to a TLS object.
351 @param[in] CipherId Pointer to a string that contains one or more
352 ciphers separated by a colon.
353 @param[in] CipherNum The number of cipher in the list.
355 @retval EFI_SUCCESS The ciphers list was set successfully.
356 @retval EFI_INVALID_PARAMETER The parameter is invalid.
357 @retval EFI_UNSUPPORTED Unsupported TLS cipher in the list.
369 Set the compression method for TLS/SSL operations.
371 This function handles TLS/SSL integrated compression methods.
373 @param[in] CompMethod The compression method ID.
375 @retval EFI_SUCCESS The compression method for the communication was
377 @retval EFI_UNSUPPORTED Unsupported compression method.
382 TlsSetCompressionMethod (
387 Set peer certificate verification mode for the TLS connection.
389 This function sets the verification mode flags for the TLS connection.
391 @param[in] Tls Pointer to the TLS object.
392 @param[in] VerifyMode A set of logically or'ed verification mode flags.
403 Sets a TLS/SSL session ID to be used during TLS/SSL connect.
405 This function sets a session ID to be used when the TLS/SSL connection is
408 @param[in] Tls Pointer to the TLS object.
409 @param[in] SessionId Session ID data used for session resumption.
410 @param[in] SessionIdLen Length of Session ID in bytes.
412 @retval EFI_SUCCESS Session ID was set successfully.
413 @retval EFI_INVALID_PARAMETER The parameter is invalid.
414 @retval EFI_UNSUPPORTED No available session for ID setting.
422 IN UINT16 SessionIdLen
426 Adds the CA to the cert store when requesting Server or Client authentication.
428 This function adds the CA certificate to the list of CAs when requesting
429 Server or Client authentication for the chosen TLS connection.
431 @param[in] Tls Pointer to the TLS object.
432 @param[in] Data Pointer to the data buffer of a DER-encoded binary
433 X.509 certificate or PEM-encoded X.509 certificate.
434 @param[in] DataSize The size of data buffer in bytes.
436 @retval EFI_SUCCESS The operation succeeded.
437 @retval EFI_INVALID_PARAMETER The parameter is invalid.
438 @retval EFI_OUT_OF_RESOURCES Required resources could not be allocated.
439 @retval EFI_ABORTED Invalid X.509 certificate.
444 TlsSetCaCertificate (
451 Loads the local public certificate into the specified TLS object.
453 This function loads the X.509 certificate into the specified TLS object
456 @param[in] Tls Pointer to the TLS object.
457 @param[in] Data Pointer to the data buffer of a DER-encoded binary
458 X.509 certificate or PEM-encoded X.509 certificate.
459 @param[in] DataSize The size of data buffer in bytes.
461 @retval EFI_SUCCESS The operation succeeded.
462 @retval EFI_INVALID_PARAMETER The parameter is invalid.
463 @retval EFI_OUT_OF_RESOURCES Required resources could not be allocated.
464 @retval EFI_ABORTED Invalid X.509 certificate.
469 TlsSetHostPublicCert (
476 Adds the local private key to the specified TLS object.
478 This function adds the local private key (PEM-encoded RSA or PKCS#8 private
479 key) into the specified TLS object for TLS negotiation.
481 @param[in] Tls Pointer to the TLS object.
482 @param[in] Data Pointer to the data buffer of a PEM-encoded RSA
483 or PKCS#8 private key.
484 @param[in] DataSize The size of data buffer in bytes.
486 @retval EFI_SUCCESS The operation succeeded.
487 @retval EFI_UNSUPPORTED This function is not supported.
488 @retval EFI_ABORTED Invalid private key data.
493 TlsSetHostPrivateKey (
500 Adds the CA-supplied certificate revocation list for certificate validation.
502 This function adds the CA-supplied certificate revocation list data for
503 certificate validity checking.
505 @param[in] Data Pointer to the data buffer of a DER-encoded CRL data.
506 @param[in] DataSize The size of data buffer in bytes.
508 @retval EFI_SUCCESS The operation succeeded.
509 @retval EFI_UNSUPPORTED This function is not supported.
510 @retval EFI_ABORTED Invalid CRL data.
515 TlsSetCertRevocationList (
521 Gets the protocol version used by the specified TLS connection.
523 This function returns the protocol version used by the specified TLS
526 If Tls is NULL, then ASSERT().
528 @param[in] Tls Pointer to the TLS object.
530 @return The protocol version of the specified TLS connection.
540 Gets the connection end of the specified TLS connection.
542 This function returns the connection end (as client or as server) used by
543 the specified TLS connection.
545 If Tls is NULL, then ASSERT().
547 @param[in] Tls Pointer to the TLS object.
549 @return The connection end used by the specified TLS connection.
554 TlsGetConnectionEnd (
559 Gets the cipher suite used by the specified TLS connection.
561 This function returns current cipher suite used by the specified
564 @param[in] Tls Pointer to the TLS object.
565 @param[in,out] CipherId The cipher suite used by the TLS object.
567 @retval EFI_SUCCESS The cipher suite was returned successfully.
568 @retval EFI_INVALID_PARAMETER The parameter is invalid.
569 @retval EFI_UNSUPPORTED Unsupported cipher suite.
574 TlsGetCurrentCipher (
576 IN OUT UINT16
*CipherId
580 Gets the compression methods used by the specified TLS connection.
582 This function returns current integrated compression methods used by
583 the specified TLS connection.
585 @param[in] Tls Pointer to the TLS object.
586 @param[in,out] CompressionId The current compression method used by
589 @retval EFI_SUCCESS The compression method was returned successfully.
590 @retval EFI_INVALID_PARAMETER The parameter is invalid.
591 @retval EFI_ABORTED Invalid Compression method.
592 @retval EFI_UNSUPPORTED This function is not supported.
597 TlsGetCurrentCompressionId (
599 IN OUT UINT8
*CompressionId
603 Gets the verification mode currently set in the TLS connection.
605 This function returns the peer verification mode currently set in the
606 specified TLS connection.
608 If Tls is NULL, then ASSERT().
610 @param[in] Tls Pointer to the TLS object.
612 @return The verification mode set in the specified TLS connection.
622 Gets the session ID used by the specified TLS connection.
624 This function returns the TLS/SSL session ID currently used by the
625 specified TLS connection.
627 @param[in] Tls Pointer to the TLS object.
628 @param[in,out] SessionId Buffer to contain the returned session ID.
629 @param[in,out] SessionIdLen The length of Session ID in bytes.
631 @retval EFI_SUCCESS The Session ID was returned successfully.
632 @retval EFI_INVALID_PARAMETER The parameter is invalid.
633 @retval EFI_UNSUPPORTED Invalid TLS/SSL session.
640 IN OUT UINT8
*SessionId
,
641 IN OUT UINT16
*SessionIdLen
645 Gets the client random data used in the specified TLS connection.
647 This function returns the TLS/SSL client random data currently used in
648 the specified TLS connection.
650 @param[in] Tls Pointer to the TLS object.
651 @param[in,out] ClientRandom Buffer to contain the returned client
652 random data (32 bytes).
659 IN OUT UINT8
*ClientRandom
663 Gets the server random data used in the specified TLS connection.
665 This function returns the TLS/SSL server random data currently used in
666 the specified TLS connection.
668 @param[in] Tls Pointer to the TLS object.
669 @param[in,out] ServerRandom Buffer to contain the returned server
670 random data (32 bytes).
677 IN OUT UINT8
*ServerRandom
681 Gets the master key data used in the specified TLS connection.
683 This function returns the TLS/SSL master key material currently used in
684 the specified TLS connection.
686 @param[in] Tls Pointer to the TLS object.
687 @param[in,out] KeyMaterial Buffer to contain the returned key material.
689 @retval EFI_SUCCESS Key material was returned successfully.
690 @retval EFI_INVALID_PARAMETER The parameter is invalid.
691 @retval EFI_UNSUPPORTED Invalid TLS/SSL session.
698 IN OUT UINT8
*KeyMaterial
702 Gets the CA Certificate from the cert store.
704 This function returns the CA certificate for the chosen
707 @param[in] Tls Pointer to the TLS object.
708 @param[out] Data Pointer to the data buffer to receive the CA
709 certificate data sent to the client.
710 @param[in,out] DataSize The size of data buffer in bytes.
712 @retval EFI_SUCCESS The operation succeeded.
713 @retval EFI_UNSUPPORTED This function is not supported.
714 @retval EFI_BUFFER_TOO_SMALL The Data is too small to hold the data.
719 TlsGetCaCertificate (
722 IN OUT UINTN
*DataSize
726 Gets the local public Certificate set in the specified TLS object.
728 This function returns the local public certificate which was currently set
729 in the specified TLS object.
731 @param[in] Tls Pointer to the TLS object.
732 @param[out] Data Pointer to the data buffer to receive the local
734 @param[in,out] DataSize The size of data buffer in bytes.
736 @retval EFI_SUCCESS The operation succeeded.
737 @retval EFI_INVALID_PARAMETER The parameter is invalid.
738 @retval EFI_NOT_FOUND The certificate is not found.
739 @retval EFI_BUFFER_TOO_SMALL The Data is too small to hold the data.
744 TlsGetHostPublicCert (
747 IN OUT UINTN
*DataSize
751 Gets the local private key set in the specified TLS object.
753 This function returns the local private key data which was currently set
754 in the specified TLS object.
756 @param[in] Tls Pointer to the TLS object.
757 @param[out] Data Pointer to the data buffer to receive the local
759 @param[in,out] DataSize The size of data buffer in bytes.
761 @retval EFI_SUCCESS The operation succeeded.
762 @retval EFI_UNSUPPORTED This function is not supported.
763 @retval EFI_BUFFER_TOO_SMALL The Data is too small to hold the data.
768 TlsGetHostPrivateKey (
771 IN OUT UINTN
*DataSize
775 Gets the CA-supplied certificate revocation list data set in the specified
778 This function returns the CA-supplied certificate revocation list data which
779 was currently set in the specified TLS object.
781 @param[out] Data Pointer to the data buffer to receive the CRL data.
782 @param[in,out] DataSize The size of data buffer in bytes.
784 @retval EFI_SUCCESS The operation succeeded.
785 @retval EFI_UNSUPPORTED This function is not supported.
786 @retval EFI_BUFFER_TOO_SMALL The Data is too small to hold the data.
791 TlsGetCertRevocationList (
793 IN OUT UINTN
*DataSize
796 #endif // __TLS_LIB_H__