Created
June 1, 2014 14:24
-
-
Save Yasushi/c57ba4c22013524ce010 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | |
} | |
} | |
} |
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
Hi Yasushi,
Thanks for this build script for crx, can you provide build.xml file?