2010-03-27 49 views
0

今天我在爲Chrome創建一個新的主題創建器時遇到了一個問題。如您所知,Chrome使用稱爲CRX的「新」文件格式來管理其插件和主題。這是一個基本的zip文件,但有點修改:如何用C#代碼替換openSSL調用?

「CR24」 + derkey +簽名+壓縮文件

這裏來的問題。只有兩個用Ruby或Python編寫的CRX創建器。我不太瞭解這兩種語言(儘管在Python中有一些基本的經驗,但主要是使用PyS60),所以我想請你幫助我將這個Python應用程序轉換爲不依賴於外部程序的C#代碼。

而且,這裏是crxmake.py來源:



#!/usr/bin/python 
# Cribbed from http://github.com/Constellation/crxmake/blob/master/lib/crxmake.rb 
# and http://src.chromium.org/viewvc/chrome/trunk/src/chrome/tools/extensions/chromium_extension.py?revision=14872&content-type=text/plain&pathrev=14872 

# from: http://grack.com/blog/2009/11/09/packing-chrome-extensions-in-python/ 
import sys 
from array import * 
from subprocess import * 
import os 
import tempfile 

def main(argv): 

    arg0,dir,key,output = argv 

    # zip up the directory 

    input = dir + ".zip" 

    if not os.path.exists(input): 
    os.system("cd %(dir)s; zip -r ../%(input)s . -x '.svn/*'" % locals()) 
    else: 
    print "'%s' already exists using it" % input 

    # Sign the zip file with the private key in PEM format 
    signature = Popen(["openssl", "sha1", "-sign", key, input], stdout=PIPE).stdout.read(); 

    # Convert the PEM key to DER (and extract the public form) for inclusion in the CRX header 
    derkey = Popen(["openssl", "rsa", "-pubout", "-inform", "PEM", "-outform", "DER", "-in", key], stdout=PIPE).stdout.read(); 

    out=open(output, "wb"); 
    out.write("Cr24") # Extension file magic number 
    header = array("l"); 
    header.append(2); # Version 2 
    header.append(len(derkey)); 
    header.append(len(signature)); 
    header.tofile(out); 
    out.write(derkey) 
    out.write(signature) 
    out.write(open(input).read()) 

    os.unlink(input) 
    print "Done." 

if __name__ == '__main__': 
    main(sys.argv) 

請你能幫助我嗎?

回答

0

對於Linux來說,有很多實用工具可以做到這一點 - 其中包括一個用於bash的工具 - 但它聽起來像是您想要Windows的東西(從您的C#評論中猜測出來)。

我曾試圖提供鏈接到所有的人 - 但我新的計算器的用戶,只能發佈1個鏈接..

無論如何,所有這些都可以在窗口工作,但是他們需要的設置語言解釋器和OpenSSL--所以我花了幾個小時,在C或Windows上運行一個版本(儘管我不確定你爲什麼要在Linux上使用它)。

它具有靜態鏈接的OpenSSL,所以沒有解釋器或庫的需求。

存儲庫可以在這裏找到:http://github.com/kylehuff/buildcrx

應該注意的,我不使用Windows - 這是寫在Linux和Linux上(以及OpenSSL庫)的win32二進制文件交叉編譯 - 我在Windows中測試過 - 但不是廣泛的。如果您遇到問題,請不要在此提出支持;我不會迴應。使用上面鏈接中的問題頁面。另外,我不會將它轉換爲C# - 我可以看到沒有理由將C#用於這樣一個簡單的實用程序,並且只會延長對「其他軟件」的需求,以便在其他平臺上有用。