开发者

How to replace openSSL calls with C# code?

Today I ran into a problem when I was making a new theme creator for chrome. As you may know, Chrome uses a "new" file format, called CRX, to manage it's plugins and themes. It is a basic zip file, but a bit modified:

"Cr24" + derkey + signature + zipFile

And here comes the problem. There are only two CRX creators, written in Ruby or Python. I don't know neither language too much (had some basic experience in Python though, but mostly with PyS60), so I would like to ask you to help me convert this python app to a C# code that doesn't depend o开发者_JAVA技巧n external programs.

Also, here is the source of 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)

Please could you help me?


For Linux, there are a variety of utilities to do this - including one for bash - but it sounds like you want something for windows (guessing from your C# comment).

I had tried to include links to all of them - but I am new stackoverflow user, and can only post 1 link..

Anyway, all of those can work in windows, however they require setup of the language interpreter and OpenSSL - so I spent a few hours and put together a version in C which runs on windows or linux (though, I'm not sure why you would use it in linux).

It has OpenSSL statically linked so there are no interpreter or library requirements.

The repository can be found here: http://github.com/kylehuff/buildcrx

It should be noted, I do not use windows - this was written on Linux and the win32 binary was cross-compiled on Linux (as well as the OpenSSL libraries) - I did test it in windows - but not extensively. If you have trouble with it, please don't request support here; I will not respond. Use the issues page at the link above.

Also, I will not convert this to C# - I can see no reason to use C# for such a simple utility and that would just perpetuate the need for "other software" in order for it be useful on other platforms.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜