VirtualBox

source: vbox/trunk/src/VBox/Devices/EFI/FirmwareNew/RedfishPkg/PrivateLibrary/RedfishLib/RedfishMisc.c@ 105670

Last change on this file since 105670 was 105670, checked in by vboxsync, 4 months ago

Devices/EFI/FirmwareNew: Merge edk2-stable-202405 and make it build on aarch64, bugref:4643

  • Property svn:eol-style set to native
File size: 6.4 KB
Line 
1/** @file
2 Internal Functions for RedfishLib.
3
4 Copyright (c) 2019, Intel Corporation. All rights reserved.<BR>
5 (C) Copyright 2021 Hewlett Packard Enterprise Development LP<BR>
6 Copyright (c) 2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
7
8 SPDX-License-Identifier: BSD-2-Clause-Patent
9
10**/
11
12#include "RedfishMisc.h"
13
14EDKII_REDFISH_CREDENTIAL_PROTOCOL *mCredentialProtocol = NULL;
15
16/**
17 This function returns the string of Redfish service version.
18
19 @param[in] RedfishService Redfish service instance.
20 @param[out] ServiceVersionStr Redfish service string.
21
22 @return EFI_STATUS
23
24**/
25EFI_STATUS
26RedfishGetServiceVersion (
27 IN REDFISH_SERVICE RedfishService,
28 OUT CHAR8 **ServiceVersionStr
29 )
30{
31 redfishService *Redfish;
32 CHAR8 **KeysArray;
33 UINTN KeysNum;
34
35 if ((RedfishService == NULL) || (ServiceVersionStr == NULL)) {
36 return EFI_INVALID_PARAMETER;
37 }
38
39 Redfish = (redfishService *)RedfishService;
40 if (Redfish->versions == NULL) {
41 return EFI_INVALID_PARAMETER;
42 }
43
44 KeysArray = JsonObjectGetKeys (Redfish->versions, &KeysNum);
45 if ((KeysNum == 0) || (KeysArray == NULL)) {
46 return EFI_NOT_FOUND;
47 }
48
49 *ServiceVersionStr = *KeysArray;
50 return EFI_SUCCESS;
51}
52
53/**
54 Creates a REDFISH_SERVICE which can be later used to access the Redfish resources.
55
56 This function will configure REST EX child according to parameters described in
57 Redfish network host interface in SMBIOS type 42 record. The service enumerator will also
58 handle the authentication flow automatically if HTTP basic auth or Redfish session
59 login is configured to use.
60
61 @param[in] RedfishConfigServiceInfo Redfish service information the EFI Redfish
62 feature driver communicates with.
63 @param[in] AuthMethod None, HTTP basic auth, or Redfish session login.
64 @param[in] UserId User Name used for authentication.
65 @param[in] Password Password used for authentication.
66
67 @return New created Redfish service, or NULL if error happens.
68
69**/
70REDFISH_SERVICE
71RedfishCreateLibredfishService (
72 IN REDFISH_CONFIG_SERVICE_INFORMATION *RedfishConfigServiceInfo,
73 IN EDKII_REDFISH_AUTH_METHOD AuthMethod,
74 IN CHAR8 *UserId,
75 IN CHAR8 *Password
76 )
77{
78 UINTN Flags;
79 enumeratorAuthentication Auth;
80 redfishService *Redfish;
81
82 Redfish = NULL;
83
84 ZeroMem (&Auth, sizeof (Auth));
85 if (AuthMethod == AuthMethodHttpBasic) {
86 Auth.authType = REDFISH_AUTH_BASIC;
87 } else if (AuthMethod == AuthMethodRedfishSession) {
88 Auth.authType = REDFISH_AUTH_SESSION;
89 }
90
91 Auth.authCodes.userPass.username = UserId;
92 Auth.authCodes.userPass.password = Password;
93
94 Flags = REDFISH_FLAG_SERVICE_NO_VERSION_DOC;
95
96 if (AuthMethod != AuthMethodNone) {
97 Redfish = createServiceEnumerator (RedfishConfigServiceInfo, NULL, &Auth, (unsigned int)Flags);
98 } else {
99 Redfish = createServiceEnumerator (RedfishConfigServiceInfo, NULL, NULL, (unsigned int)Flags);
100 }
101
102 //
103 // Zero the Password after use.
104 //
105 if (Password != NULL) {
106 ZeroMem (Password, AsciiStrLen (Password));
107 }
108
109 return (REDFISH_SERVICE)Redfish;
110}
111
112/**
113 Retrieve platform's Redfish authentication information.
114
115 This functions returns the Redfish authentication method together with the user
116 Id and password.
117 For AuthMethodNone, UserId and Password will point to NULL which means authentication
118 is not required to access the Redfish service.
119 For AuthMethodHttpBasic, the UserId and Password could be used for
120 HTTP header authentication as defined by RFC7235. For AuthMethodRedfishSession,
121 the UserId and Password could be used for Redfish session login as defined by
122 Redfish API specification (DSP0266).
123
124 Callers are responsible for freeing the returned string storage pointed by UserId
125 and Password.
126
127 @param[out] AuthMethod Type of Redfish authentication method.
128 @param[out] UserId The pointer to store the returned UserId string.
129 @param[out] Password The pointer to store the returned Password string.
130
131 @retval EFI_SUCCESS Get the authentication information successfully.
132 @retval EFI_INVALID_PARAMETER AuthMethod or UserId or Password is NULL.
133 @retval EFI_UNSUPPORTED Unsupported authentication method is found.
134**/
135EFI_STATUS
136RedfishGetAuthInfo (
137 OUT EDKII_REDFISH_AUTH_METHOD *AuthMethod,
138 OUT CHAR8 **UserId,
139 OUT CHAR8 **Password
140 )
141{
142 EFI_STATUS Status;
143
144 if ((AuthMethod == NULL) || (UserId == NULL) || (Password == NULL)) {
145 return EFI_INVALID_PARAMETER;
146 }
147
148 //
149 // Locate Redfish Credential Protocol.
150 //
151 if (mCredentialProtocol == NULL) {
152 Status = gBS->LocateProtocol (&gEdkIIRedfishCredentialProtocolGuid, NULL, (VOID **)&mCredentialProtocol);
153 if (EFI_ERROR (Status)) {
154 return EFI_UNSUPPORTED;
155 }
156 }
157
158 ASSERT (mCredentialProtocol != NULL);
159
160 Status = mCredentialProtocol->GetAuthInfo (mCredentialProtocol, AuthMethod, UserId, Password);
161 if (EFI_ERROR (Status)) {
162 DEBUG ((DEBUG_ERROR, "RedfishGetAuthInfo: failed to retrieve Redfish credential - %r\n", Status));
163 return Status;
164 }
165
166 return Status;
167}
168
169/**
170 This function returns the string of Redfish service version.
171
172 @param[in] ServiceVersionStr The string of Redfish service version.
173 @param[in] Url The URL to build Redpath with ID.
174 Start with "/", for example "/Registries"
175 @param[in] Id ID string
176 @param[out] Redpath Pointer to retrieved Redpath, caller has to free
177 the memory allocated for this string.
178 @return EFI_STATUS
179
180**/
181EFI_STATUS
182RedfishBuildRedpathUseId (
183 IN CHAR8 *ServiceVersionStr,
184 IN CHAR8 *Url,
185 IN CHAR8 *Id,
186 OUT CHAR8 **Redpath
187 )
188{
189 UINTN RedpathSize;
190
191 if ((Redpath == NULL) || (ServiceVersionStr == NULL) || (Url == NULL) || (Id == NULL)) {
192 return EFI_INVALID_PARAMETER;
193 }
194
195 RedpathSize = AsciiStrLen ("/") +
196 AsciiStrLen (ServiceVersionStr) +
197 AsciiStrLen (Url) +
198 AsciiStrLen ("[Id=]") +
199 AsciiStrLen (Id) + 1;
200 *Redpath = AllocatePool (RedpathSize);
201 if (*Redpath == NULL) {
202 return EFI_OUT_OF_RESOURCES;
203 }
204
205 AsciiSPrint (*Redpath, RedpathSize, "/%a%a[Id=%a]", ServiceVersionStr, Url, Id);
206 return EFI_SUCCESS;
207}
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette