1 | /** @file
|
---|
2 | SSL/TLS Process Null Library Wrapper Implementation.
|
---|
3 | The process includes the TLS handshake and packet I/O.
|
---|
4 |
|
---|
5 | Copyright (c) 2016 - 2017, Intel Corporation. All rights reserved.<BR>
|
---|
6 | (C) Copyright 2016 Hewlett Packard Enterprise Development LP<BR>
|
---|
7 | SPDX-License-Identifier: BSD-2-Clause-Patent
|
---|
8 |
|
---|
9 | **/
|
---|
10 |
|
---|
11 | #include "InternalTlsLib.h"
|
---|
12 |
|
---|
13 | /**
|
---|
14 | Checks if the TLS handshake was done.
|
---|
15 |
|
---|
16 | This function will check if the specified TLS handshake was done.
|
---|
17 |
|
---|
18 | @param[in] Tls Pointer to the TLS object for handshake state checking.
|
---|
19 |
|
---|
20 | @retval TRUE The TLS handshake was done.
|
---|
21 | @retval FALSE The TLS handshake was not done.
|
---|
22 |
|
---|
23 | **/
|
---|
24 | BOOLEAN
|
---|
25 | EFIAPI
|
---|
26 | TlsInHandshake (
|
---|
27 | IN VOID *Tls
|
---|
28 | )
|
---|
29 | {
|
---|
30 | ASSERT(FALSE);
|
---|
31 | return FALSE;
|
---|
32 | }
|
---|
33 |
|
---|
34 | /**
|
---|
35 | Perform a TLS/SSL handshake.
|
---|
36 |
|
---|
37 | This function will perform a TLS/SSL handshake.
|
---|
38 |
|
---|
39 | @param[in] Tls Pointer to the TLS object for handshake operation.
|
---|
40 | @param[in] BufferIn Pointer to the most recently received TLS Handshake packet.
|
---|
41 | @param[in] BufferInSize Packet size in bytes for the most recently received TLS
|
---|
42 | Handshake packet.
|
---|
43 | @param[out] BufferOut Pointer to the buffer to hold the built packet.
|
---|
44 | @param[in, out] BufferOutSize Pointer to the buffer size in bytes. On input, it is
|
---|
45 | the buffer size provided by the caller. On output, it
|
---|
46 | is the buffer size in fact needed to contain the
|
---|
47 | packet.
|
---|
48 |
|
---|
49 | @retval EFI_SUCCESS The required TLS packet is built successfully.
|
---|
50 | @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:
|
---|
51 | Tls is NULL.
|
---|
52 | BufferIn is NULL but BufferInSize is NOT 0.
|
---|
53 | BufferInSize is 0 but BufferIn is NOT NULL.
|
---|
54 | BufferOutSize is NULL.
|
---|
55 | BufferOut is NULL if *BufferOutSize is not zero.
|
---|
56 | @retval EFI_BUFFER_TOO_SMALL BufferOutSize is too small to hold the response packet.
|
---|
57 | @retval EFI_ABORTED Something wrong during handshake.
|
---|
58 |
|
---|
59 | **/
|
---|
60 | EFI_STATUS
|
---|
61 | EFIAPI
|
---|
62 | TlsDoHandshake (
|
---|
63 | IN VOID *Tls,
|
---|
64 | IN UINT8 *BufferIn, OPTIONAL
|
---|
65 | IN UINTN BufferInSize, OPTIONAL
|
---|
66 | OUT UINT8 *BufferOut, OPTIONAL
|
---|
67 | IN OUT UINTN *BufferOutSize
|
---|
68 | )
|
---|
69 | {
|
---|
70 | ASSERT(FALSE);
|
---|
71 | return EFI_UNSUPPORTED;
|
---|
72 | }
|
---|
73 |
|
---|
74 | /**
|
---|
75 | Handle Alert message recorded in BufferIn. If BufferIn is NULL and BufferInSize is zero,
|
---|
76 | TLS session has errors and the response packet needs to be Alert message based on error type.
|
---|
77 |
|
---|
78 | @param[in] Tls Pointer to the TLS object for state checking.
|
---|
79 | @param[in] BufferIn Pointer to the most recently received TLS Alert packet.
|
---|
80 | @param[in] BufferInSize Packet size in bytes for the most recently received TLS
|
---|
81 | Alert packet.
|
---|
82 | @param[out] BufferOut Pointer to the buffer to hold the built packet.
|
---|
83 | @param[in, out] BufferOutSize Pointer to the buffer size in bytes. On input, it is
|
---|
84 | the buffer size provided by the caller. On output, it
|
---|
85 | is the buffer size in fact needed to contain the
|
---|
86 | packet.
|
---|
87 |
|
---|
88 | @retval EFI_SUCCESS The required TLS packet is built successfully.
|
---|
89 | @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:
|
---|
90 | Tls is NULL.
|
---|
91 | BufferIn is NULL but BufferInSize is NOT 0.
|
---|
92 | BufferInSize is 0 but BufferIn is NOT NULL.
|
---|
93 | BufferOutSize is NULL.
|
---|
94 | BufferOut is NULL if *BufferOutSize is not zero.
|
---|
95 | @retval EFI_ABORTED An error occurred.
|
---|
96 | @retval EFI_BUFFER_TOO_SMALL BufferOutSize is too small to hold the response packet.
|
---|
97 |
|
---|
98 | **/
|
---|
99 | EFI_STATUS
|
---|
100 | EFIAPI
|
---|
101 | TlsHandleAlert (
|
---|
102 | IN VOID *Tls,
|
---|
103 | IN UINT8 *BufferIn, OPTIONAL
|
---|
104 | IN UINTN BufferInSize, OPTIONAL
|
---|
105 | OUT UINT8 *BufferOut, OPTIONAL
|
---|
106 | IN OUT UINTN *BufferOutSize
|
---|
107 | )
|
---|
108 | {
|
---|
109 | ASSERT(FALSE);
|
---|
110 | return EFI_UNSUPPORTED;
|
---|
111 | }
|
---|
112 |
|
---|
113 | /**
|
---|
114 | Build the CloseNotify packet.
|
---|
115 |
|
---|
116 | @param[in] Tls Pointer to the TLS object for state checking.
|
---|
117 | @param[in, out] Buffer Pointer to the buffer to hold the built packet.
|
---|
118 | @param[in, out] BufferSize Pointer to the buffer size in bytes. On input, it is
|
---|
119 | the buffer size provided by the caller. On output, it
|
---|
120 | is the buffer size in fact needed to contain the
|
---|
121 | packet.
|
---|
122 |
|
---|
123 | @retval EFI_SUCCESS The required TLS packet is built successfully.
|
---|
124 | @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:
|
---|
125 | Tls is NULL.
|
---|
126 | BufferSize is NULL.
|
---|
127 | Buffer is NULL if *BufferSize is not zero.
|
---|
128 | @retval EFI_BUFFER_TOO_SMALL BufferSize is too small to hold the response packet.
|
---|
129 |
|
---|
130 | **/
|
---|
131 | EFI_STATUS
|
---|
132 | EFIAPI
|
---|
133 | TlsCloseNotify (
|
---|
134 | IN VOID *Tls,
|
---|
135 | IN OUT UINT8 *Buffer,
|
---|
136 | IN OUT UINTN *BufferSize
|
---|
137 | )
|
---|
138 | {
|
---|
139 | ASSERT(FALSE);
|
---|
140 | return EFI_UNSUPPORTED;
|
---|
141 | }
|
---|
142 |
|
---|
143 | /**
|
---|
144 | Attempts to read bytes from one TLS object and places the data in Buffer.
|
---|
145 |
|
---|
146 | This function will attempt to read BufferSize bytes from the TLS object
|
---|
147 | and places the data in Buffer.
|
---|
148 |
|
---|
149 | @param[in] Tls Pointer to the TLS object.
|
---|
150 | @param[in,out] Buffer Pointer to the buffer to store the data.
|
---|
151 | @param[in] BufferSize The size of Buffer in bytes.
|
---|
152 |
|
---|
153 | @retval >0 The amount of data successfully read from the TLS object.
|
---|
154 | @retval <=0 No data was successfully read.
|
---|
155 |
|
---|
156 | **/
|
---|
157 | INTN
|
---|
158 | EFIAPI
|
---|
159 | TlsCtrlTrafficOut (
|
---|
160 | IN VOID *Tls,
|
---|
161 | IN OUT VOID *Buffer,
|
---|
162 | IN UINTN BufferSize
|
---|
163 | )
|
---|
164 | {
|
---|
165 | ASSERT(FALSE);
|
---|
166 | return 0;
|
---|
167 | }
|
---|
168 |
|
---|
169 | /**
|
---|
170 | Attempts to write data from the buffer to TLS object.
|
---|
171 |
|
---|
172 | This function will attempt to write BufferSize bytes data from the Buffer
|
---|
173 | to the TLS object.
|
---|
174 |
|
---|
175 | @param[in] Tls Pointer to the TLS object.
|
---|
176 | @param[in] Buffer Pointer to the data buffer.
|
---|
177 | @param[in] BufferSize The size of Buffer in bytes.
|
---|
178 |
|
---|
179 | @retval >0 The amount of data successfully written to the TLS object.
|
---|
180 | @retval <=0 No data was successfully written.
|
---|
181 |
|
---|
182 | **/
|
---|
183 | INTN
|
---|
184 | EFIAPI
|
---|
185 | TlsCtrlTrafficIn (
|
---|
186 | IN VOID *Tls,
|
---|
187 | IN VOID *Buffer,
|
---|
188 | IN UINTN BufferSize
|
---|
189 | )
|
---|
190 | {
|
---|
191 | ASSERT(FALSE);
|
---|
192 | return 0;
|
---|
193 | }
|
---|
194 | /**
|
---|
195 | Attempts to read bytes from the specified TLS connection into the buffer.
|
---|
196 |
|
---|
197 | This function tries to read BufferSize bytes data from the specified TLS
|
---|
198 | connection into the Buffer.
|
---|
199 |
|
---|
200 | @param[in] Tls Pointer to the TLS connection for data reading.
|
---|
201 | @param[in,out] Buffer Pointer to the data buffer.
|
---|
202 | @param[in] BufferSize The size of Buffer in bytes.
|
---|
203 |
|
---|
204 | @retval >0 The read operation was successful, and return value is the
|
---|
205 | number of bytes actually read from the TLS connection.
|
---|
206 | @retval <=0 The read operation was not successful.
|
---|
207 |
|
---|
208 | **/
|
---|
209 | INTN
|
---|
210 | EFIAPI
|
---|
211 | TlsRead (
|
---|
212 | IN VOID *Tls,
|
---|
213 | IN OUT VOID *Buffer,
|
---|
214 | IN UINTN BufferSize
|
---|
215 | )
|
---|
216 | {
|
---|
217 | ASSERT(FALSE);
|
---|
218 | return 0;
|
---|
219 | }
|
---|
220 |
|
---|
221 | /**
|
---|
222 | Attempts to write data to a TLS connection.
|
---|
223 |
|
---|
224 | This function tries to write BufferSize bytes data from the Buffer into the
|
---|
225 | specified TLS connection.
|
---|
226 |
|
---|
227 | @param[in] Tls Pointer to the TLS connection for data writing.
|
---|
228 | @param[in] Buffer Pointer to the data buffer.
|
---|
229 | @param[in] BufferSize The size of Buffer in bytes.
|
---|
230 |
|
---|
231 | @retval >0 The write operation was successful, and return value is the
|
---|
232 | number of bytes actually written to the TLS connection.
|
---|
233 | @retval <=0 The write operation was not successful.
|
---|
234 |
|
---|
235 | **/
|
---|
236 | INTN
|
---|
237 | EFIAPI
|
---|
238 | TlsWrite (
|
---|
239 | IN VOID *Tls,
|
---|
240 | IN VOID *Buffer,
|
---|
241 | IN UINTN BufferSize
|
---|
242 | )
|
---|
243 | {
|
---|
244 | ASSERT(FALSE);
|
---|
245 | return 0;
|
---|
246 | }
|
---|
247 |
|
---|