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 If Tls is NULL, then ASSERT().
647 @param[in] Tls Pointer to the TLS object.
649 @return The protocol version of the specified TLS connection.
658 TLS_CONNECTION
*TlsConn
;
660 TlsConn
= (TLS_CONNECTION
*) Tls
;
662 ASSERT (TlsConn
!= NULL
);
664 return (UINT16
)(SSL_version (TlsConn
->Ssl
));
668 Gets the connection end of the specified TLS connection.
670 This function returns the connection end (as client or as server) used by
671 the specified TLS connection.
673 If Tls is NULL, then ASSERT().
675 @param[in] Tls Pointer to the TLS object.
677 @return The connection end used by the specified TLS connection.
682 TlsGetConnectionEnd (
686 TLS_CONNECTION
*TlsConn
;
688 TlsConn
= (TLS_CONNECTION
*) Tls
;
690 ASSERT (TlsConn
!= NULL
);
692 return (UINT8
)SSL_is_server (TlsConn
->Ssl
);
696 Gets the cipher suite used by the specified TLS connection.
698 This function returns current cipher suite used by the specified
701 @param[in] Tls Pointer to the TLS object.
702 @param[in,out] CipherId The cipher suite used by the TLS object.
704 @retval EFI_SUCCESS The cipher suite was returned successfully.
705 @retval EFI_INVALID_PARAMETER The parameter is invalid.
706 @retval EFI_UNSUPPORTED Unsupported cipher suite.
711 TlsGetCurrentCipher (
713 IN OUT UINT16
*CipherId
716 TLS_CONNECTION
*TlsConn
;
717 CONST SSL_CIPHER
*Cipher
;
719 TlsConn
= (TLS_CONNECTION
*) Tls
;
722 if (TlsConn
== NULL
|| TlsConn
->Ssl
== NULL
|| CipherId
== NULL
) {
723 return EFI_INVALID_PARAMETER
;
726 Cipher
= SSL_get_current_cipher (TlsConn
->Ssl
);
727 if (Cipher
== NULL
) {
728 return EFI_UNSUPPORTED
;
731 *CipherId
= (SSL_CIPHER_get_id (Cipher
)) & 0xFFFF;
737 Gets the compression methods used by the specified TLS connection.
739 This function returns current integrated compression methods used by
740 the specified TLS connection.
742 @param[in] Tls Pointer to the TLS object.
743 @param[in,out] CompressionId The current compression method used by
746 @retval EFI_SUCCESS The compression method was returned successfully.
747 @retval EFI_INVALID_PARAMETER The parameter is invalid.
748 @retval EFI_ABORTED Invalid Compression method.
749 @retval EFI_UNSUPPORTED This function is not supported.
754 TlsGetCurrentCompressionId (
756 IN OUT UINT8
*CompressionId
759 return EFI_UNSUPPORTED
;
763 Gets the verification mode currently set in the TLS connection.
765 This function returns the peer verification mode currently set in the
766 specified TLS connection.
768 If Tls is NULL, then ASSERT().
770 @param[in] Tls Pointer to the TLS object.
772 @return The verification mode set in the specified TLS connection.
781 TLS_CONNECTION
*TlsConn
;
783 TlsConn
= (TLS_CONNECTION
*) Tls
;
785 ASSERT (TlsConn
!= NULL
);
787 return SSL_get_verify_mode (TlsConn
->Ssl
);
791 Gets the session ID used by the specified TLS connection.
793 This function returns the TLS/SSL session ID currently used by the
794 specified TLS connection.
796 @param[in] Tls Pointer to the TLS object.
797 @param[in,out] SessionId Buffer to contain the returned session ID.
798 @param[in,out] SessionIdLen The length of Session ID in bytes.
800 @retval EFI_SUCCESS The Session ID was returned successfully.
801 @retval EFI_INVALID_PARAMETER The parameter is invalid.
802 @retval EFI_UNSUPPORTED Invalid TLS/SSL session.
809 IN OUT UINT8
*SessionId
,
810 IN OUT UINT16
*SessionIdLen
813 TLS_CONNECTION
*TlsConn
;
814 SSL_SESSION
*Session
;
815 CONST UINT8
*SslSessionId
;
817 TlsConn
= (TLS_CONNECTION
*) Tls
;
820 if (TlsConn
== NULL
|| TlsConn
->Ssl
== NULL
|| SessionId
== NULL
|| SessionIdLen
== NULL
) {
821 return EFI_INVALID_PARAMETER
;
824 Session
= SSL_get_session (TlsConn
->Ssl
);
825 if (Session
== NULL
) {
826 return EFI_UNSUPPORTED
;
829 SslSessionId
= SSL_SESSION_get_id (Session
, (unsigned int *)SessionIdLen
);
830 CopyMem (SessionId
, SslSessionId
, *SessionIdLen
);
836 Gets the client random data used in the specified TLS connection.
838 This function returns the TLS/SSL client random data currently used in
839 the specified TLS connection.
841 @param[in] Tls Pointer to the TLS object.
842 @param[in,out] ClientRandom Buffer to contain the returned client
843 random data (32 bytes).
850 IN OUT UINT8
*ClientRandom
853 TLS_CONNECTION
*TlsConn
;
855 TlsConn
= (TLS_CONNECTION
*) Tls
;
857 if (TlsConn
== NULL
|| TlsConn
->Ssl
== NULL
|| ClientRandom
== NULL
) {
861 SSL_get_client_random (TlsConn
->Ssl
, ClientRandom
, SSL3_RANDOM_SIZE
);
865 Gets the server random data used in the specified TLS connection.
867 This function returns the TLS/SSL server random data currently used in
868 the specified TLS connection.
870 @param[in] Tls Pointer to the TLS object.
871 @param[in,out] ServerRandom Buffer to contain the returned server
872 random data (32 bytes).
879 IN OUT UINT8
*ServerRandom
882 TLS_CONNECTION
*TlsConn
;
884 TlsConn
= (TLS_CONNECTION
*) Tls
;
886 if (TlsConn
== NULL
|| TlsConn
->Ssl
== NULL
|| ServerRandom
== NULL
) {
890 SSL_get_server_random (TlsConn
->Ssl
, ServerRandom
, SSL3_RANDOM_SIZE
);
894 Gets the master key data used in the specified TLS connection.
896 This function returns the TLS/SSL master key material currently used in
897 the specified TLS connection.
899 @param[in] Tls Pointer to the TLS object.
900 @param[in,out] KeyMaterial Buffer to contain the returned key material.
902 @retval EFI_SUCCESS Key material was returned successfully.
903 @retval EFI_INVALID_PARAMETER The parameter is invalid.
904 @retval EFI_UNSUPPORTED Invalid TLS/SSL session.
911 IN OUT UINT8
*KeyMaterial
914 TLS_CONNECTION
*TlsConn
;
915 SSL_SESSION
*Session
;
917 TlsConn
= (TLS_CONNECTION
*) Tls
;
920 if (TlsConn
== NULL
|| TlsConn
->Ssl
== NULL
|| KeyMaterial
== NULL
) {
921 return EFI_INVALID_PARAMETER
;
924 Session
= SSL_get_session (TlsConn
->Ssl
);
926 if (Session
== NULL
) {
927 return EFI_UNSUPPORTED
;
930 SSL_SESSION_get_master_key (Session
, KeyMaterial
, SSL3_MASTER_SECRET_SIZE
);
936 Gets the CA Certificate from the cert store.
938 This function returns the CA certificate for the chosen
941 @param[in] Tls Pointer to the TLS object.
942 @param[out] Data Pointer to the data buffer to receive the CA
943 certificate data sent to the client.
944 @param[in,out] DataSize The size of data buffer in bytes.
946 @retval EFI_SUCCESS The operation succeeded.
947 @retval EFI_UNSUPPORTED This function is not supported.
948 @retval EFI_BUFFER_TOO_SMALL The Data is too small to hold the data.
953 TlsGetCaCertificate (
956 IN OUT UINTN
*DataSize
959 return EFI_UNSUPPORTED
;
963 Gets the local public Certificate set in the specified TLS object.
965 This function returns the local public certificate which was currently set
966 in the specified TLS object.
968 @param[in] Tls Pointer to the TLS object.
969 @param[out] Data Pointer to the data buffer to receive the local
971 @param[in,out] DataSize The size of data buffer in bytes.
973 @retval EFI_SUCCESS The operation succeeded.
974 @retval EFI_INVALID_PARAMETER The parameter is invalid.
975 @retval EFI_NOT_FOUND The certificate is not found.
976 @retval EFI_BUFFER_TOO_SMALL The Data is too small to hold the data.
981 TlsGetHostPublicCert (
984 IN OUT UINTN
*DataSize
988 TLS_CONNECTION
*TlsConn
;
991 TlsConn
= (TLS_CONNECTION
*) Tls
;
993 if (TlsConn
== NULL
|| TlsConn
->Ssl
== NULL
|| DataSize
== NULL
|| (*DataSize
!= 0 && Data
== NULL
)) {
994 return EFI_INVALID_PARAMETER
;
997 Cert
= SSL_get_certificate(TlsConn
->Ssl
);
999 return EFI_NOT_FOUND
;
1003 // Only DER encoding is supported currently.
1005 if (*DataSize
< (UINTN
) i2d_X509 (Cert
, NULL
)) {
1006 *DataSize
= (UINTN
) i2d_X509 (Cert
, NULL
);
1007 return EFI_BUFFER_TOO_SMALL
;
1010 *DataSize
= (UINTN
) i2d_X509 (Cert
, (unsigned char **) &Data
);
1016 Gets the local private key set in the specified TLS object.
1018 This function returns the local private key data which was currently set
1019 in the specified TLS object.
1021 @param[in] Tls Pointer to the TLS object.
1022 @param[out] Data Pointer to the data buffer to receive the local
1024 @param[in,out] DataSize The size of data buffer in bytes.
1026 @retval EFI_SUCCESS The operation succeeded.
1027 @retval EFI_UNSUPPORTED This function is not supported.
1028 @retval EFI_BUFFER_TOO_SMALL The Data is too small to hold the data.
1033 TlsGetHostPrivateKey (
1036 IN OUT UINTN
*DataSize
1039 return EFI_UNSUPPORTED
;
1043 Gets the CA-supplied certificate revocation list data set in the specified
1046 This function returns the CA-supplied certificate revocation list data which
1047 was currently set in the specified TLS object.
1049 @param[out] Data Pointer to the data buffer to receive the CRL data.
1050 @param[in,out] DataSize The size of data buffer in bytes.
1052 @retval EFI_SUCCESS The operation succeeded.
1053 @retval EFI_UNSUPPORTED This function is not supported.
1054 @retval EFI_BUFFER_TOO_SMALL The Data is too small to hold the data.
1059 TlsGetCertRevocationList (
1061 IN OUT UINTN
*DataSize
1064 return EFI_UNSUPPORTED
;