2011-02-16 83 views
5

編號喜歡能夠使用PHP生成crx文件。使用PHP創建Google Chrome Crx文件

crx文件是一個zip文件,其中包含一個額外的頭文件和一個關於如何創建頭文件的文件。如果我使用預生成的pem文件,我可以創建一個crx文件,但這會導致所有crx文件具有相同的擴展名,並且這不太好。下面有一個鏈接到什麼Ive得到到目前爲止.....
http://valorsolo.com/index.php?page=Viewing%20Message&id=1472&pagenum=2#1500

櫃面它有助於這在Python已經完成,沒有對這裏的更精細的細節極好的博客文章....
http://blog.roomanna.com/12-12-2010/packaging-chrome-extensions
和繼承人一些鏈接到關於這個問題的其他代碼.....
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/

回答

2

的CRX格式進行詳細說明的文檔頁面上: http://code.google.com/chrome/extensions/crx.html

有在該文件上的Ruby和擊的端部的示例。按照您的語言格式(PHP)。

+0

如果我能做到這一點,我不會尋求幫助;) 但是,感謝您提出這個鏈接,我忘了那個......我已經閱讀了它(很多次),它只是一個超越我。 – PAEz 2011-02-17 07:02:59

3

This ruby code was helpful。

你的公鑰必須是DER格式,不幸的是PHP的OpenSSL擴展不能這樣做,據我所知。我不得不在命令行中從我的私人密鑰生成它:

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

UPDATE:有一個PHP der2pem()函數available here,感謝tutuDajuju指點出來。

一旦這樣做了,建設的.crx文件是很容易的:

# 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); 
+0

感謝您的意見,但這幾乎是我可以做的準備。 這將簽署一個拉鍊很好,但正如我上面所述,所有的擴展將有相同的擴展ID是遠非理想。 謝謝壽。 – PAEz 2011-04-08 06:54:11