繁体   English   中英

如何用C#代码替换openSSL调用?

[英]How to replace openSSL calls with C# code?

今天,当我为chrome创建新的主题创建者时遇到了一个问题。 如您所知,Chrome使用一种称为CRX的“新”文件格式来管理其插件和主题。 这是一个基本的zip文件,但做了一些修改:

“ Cr24” + derkey +签名+ zipFile

问题来了。 只有两个用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)

请你能帮我吗?

对于Linux,有多种实用程序可以执行此操作-包括一个用于bash的实用程序-但这听起来像您想要Windows的某些功能(从C#注释中猜测)。

我试图包括所有这些的链接-但是我是新的stackoverflow用户,并且只能发布1个链接。

无论如何,所有这些都可以在Windows中工作,但是它们需要安装语言解释器和OpenSSL-因此我花了几个小时,并整理了一个可以在Windows或Linux上运行的C语言版本(尽管我不确定为什么您将在Linux中使用它)。

它具有静态链接的OpenSSL,因此没有解释器或库的要求。

该存储库可以在这里找到: http : //github.com/kylehuff/buildcrx

应当指出,我不使用Windows-这是在Linux上编写的,而Win32二进制文件是在Linux(以及OpenSSL库)上交叉编译的-我确实在Windows中对其进行了测试-但并未进行广泛的测试。 如果您有任何问题,请不要在这里寻求支持; 我不会回应。 使用上面链接中的问题页面。

另外,我不会将其转换为C#-我看不出有理由将C#用于如此简单的实用程序,而这将使对“其他软件”的需求永久存在,以使其在其他平台上有用。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM