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 (CipherNum
, sizeof (*MappedCipher
),
274 if (EFI_ERROR (Status
)) {
275 return EFI_OUT_OF_RESOURCES
;
277 MappedCipher
= AllocatePool (MappedCipherBytes
);
278 if (MappedCipher
== NULL
) {
279 return EFI_OUT_OF_RESOURCES
;
283 // Map the cipher IDs, and count the number of bytes for the full
286 MappedCipherCount
= 0;
287 CipherStringSize
= 0;
288 for (Index
= 0; Index
< CipherNum
; Index
++) {
290 // Look up the IANA-to-OpenSSL mapping.
292 Mapping
= TlsGetCipherMapping (CipherId
[Index
]);
293 if (Mapping
== NULL
) {
294 DEBUG ((DEBUG_VERBOSE
, "%a:%a: skipping CipherId=0x%04x\n",
295 gEfiCallerBaseName
, __FUNCTION__
, CipherId
[Index
]));
297 // Skipping the cipher is valid because CipherId is an ordered
298 // preference list of ciphers, thus we can filter it as long as we
299 // don't change the relative order of elements on it.
304 // Accumulate Mapping->OpensslCipherLength into CipherStringSize. If this
305 // is not the first successful mapping, account for a colon (":") prefix
308 if (MappedCipherCount
> 0) {
309 Status
= SafeUintnAdd (CipherStringSize
, 1, &CipherStringSize
);
310 if (EFI_ERROR (Status
)) {
311 Status
= EFI_OUT_OF_RESOURCES
;
312 goto FreeMappedCipher
;
315 Status
= SafeUintnAdd (CipherStringSize
, Mapping
->OpensslCipherLength
,
317 if (EFI_ERROR (Status
)) {
318 Status
= EFI_OUT_OF_RESOURCES
;
319 goto FreeMappedCipher
;
322 // Record the mapping.
324 MappedCipher
[MappedCipherCount
++] = Mapping
;
328 // Verify that at least one IANA cipher ID could be mapped; account for the
329 // terminating NUL character in CipherStringSize; allocate CipherString.
331 if (MappedCipherCount
== 0) {
332 DEBUG ((DEBUG_ERROR
, "%a:%a: no CipherId could be mapped\n",
333 gEfiCallerBaseName
, __FUNCTION__
));
334 Status
= EFI_UNSUPPORTED
;
335 goto FreeMappedCipher
;
337 Status
= SafeUintnAdd (CipherStringSize
, 1, &CipherStringSize
);
338 if (EFI_ERROR (Status
)) {
339 Status
= EFI_OUT_OF_RESOURCES
;
340 goto FreeMappedCipher
;
342 CipherString
= AllocatePool (CipherStringSize
);
343 if (CipherString
== NULL
) {
344 Status
= EFI_OUT_OF_RESOURCES
;
345 goto FreeMappedCipher
;
349 // Go over the collected mappings and populate CipherString.
351 CipherStringPosition
= CipherString
;
352 for (Index
= 0; Index
< MappedCipherCount
; Index
++) {
353 Mapping
= MappedCipher
[Index
];
355 // Append the colon (":") prefix except for the first mapping, then append
356 // Mapping->OpensslCipher.
359 *(CipherStringPosition
++) = ':';
361 CopyMem (CipherStringPosition
, Mapping
->OpensslCipher
,
362 Mapping
->OpensslCipherLength
);
363 CipherStringPosition
+= Mapping
->OpensslCipherLength
;
367 // NUL-terminate CipherString.
369 *(CipherStringPosition
++) = '\0';
370 ASSERT (CipherStringPosition
== CipherString
+ CipherStringSize
);
373 // Log CipherString for debugging. CipherString can be very long if the
374 // caller provided a large CipherId array, so log CipherString in segments of
375 // 79 non-newline characters. (MAX_DEBUG_MESSAGE_LENGTH is usually 0x100 in
376 // DebugLib instances.)
382 FullLength
= CipherStringSize
- 1;
383 DEBUG ((DEBUG_VERBOSE
, "%a:%a: CipherString={\n", gEfiCallerBaseName
,
385 for (CipherStringPosition
= CipherString
;
386 CipherStringPosition
< CipherString
+ FullLength
;
387 CipherStringPosition
+= SegmentLength
) {
388 SegmentLength
= FullLength
- (CipherStringPosition
- CipherString
);
389 if (SegmentLength
> 79) {
392 DEBUG ((DEBUG_VERBOSE
, "%.*a\n", SegmentLength
, CipherStringPosition
));
394 DEBUG ((DEBUG_VERBOSE
, "}\n"));
396 // Restore the pre-debug value of CipherStringPosition by skipping over the
399 CipherStringPosition
++;
400 ASSERT (CipherStringPosition
== CipherString
+ CipherStringSize
);
404 // Sets the ciphers for use by the Tls object.
406 if (SSL_set_cipher_list (TlsConn
->Ssl
, CipherString
) <= 0) {
407 Status
= EFI_UNSUPPORTED
;
408 goto FreeCipherString
;
411 Status
= EFI_SUCCESS
;
414 FreePool (CipherString
);
417 FreePool (MappedCipher
);
423 Set the compression method for TLS/SSL operations.
425 This function handles TLS/SSL integrated compression methods.
427 @param[in] CompMethod The compression method ID.
429 @retval EFI_SUCCESS The compression method for the communication was
431 @retval EFI_UNSUPPORTED Unsupported compression method.
436 TlsSetCompressionMethod (
446 if (CompMethod
== 0) {
448 // TLS defines one standard compression method, CompressionMethod.null (0),
449 // which specifies that data exchanged via the record protocol will not be compressed.
450 // So, return EFI_SUCCESS directly (RFC 3749).
453 } else if (CompMethod
== 1) {
456 return EFI_UNSUPPORTED
;
460 // Adds the compression method to the list of available
461 // compression methods.
463 Ret
= SSL_COMP_add_compression_method (CompMethod
, Cm
);
465 return EFI_UNSUPPORTED
;
472 Set peer certificate verification mode for the TLS connection.
474 This function sets the verification mode flags for the TLS connection.
476 @param[in] Tls Pointer to the TLS object.
477 @param[in] VerifyMode A set of logically or'ed verification mode flags.
487 TLS_CONNECTION
*TlsConn
;
489 TlsConn
= (TLS_CONNECTION
*) Tls
;
490 if (TlsConn
== NULL
|| TlsConn
->Ssl
== NULL
) {
495 // Set peer certificate verification parameters with NULL callback.
497 SSL_set_verify (TlsConn
->Ssl
, VerifyMode
, NULL
);
501 Set the specified host name to be verified.
503 @param[in] Tls Pointer to the TLS object.
504 @param[in] Flags The setting flags during the validation.
505 @param[in] HostName The specified host name to be verified.
507 @retval EFI_SUCCESS The HostName setting was set successfully.
508 @retval EFI_INVALID_PARAMETER The parameter is invalid.
509 @retval EFI_ABORTED Invalid HostName setting.
520 TLS_CONNECTION
*TlsConn
;
522 TlsConn
= (TLS_CONNECTION
*) Tls
;
523 if (TlsConn
== NULL
|| TlsConn
->Ssl
== NULL
|| HostName
== NULL
) {
524 return EFI_INVALID_PARAMETER
;
527 SSL_set_hostflags(TlsConn
->Ssl
, Flags
);
529 if (SSL_set1_host(TlsConn
->Ssl
, HostName
) == 0) {
537 Sets a TLS/SSL session ID to be used during TLS/SSL connect.
539 This function sets a session ID to be used when the TLS/SSL connection is
542 @param[in] Tls Pointer to the TLS object.
543 @param[in] SessionId Session ID data used for session resumption.
544 @param[in] SessionIdLen Length of Session ID in bytes.
546 @retval EFI_SUCCESS Session ID was set successfully.
547 @retval EFI_INVALID_PARAMETER The parameter is invalid.
548 @retval EFI_UNSUPPORTED No available session for ID setting.
556 IN UINT16 SessionIdLen
559 TLS_CONNECTION
*TlsConn
;
560 SSL_SESSION
*Session
;
562 TlsConn
= (TLS_CONNECTION
*) Tls
;
565 if (TlsConn
== NULL
|| TlsConn
->Ssl
== NULL
|| SessionId
== NULL
) {
566 return EFI_INVALID_PARAMETER
;
569 Session
= SSL_get_session (TlsConn
->Ssl
);
570 if (Session
== NULL
) {
571 return EFI_UNSUPPORTED
;
574 SSL_SESSION_set1_id (Session
, (const unsigned char *)SessionId
, SessionIdLen
);
580 Adds the CA to the cert store when requesting Server or Client authentication.
582 This function adds the CA certificate to the list of CAs when requesting
583 Server or Client authentication for the chosen TLS connection.
585 @param[in] Tls Pointer to the TLS object.
586 @param[in] Data Pointer to the data buffer of a DER-encoded binary
587 X.509 certificate or PEM-encoded X.509 certificate.
588 @param[in] DataSize The size of data buffer in bytes.
590 @retval EFI_SUCCESS The operation succeeded.
591 @retval EFI_INVALID_PARAMETER The parameter is invalid.
592 @retval EFI_OUT_OF_RESOURCES Required resources could not be allocated.
593 @retval EFI_ABORTED Invalid X.509 certificate.
598 TlsSetCaCertificate (
606 X509_STORE
*X509Store
;
608 TLS_CONNECTION
*TlsConn
;
616 Status
= EFI_SUCCESS
;
617 TlsConn
= (TLS_CONNECTION
*) Tls
;
620 if (TlsConn
== NULL
|| TlsConn
->Ssl
== NULL
|| Data
== NULL
|| DataSize
== 0) {
621 return EFI_INVALID_PARAMETER
;
625 // DER-encoded binary X.509 certificate or PEM-encoded X.509 certificate.
626 // Determine whether certificate is from DER encoding, if so, translate it to X509 structure.
628 Cert
= d2i_X509 (NULL
, (const unsigned char ** )&Data
, (long) DataSize
);
631 // Certificate is from PEM encoding.
633 BioCert
= BIO_new (BIO_s_mem ());
634 if (BioCert
== NULL
) {
635 Status
= EFI_OUT_OF_RESOURCES
;
639 if (BIO_write (BioCert
, Data
, (UINT32
) DataSize
) <= 0) {
640 Status
= EFI_ABORTED
;
644 Cert
= PEM_read_bio_X509 (BioCert
, NULL
, NULL
, NULL
);
646 Status
= EFI_ABORTED
;
651 SslCtx
= SSL_get_SSL_CTX (TlsConn
->Ssl
);
652 X509Store
= SSL_CTX_get_cert_store (SslCtx
);
653 if (X509Store
== NULL
) {
654 Status
= EFI_ABORTED
;
659 // Add certificate to X509 store
661 Ret
= X509_STORE_add_cert (X509Store
, Cert
);
663 ErrorCode
= ERR_peek_last_error ();
665 // Ignore "already in table" errors
667 if (!(ERR_GET_FUNC (ErrorCode
) == X509_F_X509_STORE_ADD_CERT
&&
668 ERR_GET_REASON (ErrorCode
) == X509_R_CERT_ALREADY_IN_HASH_TABLE
)) {
669 Status
= EFI_ABORTED
;
675 if (BioCert
!= NULL
) {
687 Loads the local public certificate into the specified TLS object.
689 This function loads the X.509 certificate into the specified TLS object
692 @param[in] Tls Pointer to the TLS object.
693 @param[in] Data Pointer to the data buffer of a DER-encoded binary
694 X.509 certificate or PEM-encoded X.509 certificate.
695 @param[in] DataSize The size of data buffer in bytes.
697 @retval EFI_SUCCESS The operation succeeded.
698 @retval EFI_INVALID_PARAMETER The parameter is invalid.
699 @retval EFI_OUT_OF_RESOURCES Required resources could not be allocated.
700 @retval EFI_ABORTED Invalid X.509 certificate.
705 TlsSetHostPublicCert (
714 TLS_CONNECTION
*TlsConn
;
718 Status
= EFI_SUCCESS
;
719 TlsConn
= (TLS_CONNECTION
*) Tls
;
721 if (TlsConn
== NULL
|| TlsConn
->Ssl
== NULL
|| Data
== NULL
|| DataSize
== 0) {
722 return EFI_INVALID_PARAMETER
;
726 // DER-encoded binary X.509 certificate or PEM-encoded X.509 certificate.
727 // Determine whether certificate is from DER encoding, if so, translate it to X509 structure.
729 Cert
= d2i_X509 (NULL
, (const unsigned char ** )&Data
, (long) DataSize
);
732 // Certificate is from PEM encoding.
734 BioCert
= BIO_new (BIO_s_mem ());
735 if (BioCert
== NULL
) {
736 Status
= EFI_OUT_OF_RESOURCES
;
740 if (BIO_write (BioCert
, Data
, (UINT32
) DataSize
) <= 0) {
741 Status
= EFI_ABORTED
;
745 Cert
= PEM_read_bio_X509 (BioCert
, NULL
, NULL
, NULL
);
747 Status
= EFI_ABORTED
;
752 if (SSL_use_certificate (TlsConn
->Ssl
, Cert
) != 1) {
753 Status
= EFI_ABORTED
;
758 if (BioCert
!= NULL
) {
770 Adds the local private key to the specified TLS object.
772 This function adds the local private key (PEM-encoded RSA or PKCS#8 private
773 key) into the specified TLS object for TLS negotiation.
775 @param[in] Tls Pointer to the TLS object.
776 @param[in] Data Pointer to the data buffer of a PEM-encoded RSA
777 or PKCS#8 private key.
778 @param[in] DataSize The size of data buffer in bytes.
780 @retval EFI_SUCCESS The operation succeeded.
781 @retval EFI_UNSUPPORTED This function is not supported.
782 @retval EFI_ABORTED Invalid private key data.
787 TlsSetHostPrivateKey (
793 return EFI_UNSUPPORTED
;
797 Adds the CA-supplied certificate revocation list for certificate validation.
799 This function adds the CA-supplied certificate revocation list data for
800 certificate validity checking.
802 @param[in] Data Pointer to the data buffer of a DER-encoded CRL data.
803 @param[in] DataSize The size of data buffer in bytes.
805 @retval EFI_SUCCESS The operation succeeded.
806 @retval EFI_UNSUPPORTED This function is not supported.
807 @retval EFI_ABORTED Invalid CRL data.
812 TlsSetCertRevocationList (
817 return EFI_UNSUPPORTED
;
821 Gets the protocol version used by the specified TLS connection.
823 This function returns the protocol version used by the specified TLS
826 If Tls is NULL, then ASSERT().
828 @param[in] Tls Pointer to the TLS object.
830 @return The protocol version of the specified TLS connection.
839 TLS_CONNECTION
*TlsConn
;
841 TlsConn
= (TLS_CONNECTION
*) Tls
;
843 ASSERT (TlsConn
!= NULL
);
845 return (UINT16
)(SSL_version (TlsConn
->Ssl
));
849 Gets the connection end of the specified TLS connection.
851 This function returns the connection end (as client or as server) used by
852 the specified TLS connection.
854 If Tls is NULL, then ASSERT().
856 @param[in] Tls Pointer to the TLS object.
858 @return The connection end used by the specified TLS connection.
863 TlsGetConnectionEnd (
867 TLS_CONNECTION
*TlsConn
;
869 TlsConn
= (TLS_CONNECTION
*) Tls
;
871 ASSERT (TlsConn
!= NULL
);
873 return (UINT8
)SSL_is_server (TlsConn
->Ssl
);
877 Gets the cipher suite used by the specified TLS connection.
879 This function returns current cipher suite used by the specified
882 @param[in] Tls Pointer to the TLS object.
883 @param[in,out] CipherId The cipher suite used by the TLS object.
885 @retval EFI_SUCCESS The cipher suite was returned successfully.
886 @retval EFI_INVALID_PARAMETER The parameter is invalid.
887 @retval EFI_UNSUPPORTED Unsupported cipher suite.
892 TlsGetCurrentCipher (
894 IN OUT UINT16
*CipherId
897 TLS_CONNECTION
*TlsConn
;
898 CONST SSL_CIPHER
*Cipher
;
900 TlsConn
= (TLS_CONNECTION
*) Tls
;
903 if (TlsConn
== NULL
|| TlsConn
->Ssl
== NULL
|| CipherId
== NULL
) {
904 return EFI_INVALID_PARAMETER
;
907 Cipher
= SSL_get_current_cipher (TlsConn
->Ssl
);
908 if (Cipher
== NULL
) {
909 return EFI_UNSUPPORTED
;
912 *CipherId
= (SSL_CIPHER_get_id (Cipher
)) & 0xFFFF;
918 Gets the compression methods used by the specified TLS connection.
920 This function returns current integrated compression methods used by
921 the specified TLS connection.
923 @param[in] Tls Pointer to the TLS object.
924 @param[in,out] CompressionId The current compression method used by
927 @retval EFI_SUCCESS The compression method was returned successfully.
928 @retval EFI_INVALID_PARAMETER The parameter is invalid.
929 @retval EFI_ABORTED Invalid Compression method.
930 @retval EFI_UNSUPPORTED This function is not supported.
935 TlsGetCurrentCompressionId (
937 IN OUT UINT8
*CompressionId
940 return EFI_UNSUPPORTED
;
944 Gets the verification mode currently set in the TLS connection.
946 This function returns the peer verification mode currently set in the
947 specified TLS connection.
949 If Tls is NULL, then ASSERT().
951 @param[in] Tls Pointer to the TLS object.
953 @return The verification mode set in the specified TLS connection.
962 TLS_CONNECTION
*TlsConn
;
964 TlsConn
= (TLS_CONNECTION
*) Tls
;
966 ASSERT (TlsConn
!= NULL
);
968 return SSL_get_verify_mode (TlsConn
->Ssl
);
972 Gets the session ID used by the specified TLS connection.
974 This function returns the TLS/SSL session ID currently used by the
975 specified TLS connection.
977 @param[in] Tls Pointer to the TLS object.
978 @param[in,out] SessionId Buffer to contain the returned session ID.
979 @param[in,out] SessionIdLen The length of Session ID in bytes.
981 @retval EFI_SUCCESS The Session ID was returned successfully.
982 @retval EFI_INVALID_PARAMETER The parameter is invalid.
983 @retval EFI_UNSUPPORTED Invalid TLS/SSL session.
990 IN OUT UINT8
*SessionId
,
991 IN OUT UINT16
*SessionIdLen
994 TLS_CONNECTION
*TlsConn
;
995 SSL_SESSION
*Session
;
996 CONST UINT8
*SslSessionId
;
998 TlsConn
= (TLS_CONNECTION
*) Tls
;
1001 if (TlsConn
== NULL
|| TlsConn
->Ssl
== NULL
|| SessionId
== NULL
|| SessionIdLen
== NULL
) {
1002 return EFI_INVALID_PARAMETER
;
1005 Session
= SSL_get_session (TlsConn
->Ssl
);
1006 if (Session
== NULL
) {
1007 return EFI_UNSUPPORTED
;
1010 SslSessionId
= SSL_SESSION_get_id (Session
, (unsigned int *)SessionIdLen
);
1011 CopyMem (SessionId
, SslSessionId
, *SessionIdLen
);
1017 Gets the client random data used in the specified TLS connection.
1019 This function returns the TLS/SSL client random data currently used in
1020 the specified TLS connection.
1022 @param[in] Tls Pointer to the TLS object.
1023 @param[in,out] ClientRandom Buffer to contain the returned client
1024 random data (32 bytes).
1029 TlsGetClientRandom (
1031 IN OUT UINT8
*ClientRandom
1034 TLS_CONNECTION
*TlsConn
;
1036 TlsConn
= (TLS_CONNECTION
*) Tls
;
1038 if (TlsConn
== NULL
|| TlsConn
->Ssl
== NULL
|| ClientRandom
== NULL
) {
1042 SSL_get_client_random (TlsConn
->Ssl
, ClientRandom
, SSL3_RANDOM_SIZE
);
1046 Gets the server random data used in the specified TLS connection.
1048 This function returns the TLS/SSL server random data currently used in
1049 the specified TLS connection.
1051 @param[in] Tls Pointer to the TLS object.
1052 @param[in,out] ServerRandom Buffer to contain the returned server
1053 random data (32 bytes).
1058 TlsGetServerRandom (
1060 IN OUT UINT8
*ServerRandom
1063 TLS_CONNECTION
*TlsConn
;
1065 TlsConn
= (TLS_CONNECTION
*) Tls
;
1067 if (TlsConn
== NULL
|| TlsConn
->Ssl
== NULL
|| ServerRandom
== NULL
) {
1071 SSL_get_server_random (TlsConn
->Ssl
, ServerRandom
, SSL3_RANDOM_SIZE
);
1075 Gets the master key data used in the specified TLS connection.
1077 This function returns the TLS/SSL master key material currently used in
1078 the specified TLS connection.
1080 @param[in] Tls Pointer to the TLS object.
1081 @param[in,out] KeyMaterial Buffer to contain the returned key material.
1083 @retval EFI_SUCCESS Key material was returned successfully.
1084 @retval EFI_INVALID_PARAMETER The parameter is invalid.
1085 @retval EFI_UNSUPPORTED Invalid TLS/SSL session.
1092 IN OUT UINT8
*KeyMaterial
1095 TLS_CONNECTION
*TlsConn
;
1096 SSL_SESSION
*Session
;
1098 TlsConn
= (TLS_CONNECTION
*) Tls
;
1101 if (TlsConn
== NULL
|| TlsConn
->Ssl
== NULL
|| KeyMaterial
== NULL
) {
1102 return EFI_INVALID_PARAMETER
;
1105 Session
= SSL_get_session (TlsConn
->Ssl
);
1107 if (Session
== NULL
) {
1108 return EFI_UNSUPPORTED
;
1111 SSL_SESSION_get_master_key (Session
, KeyMaterial
, SSL3_MASTER_SECRET_SIZE
);
1117 Gets the CA Certificate from the cert store.
1119 This function returns the CA certificate for the chosen
1122 @param[in] Tls Pointer to the TLS object.
1123 @param[out] Data Pointer to the data buffer to receive the CA
1124 certificate data sent to the client.
1125 @param[in,out] DataSize The size of data buffer in bytes.
1127 @retval EFI_SUCCESS The operation succeeded.
1128 @retval EFI_UNSUPPORTED This function is not supported.
1129 @retval EFI_BUFFER_TOO_SMALL The Data is too small to hold the data.
1134 TlsGetCaCertificate (
1137 IN OUT UINTN
*DataSize
1140 return EFI_UNSUPPORTED
;
1144 Gets the local public Certificate set in the specified TLS object.
1146 This function returns the local public certificate which was currently set
1147 in the specified TLS object.
1149 @param[in] Tls Pointer to the TLS object.
1150 @param[out] Data Pointer to the data buffer to receive the local
1152 @param[in,out] DataSize The size of data buffer in bytes.
1154 @retval EFI_SUCCESS The operation succeeded.
1155 @retval EFI_INVALID_PARAMETER The parameter is invalid.
1156 @retval EFI_NOT_FOUND The certificate is not found.
1157 @retval EFI_BUFFER_TOO_SMALL The Data is too small to hold the data.
1162 TlsGetHostPublicCert (
1165 IN OUT UINTN
*DataSize
1169 TLS_CONNECTION
*TlsConn
;
1172 TlsConn
= (TLS_CONNECTION
*) Tls
;
1174 if (TlsConn
== NULL
|| TlsConn
->Ssl
== NULL
|| DataSize
== NULL
|| (*DataSize
!= 0 && Data
== NULL
)) {
1175 return EFI_INVALID_PARAMETER
;
1178 Cert
= SSL_get_certificate(TlsConn
->Ssl
);
1180 return EFI_NOT_FOUND
;
1184 // Only DER encoding is supported currently.
1186 if (*DataSize
< (UINTN
) i2d_X509 (Cert
, NULL
)) {
1187 *DataSize
= (UINTN
) i2d_X509 (Cert
, NULL
);
1188 return EFI_BUFFER_TOO_SMALL
;
1191 *DataSize
= (UINTN
) i2d_X509 (Cert
, (unsigned char **) &Data
);
1197 Gets the local private key set in the specified TLS object.
1199 This function returns the local private key data which was currently set
1200 in the specified TLS object.
1202 @param[in] Tls Pointer to the TLS object.
1203 @param[out] Data Pointer to the data buffer to receive the local
1205 @param[in,out] DataSize The size of data buffer in bytes.
1207 @retval EFI_SUCCESS The operation succeeded.
1208 @retval EFI_UNSUPPORTED This function is not supported.
1209 @retval EFI_BUFFER_TOO_SMALL The Data is too small to hold the data.
1214 TlsGetHostPrivateKey (
1217 IN OUT UINTN
*DataSize
1220 return EFI_UNSUPPORTED
;
1224 Gets the CA-supplied certificate revocation list data set in the specified
1227 This function returns the CA-supplied certificate revocation list data which
1228 was currently set in the specified TLS object.
1230 @param[out] Data Pointer to the data buffer to receive the CRL data.
1231 @param[in,out] DataSize The size of data buffer in bytes.
1233 @retval EFI_SUCCESS The operation succeeded.
1234 @retval EFI_UNSUPPORTED This function is not supported.
1235 @retval EFI_BUFFER_TOO_SMALL The Data is too small to hold the data.
1240 TlsGetCertRevocationList (
1242 IN OUT UINTN
*DataSize
1245 return EFI_UNSUPPORTED
;