Unverified Commit 7939fb15 authored by Alexey Tsvetkov's avatar Alexey Tsvetkov Committed by GitHub

Skiko Mac signing fix (#320)

* Refactor maybeSign and remoteSignCodesign

* Remove .maybesigned suffix

* Read signed binary from `signed` directory

* Set up correct working directory
parent b2ef7847
...@@ -802,31 +802,49 @@ fun remoteSignCurl(signHost: String, lib: File, out: File) { ...@@ -802,31 +802,49 @@ fun remoteSignCurl(signHost: String, lib: File, out: File) {
} }
} }
fun remoteSignCodesign(signHost: String, lib: File, out: File) { fun remoteSignCodesign(fileToSign: File) {
val user = skiko.signUser ?: error("signUser is null") val user = skiko.signUser ?: error("signUser is null")
val token = skiko.signToken ?: error("signToken is null") val token = skiko.signToken ?: error("signToken is null")
val cmd = """ val cmd = arrayOf(
SERVICE_ACCOUNT_TOKEN=$token SERVICE_ACCOUNT_NAME=$user \ projectDir.resolve("tools/codesign-client-darwin-x64").absolutePath,
$projectDir/tools/codesign-client-darwin-x64 ${lib.absolutePath} && \ fileToSign.absolutePath
cp ${lib.absolutePath} ${out.absolutePath} )
""" val procBuilder = ProcessBuilder(*cmd).apply {
val proc = ProcessBuilder("bash", "-c", cmd) directory(fileToSign.parentFile)
.redirectOutput(ProcessBuilder.Redirect.PIPE) val env = environment()
.redirectError(ProcessBuilder.Redirect.PIPE) env["SERVICE_ACCOUNT_NAME"] = user
.start() env["SERVICE_ACCOUNT_TOKEN"] = token
redirectOutput(ProcessBuilder.Redirect.INHERIT)
redirectError(ProcessBuilder.Redirect.INHERIT)
}
logger.info("Starting remote code sign")
val proc = procBuilder.start()
proc.waitFor(5, TimeUnit.MINUTES) proc.waitFor(5, TimeUnit.MINUTES)
if (proc.exitValue() != 0) { if (proc.exitValue() != 0) {
val out = proc.inputStream.bufferedReader().readText() throw GradleException("Failed to sign $fileToSign")
val err = proc.errorStream.bufferedReader().readText()
println(out)
println(err)
throw GradleException("Cannot sign $lib: $err")
} else { } else {
val outSize = out.length() val signedDir = fileToSign.parentFile.resolve("signed")
if (outSize < 200 * 1024) { val signedFile = signedDir.resolve(fileToSign.name)
val content = out.readText() check(signedFile.exists()) {
buildString {
appendLine("Signed file does not exist: $signedFile")
appendLine("Other files in $signedDir:")
signedDir.list()?.let { names ->
names.forEach {
appendLine(" * $it")
}
}
}
}
val size = signedFile.length()
if (size < 200 * 1024) {
val content = signedFile.readText()
println(content) println(content)
throw GradleException("Output is too short $outSize: ${content.take(200)}...") throw GradleException("Output is too short $size: ${content.take(200)}...")
} else {
signedFile.copyTo(fileToSign, overwrite = true)
signedFile.delete()
logger.info("Successfully signed $fileToSign")
} }
} }
} }
...@@ -845,7 +863,7 @@ val maybeSign by project.tasks.registering { ...@@ -845,7 +863,7 @@ val maybeSign by project.tasks.registering {
inputs.files(lib) inputs.files(lib)
val outputDir = project.layout.buildDirectory.dir("maybe-signed") val outputDir = project.layout.buildDirectory.dir("maybe-signed")
val output = outputDir.map { it.asFile.resolve(lib.get().name + ".maybesigned") } val output = outputDir.map { it.asFile.resolve(lib.get().name) }
outputs.files(output) outputs.files(output)
doLast { doLast {
...@@ -856,15 +874,15 @@ val maybeSign by project.tasks.registering { ...@@ -856,15 +874,15 @@ val maybeSign by project.tasks.registering {
val libFile = lib.get() val libFile = lib.get()
val outputFile = output.get() val outputFile = output.get()
libFile.copyTo(outputFile, overwrite = true)
if (targetOs == OS.Linux) { if (targetOs == OS.Linux) {
// Linux requires additional sealing to run on wider set of platforms. // Linux requires additional sealing to run on wider set of platforms.
val sealer = "$projectDir/tools/sealer-${hostArch.id}" val sealer = "$projectDir/tools/sealer-${hostArch.id}"
sealBinary(sealer, libFile) sealBinary(sealer, outputFile)
} }
if (skiko.signHost != null) { if (skiko.signHost != null) {
remoteSignCodesign(skiko.signHost!!, libFile, outputFile) remoteSignCodesign(outputFile)
} else {
libFile.copyTo(outputFile, overwrite = true)
} }
} }
} }
...@@ -882,10 +900,6 @@ val skikoJvmRuntimeJar by project.tasks.registering(Jar::class) { ...@@ -882,10 +900,6 @@ val skikoJvmRuntimeJar by project.tasks.registering(Jar::class) {
archiveBaseName.set("skiko-$target") archiveBaseName.set("skiko-$target")
from(skikoJvmJar.map { zipTree(it.archiveFile) }) from(skikoJvmJar.map { zipTree(it.archiveFile) })
from(maybeSign.map { it.outputs.files }) from(maybeSign.map { it.outputs.files })
rename {
// Not just suffix, as could be in middle of SHA256.
it.replace(".maybesigned", "")
}
if (targetOs.isWindows) { if (targetOs.isWindows) {
from(files(skiaJvmBindingsDir.map { it.resolve("${skiaBinSubdir}/icudtl.dat") })) from(files(skiaJvmBindingsDir.map { it.resolve("${skiaBinSubdir}/icudtl.dat") }))
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment