]> git.proxmox.com Git - mirror_edk2.git/blob - NetworkPkg/TlsDxe/TlsConfigProtocol.c
NetworkPkg: Convert files to CRLF line ending
[mirror_edk2.git] / NetworkPkg / TlsDxe / TlsConfigProtocol.c
1 /** @file
2 Implementation of EFI TLS Configuration Protocol Interfaces.
3
4 Copyright (c) 2016, Intel Corporation. All rights reserved.<BR>
5
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.
10
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.
13
14 **/
15
16 #include "TlsImpl.h"
17
18 EFI_TLS_CONFIGURATION_PROTOCOL mTlsConfigurationProtocol = {
19 TlsConfigurationSetData,
20 TlsConfigurationGetData
21 };
22
23 /**
24 Set TLS configuration data.
25
26 The SetData() function sets TLS configuration to non-volatile storage or volatile
27 storage.
28
29 @param[in] This Pointer to the EFI_TLS_CONFIGURATION_PROTOCOL instance.
30 @param[in] DataType Configuration data type.
31 @param[in] Data Pointer to configuration data.
32 @param[in] DataSize Total size of configuration data.
33
34 @retval EFI_SUCCESS The TLS configuration data is set successfully.
35 @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:
36 This is NULL.
37 Data is NULL.
38 DataSize is 0.
39 @retval EFI_UNSUPPORTED The DataType is unsupported.
40 @retval EFI_OUT_OF_RESOURCES Required system resources could not be allocated.
41
42 **/
43 EFI_STATUS
44 EFIAPI
45 TlsConfigurationSetData (
46 IN EFI_TLS_CONFIGURATION_PROTOCOL *This,
47 IN EFI_TLS_CONFIG_DATA_TYPE DataType,
48 IN VOID *Data,
49 IN UINTN DataSize
50 )
51 {
52 EFI_STATUS Status;
53 TLS_INSTANCE *Instance;
54 EFI_TPL OldTpl;
55
56 Status = EFI_SUCCESS;
57
58 if (This == NULL || Data == NULL || DataSize == 0) {
59 return EFI_INVALID_PARAMETER;
60 }
61
62 OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
63
64 Instance = TLS_INSTANCE_FROM_CONFIGURATION (This);
65
66 switch (DataType) {
67 case EfiTlsConfigDataTypeCACertificate:
68 Status = TlsSetCaCertificate (Instance->TlsConn, Data, DataSize);
69 break;
70 case EfiTlsConfigDataTypeHostPublicCert:
71 Status = TlsSetHostPublicCert (Instance->TlsConn, Data, DataSize);
72 break;
73 case EfiTlsConfigDataTypeHostPrivateKey:
74 Status = TlsSetHostPrivateKey (Instance->TlsConn, Data, DataSize);
75 break;
76 case EfiTlsConfigDataTypeCertRevocationList:
77 Status = TlsSetCertRevocationList (Data, DataSize);
78 break;
79 default:
80 Status = EFI_UNSUPPORTED;
81 }
82
83 gBS->RestoreTPL (OldTpl);
84 return Status;
85 }
86
87 /**
88 Get TLS configuration data.
89
90 The GetData() function gets TLS configuration.
91
92 @param[in] This Pointer to the EFI_TLS_CONFIGURATION_PROTOCOL instance.
93 @param[in] DataType Configuration data type.
94 @param[in, out] Data Pointer to configuration data.
95 @param[in, out] DataSize Total size of configuration data. On input, it means
96 the size of Data buffer. On output, it means the size
97 of copied Data buffer if EFI_SUCCESS, and means the
98 size of desired Data buffer if EFI_BUFFER_TOO_SMALL.
99
100 @retval EFI_SUCCESS The TLS configuration data is got successfully.
101 @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:
102 This is NULL.
103 DataSize is NULL.
104 Data is NULL if *DataSize is not zero.
105 @retval EFI_UNSUPPORTED The DataType is unsupported.
106 @retval EFI_NOT_FOUND The TLS configuration data is not found.
107 @retval EFI_BUFFER_TOO_SMALL The buffer is too small to hold the data.
108 **/
109 EFI_STATUS
110 EFIAPI
111 TlsConfigurationGetData (
112 IN EFI_TLS_CONFIGURATION_PROTOCOL *This,
113 IN EFI_TLS_CONFIG_DATA_TYPE DataType,
114 IN OUT VOID *Data, OPTIONAL
115 IN OUT UINTN *DataSize
116 )
117 {
118 EFI_STATUS Status;
119 TLS_INSTANCE *Instance;
120
121 EFI_TPL OldTpl;
122
123 Status = EFI_SUCCESS;
124
125 if (This == NULL || DataSize == NULL || (Data == NULL && *DataSize != 0)) {
126 return EFI_INVALID_PARAMETER;
127 }
128
129 OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
130
131 Instance = TLS_INSTANCE_FROM_CONFIGURATION (This);
132
133 switch (DataType) {
134 case EfiTlsConfigDataTypeCACertificate:
135 Status = TlsGetCaCertificate (Instance->TlsConn, Data, DataSize);
136 break;
137 case EfiTlsConfigDataTypeHostPublicCert:
138 Status = TlsGetHostPublicCert (Instance->TlsConn, Data, DataSize);
139 break;
140 case EfiTlsConfigDataTypeHostPrivateKey:
141 Status = TlsGetHostPrivateKey (Instance->TlsConn, Data, DataSize);
142 break;
143 case EfiTlsConfigDataTypeCertRevocationList:
144 Status = TlsGetCertRevocationList (Data, DataSize);
145 break;
146 default:
147 Status = EFI_UNSUPPORTED;
148 }
149
150 gBS->RestoreTPL (OldTpl);
151 return Status;
152 }
153