forked from ibm-openbmc/phosphor-certificate-manager
-
Notifications
You must be signed in to change notification settings - Fork 0
/
certificate.cpp
713 lines (632 loc) · 22.1 KB
/
certificate.cpp
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
#include "config.h"
#include "certificate.hpp"
#include "certs_manager.hpp"
#include "x509_utils.hpp"
#include <openssl/asn1.h>
#include <openssl/bio.h>
#include <openssl/buffer.h>
#include <openssl/err.h>
#include <openssl/evp.h>
#include <openssl/obj_mac.h>
#include <openssl/objects.h>
#include <openssl/opensslv.h>
#include <openssl/pem.h>
#include <openssl/x509v3.h>
#include <phosphor-logging/elog-errors.hpp>
#include <phosphor-logging/elog.hpp>
#include <phosphor-logging/lg2.hpp>
#include <watch.hpp>
#include <xyz/openbmc_project/Certs/error.hpp>
#include <xyz/openbmc_project/Common/error.hpp>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <exception>
#include <filesystem>
#include <fstream>
#include <map>
#include <utility>
#include <vector>
namespace phosphor::certs
{
namespace
{
namespace fs = std::filesystem;
using ::phosphor::logging::elog;
using InvalidCertificateError =
::sdbusplus::xyz::openbmc_project::Certs::Error::InvalidCertificate;
using ::phosphor::logging::xyz::openbmc_project::Certs::InvalidCertificate;
using ::sdbusplus::xyz::openbmc_project::Common::Error::InternalFailure;
// RAII support for openSSL functions.
using BIOMemPtr = std::unique_ptr<BIO, decltype(&::BIO_free)>;
using X509StorePtr = std::unique_ptr<X509_STORE, decltype(&::X509_STORE_free)>;
using ASN1TimePtr = std::unique_ptr<ASN1_TIME, decltype(&ASN1_STRING_free)>;
using EVPPkeyPtr = std::unique_ptr<EVP_PKEY, decltype(&::EVP_PKEY_free)>;
using BufMemPtr = std::unique_ptr<BUF_MEM, decltype(&::BUF_MEM_free)>;
// Refer to schema 2018.3
// http://redfish.dmtf.org/schemas/v1/Certificate.json#/definitions/KeyUsage for
// supported KeyUsage types in redfish
// Refer to
// https://github.com/openssl/openssl/blob/master/include/openssl/x509v3.h for
// key usage bit fields
std::map<uint8_t, std::string> keyUsageToRfStr = {
{KU_DIGITAL_SIGNATURE, "DigitalSignature"},
{KU_NON_REPUDIATION, "NonRepudiation"},
{KU_KEY_ENCIPHERMENT, "KeyEncipherment"},
{KU_DATA_ENCIPHERMENT, "DataEncipherment"},
{KU_KEY_AGREEMENT, "KeyAgreement"},
{KU_KEY_CERT_SIGN, "KeyCertSign"},
{KU_CRL_SIGN, "CRLSigning"},
{KU_ENCIPHER_ONLY, "EncipherOnly"},
{KU_DECIPHER_ONLY, "DecipherOnly"}};
// Refer to schema 2018.3
// http://redfish.dmtf.org/schemas/v1/Certificate.json#/definitions/KeyUsage for
// supported Extended KeyUsage types in redfish
std::map<uint8_t, std::string> extendedKeyUsageToRfStr = {
{NID_server_auth, "ServerAuthentication"},
{NID_client_auth, "ClientAuthentication"},
{NID_email_protect, "EmailProtection"},
{NID_OCSP_sign, "OCSPSigning"},
{NID_ad_timeStamping, "Timestamping"},
{NID_code_sign, "CodeSigning"}};
/**
* @brief Dumps the PEM encoded certificate to installFilePath
*
* @param[in] pem - PEM encoded X509 certificate buffer.
* @param[in] certFilePath - Path to the destination file.
*
* @return void
*/
void dumpCertificate(const std::string& pem, const std::string& certFilePath)
{
std::ofstream outputCertFileStream;
outputCertFileStream.exceptions(
std::ofstream::failbit | std::ofstream::badbit | std::ofstream::eofbit);
try
{
outputCertFileStream.open(certFilePath, std::ios::out);
outputCertFileStream << pem << "\n" << std::flush;
outputCertFileStream.close();
}
catch (const std::exception& e)
{
lg2::error(
"Failed to dump certificate, ERR:{ERR}, SRC_PEM:{SRC_PEM}, DST:{DST}",
"ERR", e, "SRC_PEM", pem, "DST", certFilePath);
elog<InternalFailure>();
}
}
} // namespace
void Certificate::copyCertificate(const std::string& certSrcFilePath,
const std::string& certFilePath)
{
// Copy the certificate to the installation path
// During bootup will be parsing existing file so no need to
// copy it.
if (certSrcFilePath != certFilePath)
{
std::ifstream inputCertFileStream;
std::ofstream outputCertFileStream;
inputCertFileStream.exceptions(std::ifstream::failbit |
std::ifstream::badbit |
std::ifstream::eofbit);
outputCertFileStream.exceptions(std::ofstream::failbit |
std::ofstream::badbit |
std::ofstream::eofbit);
try
{
inputCertFileStream.open(certSrcFilePath);
outputCertFileStream.open(certFilePath, std::ios::out);
outputCertFileStream << inputCertFileStream.rdbuf() << std::flush;
inputCertFileStream.close();
outputCertFileStream.close();
}
catch (const std::exception& e)
{
lg2::error(
"Failed to copy certificate, ERR:{ERR}, SRC:{SRC}, DST:{DST}",
"ERR", e, "SRC", certSrcFilePath, "DST", certFilePath);
elog<InternalFailure>();
}
}
}
std::string
Certificate::generateUniqueFilePath(const std::string& directoryPath)
{
char* filePath = tempnam(directoryPath.c_str(), nullptr);
if (filePath == nullptr)
{
lg2::error(
"Error occurred while creating random certificate file path, DIR:{DIR}",
"DIR", directoryPath);
elog<InternalFailure>();
}
std::string filePathStr(filePath);
free(filePath);
return filePathStr;
}
std::string Certificate::generateAuthCertFileX509Path(
const std::string& certSrcFilePath, const std::string& certDstDirPath)
{
const internal::X509Ptr cert = loadCert(certSrcFilePath);
unsigned long hash = X509_subject_name_hash(cert.get());
static constexpr auto certHashLength = 9;
char hashBuf[certHashLength];
snprintf(hashBuf, certHashLength, "%08lx", hash);
const std::string certHash(hashBuf);
for (size_t i = 0; i < maxNumAuthorityCertificates; ++i)
{
const std::string certDstFileX509Path =
certDstDirPath + "/" + certHash + "." + std::to_string(i);
if (!fs::exists(certDstFileX509Path))
{
return certDstFileX509Path;
}
}
lg2::error("Authority certificate x509 file path already used, DIR:{DIR}",
"DIR", certDstDirPath);
elog<InternalFailure>();
}
std::string
Certificate::generateAuthCertFilePath(const std::string& certSrcFilePath)
{
// If there is a certificate file path (which means certificate replacement
// is doing) use it (do not create new one)
if (!certFilePath.empty())
{
return certFilePath;
}
// If source certificate file is located in the certificates directory use
// it (do not create new one)
else if (fs::path(certSrcFilePath).parent_path().string() ==
certInstallPath)
{
return certSrcFilePath;
}
// Otherwise generate new file name/path
else
{
return generateUniqueFilePath(certInstallPath);
}
}
std::string
Certificate::generateCertFilePath(const std::string& certSrcFilePath)
{
if (certType == CertificateType::authority)
{
return generateAuthCertFilePath(certSrcFilePath);
}
else
{
return certInstallPath;
}
}
Certificate::Certificate(sdbusplus::bus_t& bus, const std::string& objPath,
CertificateType type, const std::string& installPath,
const std::string& uploadPath, Watch* watch,
Manager& parent, bool restore) :
internal::CertificateInterface(
bus, objPath.c_str(),
internal::CertificateInterface::action::defer_emit),
objectPath(objPath), certType(type), certInstallPath(installPath),
certWatch(watch), manager(parent)
{
auto installHelper = [this](const auto& filePath) {
if (!compareKeys(filePath))
{
elog<InvalidCertificateError>(InvalidCertificate::REASON(
"Private key does not match the Certificate"));
};
};
typeFuncMap[CertificateType::server] = installHelper;
typeFuncMap[CertificateType::client] = installHelper;
typeFuncMap[CertificateType::authority] = [](const std::string&) {};
auto appendPrivateKey = [this](const std::string& filePath) {
checkAndAppendPrivateKey(filePath);
};
appendKeyMap[CertificateType::server] = appendPrivateKey;
appendKeyMap[CertificateType::client] = appendPrivateKey;
appendKeyMap[CertificateType::authority] = [](const std::string&) {};
// Generate certificate file path
certFilePath = generateCertFilePath(uploadPath);
// install the certificate
install(uploadPath, restore);
this->emit_object_added();
}
Certificate::Certificate(sdbusplus::bus_t& bus, const std::string& objPath,
const CertificateType& type,
const std::string& installPath, X509_STORE& x509Store,
const std::string& pem, Watch* watchPtr,
Manager& parent, bool restore) :
internal::CertificateInterface(
bus, objPath.c_str(),
internal::CertificateInterface::action::defer_emit),
objectPath(objPath), certType(type), certInstallPath(installPath),
certWatch(watchPtr), manager(parent)
{
// Generate certificate file path
certFilePath = generateUniqueFilePath(installPath);
// install the certificate
install(x509Store, pem, restore);
this->emit_object_added();
}
Certificate::~Certificate()
{
if (!fs::remove(certFilePath))
{
lg2::info("Certificate file not found! PATH:{PATH}", "PATH",
certFilePath);
}
}
void Certificate::replace(const std::string filePath)
{
manager.replaceCertificate(this, filePath);
}
void Certificate::install(const std::string& certSrcFilePath, bool restore)
{
if (restore)
{
lg2::debug("Certificate install, FILEPATH:{FILEPATH}", "FILEPATH",
certSrcFilePath);
}
else
{
lg2::info("Certificate install, FILEPATH:{FILEPATH}", "FILEPATH",
certSrcFilePath);
}
// stop watch for user initiated certificate install
if (certWatch != nullptr)
{
certWatch->stopWatch();
}
// Verify the certificate file
fs::path file(certSrcFilePath);
if (!fs::exists(file))
{
lg2::error("File is Missing, FILE:{FILE}", "FILE", certSrcFilePath);
elog<InternalFailure>();
}
try
{
if (fs::file_size(certSrcFilePath) == 0)
{
// file is empty
lg2::error("File is empty, FILE:{FILE}", "FILE", certSrcFilePath);
elog<InvalidCertificateError>(
InvalidCertificate::REASON("File is empty"));
}
}
catch (const fs::filesystem_error& e)
{
// Log Error message
lg2::error("File is empty, FILE:{FILE}, ERR:{ERR}", "FILE",
certSrcFilePath, "ERR", e);
elog<InternalFailure>();
}
X509StorePtr x509Store = getX509Store(certSrcFilePath);
// Load Certificate file into the X509 structure.
internal::X509Ptr cert = loadCert(certSrcFilePath);
// Perform validation
validateCertificateAgainstStore(*x509Store, *cert);
validateCertificateStartDate(*cert);
validateCertificateInSSLContext(*cert);
// Invoke type specific append private key function.
if (auto it = appendKeyMap.find(certType); it == appendKeyMap.end())
{
lg2::error("Unsupported Type, TYPE:{TYPE}", "TYPE",
certificateTypeToString(certType));
elog<InternalFailure>();
}
else
{
it->second(certSrcFilePath);
}
// Invoke type specific compare keys function.
if (auto it = typeFuncMap.find(certType); it == typeFuncMap.end())
{
lg2::error("Unsupported Type, TYPE:{TYPE}", "TYPE",
certificateTypeToString(certType));
elog<InternalFailure>();
}
else
{
it->second(certSrcFilePath);
}
copyCertificate(certSrcFilePath, certFilePath);
storageUpdate();
// Keep certificate ID
certId = generateCertId(*cert);
// Parse the certificate file and populate properties
populateProperties(*cert);
// restart watch
if (certWatch != nullptr)
{
certWatch->startWatch();
}
}
void Certificate::install(X509_STORE& x509Store, const std::string& pem,
bool restore)
{
if (restore)
{
lg2::debug("Certificate install, PEM_STR:{PEM_STR}", "PEM_STR", pem);
}
else
{
lg2::info("Certificate install, PEM_STR:{PEM_STR} ", "PEM_STR", pem);
}
if (certType != CertificateType::authority)
{
lg2::error("Bulk install error: Unsupported Type; only authority "
"supports bulk install, TYPE:{TYPE}",
"TYPE", certificateTypeToString(certType));
elog<InternalFailure>();
}
// stop watch for user initiated certificate install
if (certWatch)
{
certWatch->stopWatch();
}
// Load Certificate file into the X509 structure.
internal::X509Ptr cert = parseCert(pem);
// Perform validation; no type specific compare keys function
validateCertificateAgainstStore(x509Store, *cert);
validateCertificateStartDate(*cert);
validateCertificateInSSLContext(*cert);
// Copy the PEM to the installation path
dumpCertificate(pem, certFilePath);
storageUpdate();
// Keep certificate ID
certId = generateCertId(*cert);
// Parse the certificate file and populate properties
populateProperties(*cert);
// restart watch
if (certWatch)
{
certWatch->startWatch();
}
}
void Certificate::populateProperties()
{
internal::X509Ptr cert = loadCert(certInstallPath);
populateProperties(*cert);
}
std::string Certificate::getCertId() const
{
return certId;
}
bool Certificate::isSame(const std::string& certPath)
{
internal::X509Ptr cert = loadCert(certPath);
return getCertId() == generateCertId(*cert);
}
void Certificate::storageUpdate()
{
if (certType == CertificateType::authority)
{
// Create symbolic link in the certificate directory
std::string certFileX509Path;
try
{
if (!certFilePath.empty() &&
fs::is_regular_file(fs::path(certFilePath)))
{
certFileX509Path =
generateAuthCertFileX509Path(certFilePath, certInstallPath);
fs::create_symlink(fs::path(certFilePath),
fs::path(certFileX509Path));
}
}
catch (const std::exception& e)
{
lg2::error("Failed to create symlink for certificate, ERR:{ERR},"
"FILE:{FILE}, SYMLINK:{SYMLINK}",
"ERR", e, "FILE", certFilePath, "SYMLINK",
certFileX509Path);
elog<InternalFailure>();
}
}
}
void Certificate::populateProperties(X509& cert)
{
// Update properties if no error thrown
BIOMemPtr certBio(BIO_new(BIO_s_mem()), BIO_free);
PEM_write_bio_X509(certBio.get(), &cert);
BufMemPtr certBuf(BUF_MEM_new(), BUF_MEM_free);
BUF_MEM* buf = certBuf.get();
BIO_get_mem_ptr(certBio.get(), &buf);
std::string certStr(buf->data, buf->length);
certificateString(certStr);
static const int maxKeySize = 4096;
char subBuffer[maxKeySize] = {0};
BIOMemPtr subBio(BIO_new(BIO_s_mem()), BIO_free);
// This pointer cannot be freed independantly.
X509_NAME* sub = X509_get_subject_name(&cert);
X509_NAME_print_ex(subBio.get(), sub, 0, XN_FLAG_SEP_COMMA_PLUS);
BIO_read(subBio.get(), subBuffer, maxKeySize);
subject(subBuffer);
char issuerBuffer[maxKeySize] = {0};
BIOMemPtr issuerBio(BIO_new(BIO_s_mem()), BIO_free);
// This pointer cannot be freed independantly.
X509_NAME* issuerName = X509_get_issuer_name(&cert);
X509_NAME_print_ex(issuerBio.get(), issuerName, 0, XN_FLAG_SEP_COMMA_PLUS);
BIO_read(issuerBio.get(), issuerBuffer, maxKeySize);
issuer(issuerBuffer);
std::vector<std::string> keyUsageList;
ASN1_BIT_STRING* usage;
// Go through each usage in the bit string and convert to
// corresponding string value
if ((usage = static_cast<ASN1_BIT_STRING*>(
X509_get_ext_d2i(&cert, NID_key_usage, nullptr, nullptr))))
{
for (auto i = 0; i < usage->length; ++i)
{
for (auto& x : keyUsageToRfStr)
{
if (x.first & usage->data[i])
{
keyUsageList.push_back(x.second);
break;
}
}
}
}
EXTENDED_KEY_USAGE* extUsage;
if ((extUsage = static_cast<EXTENDED_KEY_USAGE*>(
X509_get_ext_d2i(&cert, NID_ext_key_usage, nullptr, nullptr))))
{
for (int i = 0; i < sk_ASN1_OBJECT_num(extUsage); i++)
{
keyUsageList.push_back(extendedKeyUsageToRfStr[OBJ_obj2nid(
sk_ASN1_OBJECT_value(extUsage, i))]);
}
}
keyUsage(keyUsageList);
int days = 0;
int secs = 0;
ASN1TimePtr epoch(ASN1_TIME_new(), ASN1_STRING_free);
// Set time to 00:00am GMT, Jan 1 1970; format: YYYYMMDDHHMMSSZ
ASN1_TIME_set_string(epoch.get(), "19700101000000Z");
static const uint64_t dayToSeconds = 24 * 60 * 60;
ASN1_TIME* notAfter = X509_get_notAfter(&cert);
ASN1_TIME_diff(&days, &secs, epoch.get(), notAfter);
validNotAfter((days * dayToSeconds) + secs);
ASN1_TIME* notBefore = X509_get_notBefore(&cert);
ASN1_TIME_diff(&days, &secs, epoch.get(), notBefore);
validNotBefore((days * dayToSeconds) + secs);
}
void Certificate::checkAndAppendPrivateKey(const std::string& filePath)
{
BIOMemPtr keyBio(BIO_new(BIO_s_file()), ::BIO_free);
if (!keyBio)
{
lg2::error("Error occurred during BIO_s_file call, FILE:{FILE}", "FILE",
filePath);
elog<InternalFailure>();
}
BIO_read_filename(keyBio.get(), filePath.c_str());
EVPPkeyPtr priKey(
PEM_read_bio_PrivateKey(keyBio.get(), nullptr, nullptr, nullptr),
::EVP_PKEY_free);
if (!priKey)
{
lg2::info("Private key not present in file, FILE:{FILE}", "FILE",
filePath);
fs::path privateKeyFile = fs::path(certInstallPath).parent_path();
privateKeyFile = privateKeyFile / defaultPrivateKeyFileName;
if (!fs::exists(privateKeyFile))
{
lg2::error("Private key file is not found, FILE:{FILE}", "FILE",
privateKeyFile);
elog<InternalFailure>();
}
std::ifstream privKeyFileStream;
std::ofstream certFileStream;
privKeyFileStream.exceptions(std::ifstream::failbit |
std::ifstream::badbit |
std::ifstream::eofbit);
certFileStream.exceptions(std::ofstream::failbit |
std::ofstream::badbit |
std::ofstream::eofbit);
try
{
privKeyFileStream.open(privateKeyFile);
certFileStream.open(filePath, std::ios::app);
certFileStream << std::endl; // insert line break
certFileStream << privKeyFileStream.rdbuf() << std::flush;
privKeyFileStream.close();
certFileStream.close();
}
catch (const std::exception& e)
{
lg2::error(
"Failed to append private key, ERR:{ERR}, SRC:{SRC}, DST:{DST}",
"ERR", e, "SRC", privateKeyFile, "DST", filePath);
elog<InternalFailure>();
}
}
}
bool Certificate::compareKeys(const std::string& filePath)
{
lg2::info("Certificate compareKeys, FILEPATH:{FILEPATH}", "FILEPATH",
filePath);
internal::X509Ptr cert(X509_new(), ::X509_free);
if (!cert)
{
lg2::error(
"Error occurred during X509_new call, FILE:{FILE}, ERRCODE:{ERRCODE}",
"FILE", filePath, "ERRCODE", ERR_get_error());
elog<InternalFailure>();
}
BIOMemPtr bioCert(BIO_new_file(filePath.c_str(), "rb"), ::BIO_free);
if (!bioCert)
{
lg2::error("Error occurred during BIO_new_file call, FILE:{FILE}",
"FILE", filePath);
elog<InternalFailure>();
}
X509* x509 = cert.get();
PEM_read_bio_X509(bioCert.get(), &x509, nullptr, nullptr);
EVPPkeyPtr pubKey(X509_get_pubkey(cert.get()), ::EVP_PKEY_free);
if (!pubKey)
{
lg2::error(
"Error occurred during X509_get_pubkey, FILE:{FILE}, ERRCODE:{ERRCODE}",
"FILE", filePath, "ERRCODE", ERR_get_error());
elog<InvalidCertificateError>(
InvalidCertificate::REASON("Failed to get public key info"));
}
BIOMemPtr keyBio(BIO_new(BIO_s_file()), ::BIO_free);
if (!keyBio)
{
lg2::error("Error occurred during BIO_s_file call, FILE:{FILE}", "FILE",
filePath);
elog<InternalFailure>();
}
BIO_read_filename(keyBio.get(), filePath.c_str());
EVPPkeyPtr priKey(
PEM_read_bio_PrivateKey(keyBio.get(), nullptr, nullptr, nullptr),
::EVP_PKEY_free);
if (!priKey)
{
lg2::error(
"Error occurred during PEM_read_bio_PrivateKey, FILE:{FILE}, ERRCODE:{ERRCODE}",
"FILE", filePath, "ERRCODE", ERR_get_error());
elog<InvalidCertificateError>(
InvalidCertificate::REASON("Failed to get private key info"));
}
#if (OPENSSL_VERSION_NUMBER < 0x30000000L)
int32_t rc = EVP_PKEY_cmp(priKey.get(), pubKey.get());
#else
int32_t rc = EVP_PKEY_eq(priKey.get(), pubKey.get());
#endif
if (rc != 1)
{
lg2::error(
"Private key is not matching with Certificate, FILE:{FILE}, ERRCODE:{ERRCODE}",
"FILE", filePath, "ERRCODE", rc);
return false;
}
return true;
}
void Certificate::delete_()
{
manager.deleteCertificate(this);
}
std::string Certificate::getObjectPath()
{
return objectPath;
}
std::string Certificate::getCertFilePath()
{
return certFilePath;
}
void Certificate::setCertFilePath(const std::string& path)
{
certFilePath = path;
}
void Certificate::setCertInstallPath(const std::string& path)
{
certInstallPath = path;
}
} // namespace phosphor::certs