MCPcopy Create free account
hub / github.com/CloverHackyColor/CloverBootloader / SetSignedVariable

Function SetSignedVariable

rEFIt_UEFI/entry_scan/securevars.cpp:371–497  ·  view source on GitHub ↗

Write signed variable

Source from the content-addressed store, hash-verified

369
370// Write signed variable
371EFI_STATUS SetSignedVariable(IN CHAR16 *DatabaseName,
372 IN EFI_GUID *DatabaseGuid,
373 IN UINT32 Attributes,
374 IN VOID *Database,
375 IN UINTN DatabaseSize)
376{
377 EFI_STATUS Status;
378 EFI_VARIABLE_AUTHENTICATION_2 *Authentication;
379 UINTN Size, NameLen;
380 UINTN DataSize = 0;
381 EFI_TIME Timestamp;
382 VOID *Data = NULL;
383 BIO *BioData = NULL;
384 PKCS7 *p7;
385 X509 *Certificate = NULL;
386 EVP_PKEY *PrivateKey = NULL;
387 const EVP_MD *md;
388 // Check parameters
389 if ((DatabaseName == NULL) || (DatabaseGuid == NULL)) {
390 return EFI_INVALID_PARAMETER;
391 }
392 DBG("Setting secure variable: %s %ls 0x%hhX (0x%hhX)\n", strguid(DatabaseGuid), DatabaseName, Database, DatabaseSize);
393 NameLen = StrLen(DatabaseName);
394 if (NameLen == 0) {
395 return EFI_INVALID_PARAMETER;
396 }
397 // Get the current time
398 DBG("Getting timestamp ...\n");
399 Status = GetUTCTime(&Timestamp);
400 if (EFI_ERROR(Status)) {
401 return Status;
402 }
403 DBG("Timestamp: %t\n", Timestamp);
404 // In user mode we need to sign the database with exchange key
405 if (!gSettings.SecureBootSetupMode) {
406 // Initialize the cyphers and digests
407 ERR_load_crypto_strings();
408 OpenSSL_add_all_digests();
409 OpenSSL_add_all_ciphers();
410 // Create signing certificate
411 BioData = BIO_new_mem_buf((void *)gSecureBootExchangeKey, sizeof(gSecureBootExchangeKey));
412 if (BioData == NULL) {
413 return EFI_OUT_OF_RESOURCES;
414 }
415 Certificate = PEM_read_bio_X509(BioData, NULL, NULL, NULL);
416 BIO_free(BioData);
417 if (Certificate == NULL) {
418 return EFI_OUT_OF_RESOURCES;
419 }
420 // Create signing private key
421 BioData = BIO_new_mem_buf((void *)gSecureBootExchangePrivateKey, sizeof(gSecureBootExchangePrivateKey));
422 if (BioData == NULL) {
423 return EFI_OUT_OF_RESOURCES;
424 }
425 PrivateKey = PEM_read_bio_PrivateKey(BioData, NULL, NULL, NULL);
426 BIO_free(BioData);
427 if (PrivateKey == NULL) {
428 X509_free(Certificate);

Callers 1

SetSignatureDatabaseFunction · 0.85

Calls 15

strguidFunction · 0.85
ERR_load_crypto_stringsFunction · 0.85
OpenSSL_add_all_digestsFunction · 0.85
OpenSSL_add_all_ciphersFunction · 0.85
BIO_new_mem_bufFunction · 0.85
BIO_freeFunction · 0.85
PEM_read_bio_PrivateKeyFunction · 0.85
BIO_newFunction · 0.85
BIO_s_memFunction · 0.85
BIO_writeFunction · 0.85
EVP_get_digestbynameFunction · 0.85
PKCS7_set_typeFunction · 0.85

Tested by

no test coverage detected