|
42 | 42 |
|
43 | 43 | #include <stdexcept>
|
44 | 44 |
|
| 45 | +#include <ctime> |
| 46 | + |
45 | 47 | namespace pipy {
|
46 | 48 | namespace crypto {
|
47 | 49 |
|
@@ -495,6 +497,20 @@ auto Certificate::subject_alt_names() -> pjs::Array* {
|
495 | 497 | return m_subject_alt_names;
|
496 | 498 | }
|
497 | 499 |
|
| 500 | +auto Certificate::not_before() -> double { |
| 501 | + std::tm tm; |
| 502 | + auto t = X509_get0_notBefore(m_x509); |
| 503 | + ASN1_TIME_to_tm(t, &tm); |
| 504 | + return (double)std::mktime(&tm) * 1000; |
| 505 | +} |
| 506 | + |
| 507 | +auto Certificate::not_after() -> double { |
| 508 | + std::tm tm; |
| 509 | + auto t = X509_get0_notAfter(m_x509); |
| 510 | + ASN1_TIME_to_tm(t, &tm); |
| 511 | + return (double)std::mktime(&tm) * 1000; |
| 512 | +} |
| 513 | + |
498 | 514 | auto Certificate::read_pem(const void *data, size_t size) -> X509* {
|
499 | 515 | auto bio = BIO_new_mem_buf(data, size);
|
500 | 516 | auto x509 = PEM_read_bio_X509(bio, nullptr, nullptr, nullptr);
|
@@ -1417,6 +1433,8 @@ template<> void ClassDef<Certificate>::init() {
|
1417 | 1433 | accessor("issuer", [](Object *obj, Value &ret) { ret.set(obj->as<Certificate>()->issuer()); });
|
1418 | 1434 | accessor("subject", [](Object *obj, Value &ret) { ret.set(obj->as<Certificate>()->subject()); });
|
1419 | 1435 | accessor("subjectAltNames", [](Object *obj, Value &ret) { ret.set(obj->as<Certificate>()->subject_alt_names()); });
|
| 1436 | + accessor("notBefore", [](Object *obj, Value &ret) { ret.set(obj->as<Certificate>()->not_before()); }); |
| 1437 | + accessor("notAfter", [](Object *obj, Value &ret) { ret.set(obj->as<Certificate>()->not_after()); }); |
1420 | 1438 | }
|
1421 | 1439 |
|
1422 | 1440 | template<> void ClassDef<Constructor<Certificate>>::init() {
|
|
0 commit comments