Create Google Chrome Crx File Using PHP

I'd like to be able to generate a crx file with PHP.

The crx file is a zip file with an additional header, and Im is a lost way to create this header. I can create a crx file if I use a pregenerated pem file, but this leads to all crx files with the same extension ID, and this is bad. Here is a link to what I had so far .....
http://valorsolo.com/index.php?page=Viewing%20Message&id=1472&pagenum=2#1500

If that helps, it was done in Python, and there is a great blog post here. http://blog.roomanna.com/12-12-2010/packaging-chrome-extensions
and there are some links to other code on the topic .....
http://code.google.com/chrome/extensions/crx.html
http://code.google.com/p/crx-packaging/source/browse/trunk/packer.py
https://github.com/bellbind/crxmake-python/blob/master/crxmake.py
http://www.curetheitch.com/projects/buildcrx/

+5
source share
3 answers

This ruby code was helpful.

Your public key must be in DER format, and unfortunately the PHP OpenSSL extension cannot do this, as far as I can tell. I had to generate it from my private key on the command line:

openssl rsa -pubout -outform DER < extension_private_key.pem > extension_public_key.pub 

UPDATE : There is a PHP der2pem () function available here , thanks to tutuDajuju for specifying it.

After that, creating a .crx file is pretty simple:

 # make a SHA1 signature using our private key $pk = openssl_pkey_get_private(file_get_contents('extension_private_key.pem')); openssl_sign(file_get_contents('extension.zip'), $signature, $pk, 'sha1'); openssl_free_key($pk); # decode the public key $key = base64_decode(file_get_contents('extension_public_key.pub')); # .crx package format: # # magic number char(4) # crx format ver byte(4) # pub key lenth byte(4) # signature length byte(4) # public key string # signature string # package contents, zipped string # # see http://code.google.com/chrome/extensions/crx.html # $fh = fopen('extension.crx', 'wb'); fwrite($fh, 'Cr24'); // extension file magic number fwrite($fh, pack('V', 2)); // crx format version fwrite($fh, pack('V', strlen($key))); // public key length fwrite($fh, pack('V', strlen($signature))); // signature length fwrite($fh, $key); // public key fwrite($fh, $signature); // signature fwrite($fh, file_get_contents('extension.zip')); // package contents, zipped fclose($fh); 
+3
source

The CRX format is described in detail on the documentation page: http://code.google.com/chrome/extensions/crx.html

At the end of this file there are examples for Ruby and Bash. Follow the format in your language (PHP).

+2
source

You can use a working PHP solution: https://github.com/andyps/crxbuild There is a PHP class that you can include in your project and in the script command line.

+2
source

All Articles