#include <sys/stat.h>
#include <sys/types.h>
+#ifndef LDID_NOSMIME
#include <openssl/err.h>
#include <openssl/pem.h>
#include <openssl/pkcs7.h>
#include <openssl/pkcs12.h>
+#endif
#ifdef __APPLE__
#include <CommonCrypto/CommonDigest.h>
#define LDID_SHA1_Final SHA1_Final
#endif
+#ifndef LDID_NOPLIST
#include <plist/plist.h>
+#endif
#include "ldid.hpp"
#define _assert__(line) \
_assert___(line)
+#ifdef __EXCEPTIONS
#define _assert_(expr, format, ...) \
do if (!(expr)) { \
fprintf(stderr, "%s(%u): _assert(): " format "\n", __FILE__, __LINE__, ## __VA_ARGS__); \
throw __FILE__ "(" _assert__(__LINE__) "): _assert(" #expr ")"; \
} while (false)
+#else
+// XXX: this is not acceptable
+#define _assert_(expr, format, ...) \
+ do if (!(expr)) { \
+ fprintf(stderr, "%s(%u): _assert(): " format "\n", __FILE__, __LINE__, ## __VA_ARGS__); \
+ exit(-1); \
+ } while (false)
+#endif
#define _assert(expr) \
_assert_(expr, "%s", #expr)
return offset;
}
+#ifndef LDID_NOSMIME
class Buffer {
private:
BIO *bio_;
return value_;
}
};
+#endif
class NullBuffer :
public std::streambuf
insert(blobs, CSSLOT_CODEDIRECTORY, CSMAGIC_CODEDIRECTORY, data);
}
+#ifndef LDID_NOSMIME
if (!key.empty()) {
std::stringbuf data;
const std::string &sign(blobs[CSSLOT_CODEDIRECTORY]);
insert(blobs, CSSLOT_SIGNATURESLOT, CSMAGIC_BLOBWRAPPER, data);
}
+#endif
return put(output, CSMAGIC_EMBEDDED_SIGNATURE, blobs);
}));
return total;
}
+#ifndef LDID_NOPLIST
static plist_t plist(const std::string &data) {
plist_t plist(NULL);
if (Starts(data, "bplist00"))
_scope({ free(data); });
return data;
}
+#endif
enum Mode {
NoMode,
}
};
+#ifndef LDID_NOPLIST
std::string Bundle(const std::string &root, Folder &folder, const std::string &key, std::map<std::string, std::vector<char>> &remote, const std::string &entitlements) {
std::string executable;
std::string identifier;
return executable;
}
+#endif
}
int main(int argc, char *argv[]) {
+#ifndef LDID_NOSMIME
OpenSSL_add_all_algorithms();
+#endif
union {
uint16_t word;
_syscall(stat(path.c_str(), &info));
if (S_ISDIR(info.st_mode)) {
+#ifndef LDID_NOPLIST
_assert(!flag_r);
ldid::DiskFolder folder(path);
std::map<std::string, std::vector<char>> hashes;
path += "/" + Bundle("", folder, key, hashes, entitlements);
+#else
+ _assert(false);
+#endif
} else if (flag_S || flag_r) {
Map input(path, O_RDONLY, PROT_READ, MAP_PRIVATE);