2 SSL/TLS Configuration Library Wrapper Implementation over OpenSSL.
4 Copyright (c) 2016 - 2017, Intel Corporation. All rights reserved.<BR>
5 (C) Copyright 2016 Hewlett Packard Enterprise Development LP<BR>
6 This program and the accompanying materials
7 are licensed and made available under the terms and conditions of the BSD License
8 which accompanies this distribution. The full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
16 #include "InternalTlsLib.h"
20 // IANA/IETF defined Cipher Suite ID
24 // OpenSSL-used Cipher Suite String
26 CONST CHAR8
*OpensslCipher
;
28 // Length of OpensslCipher
30 UINTN OpensslCipherLength
;
34 // Create a TLS_CIPHER_MAPPING initializer from IanaCipher and OpensslCipher so
35 // that OpensslCipherLength is filled in automatically. IanaCipher must be an
36 // integer constant expression, and OpensslCipher must be a string literal.
38 #define MAP(IanaCipher, OpensslCipher) \
39 { (IanaCipher), (OpensslCipher), sizeof (OpensslCipher) - 1 }
42 // The mapping table between IANA/IETF Cipher Suite definitions and
43 // OpenSSL-used Cipher Suite name.
45 // Keep the table uniquely sorted by the IanaCipher field, in increasing order.
47 STATIC CONST TLS_CIPHER_MAPPING TlsCipherMappingTable
[] = {
48 MAP ( 0x0001, "NULL-MD5" ), /// TLS_RSA_WITH_NULL_MD5
49 MAP ( 0x0002, "NULL-SHA" ), /// TLS_RSA_WITH_NULL_SHA
50 MAP ( 0x0004, "RC4-MD5" ), /// TLS_RSA_WITH_RC4_128_MD5
51 MAP ( 0x0005, "RC4-SHA" ), /// TLS_RSA_WITH_RC4_128_SHA
52 MAP ( 0x000A, "DES-CBC3-SHA" ), /// TLS_RSA_WITH_3DES_EDE_CBC_SHA, mandatory TLS 1.1
53 MAP ( 0x0016, "DHE-RSA-DES-CBC3-SHA" ), /// TLS_DHE_RSA_WITH_3DES_EDE_CBC_SHA
54 MAP ( 0x002F, "AES128-SHA" ), /// TLS_RSA_WITH_AES_128_CBC_SHA, mandatory TLS 1.2
55 MAP ( 0x0030, "DH-DSS-AES128-SHA" ), /// TLS_DH_DSS_WITH_AES_128_CBC_SHA
56 MAP ( 0x0031, "DH-RSA-AES128-SHA" ), /// TLS_DH_RSA_WITH_AES_128_CBC_SHA
57 MAP ( 0x0033, "DHE-RSA-AES128-SHA" ), /// TLS_DHE_RSA_WITH_AES_128_CBC_SHA
58 MAP ( 0x0035, "AES256-SHA" ), /// TLS_RSA_WITH_AES_256_CBC_SHA
59 MAP ( 0x0036, "DH-DSS-AES256-SHA" ), /// TLS_DH_DSS_WITH_AES_256_CBC_SHA
60 MAP ( 0x0037, "DH-RSA-AES256-SHA" ), /// TLS_DH_RSA_WITH_AES_256_CBC_SHA
61 MAP ( 0x0039, "DHE-RSA-AES256-SHA" ), /// TLS_DHE_RSA_WITH_AES_256_CBC_SHA
62 MAP ( 0x003B, "NULL-SHA256" ), /// TLS_RSA_WITH_NULL_SHA256
63 MAP ( 0x003C, "AES128-SHA256" ), /// TLS_RSA_WITH_AES_128_CBC_SHA256
64 MAP ( 0x003D, "AES256-SHA256" ), /// TLS_RSA_WITH_AES_256_CBC_SHA256
65 MAP ( 0x003E, "DH-DSS-AES128-SHA256" ), /// TLS_DH_DSS_WITH_AES_128_CBC_SHA256
66 MAP ( 0x003F, "DH-RSA-AES128-SHA256" ), /// TLS_DH_RSA_WITH_AES_128_CBC_SHA256
67 MAP ( 0x0067, "DHE-RSA-AES128-SHA256" ), /// TLS_DHE_RSA_WITH_AES_128_CBC_SHA256
68 MAP ( 0x0068, "DH-DSS-AES256-SHA256" ), /// TLS_DH_DSS_WITH_AES_256_CBC_SHA256
69 MAP ( 0x0069, "DH-RSA-AES256-SHA256" ), /// TLS_DH_RSA_WITH_AES_256_CBC_SHA256
70 MAP ( 0x006B, "DHE-RSA-AES256-SHA256" ), /// TLS_DHE_RSA_WITH_AES_256_CBC_SHA256
74 Gets the OpenSSL cipher suite mapping for the supplied IANA TLS cipher suite.
76 @param[in] CipherId The supplied IANA TLS cipher suite ID.
78 @return The corresponding OpenSSL cipher suite mapping if found,
83 CONST TLS_CIPHER_MAPPING
*
93 // Binary Search Cipher Mapping Table for IANA-OpenSSL Cipher Translation
96 Right
= ARRAY_SIZE (TlsCipherMappingTable
) - 1;
98 while (Right
>= Left
) {
99 Middle
= (Left
+ Right
) / 2;
101 if (CipherId
== TlsCipherMappingTable
[Middle
].IanaCipher
) {
103 // Translate IANA cipher suite ID to OpenSSL name.
105 return &TlsCipherMappingTable
[Middle
];
108 if (CipherId
< TlsCipherMappingTable
[Middle
].IanaCipher
) {
116 // No Cipher Mapping found, return NULL.
122 Set a new TLS/SSL method for a particular TLS object.
124 This function sets a new TLS/SSL method for a particular TLS object.
126 @param[in] Tls Pointer to a TLS object.
127 @param[in] MajorVer Major Version of TLS/SSL Protocol.
128 @param[in] MinorVer Minor Version of TLS/SSL Protocol.
130 @retval EFI_SUCCESS The TLS/SSL method was set successfully.
131 @retval EFI_INVALID_PARAMETER The parameter is invalid.
132 @retval EFI_UNSUPPORTED Unsupported TLS/SSL method.
143 TLS_CONNECTION
*TlsConn
;
146 TlsConn
= (TLS_CONNECTION
*)Tls
;
147 if (TlsConn
== NULL
|| TlsConn
->Ssl
== NULL
) {
148 return EFI_INVALID_PARAMETER
;
151 ProtoVersion
= (MajorVer
<< 8) | MinorVer
;
154 // Bound TLS method to the particular specified version.
156 switch (ProtoVersion
) {
161 SSL_set_min_proto_version (TlsConn
->Ssl
, TLS1_VERSION
);
162 SSL_set_max_proto_version (TlsConn
->Ssl
, TLS1_VERSION
);
168 SSL_set_min_proto_version (TlsConn
->Ssl
, TLS1_1_VERSION
);
169 SSL_set_max_proto_version (TlsConn
->Ssl
, TLS1_1_VERSION
);
175 SSL_set_min_proto_version (TlsConn
->Ssl
, TLS1_2_VERSION
);
176 SSL_set_max_proto_version (TlsConn
->Ssl
, TLS1_2_VERSION
);
180 // Unsupported Protocol Version
182 return EFI_UNSUPPORTED
;
189 Set TLS object to work in client or server mode.
191 This function prepares a TLS object to work in client or server mode.
193 @param[in] Tls Pointer to a TLS object.
194 @param[in] IsServer Work in server mode.
196 @retval EFI_SUCCESS The TLS/SSL work mode was set successfully.
197 @retval EFI_INVALID_PARAMETER The parameter is invalid.
198 @retval EFI_UNSUPPORTED Unsupported TLS/SSL work mode.
203 TlsSetConnectionEnd (
208 TLS_CONNECTION
*TlsConn
;
210 TlsConn
= (TLS_CONNECTION
*) Tls
;
211 if (TlsConn
== NULL
|| TlsConn
->Ssl
== NULL
) {
212 return EFI_INVALID_PARAMETER
;
217 // Set TLS to work in Client mode.
219 SSL_set_connect_state (TlsConn
->Ssl
);
222 // Set TLS to work in Server mode.
223 // It is unsupported for UEFI version currently.
225 //SSL_set_accept_state (TlsConn->Ssl);
226 return EFI_UNSUPPORTED
;
233 Set the ciphers list to be used by the TLS object.
235 This function sets the ciphers for use by a specified TLS object.
237 @param[in] Tls Pointer to a TLS object.
238 @param[in] CipherId Array of UINT16 cipher identifiers. Each UINT16
239 cipher identifier comes from the TLS Cipher Suite
240 Registry of the IANA, interpreting Byte1 and Byte2
241 in network (big endian) byte order.
242 @param[in] CipherNum The number of cipher in the list.
244 @retval EFI_SUCCESS The ciphers list was set successfully.
245 @retval EFI_INVALID_PARAMETER The parameter is invalid.
246 @retval EFI_UNSUPPORTED No supported TLS cipher was found in CipherId.
247 @retval EFI_OUT_OF_RESOURCES Memory allocation failed.
258 TLS_CONNECTION
*TlsConn
;
260 CONST TLS_CIPHER_MAPPING
**MappedCipher
;
261 UINTN MappedCipherBytes
;
262 UINTN MappedCipherCount
;
263 UINTN CipherStringSize
;
265 CONST TLS_CIPHER_MAPPING
*Mapping
;
267 CHAR8
*CipherStringPosition
;
269 TlsConn
= (TLS_CONNECTION
*) Tls
;
270 if (TlsConn
== NULL
|| TlsConn
->Ssl
== NULL
|| CipherId
== NULL
) {
271 return EFI_INVALID_PARAMETER
;
275 // Allocate the MappedCipher array for recording the mappings that we find
276 // for the input IANA identifiers in CipherId.
278 Status
= SafeUintnMult (CipherNum
, sizeof (*MappedCipher
),
280 if (EFI_ERROR (Status
)) {
281 return EFI_OUT_OF_RESOURCES
;
283 MappedCipher
= AllocatePool (MappedCipherBytes
);
284 if (MappedCipher
== NULL
) {
285 return EFI_OUT_OF_RESOURCES
;
289 // Map the cipher IDs, and count the number of bytes for the full
292 MappedCipherCount
= 0;
293 CipherStringSize
= 0;
294 for (Index
= 0; Index
< CipherNum
; Index
++) {
296 // Look up the IANA-to-OpenSSL mapping.
298 Mapping
= TlsGetCipherMapping (CipherId
[Index
]);
299 if (Mapping
== NULL
) {
300 DEBUG ((DEBUG_VERBOSE
, "%a:%a: skipping CipherId=0x%04x\n",
301 gEfiCallerBaseName
, __FUNCTION__
, CipherId
[Index
]));
303 // Skipping the cipher is valid because CipherId is an ordered
304 // preference list of ciphers, thus we can filter it as long as we
305 // don't change the relative order of elements on it.
310 // Accumulate Mapping->OpensslCipherLength into CipherStringSize. If this
311 // is not the first successful mapping, account for a colon (":") prefix
314 if (MappedCipherCount
> 0) {
315 Status
= SafeUintnAdd (CipherStringSize
, 1, &CipherStringSize
);
316 if (EFI_ERROR (Status
)) {
317 Status
= EFI_OUT_OF_RESOURCES
;
318 goto FreeMappedCipher
;
321 Status
= SafeUintnAdd (CipherStringSize
, Mapping
->OpensslCipherLength
,
323 if (EFI_ERROR (Status
)) {
324 Status
= EFI_OUT_OF_RESOURCES
;
325 goto FreeMappedCipher
;
328 // Record the mapping.
330 MappedCipher
[MappedCipherCount
++] = Mapping
;
334 // Verify that at least one IANA cipher ID could be mapped; account for the
335 // terminating NUL character in CipherStringSize; allocate CipherString.
337 if (MappedCipherCount
== 0) {
338 DEBUG ((DEBUG_ERROR
, "%a:%a: no CipherId could be mapped\n",
339 gEfiCallerBaseName
, __FUNCTION__
));
340 Status
= EFI_UNSUPPORTED
;
341 goto FreeMappedCipher
;
343 Status
= SafeUintnAdd (CipherStringSize
, 1, &CipherStringSize
);
344 if (EFI_ERROR (Status
)) {
345 Status
= EFI_OUT_OF_RESOURCES
;
346 goto FreeMappedCipher
;
348 CipherString
= AllocatePool (CipherStringSize
);
349 if (CipherString
== NULL
) {
350 Status
= EFI_OUT_OF_RESOURCES
;
351 goto FreeMappedCipher
;
355 // Go over the collected mappings and populate CipherString.
357 CipherStringPosition
= CipherString
;
358 for (Index
= 0; Index
< MappedCipherCount
; Index
++) {
359 Mapping
= MappedCipher
[Index
];
361 // Append the colon (":") prefix except for the first mapping, then append
362 // Mapping->OpensslCipher.
365 *(CipherStringPosition
++) = ':';
367 CopyMem (CipherStringPosition
, Mapping
->OpensslCipher
,
368 Mapping
->OpensslCipherLength
);
369 CipherStringPosition
+= Mapping
->OpensslCipherLength
;
373 // NUL-terminate CipherString.
375 *(CipherStringPosition
++) = '\0';
376 ASSERT (CipherStringPosition
== CipherString
+ CipherStringSize
);
379 // Log CipherString for debugging. CipherString can be very long if the
380 // caller provided a large CipherId array, so log CipherString in segments of
381 // 79 non-newline characters. (MAX_DEBUG_MESSAGE_LENGTH is usually 0x100 in
382 // DebugLib instances.)
388 FullLength
= CipherStringSize
- 1;
389 DEBUG ((DEBUG_VERBOSE
, "%a:%a: CipherString={\n", gEfiCallerBaseName
,
391 for (CipherStringPosition
= CipherString
;
392 CipherStringPosition
< CipherString
+ FullLength
;
393 CipherStringPosition
+= SegmentLength
) {
394 SegmentLength
= FullLength
- (CipherStringPosition
- CipherString
);
395 if (SegmentLength
> 79) {
398 DEBUG ((DEBUG_VERBOSE
, "%.*a\n", SegmentLength
, CipherStringPosition
));
400 DEBUG ((DEBUG_VERBOSE
, "}\n"));
402 // Restore the pre-debug value of CipherStringPosition by skipping over the
405 CipherStringPosition
++;
406 ASSERT (CipherStringPosition
== CipherString
+ CipherStringSize
);
410 // Sets the ciphers for use by the Tls object.
412 if (SSL_set_cipher_list (TlsConn
->Ssl
, CipherString
) <= 0) {
413 Status
= EFI_UNSUPPORTED
;
414 goto FreeCipherString
;
417 Status
= EFI_SUCCESS
;
420 FreePool (CipherString
);
423 FreePool (MappedCipher
);
429 Set the compression method for TLS/SSL operations.
431 This function handles TLS/SSL integrated compression methods.
433 @param[in] CompMethod The compression method ID.
435 @retval EFI_SUCCESS The compression method for the communication was
437 @retval EFI_UNSUPPORTED Unsupported compression method.
442 TlsSetCompressionMethod (
452 if (CompMethod
== 0) {
454 // TLS defines one standard compression method, CompressionMethod.null (0),
455 // which specifies that data exchanged via the record protocol will not be compressed.
456 // So, return EFI_SUCCESS directly (RFC 3749).
459 } else if (CompMethod
== 1) {
462 return EFI_UNSUPPORTED
;
466 // Adds the compression method to the list of available
467 // compression methods.
469 Ret
= SSL_COMP_add_compression_method (CompMethod
, Cm
);
471 return EFI_UNSUPPORTED
;
478 Set peer certificate verification mode for the TLS connection.
480 This function sets the verification mode flags for the TLS connection.
482 @param[in] Tls Pointer to the TLS object.
483 @param[in] VerifyMode A set of logically or'ed verification mode flags.
493 TLS_CONNECTION
*TlsConn
;
495 TlsConn
= (TLS_CONNECTION
*) Tls
;
496 if (TlsConn
== NULL
|| TlsConn
->Ssl
== NULL
) {
501 // Set peer certificate verification parameters with NULL callback.
503 SSL_set_verify (TlsConn
->Ssl
, VerifyMode
, NULL
);
507 Sets a TLS/SSL session ID to be used during TLS/SSL connect.
509 This function sets a session ID to be used when the TLS/SSL connection is
512 @param[in] Tls Pointer to the TLS object.
513 @param[in] SessionId Session ID data used for session resumption.
514 @param[in] SessionIdLen Length of Session ID in bytes.
516 @retval EFI_SUCCESS Session ID was set successfully.
517 @retval EFI_INVALID_PARAMETER The parameter is invalid.
518 @retval EFI_UNSUPPORTED No available session for ID setting.
526 IN UINT16 SessionIdLen
529 TLS_CONNECTION
*TlsConn
;
530 SSL_SESSION
*Session
;
532 TlsConn
= (TLS_CONNECTION
*) Tls
;
535 if (TlsConn
== NULL
|| TlsConn
->Ssl
== NULL
|| SessionId
== NULL
) {
536 return EFI_INVALID_PARAMETER
;
539 Session
= SSL_get_session (TlsConn
->Ssl
);
540 if (Session
== NULL
) {
541 return EFI_UNSUPPORTED
;
544 SSL_SESSION_set1_id (Session
, (const unsigned char *)SessionId
, SessionIdLen
);
550 Adds the CA to the cert store when requesting Server or Client authentication.
552 This function adds the CA certificate to the list of CAs when requesting
553 Server or Client authentication for the chosen TLS connection.
555 @param[in] Tls Pointer to the TLS object.
556 @param[in] Data Pointer to the data buffer of a DER-encoded binary
557 X.509 certificate or PEM-encoded X.509 certificate.
558 @param[in] DataSize The size of data buffer in bytes.
560 @retval EFI_SUCCESS The operation succeeded.
561 @retval EFI_INVALID_PARAMETER The parameter is invalid.
562 @retval EFI_OUT_OF_RESOURCES Required resources could not be allocated.
563 @retval EFI_ABORTED Invalid X.509 certificate.
568 TlsSetCaCertificate (
576 X509_STORE
*X509Store
;
578 TLS_CONNECTION
*TlsConn
;
586 Status
= EFI_SUCCESS
;
587 TlsConn
= (TLS_CONNECTION
*) Tls
;
590 if (TlsConn
== NULL
|| TlsConn
->Ssl
== NULL
|| Data
== NULL
|| DataSize
== 0) {
591 return EFI_INVALID_PARAMETER
;
595 // DER-encoded binary X.509 certificate or PEM-encoded X.509 certificate.
596 // Determine whether certificate is from DER encoding, if so, translate it to X509 structure.
598 Cert
= d2i_X509 (NULL
, (const unsigned char ** )&Data
, (long) DataSize
);
601 // Certificate is from PEM encoding.
603 BioCert
= BIO_new (BIO_s_mem ());
604 if (BioCert
== NULL
) {
605 Status
= EFI_OUT_OF_RESOURCES
;
609 if (BIO_write (BioCert
, Data
, (UINT32
) DataSize
) <= 0) {
610 Status
= EFI_ABORTED
;
614 Cert
= PEM_read_bio_X509 (BioCert
, NULL
, NULL
, NULL
);
616 Status
= EFI_ABORTED
;
621 SslCtx
= SSL_get_SSL_CTX (TlsConn
->Ssl
);
622 X509Store
= SSL_CTX_get_cert_store (SslCtx
);
623 if (X509Store
== NULL
) {
624 Status
= EFI_ABORTED
;
629 // Add certificate to X509 store
631 Ret
= X509_STORE_add_cert (X509Store
, Cert
);
633 ErrorCode
= ERR_peek_last_error ();
635 // Ignore "already in table" errors
637 if (!(ERR_GET_FUNC (ErrorCode
) == X509_F_X509_STORE_ADD_CERT
&&
638 ERR_GET_REASON (ErrorCode
) == X509_R_CERT_ALREADY_IN_HASH_TABLE
)) {
639 Status
= EFI_ABORTED
;
645 if (BioCert
!= NULL
) {
657 Loads the local public certificate into the specified TLS object.
659 This function loads the X.509 certificate into the specified TLS object
662 @param[in] Tls Pointer to the TLS object.
663 @param[in] Data Pointer to the data buffer of a DER-encoded binary
664 X.509 certificate or PEM-encoded X.509 certificate.
665 @param[in] DataSize The size of data buffer in bytes.
667 @retval EFI_SUCCESS The operation succeeded.
668 @retval EFI_INVALID_PARAMETER The parameter is invalid.
669 @retval EFI_OUT_OF_RESOURCES Required resources could not be allocated.
670 @retval EFI_ABORTED Invalid X.509 certificate.
675 TlsSetHostPublicCert (
684 TLS_CONNECTION
*TlsConn
;
688 Status
= EFI_SUCCESS
;
689 TlsConn
= (TLS_CONNECTION
*) Tls
;
691 if (TlsConn
== NULL
|| TlsConn
->Ssl
== NULL
|| Data
== NULL
|| DataSize
== 0) {
692 return EFI_INVALID_PARAMETER
;
696 // DER-encoded binary X.509 certificate or PEM-encoded X.509 certificate.
697 // Determine whether certificate is from DER encoding, if so, translate it to X509 structure.
699 Cert
= d2i_X509 (NULL
, (const unsigned char ** )&Data
, (long) DataSize
);
702 // Certificate is from PEM encoding.
704 BioCert
= BIO_new (BIO_s_mem ());
705 if (BioCert
== NULL
) {
706 Status
= EFI_OUT_OF_RESOURCES
;
710 if (BIO_write (BioCert
, Data
, (UINT32
) DataSize
) <= 0) {
711 Status
= EFI_ABORTED
;
715 Cert
= PEM_read_bio_X509 (BioCert
, NULL
, NULL
, NULL
);
717 Status
= EFI_ABORTED
;
722 if (SSL_use_certificate (TlsConn
->Ssl
, Cert
) != 1) {
723 Status
= EFI_ABORTED
;
728 if (BioCert
!= NULL
) {
740 Adds the local private key to the specified TLS object.
742 This function adds the local private key (PEM-encoded RSA or PKCS#8 private
743 key) into the specified TLS object for TLS negotiation.
745 @param[in] Tls Pointer to the TLS object.
746 @param[in] Data Pointer to the data buffer of a PEM-encoded RSA
747 or PKCS#8 private key.
748 @param[in] DataSize The size of data buffer in bytes.
750 @retval EFI_SUCCESS The operation succeeded.
751 @retval EFI_UNSUPPORTED This function is not supported.
752 @retval EFI_ABORTED Invalid private key data.
757 TlsSetHostPrivateKey (
763 return EFI_UNSUPPORTED
;
767 Adds the CA-supplied certificate revocation list for certificate validation.
769 This function adds the CA-supplied certificate revocation list data for
770 certificate validity checking.
772 @param[in] Data Pointer to the data buffer of a DER-encoded CRL data.
773 @param[in] 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_ABORTED Invalid CRL data.
782 TlsSetCertRevocationList (
787 return EFI_UNSUPPORTED
;
791 Gets the protocol version used by the specified TLS connection.
793 This function returns the protocol version used by the specified TLS
796 If Tls is NULL, then ASSERT().
798 @param[in] Tls Pointer to the TLS object.
800 @return The protocol version of the specified TLS connection.
809 TLS_CONNECTION
*TlsConn
;
811 TlsConn
= (TLS_CONNECTION
*) Tls
;
813 ASSERT (TlsConn
!= NULL
);
815 return (UINT16
)(SSL_version (TlsConn
->Ssl
));
819 Gets the connection end of the specified TLS connection.
821 This function returns the connection end (as client or as server) used by
822 the specified TLS connection.
824 If Tls is NULL, then ASSERT().
826 @param[in] Tls Pointer to the TLS object.
828 @return The connection end used by the specified TLS connection.
833 TlsGetConnectionEnd (
837 TLS_CONNECTION
*TlsConn
;
839 TlsConn
= (TLS_CONNECTION
*) Tls
;
841 ASSERT (TlsConn
!= NULL
);
843 return (UINT8
)SSL_is_server (TlsConn
->Ssl
);
847 Gets the cipher suite used by the specified TLS connection.
849 This function returns current cipher suite used by the specified
852 @param[in] Tls Pointer to the TLS object.
853 @param[in,out] CipherId The cipher suite used by the TLS object.
855 @retval EFI_SUCCESS The cipher suite was returned successfully.
856 @retval EFI_INVALID_PARAMETER The parameter is invalid.
857 @retval EFI_UNSUPPORTED Unsupported cipher suite.
862 TlsGetCurrentCipher (
864 IN OUT UINT16
*CipherId
867 TLS_CONNECTION
*TlsConn
;
868 CONST SSL_CIPHER
*Cipher
;
870 TlsConn
= (TLS_CONNECTION
*) Tls
;
873 if (TlsConn
== NULL
|| TlsConn
->Ssl
== NULL
|| CipherId
== NULL
) {
874 return EFI_INVALID_PARAMETER
;
877 Cipher
= SSL_get_current_cipher (TlsConn
->Ssl
);
878 if (Cipher
== NULL
) {
879 return EFI_UNSUPPORTED
;
882 *CipherId
= (SSL_CIPHER_get_id (Cipher
)) & 0xFFFF;
888 Gets the compression methods used by the specified TLS connection.
890 This function returns current integrated compression methods used by
891 the specified TLS connection.
893 @param[in] Tls Pointer to the TLS object.
894 @param[in,out] CompressionId The current compression method used by
897 @retval EFI_SUCCESS The compression method was returned successfully.
898 @retval EFI_INVALID_PARAMETER The parameter is invalid.
899 @retval EFI_ABORTED Invalid Compression method.
900 @retval EFI_UNSUPPORTED This function is not supported.
905 TlsGetCurrentCompressionId (
907 IN OUT UINT8
*CompressionId
910 return EFI_UNSUPPORTED
;
914 Gets the verification mode currently set in the TLS connection.
916 This function returns the peer verification mode currently set in the
917 specified TLS connection.
919 If Tls is NULL, then ASSERT().
921 @param[in] Tls Pointer to the TLS object.
923 @return The verification mode set in the specified TLS connection.
932 TLS_CONNECTION
*TlsConn
;
934 TlsConn
= (TLS_CONNECTION
*) Tls
;
936 ASSERT (TlsConn
!= NULL
);
938 return SSL_get_verify_mode (TlsConn
->Ssl
);
942 Gets the session ID used by the specified TLS connection.
944 This function returns the TLS/SSL session ID currently used by the
945 specified TLS connection.
947 @param[in] Tls Pointer to the TLS object.
948 @param[in,out] SessionId Buffer to contain the returned session ID.
949 @param[in,out] SessionIdLen The length of Session ID in bytes.
951 @retval EFI_SUCCESS The Session ID was returned successfully.
952 @retval EFI_INVALID_PARAMETER The parameter is invalid.
953 @retval EFI_UNSUPPORTED Invalid TLS/SSL session.
960 IN OUT UINT8
*SessionId
,
961 IN OUT UINT16
*SessionIdLen
964 TLS_CONNECTION
*TlsConn
;
965 SSL_SESSION
*Session
;
966 CONST UINT8
*SslSessionId
;
968 TlsConn
= (TLS_CONNECTION
*) Tls
;
971 if (TlsConn
== NULL
|| TlsConn
->Ssl
== NULL
|| SessionId
== NULL
|| SessionIdLen
== NULL
) {
972 return EFI_INVALID_PARAMETER
;
975 Session
= SSL_get_session (TlsConn
->Ssl
);
976 if (Session
== NULL
) {
977 return EFI_UNSUPPORTED
;
980 SslSessionId
= SSL_SESSION_get_id (Session
, (unsigned int *)SessionIdLen
);
981 CopyMem (SessionId
, SslSessionId
, *SessionIdLen
);
987 Gets the client random data used in the specified TLS connection.
989 This function returns the TLS/SSL client random data currently used in
990 the specified TLS connection.
992 @param[in] Tls Pointer to the TLS object.
993 @param[in,out] ClientRandom Buffer to contain the returned client
994 random data (32 bytes).
1001 IN OUT UINT8
*ClientRandom
1004 TLS_CONNECTION
*TlsConn
;
1006 TlsConn
= (TLS_CONNECTION
*) Tls
;
1008 if (TlsConn
== NULL
|| TlsConn
->Ssl
== NULL
|| ClientRandom
== NULL
) {
1012 SSL_get_client_random (TlsConn
->Ssl
, ClientRandom
, SSL3_RANDOM_SIZE
);
1016 Gets the server random data used in the specified TLS connection.
1018 This function returns the TLS/SSL server random data currently used in
1019 the specified TLS connection.
1021 @param[in] Tls Pointer to the TLS object.
1022 @param[in,out] ServerRandom Buffer to contain the returned server
1023 random data (32 bytes).
1028 TlsGetServerRandom (
1030 IN OUT UINT8
*ServerRandom
1033 TLS_CONNECTION
*TlsConn
;
1035 TlsConn
= (TLS_CONNECTION
*) Tls
;
1037 if (TlsConn
== NULL
|| TlsConn
->Ssl
== NULL
|| ServerRandom
== NULL
) {
1041 SSL_get_server_random (TlsConn
->Ssl
, ServerRandom
, SSL3_RANDOM_SIZE
);
1045 Gets the master key data used in the specified TLS connection.
1047 This function returns the TLS/SSL master key material currently used in
1048 the specified TLS connection.
1050 @param[in] Tls Pointer to the TLS object.
1051 @param[in,out] KeyMaterial Buffer to contain the returned key material.
1053 @retval EFI_SUCCESS Key material was returned successfully.
1054 @retval EFI_INVALID_PARAMETER The parameter is invalid.
1055 @retval EFI_UNSUPPORTED Invalid TLS/SSL session.
1062 IN OUT UINT8
*KeyMaterial
1065 TLS_CONNECTION
*TlsConn
;
1066 SSL_SESSION
*Session
;
1068 TlsConn
= (TLS_CONNECTION
*) Tls
;
1071 if (TlsConn
== NULL
|| TlsConn
->Ssl
== NULL
|| KeyMaterial
== NULL
) {
1072 return EFI_INVALID_PARAMETER
;
1075 Session
= SSL_get_session (TlsConn
->Ssl
);
1077 if (Session
== NULL
) {
1078 return EFI_UNSUPPORTED
;
1081 SSL_SESSION_get_master_key (Session
, KeyMaterial
, SSL3_MASTER_SECRET_SIZE
);
1087 Gets the CA Certificate from the cert store.
1089 This function returns the CA certificate for the chosen
1092 @param[in] Tls Pointer to the TLS object.
1093 @param[out] Data Pointer to the data buffer to receive the CA
1094 certificate data sent to the client.
1095 @param[in,out] DataSize The size of data buffer in bytes.
1097 @retval EFI_SUCCESS The operation succeeded.
1098 @retval EFI_UNSUPPORTED This function is not supported.
1099 @retval EFI_BUFFER_TOO_SMALL The Data is too small to hold the data.
1104 TlsGetCaCertificate (
1107 IN OUT UINTN
*DataSize
1110 return EFI_UNSUPPORTED
;
1114 Gets the local public Certificate set in the specified TLS object.
1116 This function returns the local public certificate which was currently set
1117 in the specified TLS object.
1119 @param[in] Tls Pointer to the TLS object.
1120 @param[out] Data Pointer to the data buffer to receive the local
1122 @param[in,out] DataSize The size of data buffer in bytes.
1124 @retval EFI_SUCCESS The operation succeeded.
1125 @retval EFI_INVALID_PARAMETER The parameter is invalid.
1126 @retval EFI_NOT_FOUND The certificate is not found.
1127 @retval EFI_BUFFER_TOO_SMALL The Data is too small to hold the data.
1132 TlsGetHostPublicCert (
1135 IN OUT UINTN
*DataSize
1139 TLS_CONNECTION
*TlsConn
;
1142 TlsConn
= (TLS_CONNECTION
*) Tls
;
1144 if (TlsConn
== NULL
|| TlsConn
->Ssl
== NULL
|| DataSize
== NULL
|| (*DataSize
!= 0 && Data
== NULL
)) {
1145 return EFI_INVALID_PARAMETER
;
1148 Cert
= SSL_get_certificate(TlsConn
->Ssl
);
1150 return EFI_NOT_FOUND
;
1154 // Only DER encoding is supported currently.
1156 if (*DataSize
< (UINTN
) i2d_X509 (Cert
, NULL
)) {
1157 *DataSize
= (UINTN
) i2d_X509 (Cert
, NULL
);
1158 return EFI_BUFFER_TOO_SMALL
;
1161 *DataSize
= (UINTN
) i2d_X509 (Cert
, (unsigned char **) &Data
);
1167 Gets the local private key set in the specified TLS object.
1169 This function returns the local private key data which was currently set
1170 in the specified TLS object.
1172 @param[in] Tls Pointer to the TLS object.
1173 @param[out] Data Pointer to the data buffer to receive the local
1175 @param[in,out] DataSize The size of data buffer in bytes.
1177 @retval EFI_SUCCESS The operation succeeded.
1178 @retval EFI_UNSUPPORTED This function is not supported.
1179 @retval EFI_BUFFER_TOO_SMALL The Data is too small to hold the data.
1184 TlsGetHostPrivateKey (
1187 IN OUT UINTN
*DataSize
1190 return EFI_UNSUPPORTED
;
1194 Gets the CA-supplied certificate revocation list data set in the specified
1197 This function returns the CA-supplied certificate revocation list data which
1198 was currently set in the specified TLS object.
1200 @param[out] Data Pointer to the data buffer to receive the CRL data.
1201 @param[in,out] DataSize The size of data buffer in bytes.
1203 @retval EFI_SUCCESS The operation succeeded.
1204 @retval EFI_UNSUPPORTED This function is not supported.
1205 @retval EFI_BUFFER_TOO_SMALL The Data is too small to hold the data.
1210 TlsGetCertRevocationList (
1212 IN OUT UINTN
*DataSize
1215 return EFI_UNSUPPORTED
;