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_MAPPING 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 mapping 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 mapping if found,
69 CONST TLS_CIPHER_MAPPING
*
74 CONST TLS_CIPHER_MAPPING
*CipherEntry
;
78 CipherEntry
= TlsCipherMappingTable
;
79 TableSize
= sizeof (TlsCipherMappingTable
) / sizeof (TLS_CIPHER_MAPPING
);
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
) {
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 TLS_CIPHER_MAPPING
*Mapping
;
235 CONST CHAR8
*MappingName
;
236 CHAR8 CipherString
[500];
238 TlsConn
= (TLS_CONNECTION
*) Tls
;
239 if (TlsConn
== NULL
|| TlsConn
->Ssl
== NULL
|| CipherId
== NULL
) {
240 return EFI_INVALID_PARAMETER
;
246 memset (CipherString
, 0, sizeof (CipherString
));
248 for (Index
= 0; Index
< CipherNum
; Index
++) {
250 // Handling OpenSSL / RFC Cipher name mapping.
252 Mapping
= TlsGetCipherMapping (*(CipherId
+ Index
));
253 if (Mapping
== NULL
) {
254 return EFI_UNSUPPORTED
;
256 MappingName
= Mapping
->OpensslCipher
;
260 // The ciphers were separated by a colon.
262 AsciiStrCatS (CipherString
, sizeof (CipherString
), ":");
265 AsciiStrCatS (CipherString
, sizeof (CipherString
), MappingName
);
268 AsciiStrCatS (CipherString
, sizeof (CipherString
), ":@STRENGTH");
271 // Sets the ciphers for use by the Tls object.
273 if (SSL_set_cipher_list (TlsConn
->Ssl
, CipherString
) <= 0) {
274 return EFI_UNSUPPORTED
;
281 Set the compression method for TLS/SSL operations.
283 This function handles TLS/SSL integrated compression methods.
285 @param[in] CompMethod The compression method ID.
287 @retval EFI_SUCCESS The compression method for the communication was
289 @retval EFI_UNSUPPORTED Unsupported compression method.
294 TlsSetCompressionMethod (
304 if (CompMethod
== 0) {
306 // TLS defines one standard compression method, CompressionMethod.null (0),
307 // which specifies that data exchanged via the record protocol will not be compressed.
308 // So, return EFI_SUCCESS directly (RFC 3749).
311 } else if (CompMethod
== 1) {
314 return EFI_UNSUPPORTED
;
318 // Adds the compression method to the list of available
319 // compression methods.
321 Ret
= SSL_COMP_add_compression_method (CompMethod
, Cm
);
323 return EFI_UNSUPPORTED
;
330 Set peer certificate verification mode for the TLS connection.
332 This function sets the verification mode flags for the TLS connection.
334 @param[in] Tls Pointer to the TLS object.
335 @param[in] VerifyMode A set of logically or'ed verification mode flags.
345 TLS_CONNECTION
*TlsConn
;
347 TlsConn
= (TLS_CONNECTION
*) Tls
;
348 if (TlsConn
== NULL
|| TlsConn
->Ssl
== NULL
) {
353 // Set peer certificate verification parameters with NULL callback.
355 SSL_set_verify (TlsConn
->Ssl
, VerifyMode
, NULL
);
359 Sets a TLS/SSL session ID to be used during TLS/SSL connect.
361 This function sets a session ID to be used when the TLS/SSL connection is
364 @param[in] Tls Pointer to the TLS object.
365 @param[in] SessionId Session ID data used for session resumption.
366 @param[in] SessionIdLen Length of Session ID in bytes.
368 @retval EFI_SUCCESS Session ID was set successfully.
369 @retval EFI_INVALID_PARAMETER The parameter is invalid.
370 @retval EFI_UNSUPPORTED No available session for ID setting.
378 IN UINT16 SessionIdLen
381 TLS_CONNECTION
*TlsConn
;
382 SSL_SESSION
*Session
;
384 TlsConn
= (TLS_CONNECTION
*) Tls
;
387 if (TlsConn
== NULL
|| TlsConn
->Ssl
== NULL
|| SessionId
== NULL
) {
388 return EFI_INVALID_PARAMETER
;
391 Session
= SSL_get_session (TlsConn
->Ssl
);
392 if (Session
== NULL
) {
393 return EFI_UNSUPPORTED
;
396 SSL_SESSION_set1_id (Session
, (const unsigned char *)SessionId
, SessionIdLen
);
402 Adds the CA to the cert store when requesting Server or Client authentication.
404 This function adds the CA certificate to the list of CAs when requesting
405 Server or Client authentication for the chosen TLS connection.
407 @param[in] Tls Pointer to the TLS object.
408 @param[in] Data Pointer to the data buffer of a DER-encoded binary
409 X.509 certificate or PEM-encoded X.509 certificate.
410 @param[in] DataSize The size of data buffer in bytes.
412 @retval EFI_SUCCESS The operation succeeded.
413 @retval EFI_INVALID_PARAMETER The parameter is invalid.
414 @retval EFI_OUT_OF_RESOURCES Required resources could not be allocated.
415 @retval EFI_ABORTED Invalid X.509 certificate.
420 TlsSetCaCertificate (
428 X509_STORE
*X509Store
;
430 TLS_CONNECTION
*TlsConn
;
438 Status
= EFI_SUCCESS
;
439 TlsConn
= (TLS_CONNECTION
*) Tls
;
442 if (TlsConn
== NULL
|| TlsConn
->Ssl
== NULL
|| Data
== NULL
|| DataSize
== 0) {
443 return EFI_INVALID_PARAMETER
;
447 // DER-encoded binary X.509 certificate or PEM-encoded X.509 certificate.
448 // Determine whether certificate is from DER encoding, if so, translate it to X509 structure.
450 Cert
= d2i_X509 (NULL
, (const unsigned char ** )&Data
, (long) DataSize
);
453 // Certificate is from PEM encoding.
455 BioCert
= BIO_new (BIO_s_mem ());
456 if (BioCert
== NULL
) {
457 Status
= EFI_OUT_OF_RESOURCES
;
461 if (BIO_write (BioCert
, Data
, (UINT32
) DataSize
) <= 0) {
462 Status
= EFI_ABORTED
;
466 Cert
= PEM_read_bio_X509 (BioCert
, NULL
, NULL
, NULL
);
468 Status
= EFI_ABORTED
;
473 SslCtx
= SSL_get_SSL_CTX (TlsConn
->Ssl
);
474 X509Store
= SSL_CTX_get_cert_store (SslCtx
);
475 if (X509Store
== NULL
) {
476 Status
= EFI_ABORTED
;
481 // Add certificate to X509 store
483 Ret
= X509_STORE_add_cert (X509Store
, Cert
);
485 ErrorCode
= ERR_peek_last_error ();
487 // Ignore "already in table" errors
489 if (!(ERR_GET_FUNC (ErrorCode
) == X509_F_X509_STORE_ADD_CERT
&&
490 ERR_GET_REASON (ErrorCode
) == X509_R_CERT_ALREADY_IN_HASH_TABLE
)) {
491 Status
= EFI_ABORTED
;
497 if (BioCert
!= NULL
) {
509 Loads the local public certificate into the specified TLS object.
511 This function loads the X.509 certificate into the specified TLS object
514 @param[in] Tls Pointer to the TLS object.
515 @param[in] Data Pointer to the data buffer of a DER-encoded binary
516 X.509 certificate or PEM-encoded X.509 certificate.
517 @param[in] DataSize The size of data buffer in bytes.
519 @retval EFI_SUCCESS The operation succeeded.
520 @retval EFI_INVALID_PARAMETER The parameter is invalid.
521 @retval EFI_OUT_OF_RESOURCES Required resources could not be allocated.
522 @retval EFI_ABORTED Invalid X.509 certificate.
527 TlsSetHostPublicCert (
536 TLS_CONNECTION
*TlsConn
;
540 Status
= EFI_SUCCESS
;
541 TlsConn
= (TLS_CONNECTION
*) Tls
;
543 if (TlsConn
== NULL
|| TlsConn
->Ssl
== NULL
|| Data
== NULL
|| DataSize
== 0) {
544 return EFI_INVALID_PARAMETER
;
548 // DER-encoded binary X.509 certificate or PEM-encoded X.509 certificate.
549 // Determine whether certificate is from DER encoding, if so, translate it to X509 structure.
551 Cert
= d2i_X509 (NULL
, (const unsigned char ** )&Data
, (long) DataSize
);
554 // Certificate is from PEM encoding.
556 BioCert
= BIO_new (BIO_s_mem ());
557 if (BioCert
== NULL
) {
558 Status
= EFI_OUT_OF_RESOURCES
;
562 if (BIO_write (BioCert
, Data
, (UINT32
) DataSize
) <= 0) {
563 Status
= EFI_ABORTED
;
567 Cert
= PEM_read_bio_X509 (BioCert
, NULL
, NULL
, NULL
);
569 Status
= EFI_ABORTED
;
574 if (SSL_use_certificate (TlsConn
->Ssl
, Cert
) != 1) {
575 Status
= EFI_ABORTED
;
580 if (BioCert
!= NULL
) {
592 Adds the local private key to the specified TLS object.
594 This function adds the local private key (PEM-encoded RSA or PKCS#8 private
595 key) into the specified TLS object for TLS negotiation.
597 @param[in] Tls Pointer to the TLS object.
598 @param[in] Data Pointer to the data buffer of a PEM-encoded RSA
599 or PKCS#8 private key.
600 @param[in] DataSize The size of data buffer in bytes.
602 @retval EFI_SUCCESS The operation succeeded.
603 @retval EFI_UNSUPPORTED This function is not supported.
604 @retval EFI_ABORTED Invalid private key data.
609 TlsSetHostPrivateKey (
615 return EFI_UNSUPPORTED
;
619 Adds the CA-supplied certificate revocation list for certificate validation.
621 This function adds the CA-supplied certificate revocation list data for
622 certificate validity checking.
624 @param[in] Data Pointer to the data buffer of a DER-encoded CRL data.
625 @param[in] DataSize The size of data buffer in bytes.
627 @retval EFI_SUCCESS The operation succeeded.
628 @retval EFI_UNSUPPORTED This function is not supported.
629 @retval EFI_ABORTED Invalid CRL data.
634 TlsSetCertRevocationList (
639 return EFI_UNSUPPORTED
;
643 Gets the protocol version used by the specified TLS connection.
645 This function returns the protocol version used by the specified TLS
648 If Tls is NULL, then ASSERT().
650 @param[in] Tls Pointer to the TLS object.
652 @return The protocol version of the specified TLS connection.
661 TLS_CONNECTION
*TlsConn
;
663 TlsConn
= (TLS_CONNECTION
*) Tls
;
665 ASSERT (TlsConn
!= NULL
);
667 return (UINT16
)(SSL_version (TlsConn
->Ssl
));
671 Gets the connection end of the specified TLS connection.
673 This function returns the connection end (as client or as server) used by
674 the specified TLS connection.
676 If Tls is NULL, then ASSERT().
678 @param[in] Tls Pointer to the TLS object.
680 @return The connection end used by the specified TLS connection.
685 TlsGetConnectionEnd (
689 TLS_CONNECTION
*TlsConn
;
691 TlsConn
= (TLS_CONNECTION
*) Tls
;
693 ASSERT (TlsConn
!= NULL
);
695 return (UINT8
)SSL_is_server (TlsConn
->Ssl
);
699 Gets the cipher suite used by the specified TLS connection.
701 This function returns current cipher suite used by the specified
704 @param[in] Tls Pointer to the TLS object.
705 @param[in,out] CipherId The cipher suite used by the TLS object.
707 @retval EFI_SUCCESS The cipher suite was returned successfully.
708 @retval EFI_INVALID_PARAMETER The parameter is invalid.
709 @retval EFI_UNSUPPORTED Unsupported cipher suite.
714 TlsGetCurrentCipher (
716 IN OUT UINT16
*CipherId
719 TLS_CONNECTION
*TlsConn
;
720 CONST SSL_CIPHER
*Cipher
;
722 TlsConn
= (TLS_CONNECTION
*) Tls
;
725 if (TlsConn
== NULL
|| TlsConn
->Ssl
== NULL
|| CipherId
== NULL
) {
726 return EFI_INVALID_PARAMETER
;
729 Cipher
= SSL_get_current_cipher (TlsConn
->Ssl
);
730 if (Cipher
== NULL
) {
731 return EFI_UNSUPPORTED
;
734 *CipherId
= (SSL_CIPHER_get_id (Cipher
)) & 0xFFFF;
740 Gets the compression methods used by the specified TLS connection.
742 This function returns current integrated compression methods used by
743 the specified TLS connection.
745 @param[in] Tls Pointer to the TLS object.
746 @param[in,out] CompressionId The current compression method used by
749 @retval EFI_SUCCESS The compression method was returned successfully.
750 @retval EFI_INVALID_PARAMETER The parameter is invalid.
751 @retval EFI_ABORTED Invalid Compression method.
752 @retval EFI_UNSUPPORTED This function is not supported.
757 TlsGetCurrentCompressionId (
759 IN OUT UINT8
*CompressionId
762 return EFI_UNSUPPORTED
;
766 Gets the verification mode currently set in the TLS connection.
768 This function returns the peer verification mode currently set in the
769 specified TLS connection.
771 If Tls is NULL, then ASSERT().
773 @param[in] Tls Pointer to the TLS object.
775 @return The verification mode set in the specified TLS connection.
784 TLS_CONNECTION
*TlsConn
;
786 TlsConn
= (TLS_CONNECTION
*) Tls
;
788 ASSERT (TlsConn
!= NULL
);
790 return SSL_get_verify_mode (TlsConn
->Ssl
);
794 Gets the session ID used by the specified TLS connection.
796 This function returns the TLS/SSL session ID currently used by the
797 specified TLS connection.
799 @param[in] Tls Pointer to the TLS object.
800 @param[in,out] SessionId Buffer to contain the returned session ID.
801 @param[in,out] SessionIdLen The length of Session ID in bytes.
803 @retval EFI_SUCCESS The Session ID was returned successfully.
804 @retval EFI_INVALID_PARAMETER The parameter is invalid.
805 @retval EFI_UNSUPPORTED Invalid TLS/SSL session.
812 IN OUT UINT8
*SessionId
,
813 IN OUT UINT16
*SessionIdLen
816 TLS_CONNECTION
*TlsConn
;
817 SSL_SESSION
*Session
;
818 CONST UINT8
*SslSessionId
;
820 TlsConn
= (TLS_CONNECTION
*) Tls
;
823 if (TlsConn
== NULL
|| TlsConn
->Ssl
== NULL
|| SessionId
== NULL
|| SessionIdLen
== NULL
) {
824 return EFI_INVALID_PARAMETER
;
827 Session
= SSL_get_session (TlsConn
->Ssl
);
828 if (Session
== NULL
) {
829 return EFI_UNSUPPORTED
;
832 SslSessionId
= SSL_SESSION_get_id (Session
, (unsigned int *)SessionIdLen
);
833 CopyMem (SessionId
, SslSessionId
, *SessionIdLen
);
839 Gets the client random data used in the specified TLS connection.
841 This function returns the TLS/SSL client random data currently used in
842 the specified TLS connection.
844 @param[in] Tls Pointer to the TLS object.
845 @param[in,out] ClientRandom Buffer to contain the returned client
846 random data (32 bytes).
853 IN OUT UINT8
*ClientRandom
856 TLS_CONNECTION
*TlsConn
;
858 TlsConn
= (TLS_CONNECTION
*) Tls
;
860 if (TlsConn
== NULL
|| TlsConn
->Ssl
== NULL
|| ClientRandom
== NULL
) {
864 SSL_get_client_random (TlsConn
->Ssl
, ClientRandom
, SSL3_RANDOM_SIZE
);
868 Gets the server random data used in the specified TLS connection.
870 This function returns the TLS/SSL server random data currently used in
871 the specified TLS connection.
873 @param[in] Tls Pointer to the TLS object.
874 @param[in,out] ServerRandom Buffer to contain the returned server
875 random data (32 bytes).
882 IN OUT UINT8
*ServerRandom
885 TLS_CONNECTION
*TlsConn
;
887 TlsConn
= (TLS_CONNECTION
*) Tls
;
889 if (TlsConn
== NULL
|| TlsConn
->Ssl
== NULL
|| ServerRandom
== NULL
) {
893 SSL_get_server_random (TlsConn
->Ssl
, ServerRandom
, SSL3_RANDOM_SIZE
);
897 Gets the master key data used in the specified TLS connection.
899 This function returns the TLS/SSL master key material currently used in
900 the specified TLS connection.
902 @param[in] Tls Pointer to the TLS object.
903 @param[in,out] KeyMaterial Buffer to contain the returned key material.
905 @retval EFI_SUCCESS Key material was returned successfully.
906 @retval EFI_INVALID_PARAMETER The parameter is invalid.
907 @retval EFI_UNSUPPORTED Invalid TLS/SSL session.
914 IN OUT UINT8
*KeyMaterial
917 TLS_CONNECTION
*TlsConn
;
918 SSL_SESSION
*Session
;
920 TlsConn
= (TLS_CONNECTION
*) Tls
;
923 if (TlsConn
== NULL
|| TlsConn
->Ssl
== NULL
|| KeyMaterial
== NULL
) {
924 return EFI_INVALID_PARAMETER
;
927 Session
= SSL_get_session (TlsConn
->Ssl
);
929 if (Session
== NULL
) {
930 return EFI_UNSUPPORTED
;
933 SSL_SESSION_get_master_key (Session
, KeyMaterial
, SSL3_MASTER_SECRET_SIZE
);
939 Gets the CA Certificate from the cert store.
941 This function returns the CA certificate for the chosen
944 @param[in] Tls Pointer to the TLS object.
945 @param[out] Data Pointer to the data buffer to receive the CA
946 certificate data sent to the client.
947 @param[in,out] DataSize The size of data buffer in bytes.
949 @retval EFI_SUCCESS The operation succeeded.
950 @retval EFI_UNSUPPORTED This function is not supported.
951 @retval EFI_BUFFER_TOO_SMALL The Data is too small to hold the data.
956 TlsGetCaCertificate (
959 IN OUT UINTN
*DataSize
962 return EFI_UNSUPPORTED
;
966 Gets the local public Certificate set in the specified TLS object.
968 This function returns the local public certificate which was currently set
969 in the specified TLS object.
971 @param[in] Tls Pointer to the TLS object.
972 @param[out] Data Pointer to the data buffer to receive the local
974 @param[in,out] DataSize The size of data buffer in bytes.
976 @retval EFI_SUCCESS The operation succeeded.
977 @retval EFI_INVALID_PARAMETER The parameter is invalid.
978 @retval EFI_NOT_FOUND The certificate is not found.
979 @retval EFI_BUFFER_TOO_SMALL The Data is too small to hold the data.
984 TlsGetHostPublicCert (
987 IN OUT UINTN
*DataSize
991 TLS_CONNECTION
*TlsConn
;
994 TlsConn
= (TLS_CONNECTION
*) Tls
;
996 if (TlsConn
== NULL
|| TlsConn
->Ssl
== NULL
|| DataSize
== NULL
|| (*DataSize
!= 0 && Data
== NULL
)) {
997 return EFI_INVALID_PARAMETER
;
1000 Cert
= SSL_get_certificate(TlsConn
->Ssl
);
1002 return EFI_NOT_FOUND
;
1006 // Only DER encoding is supported currently.
1008 if (*DataSize
< (UINTN
) i2d_X509 (Cert
, NULL
)) {
1009 *DataSize
= (UINTN
) i2d_X509 (Cert
, NULL
);
1010 return EFI_BUFFER_TOO_SMALL
;
1013 *DataSize
= (UINTN
) i2d_X509 (Cert
, (unsigned char **) &Data
);
1019 Gets the local private key set in the specified TLS object.
1021 This function returns the local private key data which was currently set
1022 in the specified TLS object.
1024 @param[in] Tls Pointer to the TLS object.
1025 @param[out] Data Pointer to the data buffer to receive the local
1027 @param[in,out] DataSize The size of data buffer in bytes.
1029 @retval EFI_SUCCESS The operation succeeded.
1030 @retval EFI_UNSUPPORTED This function is not supported.
1031 @retval EFI_BUFFER_TOO_SMALL The Data is too small to hold the data.
1036 TlsGetHostPrivateKey (
1039 IN OUT UINTN
*DataSize
1042 return EFI_UNSUPPORTED
;
1046 Gets the CA-supplied certificate revocation list data set in the specified
1049 This function returns the CA-supplied certificate revocation list data which
1050 was currently set in the specified TLS object.
1052 @param[out] Data Pointer to the data buffer to receive the CRL data.
1053 @param[in,out] DataSize The size of data buffer in bytes.
1055 @retval EFI_SUCCESS The operation succeeded.
1056 @retval EFI_UNSUPPORTED This function is not supported.
1057 @retval EFI_BUFFER_TOO_SMALL The Data is too small to hold the data.
1062 TlsGetCertRevocationList (
1064 IN OUT UINTN
*DataSize
1067 return EFI_UNSUPPORTED
;