Implement lime setup hl in a hopefully better way.

This commit is contained in:
Apprentice-Alchemist
2022-03-12 21:37:23 +01:00
parent 18f680e247
commit cb3b0240de
5 changed files with 126 additions and 66 deletions

View File

@@ -1185,47 +1185,55 @@ class PlatformSetup
public static function setupHL():Void
{
getDefineValue("HL_PATH", "Path to a custom version of Hashlink. Leave empty to use lime's default version.");
if (System.hostPlatform == MAC)
{
Log.println("To use the hashlink debugger on macOS, the hl executable needs to be signed.");
var answer = CLIHelper.ask("Would you like to do this now? (Requires sudo.)");
if (answer == YES || answer == ALWAYS)
if (ConfigHelper.getConfigValue("HL_PATH") != null)
{
final openSSLConf = System.getTemporaryFile("cnf");
final key = System.getTemporaryFile("pem");
final cert = System.getTemporaryFile("cer");
final limePath = Haxelib.getPath(new Haxelib("lime"));
final hlPath = limePath + "/templates/bin/hl/mac/hl";
final entitlementsPath = sys.FileSystem.exists(limePath + "/project") ? (limePath +
"/project/lib/hashlink/other/osx/entitlements.xml") : (limePath
+ "/templates/bin/hl/entitlements.xml");
System.runCommand("", "sudo", ["security", "delete-identity", "-c", "hl-cert"], true, false, true);
sys.io.File.saveContent(openSSLConf, [
"[req]",
"distinguished_name=codesign_dn",
"[codesign_dn]",
"commonName=hl-cert",
"[v3_req]",
"keyUsage=critical,digitalSignature",
"extendedKeyUsage=critical,codeSigning",
].join("\n"));
System.runCommand("", "openssl", [
"req", "-x509", "-newkey", "rsa:4096", "-keyout", key, "-nodes", "-days", "365", "-subj", "/CN=hl-cert", "-outform", "der", "-out", cert,
"-extensions", "v3_req", "-config", openSSLConf
], true, false, true);
System.runCommand("", "sudo", [
"security",
"add-trusted-cert",
"-d",
"-k /Library/Keychains/System.keychain",
cert
], true, false, true);
System.runCommand("", "sudo", ["security", "import", key, "-k", "/Library/Keychains/System.keychain", "-A"], true, false, true);
System.runCommand("", "codesign", ["--entitlements", entitlementsPath, "-fs", "hl-cert", hlPath], true, false, true);
for (f in [key, cert, openSSLConf])
sys.FileSystem.deleteFile(f);
Log.println("\nIf you update lime, yo will have to run this again to sign the new hl executable");
Log.println("When building HL from source, make sure to have run `make codesign_osx` before installing.");
}
else
{
var answer = CLIHelper.ask("Would you like to do this now? (Requires sudo.)");
if (answer == YES || answer == ALWAYS)
{
final openSSLConf = System.getTemporaryFile("cnf");
final key = System.getTemporaryFile("pem");
final cert = System.getTemporaryFile("cer");
final limePath = Haxelib.getPath(new Haxelib("lime"));
final hlPath = limePath + "/templates/bin/hl/mac/hl";
final entitlementsPath = sys.FileSystem.exists(limePath + "/project") ? (limePath +
"/project/lib/hashlink/other/osx/entitlements.xml") : (limePath
+ "/templates/bin/hl/entitlements.xml");
System.runCommand("", "sudo", ["security", "delete-identity", "-c", "hl-cert"], true, false, true);
sys.io.File.saveContent(openSSLConf, [
"[req]",
"distinguished_name=codesign_dn",
"[codesign_dn]",
"commonName=hl-cert",
"[v3_req]",
"keyUsage=critical,digitalSignature",
"extendedKeyUsage=critical,codeSigning",
].join("\n"));
System.runCommand("", "openssl", [
"req", "-x509", "-newkey", "rsa:4096", "-keyout", key, "-nodes", "-days", "365", "-subj", "/CN=hl-cert", "-outform", "der", "-out",
cert, "-extensions", "v3_req", "-config", openSSLConf
], true, false, true);
System.runCommand("", "sudo", [
"security",
"add-trusted-cert",
"-d",
"-k /Library/Keychains/System.keychain",
cert
], true, false, true);
System.runCommand("", "sudo", ["security", "import", key, "-k", "/Library/Keychains/System.keychain", "-A"], true, false, true);
System.runCommand("", "codesign", ["--entitlements", entitlementsPath, "-fs", "hl-cert", hlPath], true, false, true);
for (f in [key, cert, openSSLConf])
sys.FileSystem.deleteFile(f);
Log.println("\nIf you update lime, yo will have to run this again to sign the new hl executable");
}
}
}
}