1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
|
/** @file
RedfishCrentialDxe produces the EdkIIRedfishCredentialProtocol for the consumer
to get the Redfish credential Info and to restrict Redfish access from UEFI side.
(C) Copyright 2020 Hewlett Packard Enterprise Development LP<BR>
(C) Copyright 2024 American Megatrends International LLC<BR>
SPDX-License-Identifier: BSD-2-Clause-Patent
**/
#include <RedfishCredentialDxe.h>
#define REDFISH_VERSION_DEFAULT_STRING L"v1"
REDFISH_CREDENTIAL_PRIVATE *mCredentialPrivate = NULL;
/**
Callback function executed when the ExitBootServices event group is signaled.
@param[in] Event Event whose notification function is being invoked.
@param[out] Context Pointer to the buffer pass in.
**/
VOID
EFIAPI
RedfishCredentialExitBootServicesEventNotify (
IN EFI_EVENT Event,
OUT VOID *Context
)
{
LibCredentialExitBootServicesNotify ((EDKII_REDFISH_CREDENTIAL_PROTOCOL *)Context);
}
/**
Callback function executed when the EndOfDxe event group is signaled.
@param[in] Event Event whose notification function is being invoked.
@param[out] Context Pointer to the buffer pass in.
**/
VOID
EFIAPI
RedfishCredentialEndOfDxeEventNotify (
IN EFI_EVENT Event,
OUT VOID *Context
)
{
LibCredentialEndOfDxeNotify ((EDKII_REDFISH_CREDENTIAL_PROTOCOL *)Context);
//
// Close event, so it will not be invoked again.
//
gBS->CloseEvent (Event);
}
EFI_STATUS
ReleaseCredentialPrivate (
);
EFI_STATUS
IterateThroughBootstrapAccounts (
IN REDFISH_SERVICE RedfishService
);
/**
Retrieve platform's Redfish authentication information.
This functions returns the Redfish authentication method together with the user Id and
password.
- For AuthMethodNone, the UserId and Password could be used for HTTP header authentication
as defined by RFC7235.
- For AuthMethodRedfishSession, the UserId and Password could be used for Redfish
session login as defined by Redfish API specification (DSP0266).
Callers are responsible for and freeing the returned string storage.
@param[in] This Pointer to EDKII_REDFISH_CREDENTIAL_PROTOCOL instance.
@param[out] AuthMethod Type of Redfish authentication method.
@param[out] UserId The pointer to store the returned UserId string.
@param[out] Password The pointer to store the returned Password string.
@retval EFI_SUCCESS Get the authentication information successfully.
@retval EFI_ACCESS_DENIED SecureBoot is disabled after EndOfDxe.
@retval EFI_INVALID_PARAMETER This or AuthMethod or UserId or Password is NULL.
@retval EFI_OUT_OF_RESOURCES There are not enough memory resources.
@retval EFI_UNSUPPORTED Unsupported authentication method is found.
**/
EFI_STATUS
EFIAPI
RedfishCredentialGetAuthInfo (
IN EDKII_REDFISH_CREDENTIAL_PROTOCOL *This,
OUT EDKII_REDFISH_AUTH_METHOD *AuthMethod,
OUT CHAR8 **UserId,
OUT CHAR8 **Password
)
{
if ((This == NULL) || (AuthMethod == NULL) || (UserId == NULL) || (Password == NULL)) {
return EFI_INVALID_PARAMETER;
}
return LibCredentialGetAuthInfo (This, AuthMethod, UserId, Password);
}
/**
Notify the Redfish service provider to stop provide configuration service to this platform.
This function should be called when the platfrom is about to leave the safe environment.
It will notify the Redfish service provider to abort all logined session, and prohibit
further login with original auth info. GetAuthInfo() will return EFI_UNSUPPORTED once this
function is returned.
@param[in] This Pointer to EDKII_REDFISH_CREDENTIAL_PROTOCOL instance.
@param[in] ServiceStopType Reason of stopping Redfish service.
@retval EFI_SUCCESS Service has been stoped successfully.
@retval EFI_INVALID_PARAMETER This is NULL or given the worng ServiceStopType.
@retval EFI_UNSUPPORTED Not support to stop Redfish service.
@retval Others Some error happened.
**/
EFI_STATUS
EFIAPI
RedfishCredentialStopService (
IN EDKII_REDFISH_CREDENTIAL_PROTOCOL *This,
IN EDKII_REDFISH_CREDENTIAL_STOP_SERVICE_TYPE ServiceStopType
)
{
if (This == NULL) {
return EFI_INVALID_PARAMETER;
}
return LibStopRedfishService (This, ServiceStopType);
}
/**
Retrieve platform's Redfish authentication information.
This functions returns the Redfish authentication method together with the user Id and
password.
- For AuthMethodNone, the UserId and Password could be used for HTTP header authentication
as defined by RFC7235.
- For AuthMethodRedfishSession, the UserId and Password could be used for Redfish
session login as defined by Redfish API specification (DSP0266).
Callers are responsible for and freeing the returned string storage.
@param[in] This Pointer to EDKII_REDFISH_CREDENTIAL2_PROTOCOL instance.
@param[out] AuthMethod Type of Redfish authentication method.
@param[out] UserId The pointer to store the returned UserId string.
@param[out] Password The pointer to store the returned Password string.
@retval EFI_SUCCESS Get the authentication information successfully.
@retval EFI_ACCESS_DENIED SecureBoot is disabled after EndOfDxe.
@retval EFI_INVALID_PARAMETER This or AuthMethod or UserId or Password is NULL.
@retval EFI_OUT_OF_RESOURCES There are not enough memory resources.
@retval EFI_UNSUPPORTED Unsupported authentication method is found.
**/
EFI_STATUS
EFIAPI
RedfishCredential2GetAuthInfo (
IN EDKII_REDFISH_CREDENTIAL2_PROTOCOL *This,
OUT EDKII_REDFISH_AUTH_METHOD *AuthMethod,
OUT CHAR8 **UserId,
OUT CHAR8 **Password
)
{
EFI_STATUS Status;
if ((AuthMethod == NULL) || (UserId == NULL) || (Password == NULL)) {
return EFI_INVALID_PARAMETER;
}
if (mCredentialPrivate == NULL) {
DEBUG ((DEBUG_ERROR, "%a: failed with error - %r\n", __func__, EFI_NOT_STARTED));
return EFI_NOT_STARTED;
}
Status = mCredentialPrivate->RedfishCredentialProtocol.GetAuthInfo (
&mCredentialPrivate->RedfishCredentialProtocol,
AuthMethod,
UserId,
Password
);
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_ERROR, "%a: Failed to retrieve Redfish credential - %r\n", __func__, Status));
}
return Status;
}
/**
Notifies the Redfish service provider to stop providing configuration service to this platform.
Deletes the bootstrap account on BMC side, so it will not be used by any other driver.
This function should be called when the platfrom is about to leave the safe environment.
It will delete the bootstrap account sending DELETE request to BMC.
It will notify the Redfish service provider to abort all logined session, and prohibit
further login with original auth info. GetAuthInfo() will return EFI_UNSUPPORTED once this
function is returned.
@param[in] This Pointer to EDKII_REDFISH_CREDENTIAL2_PROTOCOL instance.
@param[in] ServiceStopType Reason of stopping Redfish service.
@retval EFI_SUCCESS Service has been stoped successfully.
@retval EFI_INVALID_PARAMETER This is NULL or given the worng ServiceStopType.
@retval EFI_UNSUPPORTED Not support to stop Redfish service.
@retval Others Some error happened.
**/
EFI_STATUS
EFIAPI
RedfishCredential2StopService (
IN EDKII_REDFISH_CREDENTIAL2_PROTOCOL *This,
IN EDKII_REDFISH_CREDENTIAL_STOP_SERVICE_TYPE ServiceStopType
)
{
EFI_STATUS Status;
REDFISH_SERVICE_LIST *Instance;
if (mCredentialPrivate == NULL) {
DEBUG ((DEBUG_ERROR, "%a: failed with error - %r\n", __func__, EFI_NOT_STARTED));
return EFI_NOT_STARTED;
}
if ((ServiceStopType == ServiceStopTypeExitBootService) ||
(ServiceStopType == ServiceStopTypeNone))
{
// Check PCD and skip the action if platform library is responsible for deleting account
// on exit boot service event
if (FixedPcdGetBool (PcdRedfishCredentialDeleteAccount)) {
if (!IsListEmpty (&mCredentialPrivate->RedfishServiceList)) {
Instance = (REDFISH_SERVICE_LIST *)GetFirstNode (&mCredentialPrivate->RedfishServiceList);
IterateThroughBootstrapAccounts (Instance->RedfishService);
}
ReleaseCredentialPrivate ();
}
}
Status = mCredentialPrivate->RedfishCredentialProtocol.StopService (
&mCredentialPrivate->RedfishCredentialProtocol,
ServiceStopType
);
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_ERROR, "%a: Failed to stop service - %r\n", __func__, Status));
}
return Status;
}
/**
Function sends DELETE request to BMC for the account defined by the target URI.
@param[in] RedfishService Pointer to Redfish Service to be used
for sending DELETE request to BMC.
@param[in] TargetUri URI of bootstrap account to send DELETE request to.
**/
EFI_STATUS
EFIAPI
DeleteRedfishBootstrapAccount (
IN REDFISH_SERVICE RedfishService,
IN CHAR16 *TargetUri
)
{
EFI_STATUS Status;
REDFISH_RESPONSE RedfishResponse;
if (mCredentialPrivate == NULL) {
DEBUG ((DEBUG_ERROR, "%a: failed with error - %r\n", __func__, EFI_NOT_STARTED));
return EFI_NOT_STARTED;
}
if ((RedfishService == NULL) || (mCredentialPrivate->AuthMethod != AuthMethodHttpBasic)) {
DEBUG ((DEBUG_ERROR, "%a: Redfish service is not available\n", __func__));
return EFI_INVALID_PARAMETER;
}
//
// Remove bootstrap account at /redfish/v1/AccountService/AccountId
//
ZeroMem (&RedfishResponse, sizeof (REDFISH_RESPONSE));
Status = RedfishHttpDeleteResourceEx (
RedfishService,
TargetUri,
"{}",
2,
NULL,
&RedfishResponse
);
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_ERROR, "%a: can not remove bootstrap account at BMC: %r", __func__, Status));
DumpRedfishResponse (__func__, DEBUG_ERROR, &RedfishResponse);
} else {
DEBUG (
(REDFISH_CREDENTIAL_DEBUG, "%a: bootstrap account: %a is removed from: %s\nURI - %s",
__func__, mCredentialPrivate->AccountName, REDFISH_MANAGER_ACCOUNT_COLLECTION_URI, TargetUri)
);
}
RedfishHttpFreeResponse (&RedfishResponse);
return Status;
}
/**
Get the information about specific Account.
Checks the User Name and if name matches delete that account
@param[in] RedfishService Pointer to Redfish Service to be used
for sending DELETE request to BMC.
@param[in] AccountUri URI of bootstrap account to verify.
**/
BOOLEAN
ProcessRedfishBootstarpAccount (
IN REDFISH_SERVICE RedfishService,
IN EFI_STRING AccountUri
)
{
EDKII_JSON_VALUE JsonUserName;
EDKII_JSON_VALUE JsonValue;
EFI_STATUS Status;
REDFISH_RESPONSE RedfishResponse;
REDFISH_REQUEST RedfishRequest;
BOOLEAN Ret;
if (mCredentialPrivate == NULL) {
DEBUG ((DEBUG_ERROR, "%a: failed with error - %r\n", __func__, EFI_NOT_STARTED));
return FALSE;
}
if ((RedfishService == NULL) || IS_EMPTY_STRING (AccountUri) ||
(mCredentialPrivate->AuthMethod != AuthMethodHttpBasic))
{
return FALSE;
}
ZeroMem (&RedfishResponse, sizeof (REDFISH_RESPONSE));
ZeroMem (&RedfishRequest, sizeof (REDFISH_REQUEST));
Status = RedfishHttpGetResource (RedfishService, AccountUri, &RedfishRequest, &RedfishResponse, FALSE);
if (EFI_ERROR (Status) || (RedfishResponse.Payload == NULL)) {
DEBUG ((DEBUG_ERROR, "%a: can not get account from BMC: %r", __func__, Status));
DumpRedfishResponse (__func__, DEBUG_ERROR, &RedfishResponse);
return FALSE;
}
Ret = FALSE;
JsonValue = RedfishJsonInPayload (RedfishResponse.Payload);
if (JsonValueIsObject (JsonValue)) {
JsonUserName = JsonObjectGetValue (JsonValueGetObject (JsonValue), "UserName");
if (JsonValueIsString (JsonUserName) && (JsonValueGetAsciiString (JsonUserName) != NULL)) {
if (AsciiStrCmp (mCredentialPrivate->AccountName, JsonValueGetAsciiString (JsonUserName)) == 0) {
DeleteRedfishBootstrapAccount (RedfishService, AccountUri);
Ret = TRUE;
}
}
}
RedfishHttpFreeResponse (&RedfishResponse);
RedfishHttpFreeRequest (&RedfishRequest);
return Ret;
}
/**
This function returns the string of Redfish service version.
@param[out] ServiceVersionStr Redfish service string.
@return EFI_STATUS
**/
EFI_STATUS
RedfishGetServiceVersion (
OUT CHAR16 **ServiceVersionStr
)
{
*ServiceVersionStr = (CHAR16 *)PcdGetPtr (PcdDefaultRedfishVersion);
if (*ServiceVersionStr == NULL) {
*ServiceVersionStr = REDFISH_VERSION_DEFAULT_STRING;
}
return EFI_SUCCESS;
}
/**
Iterates through all account in the account collection
Get the information about specific Account.
Checks the User Name and if name matches delete that account
@param[in] RedfishService Pointer to Redfish Service to be used
for sending DELETE request to BMC.
**/
EFI_STATUS
IterateThroughBootstrapAccounts (
IN REDFISH_SERVICE RedfishService
)
{
EFI_STATUS Status;
EDKII_JSON_VALUE JsonMembers;
EDKII_JSON_VALUE JsonValue;
EDKII_JSON_VALUE OdataId;
CHAR16 TargetUri[REDFISH_URI_LENGTH];
CHAR16 *RedfishVersion;
REDFISH_RESPONSE RedfishResponse;
REDFISH_REQUEST RedfishRequest;
UINTN MembersCount, Index;
RedfishVersion = NULL;
Status = EFI_NOT_FOUND;
if (mCredentialPrivate == NULL) {
DEBUG ((DEBUG_ERROR, "%a: failed with error - %r\n", __func__, EFI_NOT_STARTED));
return EFI_NOT_STARTED;
}
if ((RedfishService == NULL) || (mCredentialPrivate->AuthMethod != AuthMethodHttpBasic) ||
IS_EMPTY_STRING (mCredentialPrivate->AccountName))
{
return EFI_INVALID_PARAMETER;
}
//
// Carving the URI
//
Status = RedfishGetServiceVersion (&RedfishVersion);
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_ERROR, "%a: can not get Redfish version\n", __func__));
return Status;
}
UnicodeSPrint (
TargetUri,
(sizeof (CHAR16) * REDFISH_URI_LENGTH),
L"/redfish/%s/%s",
RedfishVersion,
REDFISH_MANAGER_ACCOUNT_COLLECTION_URI
);
DEBUG ((REDFISH_CREDENTIAL_DEBUG, "%a: account collection URI: %s\n", __func__, TargetUri));
ZeroMem (&RedfishResponse, sizeof (REDFISH_RESPONSE));
ZeroMem (&RedfishRequest, sizeof (REDFISH_REQUEST));
Status = RedfishHttpGetResource (RedfishService, TargetUri, &RedfishRequest, &RedfishResponse, FALSE);
if (EFI_ERROR (Status) || (RedfishResponse.Payload == NULL)) {
DEBUG ((DEBUG_ERROR, "%a: can not get accounts from BMC: %r\n", __func__, Status));
DumpRedfishResponse (__func__, DEBUG_ERROR, &RedfishResponse);
return Status;
}
JsonValue = RedfishJsonInPayload (RedfishResponse.Payload);
if (!JsonValueIsObject (JsonValue)) {
Status = EFI_LOAD_ERROR;
goto ON_EXIT;
}
JsonMembers = JsonObjectGetValue (JsonValueGetObject (JsonValue), "Members");
if (!JsonValueIsArray (JsonMembers)) {
Status = EFI_LOAD_ERROR;
goto ON_EXIT;
}
Status = EFI_NOT_FOUND;
MembersCount = JsonArrayCount (JsonValueGetArray (JsonMembers));
for (Index = 0; Index < MembersCount; Index++) {
JsonValue = JsonArrayGetValue (JsonValueGetArray (JsonMembers), Index);
if (!JsonValueIsObject (JsonValue)) {
Status = EFI_LOAD_ERROR;
goto ON_EXIT;
}
OdataId = JsonObjectGetValue (JsonValueGetObject (JsonValue), "@odata.id");
if (!JsonValueIsString (OdataId) || (JsonValueGetAsciiString (OdataId) == NULL)) {
Status = EFI_LOAD_ERROR;
goto ON_EXIT;
}
UnicodeSPrint (
TargetUri,
(sizeof (CHAR16) * REDFISH_URI_LENGTH),
L"%a",
JsonValueGetAsciiString (OdataId)
);
DEBUG ((REDFISH_CREDENTIAL_DEBUG, "%a: account URI: %s\n", __func__, TargetUri));
// Verify bootstrap account User Name and delete the account if User Name matches
if (ProcessRedfishBootstarpAccount (RedfishService, TargetUri)) {
Status = EFI_SUCCESS;
break;
}
}
ON_EXIT:
RedfishHttpFreeResponse (&RedfishResponse);
RedfishHttpFreeRequest (&RedfishRequest);
return Status;
}
/**
Retrieve platform's Redfish authentication information.
This functions returns the Redfish authentication method together with the user Id.
For AuthMethodNone, UserId will point to NULL which means authentication
is not required to access the Redfish service.
Callers are responsible for freeing the returned string storage pointed by UserId.
@param[out] AuthMethod Type of Redfish authentication method.
@param[out] UserId The pointer to store the returned UserId string.
@retval EFI_SUCCESS Get the authentication information successfully.
@retval EFI_INVALID_PARAMETER AuthMethod or UserId or Password is NULL.
@retval EFI_UNSUPPORTED Unsupported authentication method is found.
**/
EFI_STATUS
RedfishGetAuthConfig (
OUT EDKII_REDFISH_AUTH_METHOD *AuthMethod,
OUT CHAR8 **UserId
)
{
EFI_STATUS Status;
CHAR8 *Password;
Password = NULL;
if ((AuthMethod == NULL) || (UserId == NULL)) {
return EFI_INVALID_PARAMETER;
}
if (mCredentialPrivate == NULL) {
DEBUG ((DEBUG_ERROR, "%a: failed with error - %r\n", __func__, EFI_NOT_STARTED));
return EFI_NOT_STARTED;
}
Status = mCredentialPrivate->RedfishCredentialProtocol.GetAuthInfo (
&mCredentialPrivate->RedfishCredentialProtocol,
AuthMethod,
UserId,
&Password
);
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_ERROR, "%a: failed to retrieve Redfish credential - %r\n", __func__, Status));
return Status;
}
if (Password != NULL) {
ZeroMem (Password, AsciiStrSize (Password));
FreePool (Password);
}
return Status;
}
/**
This function clears Redfish service internal list.
@retval EFI_SUCCESS Redfish service is deleted from list successfully.
@retval Others Fail to remove the entry
**/
EFI_STATUS
ClearRedfishServiceList (
)
{
REDFISH_SERVICE_LIST *Instance;
REDFISH_SERVICE_LIST *NextInstance;
if (mCredentialPrivate == NULL) {
DEBUG ((DEBUG_ERROR, "%a: failed with error - %r\n", __func__, EFI_NOT_STARTED));
return EFI_NOT_STARTED;
}
if (!IsListEmpty (&mCredentialPrivate->RedfishServiceList)) {
//
// Free memory of REDFISH_SERVICE_LIST instance.
//
Instance = (REDFISH_SERVICE_LIST *)GetFirstNode (&mCredentialPrivate->RedfishServiceList);
do {
NextInstance = NULL;
if (!IsNodeAtEnd (&mCredentialPrivate->RedfishServiceList, &Instance->NextInstance)) {
NextInstance = (REDFISH_SERVICE_LIST *)GetNextNode (
&mCredentialPrivate->RedfishServiceList,
&Instance->NextInstance
);
}
RemoveEntryList (&Instance->NextInstance);
FreePool ((VOID *)Instance);
Instance = NextInstance;
} while (Instance != NULL);
}
return EFI_SUCCESS;
}
/**
The function adds a new Redfish service to internal list
@param[in] RedfishService Pointer to REDFISH_SERVICE to be added to the list.
@retval EFI_SUCCESS Redfish service is added to list successfully.
@retval EFI_OUT_OF_RESOURCES Out of resources error.
**/
EFI_STATUS
AddRedfishServiceToList (
IN REDFISH_SERVICE RedfishService
)
{
BOOLEAN ServiceFound;
REDFISH_SERVICE_LIST *RedfishServiceInstance;
RedfishServiceInstance = NULL;
ServiceFound = FALSE;
if (mCredentialPrivate == NULL) {
DEBUG ((DEBUG_ERROR, "%a: failed with error - %r\n", __func__, EFI_NOT_STARTED));
return EFI_NOT_STARTED;
}
if (!IsListEmpty (&mCredentialPrivate->RedfishServiceList)) {
RedfishServiceInstance = (REDFISH_SERVICE_LIST *)GetFirstNode (&mCredentialPrivate->RedfishServiceList);
do {
if (RedfishServiceInstance->RedfishService == RedfishService) {
ServiceFound = TRUE;
break;
}
if (IsNodeAtEnd (&mCredentialPrivate->RedfishServiceList, &RedfishServiceInstance->NextInstance)) {
break;
}
RedfishServiceInstance = (REDFISH_SERVICE_LIST *)GetNextNode (
&mCredentialPrivate->RedfishServiceList,
&RedfishServiceInstance->NextInstance
);
} while (TRUE);
}
if (!ServiceFound) {
RedfishServiceInstance = (REDFISH_SERVICE_LIST *)AllocateZeroPool (sizeof (REDFISH_SERVICE_LIST));
if (RedfishServiceInstance == NULL) {
return EFI_OUT_OF_RESOURCES;
}
RedfishServiceInstance->RedfishService = RedfishService;
InsertTailList (&mCredentialPrivate->RedfishServiceList, &RedfishServiceInstance->NextInstance);
}
return EFI_SUCCESS;
}
/**
This function deletes Redfish service from internal list.
@param[in] RedfishService Pointer to REDFISH_SERVICE to be delete from the list.
@retval EFI_SUCCESS Redfish service is deleted from list successfully.
@retval Others Fail to remove the entry
**/
EFI_STATUS
DeleteRedfishServiceFromList (
IN REDFISH_SERVICE RedfishService
)
{
REDFISH_SERVICE_LIST *RedfishServiceInstance;
if (mCredentialPrivate == NULL) {
DEBUG ((DEBUG_ERROR, "%a: failed with error - %r\n", __func__, EFI_NOT_STARTED));
return EFI_NOT_STARTED;
}
if (!IsListEmpty (&mCredentialPrivate->RedfishServiceList)) {
RedfishServiceInstance = (REDFISH_SERVICE_LIST *)GetFirstNode (&mCredentialPrivate->RedfishServiceList);
do {
if (RedfishServiceInstance->RedfishService == RedfishService) {
RemoveEntryList (&RedfishServiceInstance->NextInstance);
FreePool (RedfishServiceInstance);
return EFI_SUCCESS;
}
if (IsNodeAtEnd (&mCredentialPrivate->RedfishServiceList, &RedfishServiceInstance->NextInstance)) {
break;
}
RedfishServiceInstance = (REDFISH_SERVICE_LIST *)GetNextNode (&mCredentialPrivate->RedfishServiceList, &RedfishServiceInstance->NextInstance);
} while (TRUE);
}
return EFI_NOT_FOUND;
}
/**
Register Redfish service instance so protocol knows that some module uses bootstrap account.
@param[in] This Pointer to EDKII_REDFISH_CREDENTIAL_PROTOCOL instance.
@param[in] RedfishService Redfish service instance to register.
@retval EFI_SUCCESS This Redfish service instance has been registered successfully.
@retval Others Fail to register Redfish Service
**/
EFI_STATUS
EFIAPI
RedfishCredential2RegisterService (
IN EDKII_REDFISH_CREDENTIAL2_PROTOCOL *This,
IN REDFISH_SERVICE RedfishService
)
{
EFI_STATUS Status;
Status = EFI_SUCCESS;
if (mCredentialPrivate == NULL) {
DEBUG ((DEBUG_ERROR, "%a: failed with error - %r\n", __func__, EFI_NOT_STARTED));
return EFI_NOT_STARTED;
}
// Check if AuthMethod has been initialized yet
if (mCredentialPrivate->AuthMethod == AuthMethodMax) {
Status = RedfishGetAuthConfig (
&mCredentialPrivate->AuthMethod,
&mCredentialPrivate->AccountName
);
}
// Bootstrap account should be deleted only if Basic Authentication is used.
if (!EFI_ERROR (Status) && (mCredentialPrivate->AuthMethod == AuthMethodHttpBasic)) {
Status = AddRedfishServiceToList (RedfishService);
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_ERROR, "%a: Failed to register Redfish service - %r\n", __func__, Status));
}
}
return Status;
}
/**
Unregister Redfish service instance and delete the bootstrap account
when all registered services unregistered.
@param[in] This Pointer to EDKII_REDFISH_CREDENTIAL_PROTOCOL instance.
@param[in] RedfishService Redfish service instance to unregister.
@retval EFI_SUCCESS This Redfish service instance has been unregistered successfully.
@retval Others Fail to unregister Redfish Service
**/
EFI_STATUS
EFIAPI
RedfishCredential2UnregisterService (
IN EDKII_REDFISH_CREDENTIAL2_PROTOCOL *This,
IN REDFISH_SERVICE RedfishService
)
{
EFI_STATUS Status;
// Bootstrap account should be deleted only if Basic Authentication is used.
if (mCredentialPrivate->AuthMethod != AuthMethodHttpBasic) {
return EFI_SUCCESS;
}
// Delete Redfish Service from the registered list
Status = DeleteRedfishServiceFromList (RedfishService);
// Check if registered list is empty
if (IsListEmpty (&mCredentialPrivate->RedfishServiceList)) {
// Iterate through all accounts in the account collection and delete the bootstrap account
Status = IterateThroughBootstrapAccounts (RedfishService);
if (!EFI_ERROR (Status)) {
if (mCredentialPrivate->AccountName != NULL) {
ZeroMem (mCredentialPrivate->AccountName, AsciiStrSize (mCredentialPrivate->AccountName));
FreePool (mCredentialPrivate->AccountName);
mCredentialPrivate->AccountName = NULL;
}
mCredentialPrivate->AuthMethod = AuthMethodMax;
Status = mCredentialPrivate->RedfishCredentialProtocol.StopService (
&mCredentialPrivate->RedfishCredentialProtocol,
ServiceStopTypeNone
);
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_ERROR, "%a: Failed to stop service - %r\n", __func__, Status));
}
}
}
return Status;
}
/**
Main entry for this driver.
@param ImageHandle Image handle this driver.
@param SystemTable Pointer to SystemTable.
@retval EFI_SUCCESS This function always complete successfully.
**/
EFI_STATUS
EFIAPI
RedfishCredentialDxeDriverEntryPoint (
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
)
{
EFI_STATUS Status;
mCredentialPrivate = (REDFISH_CREDENTIAL_PRIVATE *)AllocateZeroPool (sizeof (REDFISH_CREDENTIAL_PRIVATE));
if (mCredentialPrivate == NULL) {
return EFI_OUT_OF_RESOURCES;
}
mCredentialPrivate->AuthMethod = AuthMethodMax;
InitializeListHead (&mCredentialPrivate->RedfishServiceList);
mCredentialPrivate->RedfishCredentialProtocol.GetAuthInfo = RedfishCredentialGetAuthInfo;
mCredentialPrivate->RedfishCredentialProtocol.StopService = RedfishCredentialStopService;
mCredentialPrivate->RedfishCredential2Protocol.Revision = REDFISH_CREDENTIAL_PROTOCOL_REVISION;
mCredentialPrivate->RedfishCredential2Protocol.GetAuthInfo = RedfishCredential2GetAuthInfo;
mCredentialPrivate->RedfishCredential2Protocol.StopService = RedfishCredential2StopService;
mCredentialPrivate->RedfishCredential2Protocol.RegisterRedfishService = RedfishCredential2RegisterService;
mCredentialPrivate->RedfishCredential2Protocol.UnregisterRedfishService = RedfishCredential2UnregisterService;
//
// Install the RedfishCredentialProtocol onto Handle.
//
Status = gBS->InstallMultipleProtocolInterfaces (
&mCredentialPrivate->Handle,
&gEdkIIRedfishCredentialProtocolGuid,
&mCredentialPrivate->RedfishCredentialProtocol,
&gEdkIIRedfishCredential2ProtocolGuid,
&mCredentialPrivate->RedfishCredential2Protocol,
NULL
);
if (EFI_ERROR (Status)) {
return Status;
}
//
// After EndOfDxe, if SecureBoot is disabled, Redfish Credential Protocol should return
// error code to caller to avoid the 3rd code to bypass Redfish Credential Protocol and
// retrieve userid/pwd directly. So, here, we create EndOfDxe Event to check SecureBoot
// status.
//
Status = gBS->CreateEventEx (
EVT_NOTIFY_SIGNAL,
TPL_CALLBACK,
RedfishCredentialEndOfDxeEventNotify,
(VOID *)&mCredentialPrivate->RedfishCredentialProtocol,
&gEfiEndOfDxeEventGroupGuid,
&mCredentialPrivate->EndOfDxeEvent
);
if (EFI_ERROR (Status)) {
goto ON_ERROR;
}
//
// After ExitBootServices, Redfish Credential Protocol should stop the service.
// So, here, we create ExitBootService Event to stop service.
//
Status = gBS->CreateEventEx (
EVT_NOTIFY_SIGNAL,
TPL_CALLBACK,
RedfishCredentialExitBootServicesEventNotify,
(VOID *)&mCredentialPrivate->RedfishCredentialProtocol,
&gEfiEventExitBootServicesGuid,
&mCredentialPrivate->ExitBootServiceEvent
);
if (EFI_ERROR (Status)) {
gBS->CloseEvent (mCredentialPrivate->EndOfDxeEvent);
mCredentialPrivate->EndOfDxeEvent = NULL;
goto ON_ERROR;
}
return EFI_SUCCESS;
ON_ERROR:
gBS->UninstallMultipleProtocolInterfaces (
mCredentialPrivate->Handle,
&gEdkIIRedfishCredentialProtocolGuid,
&mCredentialPrivate->RedfishCredentialProtocol,
&gEdkIIRedfishCredential2ProtocolGuid,
&mCredentialPrivate->RedfishCredential2Protocol,
NULL
);
FreePool (mCredentialPrivate);
return Status;
}
/**
Releases all resources allocated by the module.
Uninstall all the protocols installed in the driver entry point.
@retval EFI_SUCCESS The resources are released.
@retval Others Failed to release the resources.
**/
EFI_STATUS
ReleaseCredentialPrivate (
)
{
if (mCredentialPrivate != NULL) {
if (mCredentialPrivate->AccountName != NULL) {
ZeroMem (mCredentialPrivate->AccountName, AsciiStrSize (mCredentialPrivate->AccountName));
FreePool (mCredentialPrivate->AccountName);
mCredentialPrivate->AccountName = NULL;
}
ClearRedfishServiceList (mCredentialPrivate);
}
return EFI_SUCCESS;
}
/**
This is the unload handle for Redfish Credentials module.
Uninstall all the protocols installed in the driver entry point.
Clear all allocated resources.
@param[in] ImageHandle The drivers' driver image.
@retval EFI_SUCCESS The image is unloaded.
@retval Others Failed to unload the image.
**/
EFI_STATUS
EFIAPI
RedfishCredentialDxeDriverUnload (
IN EFI_HANDLE ImageHandle
)
{
if (mCredentialPrivate != NULL) {
gBS->UninstallMultipleProtocolInterfaces (
mCredentialPrivate->Handle,
&gEdkIIRedfishCredentialProtocolGuid,
&mCredentialPrivate->RedfishCredentialProtocol,
&gEdkIIRedfishCredential2ProtocolGuid,
&mCredentialPrivate->RedfishCredential2Protocol,
NULL
);
if (mCredentialPrivate->EndOfDxeEvent != NULL) {
gBS->CloseEvent (mCredentialPrivate->EndOfDxeEvent);
mCredentialPrivate->EndOfDxeEvent = NULL;
}
if (mCredentialPrivate->ExitBootServiceEvent != NULL) {
gBS->CloseEvent (mCredentialPrivate->ExitBootServiceEvent);
mCredentialPrivate->ExitBootServiceEvent = NULL;
}
ReleaseCredentialPrivate ();
FreePool (mCredentialPrivate);
mCredentialPrivate = NULL;
}
return EFI_SUCCESS;
}
|