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 Pointer to a UINT16 cipher Id.
239 @param[in] CipherNum The number of cipher in the list.
241 @retval EFI_SUCCESS The ciphers list was set successfully.
242 @retval EFI_INVALID_PARAMETER The parameter is invalid.
243 @retval EFI_UNSUPPORTED Unsupported TLS cipher in the list.
254 TLS_CONNECTION
*TlsConn
;
256 CONST TLS_CIPHER_MAPPING
*Mapping
;
257 CONST CHAR8
*MappingName
;
258 CHAR8 CipherString
[500];
260 TlsConn
= (TLS_CONNECTION
*) Tls
;
261 if (TlsConn
== NULL
|| TlsConn
->Ssl
== NULL
|| CipherId
== NULL
) {
262 return EFI_INVALID_PARAMETER
;
268 memset (CipherString
, 0, sizeof (CipherString
));
270 for (Index
= 0; Index
< CipherNum
; Index
++) {
272 // Handling OpenSSL / RFC Cipher name mapping.
274 Mapping
= TlsGetCipherMapping (*(CipherId
+ Index
));
275 if (Mapping
== NULL
) {
276 return EFI_UNSUPPORTED
;
278 MappingName
= Mapping
->OpensslCipher
;
282 // The ciphers were separated by a colon.
284 AsciiStrCatS (CipherString
, sizeof (CipherString
), ":");
287 AsciiStrCatS (CipherString
, sizeof (CipherString
), MappingName
);
290 AsciiStrCatS (CipherString
, sizeof (CipherString
), ":@STRENGTH");
293 // Sets the ciphers for use by the Tls object.
295 if (SSL_set_cipher_list (TlsConn
->Ssl
, CipherString
) <= 0) {
296 return EFI_UNSUPPORTED
;
303 Set the compression method for TLS/SSL operations.
305 This function handles TLS/SSL integrated compression methods.
307 @param[in] CompMethod The compression method ID.
309 @retval EFI_SUCCESS The compression method for the communication was
311 @retval EFI_UNSUPPORTED Unsupported compression method.
316 TlsSetCompressionMethod (
326 if (CompMethod
== 0) {
328 // TLS defines one standard compression method, CompressionMethod.null (0),
329 // which specifies that data exchanged via the record protocol will not be compressed.
330 // So, return EFI_SUCCESS directly (RFC 3749).
333 } else if (CompMethod
== 1) {
336 return EFI_UNSUPPORTED
;
340 // Adds the compression method to the list of available
341 // compression methods.
343 Ret
= SSL_COMP_add_compression_method (CompMethod
, Cm
);
345 return EFI_UNSUPPORTED
;
352 Set peer certificate verification mode for the TLS connection.
354 This function sets the verification mode flags for the TLS connection.
356 @param[in] Tls Pointer to the TLS object.
357 @param[in] VerifyMode A set of logically or'ed verification mode flags.
367 TLS_CONNECTION
*TlsConn
;
369 TlsConn
= (TLS_CONNECTION
*) Tls
;
370 if (TlsConn
== NULL
|| TlsConn
->Ssl
== NULL
) {
375 // Set peer certificate verification parameters with NULL callback.
377 SSL_set_verify (TlsConn
->Ssl
, VerifyMode
, NULL
);
381 Sets a TLS/SSL session ID to be used during TLS/SSL connect.
383 This function sets a session ID to be used when the TLS/SSL connection is
386 @param[in] Tls Pointer to the TLS object.
387 @param[in] SessionId Session ID data used for session resumption.
388 @param[in] SessionIdLen Length of Session ID in bytes.
390 @retval EFI_SUCCESS Session ID was set successfully.
391 @retval EFI_INVALID_PARAMETER The parameter is invalid.
392 @retval EFI_UNSUPPORTED No available session for ID setting.
400 IN UINT16 SessionIdLen
403 TLS_CONNECTION
*TlsConn
;
404 SSL_SESSION
*Session
;
406 TlsConn
= (TLS_CONNECTION
*) Tls
;
409 if (TlsConn
== NULL
|| TlsConn
->Ssl
== NULL
|| SessionId
== NULL
) {
410 return EFI_INVALID_PARAMETER
;
413 Session
= SSL_get_session (TlsConn
->Ssl
);
414 if (Session
== NULL
) {
415 return EFI_UNSUPPORTED
;
418 SSL_SESSION_set1_id (Session
, (const unsigned char *)SessionId
, SessionIdLen
);
424 Adds the CA to the cert store when requesting Server or Client authentication.
426 This function adds the CA certificate to the list of CAs when requesting
427 Server or Client authentication for the chosen TLS connection.
429 @param[in] Tls Pointer to the TLS object.
430 @param[in] Data Pointer to the data buffer of a DER-encoded binary
431 X.509 certificate or PEM-encoded X.509 certificate.
432 @param[in] DataSize The size of data buffer in bytes.
434 @retval EFI_SUCCESS The operation succeeded.
435 @retval EFI_INVALID_PARAMETER The parameter is invalid.
436 @retval EFI_OUT_OF_RESOURCES Required resources could not be allocated.
437 @retval EFI_ABORTED Invalid X.509 certificate.
442 TlsSetCaCertificate (
450 X509_STORE
*X509Store
;
452 TLS_CONNECTION
*TlsConn
;
460 Status
= EFI_SUCCESS
;
461 TlsConn
= (TLS_CONNECTION
*) Tls
;
464 if (TlsConn
== NULL
|| TlsConn
->Ssl
== NULL
|| Data
== NULL
|| DataSize
== 0) {
465 return EFI_INVALID_PARAMETER
;
469 // DER-encoded binary X.509 certificate or PEM-encoded X.509 certificate.
470 // Determine whether certificate is from DER encoding, if so, translate it to X509 structure.
472 Cert
= d2i_X509 (NULL
, (const unsigned char ** )&Data
, (long) DataSize
);
475 // Certificate is from PEM encoding.
477 BioCert
= BIO_new (BIO_s_mem ());
478 if (BioCert
== NULL
) {
479 Status
= EFI_OUT_OF_RESOURCES
;
483 if (BIO_write (BioCert
, Data
, (UINT32
) DataSize
) <= 0) {
484 Status
= EFI_ABORTED
;
488 Cert
= PEM_read_bio_X509 (BioCert
, NULL
, NULL
, NULL
);
490 Status
= EFI_ABORTED
;
495 SslCtx
= SSL_get_SSL_CTX (TlsConn
->Ssl
);
496 X509Store
= SSL_CTX_get_cert_store (SslCtx
);
497 if (X509Store
== NULL
) {
498 Status
= EFI_ABORTED
;
503 // Add certificate to X509 store
505 Ret
= X509_STORE_add_cert (X509Store
, Cert
);
507 ErrorCode
= ERR_peek_last_error ();
509 // Ignore "already in table" errors
511 if (!(ERR_GET_FUNC (ErrorCode
) == X509_F_X509_STORE_ADD_CERT
&&
512 ERR_GET_REASON (ErrorCode
) == X509_R_CERT_ALREADY_IN_HASH_TABLE
)) {
513 Status
= EFI_ABORTED
;
519 if (BioCert
!= NULL
) {
531 Loads the local public certificate into the specified TLS object.
533 This function loads the X.509 certificate into the specified TLS object
536 @param[in] Tls Pointer to the TLS object.
537 @param[in] Data Pointer to the data buffer of a DER-encoded binary
538 X.509 certificate or PEM-encoded X.509 certificate.
539 @param[in] DataSize The size of data buffer in bytes.
541 @retval EFI_SUCCESS The operation succeeded.
542 @retval EFI_INVALID_PARAMETER The parameter is invalid.
543 @retval EFI_OUT_OF_RESOURCES Required resources could not be allocated.
544 @retval EFI_ABORTED Invalid X.509 certificate.
549 TlsSetHostPublicCert (
558 TLS_CONNECTION
*TlsConn
;
562 Status
= EFI_SUCCESS
;
563 TlsConn
= (TLS_CONNECTION
*) Tls
;
565 if (TlsConn
== NULL
|| TlsConn
->Ssl
== NULL
|| Data
== NULL
|| DataSize
== 0) {
566 return EFI_INVALID_PARAMETER
;
570 // DER-encoded binary X.509 certificate or PEM-encoded X.509 certificate.
571 // Determine whether certificate is from DER encoding, if so, translate it to X509 structure.
573 Cert
= d2i_X509 (NULL
, (const unsigned char ** )&Data
, (long) DataSize
);
576 // Certificate is from PEM encoding.
578 BioCert
= BIO_new (BIO_s_mem ());
579 if (BioCert
== NULL
) {
580 Status
= EFI_OUT_OF_RESOURCES
;
584 if (BIO_write (BioCert
, Data
, (UINT32
) DataSize
) <= 0) {
585 Status
= EFI_ABORTED
;
589 Cert
= PEM_read_bio_X509 (BioCert
, NULL
, NULL
, NULL
);
591 Status
= EFI_ABORTED
;
596 if (SSL_use_certificate (TlsConn
->Ssl
, Cert
) != 1) {
597 Status
= EFI_ABORTED
;
602 if (BioCert
!= NULL
) {
614 Adds the local private key to the specified TLS object.
616 This function adds the local private key (PEM-encoded RSA or PKCS#8 private
617 key) into the specified TLS object for TLS negotiation.
619 @param[in] Tls Pointer to the TLS object.
620 @param[in] Data Pointer to the data buffer of a PEM-encoded RSA
621 or PKCS#8 private key.
622 @param[in] DataSize The size of data buffer in bytes.
624 @retval EFI_SUCCESS The operation succeeded.
625 @retval EFI_UNSUPPORTED This function is not supported.
626 @retval EFI_ABORTED Invalid private key data.
631 TlsSetHostPrivateKey (
637 return EFI_UNSUPPORTED
;
641 Adds the CA-supplied certificate revocation list for certificate validation.
643 This function adds the CA-supplied certificate revocation list data for
644 certificate validity checking.
646 @param[in] Data Pointer to the data buffer of a DER-encoded CRL data.
647 @param[in] DataSize The size of data buffer in bytes.
649 @retval EFI_SUCCESS The operation succeeded.
650 @retval EFI_UNSUPPORTED This function is not supported.
651 @retval EFI_ABORTED Invalid CRL data.
656 TlsSetCertRevocationList (
661 return EFI_UNSUPPORTED
;
665 Gets the protocol version used by the specified TLS connection.
667 This function returns the protocol version used by the specified TLS
670 If Tls is NULL, then ASSERT().
672 @param[in] Tls Pointer to the TLS object.
674 @return The protocol version of the specified TLS connection.
683 TLS_CONNECTION
*TlsConn
;
685 TlsConn
= (TLS_CONNECTION
*) Tls
;
687 ASSERT (TlsConn
!= NULL
);
689 return (UINT16
)(SSL_version (TlsConn
->Ssl
));
693 Gets the connection end of the specified TLS connection.
695 This function returns the connection end (as client or as server) used by
696 the specified TLS connection.
698 If Tls is NULL, then ASSERT().
700 @param[in] Tls Pointer to the TLS object.
702 @return The connection end used by the specified TLS connection.
707 TlsGetConnectionEnd (
711 TLS_CONNECTION
*TlsConn
;
713 TlsConn
= (TLS_CONNECTION
*) Tls
;
715 ASSERT (TlsConn
!= NULL
);
717 return (UINT8
)SSL_is_server (TlsConn
->Ssl
);
721 Gets the cipher suite used by the specified TLS connection.
723 This function returns current cipher suite used by the specified
726 @param[in] Tls Pointer to the TLS object.
727 @param[in,out] CipherId The cipher suite used by the TLS object.
729 @retval EFI_SUCCESS The cipher suite was returned successfully.
730 @retval EFI_INVALID_PARAMETER The parameter is invalid.
731 @retval EFI_UNSUPPORTED Unsupported cipher suite.
736 TlsGetCurrentCipher (
738 IN OUT UINT16
*CipherId
741 TLS_CONNECTION
*TlsConn
;
742 CONST SSL_CIPHER
*Cipher
;
744 TlsConn
= (TLS_CONNECTION
*) Tls
;
747 if (TlsConn
== NULL
|| TlsConn
->Ssl
== NULL
|| CipherId
== NULL
) {
748 return EFI_INVALID_PARAMETER
;
751 Cipher
= SSL_get_current_cipher (TlsConn
->Ssl
);
752 if (Cipher
== NULL
) {
753 return EFI_UNSUPPORTED
;
756 *CipherId
= (SSL_CIPHER_get_id (Cipher
)) & 0xFFFF;
762 Gets the compression methods used by the specified TLS connection.
764 This function returns current integrated compression methods used by
765 the specified TLS connection.
767 @param[in] Tls Pointer to the TLS object.
768 @param[in,out] CompressionId The current compression method used by
771 @retval EFI_SUCCESS The compression method was returned successfully.
772 @retval EFI_INVALID_PARAMETER The parameter is invalid.
773 @retval EFI_ABORTED Invalid Compression method.
774 @retval EFI_UNSUPPORTED This function is not supported.
779 TlsGetCurrentCompressionId (
781 IN OUT UINT8
*CompressionId
784 return EFI_UNSUPPORTED
;
788 Gets the verification mode currently set in the TLS connection.
790 This function returns the peer verification mode currently set in the
791 specified TLS connection.
793 If Tls is NULL, then ASSERT().
795 @param[in] Tls Pointer to the TLS object.
797 @return The verification mode set in the specified TLS connection.
806 TLS_CONNECTION
*TlsConn
;
808 TlsConn
= (TLS_CONNECTION
*) Tls
;
810 ASSERT (TlsConn
!= NULL
);
812 return SSL_get_verify_mode (TlsConn
->Ssl
);
816 Gets the session ID used by the specified TLS connection.
818 This function returns the TLS/SSL session ID currently used by the
819 specified TLS connection.
821 @param[in] Tls Pointer to the TLS object.
822 @param[in,out] SessionId Buffer to contain the returned session ID.
823 @param[in,out] SessionIdLen The length of Session ID in bytes.
825 @retval EFI_SUCCESS The Session ID was returned successfully.
826 @retval EFI_INVALID_PARAMETER The parameter is invalid.
827 @retval EFI_UNSUPPORTED Invalid TLS/SSL session.
834 IN OUT UINT8
*SessionId
,
835 IN OUT UINT16
*SessionIdLen
838 TLS_CONNECTION
*TlsConn
;
839 SSL_SESSION
*Session
;
840 CONST UINT8
*SslSessionId
;
842 TlsConn
= (TLS_CONNECTION
*) Tls
;
845 if (TlsConn
== NULL
|| TlsConn
->Ssl
== NULL
|| SessionId
== NULL
|| SessionIdLen
== NULL
) {
846 return EFI_INVALID_PARAMETER
;
849 Session
= SSL_get_session (TlsConn
->Ssl
);
850 if (Session
== NULL
) {
851 return EFI_UNSUPPORTED
;
854 SslSessionId
= SSL_SESSION_get_id (Session
, (unsigned int *)SessionIdLen
);
855 CopyMem (SessionId
, SslSessionId
, *SessionIdLen
);
861 Gets the client random data used in the specified TLS connection.
863 This function returns the TLS/SSL client random data currently used in
864 the specified TLS connection.
866 @param[in] Tls Pointer to the TLS object.
867 @param[in,out] ClientRandom Buffer to contain the returned client
868 random data (32 bytes).
875 IN OUT UINT8
*ClientRandom
878 TLS_CONNECTION
*TlsConn
;
880 TlsConn
= (TLS_CONNECTION
*) Tls
;
882 if (TlsConn
== NULL
|| TlsConn
->Ssl
== NULL
|| ClientRandom
== NULL
) {
886 SSL_get_client_random (TlsConn
->Ssl
, ClientRandom
, SSL3_RANDOM_SIZE
);
890 Gets the server random data used in the specified TLS connection.
892 This function returns the TLS/SSL server random data currently used in
893 the specified TLS connection.
895 @param[in] Tls Pointer to the TLS object.
896 @param[in,out] ServerRandom Buffer to contain the returned server
897 random data (32 bytes).
904 IN OUT UINT8
*ServerRandom
907 TLS_CONNECTION
*TlsConn
;
909 TlsConn
= (TLS_CONNECTION
*) Tls
;
911 if (TlsConn
== NULL
|| TlsConn
->Ssl
== NULL
|| ServerRandom
== NULL
) {
915 SSL_get_server_random (TlsConn
->Ssl
, ServerRandom
, SSL3_RANDOM_SIZE
);
919 Gets the master key data used in the specified TLS connection.
921 This function returns the TLS/SSL master key material currently used in
922 the specified TLS connection.
924 @param[in] Tls Pointer to the TLS object.
925 @param[in,out] KeyMaterial Buffer to contain the returned key material.
927 @retval EFI_SUCCESS Key material was returned successfully.
928 @retval EFI_INVALID_PARAMETER The parameter is invalid.
929 @retval EFI_UNSUPPORTED Invalid TLS/SSL session.
936 IN OUT UINT8
*KeyMaterial
939 TLS_CONNECTION
*TlsConn
;
940 SSL_SESSION
*Session
;
942 TlsConn
= (TLS_CONNECTION
*) Tls
;
945 if (TlsConn
== NULL
|| TlsConn
->Ssl
== NULL
|| KeyMaterial
== NULL
) {
946 return EFI_INVALID_PARAMETER
;
949 Session
= SSL_get_session (TlsConn
->Ssl
);
951 if (Session
== NULL
) {
952 return EFI_UNSUPPORTED
;
955 SSL_SESSION_get_master_key (Session
, KeyMaterial
, SSL3_MASTER_SECRET_SIZE
);
961 Gets the CA Certificate from the cert store.
963 This function returns the CA certificate for the chosen
966 @param[in] Tls Pointer to the TLS object.
967 @param[out] Data Pointer to the data buffer to receive the CA
968 certificate data sent to the client.
969 @param[in,out] DataSize The size of data buffer in bytes.
971 @retval EFI_SUCCESS The operation succeeded.
972 @retval EFI_UNSUPPORTED This function is not supported.
973 @retval EFI_BUFFER_TOO_SMALL The Data is too small to hold the data.
978 TlsGetCaCertificate (
981 IN OUT UINTN
*DataSize
984 return EFI_UNSUPPORTED
;
988 Gets the local public Certificate set in the specified TLS object.
990 This function returns the local public certificate which was currently set
991 in the specified TLS object.
993 @param[in] Tls Pointer to the TLS object.
994 @param[out] Data Pointer to the data buffer to receive the local
996 @param[in,out] DataSize The size of data buffer in bytes.
998 @retval EFI_SUCCESS The operation succeeded.
999 @retval EFI_INVALID_PARAMETER The parameter is invalid.
1000 @retval EFI_NOT_FOUND The certificate is not found.
1001 @retval EFI_BUFFER_TOO_SMALL The Data is too small to hold the data.
1006 TlsGetHostPublicCert (
1009 IN OUT UINTN
*DataSize
1013 TLS_CONNECTION
*TlsConn
;
1016 TlsConn
= (TLS_CONNECTION
*) Tls
;
1018 if (TlsConn
== NULL
|| TlsConn
->Ssl
== NULL
|| DataSize
== NULL
|| (*DataSize
!= 0 && Data
== NULL
)) {
1019 return EFI_INVALID_PARAMETER
;
1022 Cert
= SSL_get_certificate(TlsConn
->Ssl
);
1024 return EFI_NOT_FOUND
;
1028 // Only DER encoding is supported currently.
1030 if (*DataSize
< (UINTN
) i2d_X509 (Cert
, NULL
)) {
1031 *DataSize
= (UINTN
) i2d_X509 (Cert
, NULL
);
1032 return EFI_BUFFER_TOO_SMALL
;
1035 *DataSize
= (UINTN
) i2d_X509 (Cert
, (unsigned char **) &Data
);
1041 Gets the local private key set in the specified TLS object.
1043 This function returns the local private key data which was currently set
1044 in the specified TLS object.
1046 @param[in] Tls Pointer to the TLS object.
1047 @param[out] Data Pointer to the data buffer to receive the local
1049 @param[in,out] DataSize The size of data buffer in bytes.
1051 @retval EFI_SUCCESS The operation succeeded.
1052 @retval EFI_UNSUPPORTED This function is not supported.
1053 @retval EFI_BUFFER_TOO_SMALL The Data is too small to hold the data.
1058 TlsGetHostPrivateKey (
1061 IN OUT UINTN
*DataSize
1064 return EFI_UNSUPPORTED
;
1068 Gets the CA-supplied certificate revocation list data set in the specified
1071 This function returns the CA-supplied certificate revocation list data which
1072 was currently set in the specified TLS object.
1074 @param[out] Data Pointer to the data buffer to receive the CRL data.
1075 @param[in,out] DataSize The size of data buffer in bytes.
1077 @retval EFI_SUCCESS The operation succeeded.
1078 @retval EFI_UNSUPPORTED This function is not supported.
1079 @retval EFI_BUFFER_TOO_SMALL The Data is too small to hold the data.
1084 TlsGetCertRevocationList (
1086 IN OUT UINTN
*DataSize
1089 return EFI_UNSUPPORTED
;