2 SSL/TLS Configuration Library Wrapper Implementation over OpenSSL.
4 Copyright (c) 2016 - 2018, Intel Corporation. All rights reserved.<BR>
5 (C) Copyright 2016 Hewlett Packard Enterprise Development LP<BR>
6 SPDX-License-Identifier: BSD-2-Clause-Patent
10 #include "InternalTlsLib.h"
14 // IANA/IETF defined Cipher Suite ID
18 // OpenSSL-used Cipher Suite String
20 CONST CHAR8
*OpensslCipher
;
22 // Length of OpensslCipher
24 UINTN OpensslCipherLength
;
28 // Create a TLS_CIPHER_MAPPING initializer from IanaCipher and OpensslCipher so
29 // that OpensslCipherLength is filled in automatically. IanaCipher must be an
30 // integer constant expression, and OpensslCipher must be a string literal.
32 #define MAP(IanaCipher, OpensslCipher) \
33 { (IanaCipher), (OpensslCipher), sizeof (OpensslCipher) - 1 }
36 // The mapping table between IANA/IETF Cipher Suite definitions and
37 // OpenSSL-used Cipher Suite name.
39 // Keep the table uniquely sorted by the IanaCipher field, in increasing order.
41 STATIC CONST TLS_CIPHER_MAPPING TlsCipherMappingTable
[] = {
42 MAP (0x0001, "NULL-MD5"), /// TLS_RSA_WITH_NULL_MD5
43 MAP (0x0002, "NULL-SHA"), /// TLS_RSA_WITH_NULL_SHA
44 MAP (0x0004, "RC4-MD5"), /// TLS_RSA_WITH_RC4_128_MD5
45 MAP (0x0005, "RC4-SHA"), /// TLS_RSA_WITH_RC4_128_SHA
46 MAP (0x000A, "DES-CBC3-SHA"), /// TLS_RSA_WITH_3DES_EDE_CBC_SHA, mandatory TLS 1.1
47 MAP (0x0016, "DHE-RSA-DES-CBC3-SHA"), /// TLS_DHE_RSA_WITH_3DES_EDE_CBC_SHA
48 MAP (0x002F, "AES128-SHA"), /// TLS_RSA_WITH_AES_128_CBC_SHA, mandatory TLS 1.2
49 MAP (0x0030, "DH-DSS-AES128-SHA"), /// TLS_DH_DSS_WITH_AES_128_CBC_SHA
50 MAP (0x0031, "DH-RSA-AES128-SHA"), /// TLS_DH_RSA_WITH_AES_128_CBC_SHA
51 MAP (0x0033, "DHE-RSA-AES128-SHA"), /// TLS_DHE_RSA_WITH_AES_128_CBC_SHA
52 MAP (0x0035, "AES256-SHA"), /// TLS_RSA_WITH_AES_256_CBC_SHA
53 MAP (0x0036, "DH-DSS-AES256-SHA"), /// TLS_DH_DSS_WITH_AES_256_CBC_SHA
54 MAP (0x0037, "DH-RSA-AES256-SHA"), /// TLS_DH_RSA_WITH_AES_256_CBC_SHA
55 MAP (0x0039, "DHE-RSA-AES256-SHA"), /// TLS_DHE_RSA_WITH_AES_256_CBC_SHA
56 MAP (0x003B, "NULL-SHA256"), /// TLS_RSA_WITH_NULL_SHA256
57 MAP (0x003C, "AES128-SHA256"), /// TLS_RSA_WITH_AES_128_CBC_SHA256
58 MAP (0x003D, "AES256-SHA256"), /// TLS_RSA_WITH_AES_256_CBC_SHA256
59 MAP (0x003E, "DH-DSS-AES128-SHA256"), /// TLS_DH_DSS_WITH_AES_128_CBC_SHA256
60 MAP (0x003F, "DH-RSA-AES128-SHA256"), /// TLS_DH_RSA_WITH_AES_128_CBC_SHA256
61 MAP (0x0067, "DHE-RSA-AES128-SHA256"), /// TLS_DHE_RSA_WITH_AES_128_CBC_SHA256
62 MAP (0x0068, "DH-DSS-AES256-SHA256"), /// TLS_DH_DSS_WITH_AES_256_CBC_SHA256
63 MAP (0x0069, "DH-RSA-AES256-SHA256"), /// TLS_DH_RSA_WITH_AES_256_CBC_SHA256
64 MAP (0x006B, "DHE-RSA-AES256-SHA256"), /// TLS_DHE_RSA_WITH_AES_256_CBC_SHA256
68 Gets the OpenSSL cipher suite mapping for the supplied IANA TLS cipher suite.
70 @param[in] CipherId The supplied IANA TLS cipher suite ID.
72 @return The corresponding OpenSSL cipher suite mapping if found,
77 CONST TLS_CIPHER_MAPPING
*
87 // Binary Search Cipher Mapping Table for IANA-OpenSSL Cipher Translation
90 Right
= ARRAY_SIZE (TlsCipherMappingTable
) - 1;
92 while (Right
>= Left
) {
93 Middle
= (Left
+ Right
) / 2;
95 if (CipherId
== TlsCipherMappingTable
[Middle
].IanaCipher
) {
97 // Translate IANA cipher suite ID to OpenSSL name.
99 return &TlsCipherMappingTable
[Middle
];
102 if (CipherId
< TlsCipherMappingTable
[Middle
].IanaCipher
) {
110 // No Cipher Mapping found, return NULL.
116 Set a new TLS/SSL method for a particular TLS object.
118 This function sets a new TLS/SSL method for a particular TLS object.
120 @param[in] Tls Pointer to a TLS object.
121 @param[in] MajorVer Major Version of TLS/SSL Protocol.
122 @param[in] MinorVer Minor Version of TLS/SSL Protocol.
124 @retval EFI_SUCCESS The TLS/SSL method was set successfully.
125 @retval EFI_INVALID_PARAMETER The parameter is invalid.
126 @retval EFI_UNSUPPORTED Unsupported TLS/SSL method.
137 TLS_CONNECTION
*TlsConn
;
140 TlsConn
= (TLS_CONNECTION
*)Tls
;
141 if ((TlsConn
== NULL
) || (TlsConn
->Ssl
== NULL
)) {
142 return EFI_INVALID_PARAMETER
;
145 ProtoVersion
= (MajorVer
<< 8) | MinorVer
;
148 // Bound TLS method to the particular specified version.
150 switch (ProtoVersion
) {
155 SSL_set_min_proto_version (TlsConn
->Ssl
, TLS1_VERSION
);
156 SSL_set_max_proto_version (TlsConn
->Ssl
, TLS1_VERSION
);
162 SSL_set_min_proto_version (TlsConn
->Ssl
, TLS1_1_VERSION
);
163 SSL_set_max_proto_version (TlsConn
->Ssl
, TLS1_1_VERSION
);
169 SSL_set_min_proto_version (TlsConn
->Ssl
, TLS1_2_VERSION
);
170 SSL_set_max_proto_version (TlsConn
->Ssl
, TLS1_2_VERSION
);
174 // Unsupported Protocol Version
176 return EFI_UNSUPPORTED
;
183 Set TLS object to work in client or server mode.
185 This function prepares a TLS object to work in client or server mode.
187 @param[in] Tls Pointer to a TLS object.
188 @param[in] IsServer Work in server mode.
190 @retval EFI_SUCCESS The TLS/SSL work mode was set successfully.
191 @retval EFI_INVALID_PARAMETER The parameter is invalid.
192 @retval EFI_UNSUPPORTED Unsupported TLS/SSL work mode.
197 TlsSetConnectionEnd (
202 TLS_CONNECTION
*TlsConn
;
204 TlsConn
= (TLS_CONNECTION
*)Tls
;
205 if ((TlsConn
== NULL
) || (TlsConn
->Ssl
== NULL
)) {
206 return EFI_INVALID_PARAMETER
;
211 // Set TLS to work in Client mode.
213 SSL_set_connect_state (TlsConn
->Ssl
);
216 // Set TLS to work in Server mode.
217 // It is unsupported for UEFI version currently.
219 // SSL_set_accept_state (TlsConn->Ssl);
220 return EFI_UNSUPPORTED
;
227 Set the ciphers list to be used by the TLS object.
229 This function sets the ciphers for use by a specified TLS object.
231 @param[in] Tls Pointer to a TLS object.
232 @param[in] CipherId Array of UINT16 cipher identifiers. Each UINT16
233 cipher identifier comes from the TLS Cipher Suite
234 Registry of the IANA, interpreting Byte1 and Byte2
235 in network (big endian) byte order.
236 @param[in] CipherNum The number of cipher in the list.
238 @retval EFI_SUCCESS The ciphers list was set successfully.
239 @retval EFI_INVALID_PARAMETER The parameter is invalid.
240 @retval EFI_UNSUPPORTED No supported TLS cipher was found in CipherId.
241 @retval EFI_OUT_OF_RESOURCES Memory allocation failed.
252 TLS_CONNECTION
*TlsConn
;
254 CONST TLS_CIPHER_MAPPING
**MappedCipher
;
255 UINTN MappedCipherBytes
;
256 UINTN MappedCipherCount
;
257 UINTN CipherStringSize
;
259 CONST TLS_CIPHER_MAPPING
*Mapping
;
261 CHAR8
*CipherStringPosition
;
263 TlsConn
= (TLS_CONNECTION
*)Tls
;
264 if ((TlsConn
== NULL
) || (TlsConn
->Ssl
== NULL
) || (CipherId
== NULL
)) {
265 return EFI_INVALID_PARAMETER
;
269 // Allocate the MappedCipher array for recording the mappings that we find
270 // for the input IANA identifiers in CipherId.
272 Status
= SafeUintnMult (
274 sizeof (*MappedCipher
),
277 if (EFI_ERROR (Status
)) {
278 return EFI_OUT_OF_RESOURCES
;
281 MappedCipher
= AllocatePool (MappedCipherBytes
);
282 if (MappedCipher
== NULL
) {
283 return EFI_OUT_OF_RESOURCES
;
287 // Map the cipher IDs, and count the number of bytes for the full
290 MappedCipherCount
= 0;
291 CipherStringSize
= 0;
292 for (Index
= 0; Index
< CipherNum
; Index
++) {
294 // Look up the IANA-to-OpenSSL mapping.
296 Mapping
= TlsGetCipherMapping (CipherId
[Index
]);
297 if (Mapping
== NULL
) {
300 "%a:%a: skipping CipherId=0x%04x\n",
306 // Skipping the cipher is valid because CipherId is an ordered
307 // preference list of ciphers, thus we can filter it as long as we
308 // don't change the relative order of elements on it.
314 // Accumulate Mapping->OpensslCipherLength into CipherStringSize. If this
315 // is not the first successful mapping, account for a colon (":") prefix
318 if (MappedCipherCount
> 0) {
319 Status
= SafeUintnAdd (CipherStringSize
, 1, &CipherStringSize
);
320 if (EFI_ERROR (Status
)) {
321 Status
= EFI_OUT_OF_RESOURCES
;
322 goto FreeMappedCipher
;
326 Status
= SafeUintnAdd (
328 Mapping
->OpensslCipherLength
,
331 if (EFI_ERROR (Status
)) {
332 Status
= EFI_OUT_OF_RESOURCES
;
333 goto FreeMappedCipher
;
337 // Record the mapping.
339 MappedCipher
[MappedCipherCount
++] = Mapping
;
343 // Verify that at least one IANA cipher ID could be mapped; account for the
344 // terminating NUL character in CipherStringSize; allocate CipherString.
346 if (MappedCipherCount
== 0) {
349 "%a:%a: no CipherId could be mapped\n",
353 Status
= EFI_UNSUPPORTED
;
354 goto FreeMappedCipher
;
357 Status
= SafeUintnAdd (CipherStringSize
, 1, &CipherStringSize
);
358 if (EFI_ERROR (Status
)) {
359 Status
= EFI_OUT_OF_RESOURCES
;
360 goto FreeMappedCipher
;
363 CipherString
= AllocatePool (CipherStringSize
);
364 if (CipherString
== NULL
) {
365 Status
= EFI_OUT_OF_RESOURCES
;
366 goto FreeMappedCipher
;
370 // Go over the collected mappings and populate CipherString.
372 CipherStringPosition
= CipherString
;
373 for (Index
= 0; Index
< MappedCipherCount
; Index
++) {
374 Mapping
= MappedCipher
[Index
];
376 // Append the colon (":") prefix except for the first mapping, then append
377 // Mapping->OpensslCipher.
380 *(CipherStringPosition
++) = ':';
384 CipherStringPosition
,
385 Mapping
->OpensslCipher
,
386 Mapping
->OpensslCipherLength
388 CipherStringPosition
+= Mapping
->OpensslCipherLength
;
392 // NUL-terminate CipherString.
394 *(CipherStringPosition
++) = '\0';
395 ASSERT (CipherStringPosition
== CipherString
+ CipherStringSize
);
398 // Log CipherString for debugging. CipherString can be very long if the
399 // caller provided a large CipherId array, so log CipherString in segments of
400 // 79 non-newline characters. (MAX_DEBUG_MESSAGE_LENGTH is usually 0x100 in
401 // DebugLib instances.)
407 FullLength
= CipherStringSize
- 1;
410 "%a:%a: CipherString={\n",
414 for (CipherStringPosition
= CipherString
;
415 CipherStringPosition
< CipherString
+ FullLength
;
416 CipherStringPosition
+= SegmentLength
)
418 SegmentLength
= FullLength
- (CipherStringPosition
- CipherString
);
419 if (SegmentLength
> 79) {
423 DEBUG ((DEBUG_VERBOSE
, "%.*a\n", SegmentLength
, CipherStringPosition
));
426 DEBUG ((DEBUG_VERBOSE
, "}\n"));
428 // Restore the pre-debug value of CipherStringPosition by skipping over the
431 CipherStringPosition
++;
432 ASSERT (CipherStringPosition
== CipherString
+ CipherStringSize
);
436 // Sets the ciphers for use by the Tls object.
438 if (SSL_set_cipher_list (TlsConn
->Ssl
, CipherString
) <= 0) {
439 Status
= EFI_UNSUPPORTED
;
440 goto FreeCipherString
;
443 Status
= EFI_SUCCESS
;
446 FreePool (CipherString
);
449 FreePool (MappedCipher
);
455 Set the compression method for TLS/SSL operations.
457 This function handles TLS/SSL integrated compression methods.
459 @param[in] CompMethod The compression method ID.
461 @retval EFI_SUCCESS The compression method for the communication was
463 @retval EFI_UNSUPPORTED Unsupported compression method.
468 TlsSetCompressionMethod (
478 if (CompMethod
== 0) {
480 // TLS defines one standard compression method, CompressionMethod.null (0),
481 // which specifies that data exchanged via the record protocol will not be compressed.
482 // So, return EFI_SUCCESS directly (RFC 3749).
485 } else if (CompMethod
== 1) {
488 return EFI_UNSUPPORTED
;
492 // Adds the compression method to the list of available
493 // compression methods.
495 Ret
= SSL_COMP_add_compression_method (CompMethod
, Cm
);
497 return EFI_UNSUPPORTED
;
504 Set peer certificate verification mode for the TLS connection.
506 This function sets the verification mode flags for the TLS connection.
508 @param[in] Tls Pointer to the TLS object.
509 @param[in] VerifyMode A set of logically or'ed verification mode flags.
519 TLS_CONNECTION
*TlsConn
;
521 TlsConn
= (TLS_CONNECTION
*)Tls
;
522 if ((TlsConn
== NULL
) || (TlsConn
->Ssl
== NULL
)) {
527 // Set peer certificate verification parameters with NULL callback.
529 SSL_set_verify (TlsConn
->Ssl
, VerifyMode
, NULL
);
533 Set the specified host name to be verified.
535 @param[in] Tls Pointer to the TLS object.
536 @param[in] Flags The setting flags during the validation.
537 @param[in] HostName The specified host name to be verified.
539 @retval EFI_SUCCESS The HostName setting was set successfully.
540 @retval EFI_INVALID_PARAMETER The parameter is invalid.
541 @retval EFI_ABORTED Invalid HostName setting.
552 TLS_CONNECTION
*TlsConn
;
553 X509_VERIFY_PARAM
*VerifyParam
;
554 UINTN BinaryAddressSize
;
555 UINT8 BinaryAddress
[MAX (NS_INADDRSZ
, NS_IN6ADDRSZ
)];
558 TlsConn
= (TLS_CONNECTION
*)Tls
;
559 if ((TlsConn
== NULL
) || (TlsConn
->Ssl
== NULL
) || (HostName
== NULL
)) {
560 return EFI_INVALID_PARAMETER
;
563 SSL_set_hostflags (TlsConn
->Ssl
, Flags
);
565 VerifyParam
= SSL_get0_param (TlsConn
->Ssl
);
566 ASSERT (VerifyParam
!= NULL
);
568 BinaryAddressSize
= 0;
569 if (inet_pton (AF_INET6
, HostName
, BinaryAddress
) == 1) {
570 BinaryAddressSize
= NS_IN6ADDRSZ
;
571 } else if (inet_pton (AF_INET
, HostName
, BinaryAddress
) == 1) {
572 BinaryAddressSize
= NS_INADDRSZ
;
575 if (BinaryAddressSize
> 0) {
578 "%a:%a: parsed \"%a\" as an IPv%c address "
583 (UINTN
)((BinaryAddressSize
== NS_IN6ADDRSZ
) ? '6' : '4')
585 ParamStatus
= X509_VERIFY_PARAM_set1_ip (
591 ParamStatus
= X509_VERIFY_PARAM_set1_host (VerifyParam
, HostName
, 0);
594 return (ParamStatus
== 1) ? EFI_SUCCESS
: EFI_ABORTED
;
598 Sets a TLS/SSL session ID to be used during TLS/SSL connect.
600 This function sets a session ID to be used when the TLS/SSL connection is
603 @param[in] Tls Pointer to the TLS object.
604 @param[in] SessionId Session ID data used for session resumption.
605 @param[in] SessionIdLen Length of Session ID in bytes.
607 @retval EFI_SUCCESS Session ID was set successfully.
608 @retval EFI_INVALID_PARAMETER The parameter is invalid.
609 @retval EFI_UNSUPPORTED No available session for ID setting.
617 IN UINT16 SessionIdLen
620 TLS_CONNECTION
*TlsConn
;
621 SSL_SESSION
*Session
;
623 TlsConn
= (TLS_CONNECTION
*)Tls
;
626 if ((TlsConn
== NULL
) || (TlsConn
->Ssl
== NULL
) || (SessionId
== NULL
)) {
627 return EFI_INVALID_PARAMETER
;
630 Session
= SSL_get_session (TlsConn
->Ssl
);
631 if (Session
== NULL
) {
632 return EFI_UNSUPPORTED
;
635 SSL_SESSION_set1_id (Session
, (const unsigned char *)SessionId
, SessionIdLen
);
641 Adds the CA to the cert store when requesting Server or Client authentication.
643 This function adds the CA certificate to the list of CAs when requesting
644 Server or Client authentication for the chosen TLS connection.
646 @param[in] Tls Pointer to the TLS object.
647 @param[in] Data Pointer to the data buffer of a DER-encoded binary
648 X.509 certificate or PEM-encoded X.509 certificate.
649 @param[in] DataSize The size of data buffer in bytes.
651 @retval EFI_SUCCESS The operation succeeded.
652 @retval EFI_INVALID_PARAMETER The parameter is invalid.
653 @retval EFI_OUT_OF_RESOURCES Required resources could not be allocated.
654 @retval EFI_ABORTED Invalid X.509 certificate.
659 TlsSetCaCertificate (
667 X509_STORE
*X509Store
;
669 TLS_CONNECTION
*TlsConn
;
677 Status
= EFI_SUCCESS
;
678 TlsConn
= (TLS_CONNECTION
*)Tls
;
681 if ((TlsConn
== NULL
) || (TlsConn
->Ssl
== NULL
) || (Data
== NULL
) || (DataSize
== 0)) {
682 return EFI_INVALID_PARAMETER
;
686 // DER-encoded binary X.509 certificate or PEM-encoded X.509 certificate.
687 // Determine whether certificate is from DER encoding, if so, translate it to X509 structure.
689 Cert
= d2i_X509 (NULL
, (const unsigned char **)&Data
, (long)DataSize
);
692 // Certificate is from PEM encoding.
694 BioCert
= BIO_new (BIO_s_mem ());
695 if (BioCert
== NULL
) {
696 Status
= EFI_OUT_OF_RESOURCES
;
700 if (BIO_write (BioCert
, Data
, (UINT32
)DataSize
) <= 0) {
701 Status
= EFI_ABORTED
;
705 Cert
= PEM_read_bio_X509 (BioCert
, NULL
, NULL
, NULL
);
707 Status
= EFI_ABORTED
;
712 SslCtx
= SSL_get_SSL_CTX (TlsConn
->Ssl
);
713 X509Store
= SSL_CTX_get_cert_store (SslCtx
);
714 if (X509Store
== NULL
) {
715 Status
= EFI_ABORTED
;
720 // Add certificate to X509 store
722 Ret
= X509_STORE_add_cert (X509Store
, Cert
);
724 ErrorCode
= ERR_peek_last_error ();
726 // Ignore "already in table" errors
728 if (!((ERR_GET_FUNC (ErrorCode
) == X509_F_X509_STORE_ADD_CERT
) &&
729 (ERR_GET_REASON (ErrorCode
) == X509_R_CERT_ALREADY_IN_HASH_TABLE
)))
731 Status
= EFI_ABORTED
;
737 if (BioCert
!= NULL
) {
749 Loads the local public certificate into the specified TLS object.
751 This function loads the X.509 certificate into the specified TLS object
754 @param[in] Tls Pointer to the TLS object.
755 @param[in] Data Pointer to the data buffer of a DER-encoded binary
756 X.509 certificate or PEM-encoded X.509 certificate.
757 @param[in] DataSize The size of data buffer in bytes.
759 @retval EFI_SUCCESS The operation succeeded.
760 @retval EFI_INVALID_PARAMETER The parameter is invalid.
761 @retval EFI_OUT_OF_RESOURCES Required resources could not be allocated.
762 @retval EFI_ABORTED Invalid X.509 certificate.
767 TlsSetHostPublicCert (
776 TLS_CONNECTION
*TlsConn
;
780 Status
= EFI_SUCCESS
;
781 TlsConn
= (TLS_CONNECTION
*)Tls
;
783 if ((TlsConn
== NULL
) || (TlsConn
->Ssl
== NULL
) || (Data
== NULL
) || (DataSize
== 0)) {
784 return EFI_INVALID_PARAMETER
;
788 // DER-encoded binary X.509 certificate or PEM-encoded X.509 certificate.
789 // Determine whether certificate is from DER encoding, if so, translate it to X509 structure.
791 Cert
= d2i_X509 (NULL
, (const unsigned char **)&Data
, (long)DataSize
);
794 // Certificate is from PEM encoding.
796 BioCert
= BIO_new (BIO_s_mem ());
797 if (BioCert
== NULL
) {
798 Status
= EFI_OUT_OF_RESOURCES
;
802 if (BIO_write (BioCert
, Data
, (UINT32
)DataSize
) <= 0) {
803 Status
= EFI_ABORTED
;
807 Cert
= PEM_read_bio_X509 (BioCert
, NULL
, NULL
, NULL
);
809 Status
= EFI_ABORTED
;
814 if (SSL_use_certificate (TlsConn
->Ssl
, Cert
) != 1) {
815 Status
= EFI_ABORTED
;
820 if (BioCert
!= NULL
) {
832 Adds the local private key to the specified TLS object.
834 This function adds the local private key (PEM-encoded RSA or PKCS#8 private
835 key) into the specified TLS object for TLS negotiation.
837 @param[in] Tls Pointer to the TLS object.
838 @param[in] Data Pointer to the data buffer of a PEM-encoded RSA
839 or PKCS#8 private key.
840 @param[in] DataSize The size of data buffer in bytes.
842 @retval EFI_SUCCESS The operation succeeded.
843 @retval EFI_UNSUPPORTED This function is not supported.
844 @retval EFI_ABORTED Invalid private key data.
849 TlsSetHostPrivateKey (
855 return EFI_UNSUPPORTED
;
859 Adds the CA-supplied certificate revocation list for certificate validation.
861 This function adds the CA-supplied certificate revocation list data for
862 certificate validity checking.
864 @param[in] Data Pointer to the data buffer of a DER-encoded CRL data.
865 @param[in] DataSize The size of data buffer in bytes.
867 @retval EFI_SUCCESS The operation succeeded.
868 @retval EFI_UNSUPPORTED This function is not supported.
869 @retval EFI_ABORTED Invalid CRL data.
874 TlsSetCertRevocationList (
879 return EFI_UNSUPPORTED
;
883 Gets the protocol version used by the specified TLS connection.
885 This function returns the protocol version used by the specified TLS
888 If Tls is NULL, then ASSERT().
890 @param[in] Tls Pointer to the TLS object.
892 @return The protocol version of the specified TLS connection.
901 TLS_CONNECTION
*TlsConn
;
903 TlsConn
= (TLS_CONNECTION
*)Tls
;
905 ASSERT (TlsConn
!= NULL
);
907 return (UINT16
)(SSL_version (TlsConn
->Ssl
));
911 Gets the connection end of the specified TLS connection.
913 This function returns the connection end (as client or as server) used by
914 the specified TLS connection.
916 If Tls is NULL, then ASSERT().
918 @param[in] Tls Pointer to the TLS object.
920 @return The connection end used by the specified TLS connection.
925 TlsGetConnectionEnd (
929 TLS_CONNECTION
*TlsConn
;
931 TlsConn
= (TLS_CONNECTION
*)Tls
;
933 ASSERT (TlsConn
!= NULL
);
935 return (UINT8
)SSL_is_server (TlsConn
->Ssl
);
939 Gets the cipher suite used by the specified TLS connection.
941 This function returns current cipher suite used by the specified
944 @param[in] Tls Pointer to the TLS object.
945 @param[in,out] CipherId The cipher suite used by the TLS object.
947 @retval EFI_SUCCESS The cipher suite was returned successfully.
948 @retval EFI_INVALID_PARAMETER The parameter is invalid.
949 @retval EFI_UNSUPPORTED Unsupported cipher suite.
954 TlsGetCurrentCipher (
956 IN OUT UINT16
*CipherId
959 TLS_CONNECTION
*TlsConn
;
960 CONST SSL_CIPHER
*Cipher
;
962 TlsConn
= (TLS_CONNECTION
*)Tls
;
965 if ((TlsConn
== NULL
) || (TlsConn
->Ssl
== NULL
) || (CipherId
== NULL
)) {
966 return EFI_INVALID_PARAMETER
;
969 Cipher
= SSL_get_current_cipher (TlsConn
->Ssl
);
970 if (Cipher
== NULL
) {
971 return EFI_UNSUPPORTED
;
974 *CipherId
= (SSL_CIPHER_get_id (Cipher
)) & 0xFFFF;
980 Gets the compression methods used by the specified TLS connection.
982 This function returns current integrated compression methods used by
983 the specified TLS connection.
985 @param[in] Tls Pointer to the TLS object.
986 @param[in,out] CompressionId The current compression method used by
989 @retval EFI_SUCCESS The compression method was returned successfully.
990 @retval EFI_INVALID_PARAMETER The parameter is invalid.
991 @retval EFI_ABORTED Invalid Compression method.
992 @retval EFI_UNSUPPORTED This function is not supported.
997 TlsGetCurrentCompressionId (
999 IN OUT UINT8
*CompressionId
1002 return EFI_UNSUPPORTED
;
1006 Gets the verification mode currently set in the TLS connection.
1008 This function returns the peer verification mode currently set in the
1009 specified TLS connection.
1011 If Tls is NULL, then ASSERT().
1013 @param[in] Tls Pointer to the TLS object.
1015 @return The verification mode set in the specified TLS connection.
1024 TLS_CONNECTION
*TlsConn
;
1026 TlsConn
= (TLS_CONNECTION
*)Tls
;
1028 ASSERT (TlsConn
!= NULL
);
1030 return SSL_get_verify_mode (TlsConn
->Ssl
);
1034 Gets the session ID used by the specified TLS connection.
1036 This function returns the TLS/SSL session ID currently used by the
1037 specified TLS connection.
1039 @param[in] Tls Pointer to the TLS object.
1040 @param[in,out] SessionId Buffer to contain the returned session ID.
1041 @param[in,out] SessionIdLen The length of Session ID in bytes.
1043 @retval EFI_SUCCESS The Session ID was returned successfully.
1044 @retval EFI_INVALID_PARAMETER The parameter is invalid.
1045 @retval EFI_UNSUPPORTED Invalid TLS/SSL session.
1052 IN OUT UINT8
*SessionId
,
1053 IN OUT UINT16
*SessionIdLen
1056 TLS_CONNECTION
*TlsConn
;
1057 SSL_SESSION
*Session
;
1058 CONST UINT8
*SslSessionId
;
1060 TlsConn
= (TLS_CONNECTION
*)Tls
;
1063 if ((TlsConn
== NULL
) || (TlsConn
->Ssl
== NULL
) || (SessionId
== NULL
) || (SessionIdLen
== NULL
)) {
1064 return EFI_INVALID_PARAMETER
;
1067 Session
= SSL_get_session (TlsConn
->Ssl
);
1068 if (Session
== NULL
) {
1069 return EFI_UNSUPPORTED
;
1072 SslSessionId
= SSL_SESSION_get_id (Session
, (unsigned int *)SessionIdLen
);
1073 CopyMem (SessionId
, SslSessionId
, *SessionIdLen
);
1079 Gets the client random data used in the specified TLS connection.
1081 This function returns the TLS/SSL client random data currently used in
1082 the specified TLS connection.
1084 @param[in] Tls Pointer to the TLS object.
1085 @param[in,out] ClientRandom Buffer to contain the returned client
1086 random data (32 bytes).
1091 TlsGetClientRandom (
1093 IN OUT UINT8
*ClientRandom
1096 TLS_CONNECTION
*TlsConn
;
1098 TlsConn
= (TLS_CONNECTION
*)Tls
;
1100 if ((TlsConn
== NULL
) || (TlsConn
->Ssl
== NULL
) || (ClientRandom
== NULL
)) {
1104 SSL_get_client_random (TlsConn
->Ssl
, ClientRandom
, SSL3_RANDOM_SIZE
);
1108 Gets the server random data used in the specified TLS connection.
1110 This function returns the TLS/SSL server random data currently used in
1111 the specified TLS connection.
1113 @param[in] Tls Pointer to the TLS object.
1114 @param[in,out] ServerRandom Buffer to contain the returned server
1115 random data (32 bytes).
1120 TlsGetServerRandom (
1122 IN OUT UINT8
*ServerRandom
1125 TLS_CONNECTION
*TlsConn
;
1127 TlsConn
= (TLS_CONNECTION
*)Tls
;
1129 if ((TlsConn
== NULL
) || (TlsConn
->Ssl
== NULL
) || (ServerRandom
== NULL
)) {
1133 SSL_get_server_random (TlsConn
->Ssl
, ServerRandom
, SSL3_RANDOM_SIZE
);
1137 Gets the master key data used in the specified TLS connection.
1139 This function returns the TLS/SSL master key material currently used in
1140 the specified TLS connection.
1142 @param[in] Tls Pointer to the TLS object.
1143 @param[in,out] KeyMaterial Buffer to contain the returned key material.
1145 @retval EFI_SUCCESS Key material was returned successfully.
1146 @retval EFI_INVALID_PARAMETER The parameter is invalid.
1147 @retval EFI_UNSUPPORTED Invalid TLS/SSL session.
1154 IN OUT UINT8
*KeyMaterial
1157 TLS_CONNECTION
*TlsConn
;
1158 SSL_SESSION
*Session
;
1160 TlsConn
= (TLS_CONNECTION
*)Tls
;
1163 if ((TlsConn
== NULL
) || (TlsConn
->Ssl
== NULL
) || (KeyMaterial
== NULL
)) {
1164 return EFI_INVALID_PARAMETER
;
1167 Session
= SSL_get_session (TlsConn
->Ssl
);
1169 if (Session
== NULL
) {
1170 return EFI_UNSUPPORTED
;
1173 SSL_SESSION_get_master_key (Session
, KeyMaterial
, SSL3_MASTER_SECRET_SIZE
);
1179 Gets the CA Certificate from the cert store.
1181 This function returns the CA certificate for the chosen
1184 @param[in] Tls Pointer to the TLS object.
1185 @param[out] Data Pointer to the data buffer to receive the CA
1186 certificate data sent to the client.
1187 @param[in,out] DataSize The size of data buffer in bytes.
1189 @retval EFI_SUCCESS The operation succeeded.
1190 @retval EFI_UNSUPPORTED This function is not supported.
1191 @retval EFI_BUFFER_TOO_SMALL The Data is too small to hold the data.
1196 TlsGetCaCertificate (
1199 IN OUT UINTN
*DataSize
1202 return EFI_UNSUPPORTED
;
1206 Gets the local public Certificate set in the specified TLS object.
1208 This function returns the local public certificate which was currently set
1209 in the specified TLS object.
1211 @param[in] Tls Pointer to the TLS object.
1212 @param[out] Data Pointer to the data buffer to receive the local
1214 @param[in,out] DataSize The size of data buffer in bytes.
1216 @retval EFI_SUCCESS The operation succeeded.
1217 @retval EFI_INVALID_PARAMETER The parameter is invalid.
1218 @retval EFI_NOT_FOUND The certificate is not found.
1219 @retval EFI_BUFFER_TOO_SMALL The Data is too small to hold the data.
1224 TlsGetHostPublicCert (
1227 IN OUT UINTN
*DataSize
1231 TLS_CONNECTION
*TlsConn
;
1234 TlsConn
= (TLS_CONNECTION
*)Tls
;
1236 if ((TlsConn
== NULL
) || (TlsConn
->Ssl
== NULL
) || (DataSize
== NULL
) || ((*DataSize
!= 0) && (Data
== NULL
))) {
1237 return EFI_INVALID_PARAMETER
;
1240 Cert
= SSL_get_certificate (TlsConn
->Ssl
);
1242 return EFI_NOT_FOUND
;
1246 // Only DER encoding is supported currently.
1248 if (*DataSize
< (UINTN
)i2d_X509 (Cert
, NULL
)) {
1249 *DataSize
= (UINTN
)i2d_X509 (Cert
, NULL
);
1250 return EFI_BUFFER_TOO_SMALL
;
1253 *DataSize
= (UINTN
)i2d_X509 (Cert
, (unsigned char **)&Data
);
1259 Gets the local private key set in the specified TLS object.
1261 This function returns the local private key data which was currently set
1262 in the specified TLS object.
1264 @param[in] Tls Pointer to the TLS object.
1265 @param[out] Data Pointer to the data buffer to receive the local
1267 @param[in,out] DataSize The size of data buffer in bytes.
1269 @retval EFI_SUCCESS The operation succeeded.
1270 @retval EFI_UNSUPPORTED This function is not supported.
1271 @retval EFI_BUFFER_TOO_SMALL The Data is too small to hold the data.
1276 TlsGetHostPrivateKey (
1279 IN OUT UINTN
*DataSize
1282 return EFI_UNSUPPORTED
;
1286 Gets the CA-supplied certificate revocation list data set in the specified
1289 This function returns the CA-supplied certificate revocation list data which
1290 was currently set in the specified TLS object.
1292 @param[out] Data Pointer to the data buffer to receive the CRL data.
1293 @param[in,out] DataSize The size of data buffer in bytes.
1295 @retval EFI_SUCCESS The operation succeeded.
1296 @retval EFI_UNSUPPORTED This function is not supported.
1297 @retval EFI_BUFFER_TOO_SMALL The Data is too small to hold the data.
1302 TlsGetCertRevocationList (
1304 IN OUT UINTN
*DataSize
1307 return EFI_UNSUPPORTED
;