2010-03-27 51 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#用于这样一个简单的实用程序,并且只会延长对“其他软件”的需求,以便在其他平台上有用。