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 // Keep the table uniquely sorted by the IanaCipher field, in increasing order.
35 STATIC CONST TLS_CIPHER_MAPPING TlsCipherMappingTable
[] = {
36 { 0x0001, "NULL-MD5" }, /// TLS_RSA_WITH_NULL_MD5
37 { 0x0002, "NULL-SHA" }, /// TLS_RSA_WITH_NULL_SHA
38 { 0x0004, "RC4-MD5" }, /// TLS_RSA_WITH_RC4_128_MD5
39 { 0x0005, "RC4-SHA" }, /// TLS_RSA_WITH_RC4_128_SHA
40 { 0x000A, "DES-CBC3-SHA" }, /// TLS_RSA_WITH_3DES_EDE_CBC_SHA, mandatory TLS 1.1
41 { 0x0016, "DHE-RSA-DES-CBC3-SHA" }, /// TLS_DHE_RSA_WITH_3DES_EDE_CBC_SHA
42 { 0x002F, "AES128-SHA" }, /// TLS_RSA_WITH_AES_128_CBC_SHA, mandatory TLS 1.2
43 { 0x0030, "DH-DSS-AES128-SHA" }, /// TLS_DH_DSS_WITH_AES_128_CBC_SHA
44 { 0x0031, "DH-RSA-AES128-SHA" }, /// TLS_DH_RSA_WITH_AES_128_CBC_SHA
45 { 0x0033, "DHE-RSA-AES128-SHA" }, /// TLS_DHE_RSA_WITH_AES_128_CBC_SHA
46 { 0x0035, "AES256-SHA" }, /// TLS_RSA_WITH_AES_256_CBC_SHA
47 { 0x0036, "DH-DSS-AES256-SHA" }, /// TLS_DH_DSS_WITH_AES_256_CBC_SHA
48 { 0x0037, "DH-RSA-AES256-SHA" }, /// TLS_DH_RSA_WITH_AES_256_CBC_SHA
49 { 0x0039, "DHE-RSA-AES256-SHA" }, /// TLS_DHE_RSA_WITH_AES_256_CBC_SHA
50 { 0x003B, "NULL-SHA256" }, /// TLS_RSA_WITH_NULL_SHA256
51 { 0x003C, "AES128-SHA256" }, /// TLS_RSA_WITH_AES_128_CBC_SHA256
52 { 0x003D, "AES256-SHA256" }, /// TLS_RSA_WITH_AES_256_CBC_SHA256
53 { 0x003E, "DH-DSS-AES128-SHA256" }, /// TLS_DH_DSS_WITH_AES_128_CBC_SHA256
54 { 0x003F, "DH-RSA-AES128-SHA256" }, /// TLS_DH_RSA_WITH_AES_128_CBC_SHA256
55 { 0x0067, "DHE-RSA-AES128-SHA256" }, /// TLS_DHE_RSA_WITH_AES_128_CBC_SHA256
56 { 0x0068, "DH-DSS-AES256-SHA256" }, /// TLS_DH_DSS_WITH_AES_256_CBC_SHA256
57 { 0x0069, "DH-RSA-AES256-SHA256" }, /// TLS_DH_RSA_WITH_AES_256_CBC_SHA256
58 { 0x006B, "DHE-RSA-AES256-SHA256" } /// TLS_DHE_RSA_WITH_AES_256_CBC_SHA256
62 Gets the OpenSSL cipher suite mapping for the supplied IANA TLS cipher suite.
64 @param[in] CipherId The supplied IANA TLS cipher suite ID.
66 @return The corresponding OpenSSL cipher suite mapping if found,
71 CONST TLS_CIPHER_MAPPING
*
81 // Binary Search Cipher Mapping Table for IANA-OpenSSL Cipher Translation
84 Right
= ARRAY_SIZE (TlsCipherMappingTable
) - 1;
86 while (Right
>= Left
) {
87 Middle
= (Left
+ Right
) / 2;
89 if (CipherId
== TlsCipherMappingTable
[Middle
].IanaCipher
) {
91 // Translate IANA cipher suite ID to OpenSSL name.
93 return &TlsCipherMappingTable
[Middle
];
96 if (CipherId
< TlsCipherMappingTable
[Middle
].IanaCipher
) {
104 // No Cipher Mapping found, return NULL.
110 Set a new TLS/SSL method for a particular TLS object.
112 This function sets a new TLS/SSL method for a particular TLS object.
114 @param[in] Tls Pointer to a TLS object.
115 @param[in] MajorVer Major Version of TLS/SSL Protocol.
116 @param[in] MinorVer Minor Version of TLS/SSL Protocol.
118 @retval EFI_SUCCESS The TLS/SSL method was set successfully.
119 @retval EFI_INVALID_PARAMETER The parameter is invalid.
120 @retval EFI_UNSUPPORTED Unsupported TLS/SSL method.
131 TLS_CONNECTION
*TlsConn
;
134 TlsConn
= (TLS_CONNECTION
*)Tls
;
135 if (TlsConn
== NULL
|| TlsConn
->Ssl
== NULL
) {
136 return EFI_INVALID_PARAMETER
;
139 ProtoVersion
= (MajorVer
<< 8) | MinorVer
;
142 // Bound TLS method to the particular specified version.
144 switch (ProtoVersion
) {
149 SSL_set_min_proto_version (TlsConn
->Ssl
, TLS1_VERSION
);
150 SSL_set_max_proto_version (TlsConn
->Ssl
, TLS1_VERSION
);
156 SSL_set_min_proto_version (TlsConn
->Ssl
, TLS1_1_VERSION
);
157 SSL_set_max_proto_version (TlsConn
->Ssl
, TLS1_1_VERSION
);
163 SSL_set_min_proto_version (TlsConn
->Ssl
, TLS1_2_VERSION
);
164 SSL_set_max_proto_version (TlsConn
->Ssl
, TLS1_2_VERSION
);
168 // Unsupported Protocol Version
170 return EFI_UNSUPPORTED
;
177 Set TLS object to work in client or server mode.
179 This function prepares a TLS object to work in client or server mode.
181 @param[in] Tls Pointer to a TLS object.
182 @param[in] IsServer Work in server mode.
184 @retval EFI_SUCCESS The TLS/SSL work mode was set successfully.
185 @retval EFI_INVALID_PARAMETER The parameter is invalid.
186 @retval EFI_UNSUPPORTED Unsupported TLS/SSL work mode.
191 TlsSetConnectionEnd (
196 TLS_CONNECTION
*TlsConn
;
198 TlsConn
= (TLS_CONNECTION
*) Tls
;
199 if (TlsConn
== NULL
|| TlsConn
->Ssl
== NULL
) {
200 return EFI_INVALID_PARAMETER
;
205 // Set TLS to work in Client mode.
207 SSL_set_connect_state (TlsConn
->Ssl
);
210 // Set TLS to work in Server mode.
211 // It is unsupported for UEFI version currently.
213 //SSL_set_accept_state (TlsConn->Ssl);
214 return EFI_UNSUPPORTED
;
221 Set the ciphers list to be used by the TLS object.
223 This function sets the ciphers for use by a specified TLS object.
225 @param[in] Tls Pointer to a TLS object.
226 @param[in] CipherId Pointer to a UINT16 cipher Id.
227 @param[in] CipherNum The number of cipher in the list.
229 @retval EFI_SUCCESS The ciphers list was set successfully.
230 @retval EFI_INVALID_PARAMETER The parameter is invalid.
231 @retval EFI_UNSUPPORTED Unsupported TLS cipher in the list.
242 TLS_CONNECTION
*TlsConn
;
244 CONST TLS_CIPHER_MAPPING
*Mapping
;
245 CONST CHAR8
*MappingName
;
246 CHAR8 CipherString
[500];
248 TlsConn
= (TLS_CONNECTION
*) Tls
;
249 if (TlsConn
== NULL
|| TlsConn
->Ssl
== NULL
|| CipherId
== NULL
) {
250 return EFI_INVALID_PARAMETER
;
256 memset (CipherString
, 0, sizeof (CipherString
));
258 for (Index
= 0; Index
< CipherNum
; Index
++) {
260 // Handling OpenSSL / RFC Cipher name mapping.
262 Mapping
= TlsGetCipherMapping (*(CipherId
+ Index
));
263 if (Mapping
== NULL
) {
264 return EFI_UNSUPPORTED
;
266 MappingName
= Mapping
->OpensslCipher
;
270 // The ciphers were separated by a colon.
272 AsciiStrCatS (CipherString
, sizeof (CipherString
), ":");
275 AsciiStrCatS (CipherString
, sizeof (CipherString
), MappingName
);
278 AsciiStrCatS (CipherString
, sizeof (CipherString
), ":@STRENGTH");
281 // Sets the ciphers for use by the Tls object.
283 if (SSL_set_cipher_list (TlsConn
->Ssl
, CipherString
) <= 0) {
284 return EFI_UNSUPPORTED
;
291 Set the compression method for TLS/SSL operations.
293 This function handles TLS/SSL integrated compression methods.
295 @param[in] CompMethod The compression method ID.
297 @retval EFI_SUCCESS The compression method for the communication was
299 @retval EFI_UNSUPPORTED Unsupported compression method.
304 TlsSetCompressionMethod (
314 if (CompMethod
== 0) {
316 // TLS defines one standard compression method, CompressionMethod.null (0),
317 // which specifies that data exchanged via the record protocol will not be compressed.
318 // So, return EFI_SUCCESS directly (RFC 3749).
321 } else if (CompMethod
== 1) {
324 return EFI_UNSUPPORTED
;
328 // Adds the compression method to the list of available
329 // compression methods.
331 Ret
= SSL_COMP_add_compression_method (CompMethod
, Cm
);
333 return EFI_UNSUPPORTED
;
340 Set peer certificate verification mode for the TLS connection.
342 This function sets the verification mode flags for the TLS connection.
344 @param[in] Tls Pointer to the TLS object.
345 @param[in] VerifyMode A set of logically or'ed verification mode flags.
355 TLS_CONNECTION
*TlsConn
;
357 TlsConn
= (TLS_CONNECTION
*) Tls
;
358 if (TlsConn
== NULL
|| TlsConn
->Ssl
== NULL
) {
363 // Set peer certificate verification parameters with NULL callback.
365 SSL_set_verify (TlsConn
->Ssl
, VerifyMode
, NULL
);
369 Sets a TLS/SSL session ID to be used during TLS/SSL connect.
371 This function sets a session ID to be used when the TLS/SSL connection is
374 @param[in] Tls Pointer to the TLS object.
375 @param[in] SessionId Session ID data used for session resumption.
376 @param[in] SessionIdLen Length of Session ID in bytes.
378 @retval EFI_SUCCESS Session ID was set successfully.
379 @retval EFI_INVALID_PARAMETER The parameter is invalid.
380 @retval EFI_UNSUPPORTED No available session for ID setting.
388 IN UINT16 SessionIdLen
391 TLS_CONNECTION
*TlsConn
;
392 SSL_SESSION
*Session
;
394 TlsConn
= (TLS_CONNECTION
*) Tls
;
397 if (TlsConn
== NULL
|| TlsConn
->Ssl
== NULL
|| SessionId
== NULL
) {
398 return EFI_INVALID_PARAMETER
;
401 Session
= SSL_get_session (TlsConn
->Ssl
);
402 if (Session
== NULL
) {
403 return EFI_UNSUPPORTED
;
406 SSL_SESSION_set1_id (Session
, (const unsigned char *)SessionId
, SessionIdLen
);
412 Adds the CA to the cert store when requesting Server or Client authentication.
414 This function adds the CA certificate to the list of CAs when requesting
415 Server or Client authentication for the chosen TLS connection.
417 @param[in] Tls Pointer to the TLS object.
418 @param[in] Data Pointer to the data buffer of a DER-encoded binary
419 X.509 certificate or PEM-encoded X.509 certificate.
420 @param[in] DataSize The size of data buffer in bytes.
422 @retval EFI_SUCCESS The operation succeeded.
423 @retval EFI_INVALID_PARAMETER The parameter is invalid.
424 @retval EFI_OUT_OF_RESOURCES Required resources could not be allocated.
425 @retval EFI_ABORTED Invalid X.509 certificate.
430 TlsSetCaCertificate (
438 X509_STORE
*X509Store
;
440 TLS_CONNECTION
*TlsConn
;
448 Status
= EFI_SUCCESS
;
449 TlsConn
= (TLS_CONNECTION
*) Tls
;
452 if (TlsConn
== NULL
|| TlsConn
->Ssl
== NULL
|| Data
== NULL
|| DataSize
== 0) {
453 return EFI_INVALID_PARAMETER
;
457 // DER-encoded binary X.509 certificate or PEM-encoded X.509 certificate.
458 // Determine whether certificate is from DER encoding, if so, translate it to X509 structure.
460 Cert
= d2i_X509 (NULL
, (const unsigned char ** )&Data
, (long) DataSize
);
463 // Certificate is from PEM encoding.
465 BioCert
= BIO_new (BIO_s_mem ());
466 if (BioCert
== NULL
) {
467 Status
= EFI_OUT_OF_RESOURCES
;
471 if (BIO_write (BioCert
, Data
, (UINT32
) DataSize
) <= 0) {
472 Status
= EFI_ABORTED
;
476 Cert
= PEM_read_bio_X509 (BioCert
, NULL
, NULL
, NULL
);
478 Status
= EFI_ABORTED
;
483 SslCtx
= SSL_get_SSL_CTX (TlsConn
->Ssl
);
484 X509Store
= SSL_CTX_get_cert_store (SslCtx
);
485 if (X509Store
== NULL
) {
486 Status
= EFI_ABORTED
;
491 // Add certificate to X509 store
493 Ret
= X509_STORE_add_cert (X509Store
, Cert
);
495 ErrorCode
= ERR_peek_last_error ();
497 // Ignore "already in table" errors
499 if (!(ERR_GET_FUNC (ErrorCode
) == X509_F_X509_STORE_ADD_CERT
&&
500 ERR_GET_REASON (ErrorCode
) == X509_R_CERT_ALREADY_IN_HASH_TABLE
)) {
501 Status
= EFI_ABORTED
;
507 if (BioCert
!= NULL
) {
519 Loads the local public certificate into the specified TLS object.
521 This function loads the X.509 certificate into the specified TLS object
524 @param[in] Tls Pointer to the TLS object.
525 @param[in] Data Pointer to the data buffer of a DER-encoded binary
526 X.509 certificate or PEM-encoded X.509 certificate.
527 @param[in] DataSize The size of data buffer in bytes.
529 @retval EFI_SUCCESS The operation succeeded.
530 @retval EFI_INVALID_PARAMETER The parameter is invalid.
531 @retval EFI_OUT_OF_RESOURCES Required resources could not be allocated.
532 @retval EFI_ABORTED Invalid X.509 certificate.
537 TlsSetHostPublicCert (
546 TLS_CONNECTION
*TlsConn
;
550 Status
= EFI_SUCCESS
;
551 TlsConn
= (TLS_CONNECTION
*) Tls
;
553 if (TlsConn
== NULL
|| TlsConn
->Ssl
== NULL
|| Data
== NULL
|| DataSize
== 0) {
554 return EFI_INVALID_PARAMETER
;
558 // DER-encoded binary X.509 certificate or PEM-encoded X.509 certificate.
559 // Determine whether certificate is from DER encoding, if so, translate it to X509 structure.
561 Cert
= d2i_X509 (NULL
, (const unsigned char ** )&Data
, (long) DataSize
);
564 // Certificate is from PEM encoding.
566 BioCert
= BIO_new (BIO_s_mem ());
567 if (BioCert
== NULL
) {
568 Status
= EFI_OUT_OF_RESOURCES
;
572 if (BIO_write (BioCert
, Data
, (UINT32
) DataSize
) <= 0) {
573 Status
= EFI_ABORTED
;
577 Cert
= PEM_read_bio_X509 (BioCert
, NULL
, NULL
, NULL
);
579 Status
= EFI_ABORTED
;
584 if (SSL_use_certificate (TlsConn
->Ssl
, Cert
) != 1) {
585 Status
= EFI_ABORTED
;
590 if (BioCert
!= NULL
) {
602 Adds the local private key to the specified TLS object.
604 This function adds the local private key (PEM-encoded RSA or PKCS#8 private
605 key) into the specified TLS object for TLS negotiation.
607 @param[in] Tls Pointer to the TLS object.
608 @param[in] Data Pointer to the data buffer of a PEM-encoded RSA
609 or PKCS#8 private key.
610 @param[in] DataSize The size of data buffer in bytes.
612 @retval EFI_SUCCESS The operation succeeded.
613 @retval EFI_UNSUPPORTED This function is not supported.
614 @retval EFI_ABORTED Invalid private key data.
619 TlsSetHostPrivateKey (
625 return EFI_UNSUPPORTED
;
629 Adds the CA-supplied certificate revocation list for certificate validation.
631 This function adds the CA-supplied certificate revocation list data for
632 certificate validity checking.
634 @param[in] Data Pointer to the data buffer of a DER-encoded CRL data.
635 @param[in] DataSize The size of data buffer in bytes.
637 @retval EFI_SUCCESS The operation succeeded.
638 @retval EFI_UNSUPPORTED This function is not supported.
639 @retval EFI_ABORTED Invalid CRL data.
644 TlsSetCertRevocationList (
649 return EFI_UNSUPPORTED
;
653 Gets the protocol version used by the specified TLS connection.
655 This function returns the protocol version used by the specified TLS
658 If Tls is NULL, then ASSERT().
660 @param[in] Tls Pointer to the TLS object.
662 @return The protocol version of the specified TLS connection.
671 TLS_CONNECTION
*TlsConn
;
673 TlsConn
= (TLS_CONNECTION
*) Tls
;
675 ASSERT (TlsConn
!= NULL
);
677 return (UINT16
)(SSL_version (TlsConn
->Ssl
));
681 Gets the connection end of the specified TLS connection.
683 This function returns the connection end (as client or as server) used by
684 the specified TLS connection.
686 If Tls is NULL, then ASSERT().
688 @param[in] Tls Pointer to the TLS object.
690 @return The connection end used by the specified TLS connection.
695 TlsGetConnectionEnd (
699 TLS_CONNECTION
*TlsConn
;
701 TlsConn
= (TLS_CONNECTION
*) Tls
;
703 ASSERT (TlsConn
!= NULL
);
705 return (UINT8
)SSL_is_server (TlsConn
->Ssl
);
709 Gets the cipher suite used by the specified TLS connection.
711 This function returns current cipher suite used by the specified
714 @param[in] Tls Pointer to the TLS object.
715 @param[in,out] CipherId The cipher suite used by the TLS object.
717 @retval EFI_SUCCESS The cipher suite was returned successfully.
718 @retval EFI_INVALID_PARAMETER The parameter is invalid.
719 @retval EFI_UNSUPPORTED Unsupported cipher suite.
724 TlsGetCurrentCipher (
726 IN OUT UINT16
*CipherId
729 TLS_CONNECTION
*TlsConn
;
730 CONST SSL_CIPHER
*Cipher
;
732 TlsConn
= (TLS_CONNECTION
*) Tls
;
735 if (TlsConn
== NULL
|| TlsConn
->Ssl
== NULL
|| CipherId
== NULL
) {
736 return EFI_INVALID_PARAMETER
;
739 Cipher
= SSL_get_current_cipher (TlsConn
->Ssl
);
740 if (Cipher
== NULL
) {
741 return EFI_UNSUPPORTED
;
744 *CipherId
= (SSL_CIPHER_get_id (Cipher
)) & 0xFFFF;
750 Gets the compression methods used by the specified TLS connection.
752 This function returns current integrated compression methods used by
753 the specified TLS connection.
755 @param[in] Tls Pointer to the TLS object.
756 @param[in,out] CompressionId The current compression method used by
759 @retval EFI_SUCCESS The compression method was returned successfully.
760 @retval EFI_INVALID_PARAMETER The parameter is invalid.
761 @retval EFI_ABORTED Invalid Compression method.
762 @retval EFI_UNSUPPORTED This function is not supported.
767 TlsGetCurrentCompressionId (
769 IN OUT UINT8
*CompressionId
772 return EFI_UNSUPPORTED
;
776 Gets the verification mode currently set in the TLS connection.
778 This function returns the peer verification mode currently set in the
779 specified TLS connection.
781 If Tls is NULL, then ASSERT().
783 @param[in] Tls Pointer to the TLS object.
785 @return The verification mode set in the specified TLS connection.
794 TLS_CONNECTION
*TlsConn
;
796 TlsConn
= (TLS_CONNECTION
*) Tls
;
798 ASSERT (TlsConn
!= NULL
);
800 return SSL_get_verify_mode (TlsConn
->Ssl
);
804 Gets the session ID used by the specified TLS connection.
806 This function returns the TLS/SSL session ID currently used by the
807 specified TLS connection.
809 @param[in] Tls Pointer to the TLS object.
810 @param[in,out] SessionId Buffer to contain the returned session ID.
811 @param[in,out] SessionIdLen The length of Session ID in bytes.
813 @retval EFI_SUCCESS The Session ID was returned successfully.
814 @retval EFI_INVALID_PARAMETER The parameter is invalid.
815 @retval EFI_UNSUPPORTED Invalid TLS/SSL session.
822 IN OUT UINT8
*SessionId
,
823 IN OUT UINT16
*SessionIdLen
826 TLS_CONNECTION
*TlsConn
;
827 SSL_SESSION
*Session
;
828 CONST UINT8
*SslSessionId
;
830 TlsConn
= (TLS_CONNECTION
*) Tls
;
833 if (TlsConn
== NULL
|| TlsConn
->Ssl
== NULL
|| SessionId
== NULL
|| SessionIdLen
== NULL
) {
834 return EFI_INVALID_PARAMETER
;
837 Session
= SSL_get_session (TlsConn
->Ssl
);
838 if (Session
== NULL
) {
839 return EFI_UNSUPPORTED
;
842 SslSessionId
= SSL_SESSION_get_id (Session
, (unsigned int *)SessionIdLen
);
843 CopyMem (SessionId
, SslSessionId
, *SessionIdLen
);
849 Gets the client random data used in the specified TLS connection.
851 This function returns the TLS/SSL client random data currently used in
852 the specified TLS connection.
854 @param[in] Tls Pointer to the TLS object.
855 @param[in,out] ClientRandom Buffer to contain the returned client
856 random data (32 bytes).
863 IN OUT UINT8
*ClientRandom
866 TLS_CONNECTION
*TlsConn
;
868 TlsConn
= (TLS_CONNECTION
*) Tls
;
870 if (TlsConn
== NULL
|| TlsConn
->Ssl
== NULL
|| ClientRandom
== NULL
) {
874 SSL_get_client_random (TlsConn
->Ssl
, ClientRandom
, SSL3_RANDOM_SIZE
);
878 Gets the server random data used in the specified TLS connection.
880 This function returns the TLS/SSL server random data currently used in
881 the specified TLS connection.
883 @param[in] Tls Pointer to the TLS object.
884 @param[in,out] ServerRandom Buffer to contain the returned server
885 random data (32 bytes).
892 IN OUT UINT8
*ServerRandom
895 TLS_CONNECTION
*TlsConn
;
897 TlsConn
= (TLS_CONNECTION
*) Tls
;
899 if (TlsConn
== NULL
|| TlsConn
->Ssl
== NULL
|| ServerRandom
== NULL
) {
903 SSL_get_server_random (TlsConn
->Ssl
, ServerRandom
, SSL3_RANDOM_SIZE
);
907 Gets the master key data used in the specified TLS connection.
909 This function returns the TLS/SSL master key material currently used in
910 the specified TLS connection.
912 @param[in] Tls Pointer to the TLS object.
913 @param[in,out] KeyMaterial Buffer to contain the returned key material.
915 @retval EFI_SUCCESS Key material was returned successfully.
916 @retval EFI_INVALID_PARAMETER The parameter is invalid.
917 @retval EFI_UNSUPPORTED Invalid TLS/SSL session.
924 IN OUT UINT8
*KeyMaterial
927 TLS_CONNECTION
*TlsConn
;
928 SSL_SESSION
*Session
;
930 TlsConn
= (TLS_CONNECTION
*) Tls
;
933 if (TlsConn
== NULL
|| TlsConn
->Ssl
== NULL
|| KeyMaterial
== NULL
) {
934 return EFI_INVALID_PARAMETER
;
937 Session
= SSL_get_session (TlsConn
->Ssl
);
939 if (Session
== NULL
) {
940 return EFI_UNSUPPORTED
;
943 SSL_SESSION_get_master_key (Session
, KeyMaterial
, SSL3_MASTER_SECRET_SIZE
);
949 Gets the CA Certificate from the cert store.
951 This function returns the CA certificate for the chosen
954 @param[in] Tls Pointer to the TLS object.
955 @param[out] Data Pointer to the data buffer to receive the CA
956 certificate data sent to the client.
957 @param[in,out] DataSize The size of data buffer in bytes.
959 @retval EFI_SUCCESS The operation succeeded.
960 @retval EFI_UNSUPPORTED This function is not supported.
961 @retval EFI_BUFFER_TOO_SMALL The Data is too small to hold the data.
966 TlsGetCaCertificate (
969 IN OUT UINTN
*DataSize
972 return EFI_UNSUPPORTED
;
976 Gets the local public Certificate set in the specified TLS object.
978 This function returns the local public certificate which was currently set
979 in the specified TLS object.
981 @param[in] Tls Pointer to the TLS object.
982 @param[out] Data Pointer to the data buffer to receive the local
984 @param[in,out] DataSize The size of data buffer in bytes.
986 @retval EFI_SUCCESS The operation succeeded.
987 @retval EFI_INVALID_PARAMETER The parameter is invalid.
988 @retval EFI_NOT_FOUND The certificate is not found.
989 @retval EFI_BUFFER_TOO_SMALL The Data is too small to hold the data.
994 TlsGetHostPublicCert (
997 IN OUT UINTN
*DataSize
1001 TLS_CONNECTION
*TlsConn
;
1004 TlsConn
= (TLS_CONNECTION
*) Tls
;
1006 if (TlsConn
== NULL
|| TlsConn
->Ssl
== NULL
|| DataSize
== NULL
|| (*DataSize
!= 0 && Data
== NULL
)) {
1007 return EFI_INVALID_PARAMETER
;
1010 Cert
= SSL_get_certificate(TlsConn
->Ssl
);
1012 return EFI_NOT_FOUND
;
1016 // Only DER encoding is supported currently.
1018 if (*DataSize
< (UINTN
) i2d_X509 (Cert
, NULL
)) {
1019 *DataSize
= (UINTN
) i2d_X509 (Cert
, NULL
);
1020 return EFI_BUFFER_TOO_SMALL
;
1023 *DataSize
= (UINTN
) i2d_X509 (Cert
, (unsigned char **) &Data
);
1029 Gets the local private key set in the specified TLS object.
1031 This function returns the local private key data which was currently set
1032 in the specified TLS object.
1034 @param[in] Tls Pointer to the TLS object.
1035 @param[out] Data Pointer to the data buffer to receive the local
1037 @param[in,out] DataSize The size of data buffer in bytes.
1039 @retval EFI_SUCCESS The operation succeeded.
1040 @retval EFI_UNSUPPORTED This function is not supported.
1041 @retval EFI_BUFFER_TOO_SMALL The Data is too small to hold the data.
1046 TlsGetHostPrivateKey (
1049 IN OUT UINTN
*DataSize
1052 return EFI_UNSUPPORTED
;
1056 Gets the CA-supplied certificate revocation list data set in the specified
1059 This function returns the CA-supplied certificate revocation list data which
1060 was currently set in the specified TLS object.
1062 @param[out] Data Pointer to the data buffer to receive the CRL data.
1063 @param[in,out] DataSize The size of data buffer in bytes.
1065 @retval EFI_SUCCESS The operation succeeded.
1066 @retval EFI_UNSUPPORTED This function is not supported.
1067 @retval EFI_BUFFER_TOO_SMALL The Data is too small to hold the data.
1072 TlsGetCertRevocationList (
1074 IN OUT UINTN
*DataSize
1077 return EFI_UNSUPPORTED
;