Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion ldid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
#include <openssl/pem.h>
#include <openssl/pkcs7.h>
#include <openssl/pkcs12.h>
#include <openssl/ui.h>
#endif

#ifdef __APPLE__
Expand Down Expand Up @@ -141,6 +142,10 @@
#define _packed \
__attribute__((packed))

#ifndef LDID_NOSMIME
std::string password;
#endif

template <typename Type_>
struct Iterator_ {
typedef typename Type_::const_iterator Result;
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -3097,6 +3108,7 @@ static void usage(const char *argv0) {
fprintf(stderr, "\n");
fprintf(stderr, "Other Options\n");
fprintf(stderr, " -Kkey.p12 Sign using private key in key.p12\n");
fprintf(stderr, " -Upassword Use password to unlock key.p12\n");
fprintf(stderr, " -M Merge entitlements with any existing\n");
fprintf(stderr, " -h Print CDHash of file\n");
}
Expand Down Expand Up @@ -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);
Expand Down