From 517bae5ce953cbade73a64cb7a6d91c9af800e7e Mon Sep 17 00:00:00 2001 From: sunchipnacho <22717474+sunflsks@users.noreply.github.com> Date: Fri, 8 Oct 2021 11:59:49 -0500 Subject: [PATCH] p12 password support --- ldid.cpp | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/ldid.cpp b/ldid.cpp index b017ebe..3d01ff4 100644 --- a/ldid.cpp +++ b/ldid.cpp @@ -47,6 +47,7 @@ #include #include #include +#include #endif #ifdef __APPLE__ @@ -141,6 +142,10 @@ #define _packed \ __attribute__((packed)) +#ifndef LDID_NOSMIME +std::string password; +#endif + template struct Iterator_ { typedef typename Type_::const_iterator Result; @@ -1784,8 +1789,14 @@ class Stuff { ca_(NULL) { _assert(value_ != NULL); - _assert(PKCS12_parse(value_, "", &key_, &cert_, &ca_) != 0); + if (!PKCS12_verify_mac(value_, "", 0) && password.empty()) { + char passbuf[2048]; + UI_UTIL_read_pw_string(passbuf, 2048, "Enter password: ", 0); + password = passbuf; + } + + _assert(PKCS12_parse(value_, password.c_str(), &key_, &cert_, &ca_) != 0); _assert(key_ != NULL); _assert(cert_ != NULL); @@ -3286,6 +3298,10 @@ int main(int argc, char *argv[]) { flag_M = true; break; + case 'U': + password = argv[argi] + 2; + break; + case 'K': if (argv[argi][2] != '\0') key.open(argv[argi] + 2, O_RDONLY, PROT_READ, MAP_PRIVATE); -- 2.33.0