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
;
30 // The mapping table between IANA/IETF Cipher Suite definitions and
31 // OpenSSL-used Cipher Suite name.
33 STATIC CONST TLS_CIPHER_PAIR TlsCipherMappingTable
[] = {
34 { 0x0001, "NULL-MD5" }, /// TLS_RSA_WITH_NULL_MD5
35 { 0x0002, "NULL-SHA" }, /// TLS_RSA_WITH_NULL_SHA
36 { 0x0004, "RC4-MD5" }, /// TLS_RSA_WITH_RC4_128_MD5
37 { 0x0005, "RC4-SHA" }, /// TLS_RSA_WITH_RC4_128_SHA
38 { 0x000A, "DES-CBC3-SHA" }, /// TLS_RSA_WITH_3DES_EDE_CBC_SHA, mandatory TLS 1.1
39 { 0x0016, "DHE-RSA-DES-CBC3-SHA" }, /// TLS_DHE_RSA_WITH_3DES_EDE_CBC_SHA
40 { 0x002F, "AES128-SHA" }, /// TLS_RSA_WITH_AES_128_CBC_SHA, mandatory TLS 1.2
41 { 0x0030, "DH-DSS-AES128-SHA" }, /// TLS_DH_DSS_WITH_AES_128_CBC_SHA
42 { 0x0031, "DH-RSA-AES128-SHA" }, /// TLS_DH_RSA_WITH_AES_128_CBC_SHA
43 { 0x0033, "DHE-RSA-AES128-SHA" }, /// TLS_DHE_RSA_WITH_AES_128_CBC_SHA
44 { 0x0035, "AES256-SHA" }, /// TLS_RSA_WITH_AES_256_CBC_SHA
45 { 0x0036, "DH-DSS-AES256-SHA" }, /// TLS_DH_DSS_WITH_AES_256_CBC_SHA
46 { 0x0037, "DH-RSA-AES256-SHA" }, /// TLS_DH_RSA_WITH_AES_256_CBC_SHA
47 { 0x0039, "DHE-RSA-AES256-SHA" }, /// TLS_DHE_RSA_WITH_AES_256_CBC_SHA
48 { 0x003B, "NULL-SHA256" }, /// TLS_RSA_WITH_NULL_SHA256
49 { 0x003C, "AES128-SHA256" }, /// TLS_RSA_WITH_AES_128_CBC_SHA256
50 { 0x003D, "AES256-SHA256" }, /// TLS_RSA_WITH_AES_256_CBC_SHA256
51 { 0x003E, "DH-DSS-AES128-SHA256" }, /// TLS_DH_DSS_WITH_AES_128_CBC_SHA256
52 { 0x003F, "DH-RSA-AES128-SHA256" }, /// TLS_DH_RSA_WITH_AES_128_CBC_SHA256
53 { 0x0067, "DHE-RSA-AES128-SHA256" }, /// TLS_DHE_RSA_WITH_AES_128_CBC_SHA256
54 { 0x0068, "DH-DSS-AES256-SHA256" }, /// TLS_DH_DSS_WITH_AES_256_CBC_SHA256
55 { 0x0069, "DH-RSA-AES256-SHA256" }, /// TLS_DH_RSA_WITH_AES_256_CBC_SHA256
56 { 0x006B, "DHE-RSA-AES256-SHA256" } /// TLS_DHE_RSA_WITH_AES_256_CBC_SHA256
60 Gets the OpenSSL cipher suite string for the supplied IANA TLS cipher suite.
62 @param[in] CipherId The supplied IANA TLS cipher suite ID.
64 @return The corresponding OpenSSL cipher suite string if found,
74 CONST TLS_CIPHER_PAIR
*CipherEntry
;
78 CipherEntry
= TlsCipherMappingTable
;
79 TableSize
= sizeof (TlsCipherMappingTable
) / sizeof (TLS_CIPHER_PAIR
);
82 // Search Cipher Mapping Table for IANA-OpenSSL Cipher Translation
84 for (Index
= 0; Index
< TableSize
; Index
++, CipherEntry
++) {
86 // Translate IANA cipher suite name to OpenSSL name.
88 if (CipherEntry
->IanaCipher
== CipherId
) {
89 return CipherEntry
->OpensslCipher
;
94 // No Cipher Mapping found, return NULL.
100 Set a new TLS/SSL method for a particular TLS object.
102 This function sets a new TLS/SSL method for a particular TLS object.
104 @param[in] Tls Pointer to a TLS object.
105 @param[in] MajorVer Major Version of TLS/SSL Protocol.
106 @param[in] MinorVer Minor Version of TLS/SSL Protocol.
108 @retval EFI_SUCCESS The TLS/SSL method was set successfully.
109 @retval EFI_INVALID_PARAMETER The parameter is invalid.
110 @retval EFI_UNSUPPORTED Unsupported TLS/SSL method.
121 TLS_CONNECTION
*TlsConn
;
124 TlsConn
= (TLS_CONNECTION
*)Tls
;
125 if (TlsConn
== NULL
|| TlsConn
->Ssl
== NULL
) {
126 return EFI_INVALID_PARAMETER
;
129 ProtoVersion
= (MajorVer
<< 8) | MinorVer
;
132 // Bound TLS method to the particular specified version.
134 switch (ProtoVersion
) {
139 SSL_set_min_proto_version (TlsConn
->Ssl
, TLS1_VERSION
);
140 SSL_set_max_proto_version (TlsConn
->Ssl
, TLS1_VERSION
);
146 SSL_set_min_proto_version (TlsConn
->Ssl
, TLS1_1_VERSION
);
147 SSL_set_max_proto_version (TlsConn
->Ssl
, TLS1_1_VERSION
);
153 SSL_set_min_proto_version (TlsConn
->Ssl
, TLS1_2_VERSION
);
154 SSL_set_max_proto_version (TlsConn
->Ssl
, TLS1_2_VERSION
);
158 // Unsupported Protocol Version
160 return EFI_UNSUPPORTED
;
167 Set TLS object to work in client or server mode.
169 This function prepares a TLS object to work in client or server mode.
171 @param[in] Tls Pointer to a TLS object.
172 @param[in] IsServer Work in server mode.
174 @retval EFI_SUCCESS The TLS/SSL work mode was set successfully.
175 @retval EFI_INVALID_PARAMETER The parameter is invalid.
176 @retval EFI_UNSUPPORTED Unsupported TLS/SSL work mode.
181 TlsSetConnectionEnd (
186 TLS_CONNECTION
*TlsConn
;
188 TlsConn
= (TLS_CONNECTION
*) Tls
;
189 if (TlsConn
== NULL
|| TlsConn
->Ssl
== NULL
) {
190 return EFI_INVALID_PARAMETER
;
195 // Set TLS to work in Client mode.
197 SSL_set_connect_state (TlsConn
->Ssl
);
200 // Set TLS to work in Server mode.
201 // It is unsupported for UEFI version currently.
203 //SSL_set_accept_state (TlsConn->Ssl);
204 return EFI_UNSUPPORTED
;
211 Set the ciphers list to be used by the TLS object.
213 This function sets the ciphers for use by a specified TLS object.
215 @param[in] Tls Pointer to a TLS object.
216 @param[in] CipherId Pointer to a UINT16 cipher Id.
217 @param[in] CipherNum The number of cipher in the list.
219 @retval EFI_SUCCESS The ciphers list was set successfully.
220 @retval EFI_INVALID_PARAMETER The parameter is invalid.
221 @retval EFI_UNSUPPORTED Unsupported TLS cipher in the list.
232 TLS_CONNECTION
*TlsConn
;
234 CONST CHAR8
*MappingName
;
235 CHAR8 CipherString
[500];
237 TlsConn
= (TLS_CONNECTION
*) Tls
;
238 if (TlsConn
== NULL
|| TlsConn
->Ssl
== NULL
|| CipherId
== NULL
) {
239 return EFI_INVALID_PARAMETER
;
244 memset (CipherString
, 0, sizeof (CipherString
));
246 for (Index
= 0; Index
< CipherNum
; Index
++) {
248 // Handling OpenSSL / RFC Cipher name mapping.
250 MappingName
= TlsGetCipherString (*(CipherId
+ Index
));
251 if (MappingName
== NULL
) {
252 return EFI_UNSUPPORTED
;
257 // The ciphers were separated by a colon.
259 AsciiStrCatS (CipherString
, sizeof (CipherString
), ":");
262 AsciiStrCatS (CipherString
, sizeof (CipherString
), MappingName
);
265 AsciiStrCatS (CipherString
, sizeof (CipherString
), ":@STRENGTH");
268 // Sets the ciphers for use by the Tls object.
270 if (SSL_set_cipher_list (TlsConn
->Ssl
, CipherString
) <= 0) {
271 return EFI_UNSUPPORTED
;
278 Set the compression method for TLS/SSL operations.
280 This function handles TLS/SSL integrated compression methods.
282 @param[in] CompMethod The compression method ID.
284 @retval EFI_SUCCESS The compression method for the communication was
286 @retval EFI_UNSUPPORTED Unsupported compression method.
291 TlsSetCompressionMethod (
301 if (CompMethod
== 0) {
303 // TLS defines one standard compression method, CompressionMethod.null (0),
304 // which specifies that data exchanged via the record protocol will not be compressed.
305 // So, return EFI_SUCCESS directly (RFC 3749).
308 } else if (CompMethod
== 1) {
311 return EFI_UNSUPPORTED
;
315 // Adds the compression method to the list of available
316 // compression methods.
318 Ret
= SSL_COMP_add_compression_method (CompMethod
, Cm
);
320 return EFI_UNSUPPORTED
;
327 Set peer certificate verification mode for the TLS connection.
329 This function sets the verification mode flags for the TLS connection.
331 @param[in] Tls Pointer to the TLS object.
332 @param[in] VerifyMode A set of logically or'ed verification mode flags.
342 TLS_CONNECTION
*TlsConn
;
344 TlsConn
= (TLS_CONNECTION
*) Tls
;
345 if (TlsConn
== NULL
|| TlsConn
->Ssl
== NULL
) {
350 // Set peer certificate verification parameters with NULL callback.
352 SSL_set_verify (TlsConn
->Ssl
, VerifyMode
, NULL
);
356 Sets a TLS/SSL session ID to be used during TLS/SSL connect.
358 This function sets a session ID to be used when the TLS/SSL connection is
361 @param[in] Tls Pointer to the TLS object.
362 @param[in] SessionId Session ID data used for session resumption.
363 @param[in] SessionIdLen Length of Session ID in bytes.
365 @retval EFI_SUCCESS Session ID was set successfully.
366 @retval EFI_INVALID_PARAMETER The parameter is invalid.
367 @retval EFI_UNSUPPORTED No available session for ID setting.
375 IN UINT16 SessionIdLen
378 TLS_CONNECTION
*TlsConn
;
379 SSL_SESSION
*Session
;
381 TlsConn
= (TLS_CONNECTION
*) Tls
;
384 if (TlsConn
== NULL
|| TlsConn
->Ssl
== NULL
|| SessionId
== NULL
) {
385 return EFI_INVALID_PARAMETER
;
388 Session
= SSL_get_session (TlsConn
->Ssl
);
389 if (Session
== NULL
) {
390 return EFI_UNSUPPORTED
;
393 SSL_SESSION_set1_id (Session
, (const unsigned char *)SessionId
, SessionIdLen
);
399 Adds the CA to the cert store when requesting Server or Client authentication.
401 This function adds the CA certificate to the list of CAs when requesting
402 Server or Client authentication for the chosen TLS connection.
404 @param[in] Tls Pointer to the TLS object.
405 @param[in] Data Pointer to the data buffer of a DER-encoded binary
406 X.509 certificate or PEM-encoded X.509 certificate.
407 @param[in] DataSize The size of data buffer in bytes.
409 @retval EFI_SUCCESS The operation succeeded.
410 @retval EFI_INVALID_PARAMETER The parameter is invalid.
411 @retval EFI_OUT_OF_RESOURCES Required resources could not be allocated.
412 @retval EFI_ABORTED Invalid X.509 certificate.
417 TlsSetCaCertificate (
425 X509_STORE
*X509Store
;
427 TLS_CONNECTION
*TlsConn
;
435 Status
= EFI_SUCCESS
;
436 TlsConn
= (TLS_CONNECTION
*) Tls
;
439 if (TlsConn
== NULL
|| TlsConn
->Ssl
== NULL
|| Data
== NULL
|| DataSize
== 0) {
440 return EFI_INVALID_PARAMETER
;
444 // DER-encoded binary X.509 certificate or PEM-encoded X.509 certificate.
445 // Determine whether certificate is from DER encoding, if so, translate it to X509 structure.
447 Cert
= d2i_X509 (NULL
, (const unsigned char ** )&Data
, (long) DataSize
);
450 // Certificate is from PEM encoding.
452 BioCert
= BIO_new (BIO_s_mem ());
453 if (BioCert
== NULL
) {
454 Status
= EFI_OUT_OF_RESOURCES
;
458 if (BIO_write (BioCert
, Data
, (UINT32
) DataSize
) <= 0) {
459 Status
= EFI_ABORTED
;
463 Cert
= PEM_read_bio_X509 (BioCert
, NULL
, NULL
, NULL
);
465 Status
= EFI_ABORTED
;
470 SslCtx
= SSL_get_SSL_CTX (TlsConn
->Ssl
);
471 X509Store
= SSL_CTX_get_cert_store (SslCtx
);
472 if (X509Store
== NULL
) {
473 Status
= EFI_ABORTED
;
478 // Add certificate to X509 store
480 Ret
= X509_STORE_add_cert (X509Store
, Cert
);
482 ErrorCode
= ERR_peek_last_error ();
484 // Ignore "already in table" errors
486 if (!(ERR_GET_FUNC (ErrorCode
) == X509_F_X509_STORE_ADD_CERT
&&
487 ERR_GET_REASON (ErrorCode
) == X509_R_CERT_ALREADY_IN_HASH_TABLE
)) {
488 Status
= EFI_ABORTED
;
494 if (BioCert
!= NULL
) {
506 Loads the local public certificate into the specified TLS object.
508 This function loads the X.509 certificate into the specified TLS object
511 @param[in] Tls Pointer to the TLS object.
512 @param[in] Data Pointer to the data buffer of a DER-encoded binary
513 X.509 certificate or PEM-encoded X.509 certificate.
514 @param[in] DataSize The size of data buffer in bytes.
516 @retval EFI_SUCCESS The operation succeeded.
517 @retval EFI_INVALID_PARAMETER The parameter is invalid.
518 @retval EFI_OUT_OF_RESOURCES Required resources could not be allocated.
519 @retval EFI_ABORTED Invalid X.509 certificate.
524 TlsSetHostPublicCert (
533 TLS_CONNECTION
*TlsConn
;
537 Status
= EFI_SUCCESS
;
538 TlsConn
= (TLS_CONNECTION
*) Tls
;
540 if (TlsConn
== NULL
|| TlsConn
->Ssl
== NULL
|| Data
== NULL
|| DataSize
== 0) {
541 return EFI_INVALID_PARAMETER
;
545 // DER-encoded binary X.509 certificate or PEM-encoded X.509 certificate.
546 // Determine whether certificate is from DER encoding, if so, translate it to X509 structure.
548 Cert
= d2i_X509 (NULL
, (const unsigned char ** )&Data
, (long) DataSize
);
551 // Certificate is from PEM encoding.
553 BioCert
= BIO_new (BIO_s_mem ());
554 if (BioCert
== NULL
) {
555 Status
= EFI_OUT_OF_RESOURCES
;
559 if (BIO_write (BioCert
, Data
, (UINT32
) DataSize
) <= 0) {
560 Status
= EFI_ABORTED
;
564 Cert
= PEM_read_bio_X509 (BioCert
, NULL
, NULL
, NULL
);
566 Status
= EFI_ABORTED
;
571 if (SSL_use_certificate (TlsConn
->Ssl
, Cert
) != 1) {
572 Status
= EFI_ABORTED
;
577 if (BioCert
!= NULL
) {
589 Adds the local private key to the specified TLS object.
591 This function adds the local private key (PEM-encoded RSA or PKCS#8 private
592 key) into the specified TLS object for TLS negotiation.
594 @param[in] Tls Pointer to the TLS object.
595 @param[in] Data Pointer to the data buffer of a PEM-encoded RSA
596 or PKCS#8 private key.
597 @param[in] DataSize The size of data buffer in bytes.
599 @retval EFI_SUCCESS The operation succeeded.
600 @retval EFI_UNSUPPORTED This function is not supported.
601 @retval EFI_ABORTED Invalid private key data.
606 TlsSetHostPrivateKey (
612 return EFI_UNSUPPORTED
;
616 Adds the CA-supplied certificate revocation list for certificate validation.
618 This function adds the CA-supplied certificate revocation list data for
619 certificate validity checking.
621 @param[in] Data Pointer to the data buffer of a DER-encoded CRL data.
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 CRL data.
631 TlsSetCertRevocationList (
636 return EFI_UNSUPPORTED
;
640 Gets the protocol version used by the specified TLS connection.
642 This function returns the protocol version used by the specified TLS
645 @param[in] Tls Pointer to the TLS object.
647 @return The protocol version of the specified TLS connection.
656 TLS_CONNECTION
*TlsConn
;
658 TlsConn
= (TLS_CONNECTION
*) Tls
;
660 ASSERT (TlsConn
!= NULL
);
662 return (UINT16
)(SSL_version (TlsConn
->Ssl
));
666 Gets the connection end of the specified TLS connection.
668 This function returns the connection end (as client or as server) used by
669 the specified TLS connection.
671 @param[in] Tls Pointer to the TLS object.
673 @return The connection end used by the specified TLS connection.
678 TlsGetConnectionEnd (
682 TLS_CONNECTION
*TlsConn
;
684 TlsConn
= (TLS_CONNECTION
*) Tls
;
686 ASSERT (TlsConn
!= NULL
);
688 return (UINT8
)SSL_is_server (TlsConn
->Ssl
);
692 Gets the cipher suite used by the specified TLS connection.
694 This function returns current cipher suite used by the specified
697 @param[in] Tls Pointer to the TLS object.
698 @param[in,out] CipherId The cipher suite used by the TLS object.
700 @retval EFI_SUCCESS The cipher suite was returned successfully.
701 @retval EFI_INVALID_PARAMETER The parameter is invalid.
702 @retval EFI_UNSUPPORTED Unsupported cipher suite.
707 TlsGetCurrentCipher (
709 IN OUT UINT16
*CipherId
712 TLS_CONNECTION
*TlsConn
;
713 CONST SSL_CIPHER
*Cipher
;
715 TlsConn
= (TLS_CONNECTION
*) Tls
;
718 if (TlsConn
== NULL
|| TlsConn
->Ssl
== NULL
|| CipherId
== NULL
) {
719 return EFI_INVALID_PARAMETER
;
722 Cipher
= SSL_get_current_cipher (TlsConn
->Ssl
);
723 if (Cipher
== NULL
) {
724 return EFI_UNSUPPORTED
;
727 *CipherId
= (SSL_CIPHER_get_id (Cipher
)) & 0xFFFF;
733 Gets the compression methods used by the specified TLS connection.
735 This function returns current integrated compression methods used by
736 the specified TLS connection.
738 @param[in] Tls Pointer to the TLS object.
739 @param[in,out] CompressionId The current compression method used by
742 @retval EFI_SUCCESS The compression method was returned successfully.
743 @retval EFI_INVALID_PARAMETER The parameter is invalid.
744 @retval EFI_ABORTED Invalid Compression method.
745 @retval EFI_UNSUPPORTED This function is not supported.
750 TlsGetCurrentCompressionId (
752 IN OUT UINT8
*CompressionId
755 return EFI_UNSUPPORTED
;
759 Gets the verification mode currently set in the TLS connection.
761 This function returns the peer verification mode currently set in the
762 specified TLS connection.
764 @param[in] Tls Pointer to the TLS object.
766 @return The verification mode set in the specified TLS connection.
775 TLS_CONNECTION
*TlsConn
;
777 TlsConn
= (TLS_CONNECTION
*) Tls
;
779 ASSERT (TlsConn
!= NULL
);
781 return SSL_get_verify_mode (TlsConn
->Ssl
);
785 Gets the session ID used by the specified TLS connection.
787 This function returns the TLS/SSL session ID currently used by the
788 specified TLS connection.
790 @param[in] Tls Pointer to the TLS object.
791 @param[in,out] SessionId Buffer to contain the returned session ID.
792 @param[in,out] SessionIdLen The length of Session ID in bytes.
794 @retval EFI_SUCCESS The Session ID was returned successfully.
795 @retval EFI_INVALID_PARAMETER The parameter is invalid.
796 @retval EFI_UNSUPPORTED Invalid TLS/SSL session.
803 IN OUT UINT8
*SessionId
,
804 IN OUT UINT16
*SessionIdLen
807 TLS_CONNECTION
*TlsConn
;
808 SSL_SESSION
*Session
;
809 CONST UINT8
*SslSessionId
;
811 TlsConn
= (TLS_CONNECTION
*) Tls
;
814 if (TlsConn
== NULL
|| TlsConn
->Ssl
== NULL
|| SessionId
== NULL
|| SessionIdLen
== NULL
) {
815 return EFI_INVALID_PARAMETER
;
818 Session
= SSL_get_session (TlsConn
->Ssl
);
819 if (Session
== NULL
) {
820 return EFI_UNSUPPORTED
;
823 SslSessionId
= SSL_SESSION_get_id (Session
, (unsigned int *)SessionIdLen
);
824 CopyMem (SessionId
, SslSessionId
, *SessionIdLen
);
830 Gets the client random data used in the specified TLS connection.
832 This function returns the TLS/SSL client random data currently used in
833 the specified TLS connection.
835 @param[in] Tls Pointer to the TLS object.
836 @param[in,out] ClientRandom Buffer to contain the returned client
837 random data (32 bytes).
844 IN OUT UINT8
*ClientRandom
847 TLS_CONNECTION
*TlsConn
;
849 TlsConn
= (TLS_CONNECTION
*) Tls
;
851 if (TlsConn
== NULL
|| TlsConn
->Ssl
== NULL
|| ClientRandom
== NULL
) {
855 SSL_get_client_random (TlsConn
->Ssl
, ClientRandom
, SSL3_RANDOM_SIZE
);
859 Gets the server random data used in the specified TLS connection.
861 This function returns the TLS/SSL server random data currently used in
862 the specified TLS connection.
864 @param[in] Tls Pointer to the TLS object.
865 @param[in,out] ServerRandom Buffer to contain the returned server
866 random data (32 bytes).
873 IN OUT UINT8
*ServerRandom
876 TLS_CONNECTION
*TlsConn
;
878 TlsConn
= (TLS_CONNECTION
*) Tls
;
880 if (TlsConn
== NULL
|| TlsConn
->Ssl
== NULL
|| ServerRandom
== NULL
) {
884 SSL_get_server_random (TlsConn
->Ssl
, ServerRandom
, SSL3_RANDOM_SIZE
);
888 Gets the master key data used in the specified TLS connection.
890 This function returns the TLS/SSL master key material currently used in
891 the specified TLS connection.
893 @param[in] Tls Pointer to the TLS object.
894 @param[in,out] KeyMaterial Buffer to contain the returned key material.
896 @retval EFI_SUCCESS Key material was returned successfully.
897 @retval EFI_INVALID_PARAMETER The parameter is invalid.
898 @retval EFI_UNSUPPORTED Invalid TLS/SSL session.
905 IN OUT UINT8
*KeyMaterial
908 TLS_CONNECTION
*TlsConn
;
909 SSL_SESSION
*Session
;
911 TlsConn
= (TLS_CONNECTION
*) Tls
;
914 if (TlsConn
== NULL
|| TlsConn
->Ssl
== NULL
|| KeyMaterial
== NULL
) {
915 return EFI_INVALID_PARAMETER
;
918 Session
= SSL_get_session (TlsConn
->Ssl
);
920 if (Session
== NULL
) {
921 return EFI_UNSUPPORTED
;
924 SSL_SESSION_get_master_key (Session
, KeyMaterial
, SSL3_MASTER_SECRET_SIZE
);
930 Gets the CA Certificate from the cert store.
932 This function returns the CA certificate for the chosen
935 @param[in] Tls Pointer to the TLS object.
936 @param[out] Data Pointer to the data buffer to receive the CA
937 certificate data sent to the client.
938 @param[in,out] DataSize The size of data buffer in bytes.
940 @retval EFI_SUCCESS The operation succeeded.
941 @retval EFI_UNSUPPORTED This function is not supported.
942 @retval EFI_BUFFER_TOO_SMALL The Data is too small to hold the data.
947 TlsGetCaCertificate (
950 IN OUT UINTN
*DataSize
953 return EFI_UNSUPPORTED
;
957 Gets the local public Certificate set in the specified TLS object.
959 This function returns the local public certificate which was currently set
960 in the specified TLS object.
962 @param[in] Tls Pointer to the TLS object.
963 @param[out] Data Pointer to the data buffer to receive the local
965 @param[in,out] DataSize The size of data buffer in bytes.
967 @retval EFI_SUCCESS The operation succeeded.
968 @retval EFI_INVALID_PARAMETER The parameter is invalid.
969 @retval EFI_NOT_FOUND The certificate is not found.
970 @retval EFI_BUFFER_TOO_SMALL The Data is too small to hold the data.
975 TlsGetHostPublicCert (
978 IN OUT UINTN
*DataSize
982 TLS_CONNECTION
*TlsConn
;
985 TlsConn
= (TLS_CONNECTION
*) Tls
;
987 if (TlsConn
== NULL
|| TlsConn
->Ssl
== NULL
|| DataSize
== NULL
) {
988 return EFI_INVALID_PARAMETER
;
991 Cert
= SSL_get_certificate(TlsConn
->Ssl
);
993 return EFI_NOT_FOUND
;
997 // Only DER encoding is supported currently.
999 if (*DataSize
< (UINTN
) i2d_X509 (Cert
, NULL
)) {
1000 *DataSize
= (UINTN
) i2d_X509 (Cert
, NULL
);
1001 return EFI_BUFFER_TOO_SMALL
;
1004 *DataSize
= (UINTN
) i2d_X509 (Cert
, (unsigned char **) &Data
);
1010 Gets the local private key set in the specified TLS object.
1012 This function returns the local private key data which was currently set
1013 in the specified TLS object.
1015 @param[in] Tls Pointer to the TLS object.
1016 @param[out] Data Pointer to the data buffer to receive the local
1018 @param[in,out] DataSize The size of data buffer in bytes.
1020 @retval EFI_SUCCESS The operation succeeded.
1021 @retval EFI_UNSUPPORTED This function is not supported.
1022 @retval EFI_BUFFER_TOO_SMALL The Data is too small to hold the data.
1027 TlsGetHostPrivateKey (
1030 IN OUT UINTN
*DataSize
1033 return EFI_UNSUPPORTED
;
1037 Gets the CA-supplied certificate revocation list data set in the specified
1040 This function returns the CA-supplied certificate revocation list data which
1041 was currently set in the specified TLS object.
1043 @param[out] Data Pointer to the data buffer to receive the CRL data.
1044 @param[in,out] DataSize The size of data buffer in bytes.
1046 @retval EFI_SUCCESS The operation succeeded.
1047 @retval EFI_UNSUPPORTED This function is not supported.
1048 @retval EFI_BUFFER_TOO_SMALL The Data is too small to hold the data.
1053 TlsGetCertRevocationList (
1055 IN OUT UINTN
*DataSize
1058 return EFI_UNSUPPORTED
;