Commit 45a0700f authored by Romain Bioteau's avatar Romain Bioteau

fix(mac) fix mac codesign

parent 277776f4
......@@ -26,6 +26,9 @@ import java.io.File
import java.io.FileInputStream
import java.nio.file.Files
import javax.servlet.http.HttpServletResponse
import java.nio.file.Path
import java.nio.file.Paths
import java.io.FileOutputStream
@RestController
class CodeSigningRestController {
......@@ -47,7 +50,7 @@ class CodeSigningRestController {
}
try {
val exeCopy: File = Files.createTempFile(file.originalFilename, "").toFile()
val exeCopy: File = Files.createFile(Paths.get(file.originalFilename+System.currentTimeMillis())).toFile().absoluteFile
logger.info("Copy of input file as $exeCopy....")
file.transferTo(exeCopy)
......@@ -59,24 +62,26 @@ class CodeSigningRestController {
} else {
fileSigned = windowsCodeSign.signWindowsProduct(exeCopy)
}
response.setContentType("application/octet-stream")
response.setHeader("Content-Disposition", "attachment; filename='${fileSigned.name}'")
FileInputStream(fileSigned.canonicalFile).use { inputStream ->
inputStream.copyTo(response.outputStream)
response.outputStream.close()
}
return
} catch (e: SignException) {
logger.error(e)
response.setStatus(500)
response.outputStream.write("An error occured while signing file.".toByteArray())
response.outputStream.close()
return
}
response.setContentType("application/octet-stream")
response.setHeader("Content-Disposition", "attachment; filename='${fileSigned.name}'")
}finally{
if (!exeCopy.delete()) {
logger.error("Failed to delete temp file $exeCopy")
}
}
FileInputStream(fileSigned.canonicalFile).use { inputStream ->
inputStream.copyTo(response.outputStream)
response.outputStream.close()
}
if (!fileSigned.delete()) {
logger.error("Failed to delete temp file $fileSigned")
}
} catch (e: Throwable) {
logger.error("An error occured", e)
}
......@@ -113,6 +118,7 @@ class CodeSigningRestController {
if (!fileSigned.delete()) {
logger.error("Failed to delete temp file $fileSigned")
}
return
} catch (e: SignException) {
logger.error(e)
response.setStatus(500);
......
......@@ -19,6 +19,8 @@ import org.apache.commons.logging.LogFactory
import org.bonitasoft.exception.BuildDmgException
import org.bonitasoft.exception.SignException
import java.io.File
import java.io.IOException
import java.io.FileNotFoundException
class MacCodeSign {
val logger: Log = LogFactory.getLog(javaClass)
......@@ -51,7 +53,7 @@ class MacCodeSign {
fun buildAndSignMacInstaller(zipFile: File): File {
val file: File = unzip(zipFile);
if (!zipFile.delete()) {
throw Throwable("Failed to delete temp file $zipFile")
throw IOException("Failed to delete temp file $zipFile")
}
logger.info("Signing macOS installer...")
......@@ -93,28 +95,24 @@ class MacCodeSign {
deleteApplication(file)
logger.info("dmg has been created and signed successfully")
val zipDmg : File = zip(dmg)
if (!dmg.delete()) {
throw Throwable("Failed to delete temp file $dmg")
}
return zipDmg
return dmg
}
fun unzip(zipFile: File): File {
ProcessBuilder()
val result = ProcessBuilder()
.inheritIO()
.directory(zipFile.parentFile)
.command("unzip", zipFile.name)
.start()
.waitFor()
var file: File = File(zipFile.parentFile.canonicalPath + separator + zipFile.nameWithoutExtension + ".app")
if (!file.exists()) {
throw Throwable("failed to unzip $zipFile")
if (result != 0) {
throw IOException("failed to unzip $zipFile. 'unzip' command return code: $result")
}
var file: File = File(zipFile.parentFile.canonicalPath + separator + zipFile.nameWithoutExtension)
if(!file.exists()){
throw FileNotFoundException("$zipFile.nameWithoutExtension not found in $zipFile.parentFile.canonicalPath")
}
return file
}
......
......@@ -29,8 +29,7 @@ class WindowsCodeSign {
"/td", "sha256", "/fd", "sha256", "/a", file.canonicalFile.absolutePath)
logger.info("Signing windows file...")
val signResult = processBuilder.inheritIO().start().waitFor()
if (signResult != 0) {
if (signResult == 1) {
throw SignException("An error occured while signing file.")
}
......
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