Skip to content

Instantly share code, notes, and snippets.

@Yasushi
Created June 1, 2014 14:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Yasushi/c57ba4c22013524ce010 to your computer and use it in GitHub Desktop.
Save Yasushi/c57ba4c22013524ce010 to your computer and use it in GitHub Desktop.
ant.importBuild "build.xml"
defaultTasks 'crx'
def keystore = ant.properties['cert.chromePath']+"/"+ant.properties.name+".p12"
def chromeCrx = ant.properties.dist+"/"+ant.properties.name+".crx"
import java.security.*
import java.security.spec.*
import java.nio.ByteBuffer
import java.nio.ByteOrder
task genkeypair(type: Exec) {
outputs.file keystore
commandLine "keytool", "-genkey", "-keyalg", "RSA", "-keysize", "1024", "-alias", "crx", "-keystore", keystore, "-storepass", "changeit", "-storetype", "PKCS12", "-dname", "CN=crx"
}
task chromeZip(dependsOn: ['preinit','copy-chrome'], type: Zip) {
from ant.properties.buildDir
baseName = "chrome"
destinationDir = new File(ant.properties.build)
excludes = ["chrome.zip"]
}
task crx(dependsOn: ['genkeypair', 'chromeZip']) {
inputs.files keystore,chromeZip.archivePath
outputs.file chromeCrx
doLast {
def password = "changeit".toCharArray()
def ks = KeyStore.getInstance("PKCS12")
new File(keystore).withInputStream(){ks.load(it, password)}
def privateKey = ks.getKey("crx", password)
def publicKey = ks.getCertificate("crx").getPublicKey().getEncoded()
def signer = Signature.getInstance("SHA1withRSA")
signer.initSign(privateKey)
signer.update(chromeZip.archivePath.readBytes())
def signature = signer.sign()
new File(chromeCrx).withOutputStream { out ->
def header = ByteBuffer.allocate(16)
header.order(ByteOrder.LITTLE_ENDIAN)
header.putInt(0x34327243)
header.putInt(2)
header.putInt(publicKey.length)
header.putInt(signature.length)
out << header.array()
out << publicKey
out << signature
out << chromeZip.archivePath.readBytes()
}
}
}
@aliab01
Copy link

aliab01 commented Jul 30, 2015

Hi Yasushi,
Thanks for this build script for crx, can you provide build.xml file?

@aliab01
Copy link

aliab01 commented Jul 30, 2015

Never mind Yasushi. Please my previous question.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment