Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You were using <code>openssl_pkey_export</code> wrong and you haven't removed </p> <pre><code>-----BEGIN PUBLIC KEY----- ... -----END PUBLIC KEY----- </code></pre> <p>from public key string before decoding it. I figured this out by looking at length of public key and signature. First one should be 161 and second one should be 128 bytes long (<a href="http://developer.chrome.com/extensions/crx.html#example" rel="nofollow">source</a>):</p> <pre><code>A2 00 00 00 # 162 -- length of public key in bytes 80 00 00 00 # 128 -- length of signature in bytes </code></pre> <p>Here is the fixed code (PHP 5.4):</p> <pre><code>$pk=file_get_contents('pk.pem'); $priv = openssl_pkey_get_private($pk); $pub = openssl_pkey_get_details($priv)['key']; # make a SHA1 signature using our private key openssl_sign(file_get_contents('download.zip'), $signature, $priv, OPENSSL_ALGO_SHA1); # geting rid of -----BEGIN/END PUBLIC KEY----- # you can probably do it better using preg_match_all / explode(PHP_EOL, $pub) etc. $pub = trim(explode('-----',$pub)[2]); # decode the public key $pub = base64_decode($pub); # .crx package format: # # magic number char(4) # crx format ver byte(4) # pub key lenth byte(4) # signature length byte(4) # public key string # signature string # package contents, zipped string # # see http://code.google.com/chrome/extensions/crx.html # $fh = fopen('extension.crx', 'wb'); fwrite($fh, 'Cr24'); // extension file magic number fwrite($fh, pack('V', 2)); // crx format version fwrite($fh, pack('V', strlen($pub))); // public key length fwrite($fh, pack('V', strlen($signature))); // signature length fwrite($fh, $pub); // public key fwrite($fh, $signature); // signature fwrite($fh, file_get_contents('download.zip')); // package contents, zipped fclose($fh); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload