Python to C# with openSSL requirement

Posted by fonix232 on Stack Overflow See other posts from Stack Overflow or by fonix232
Published on 2010-03-27T09:54:57Z Indexed on 2010/03/27 10:03 UTC
Read the original article Hit count: 295

Filed under:
|
|
|

Hey there again! 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# class.

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?

© Stack Overflow or respective owner

Related posts about python

Related posts about c#