]> git.mxchange.org Git - friendica.git/blobdiff - include/crypto.php
Merge https://github.com/friendica/friendica into pull
[friendica.git] / include / crypto.php
index 88e05b9eb0e34a75a2a2eff9beadfe866cf8c364..6fc9a287e4238ca5743c35920fab1d2c48afc91d 100644 (file)
@@ -262,24 +262,27 @@ function aes_unencapsulate($data,$prvkey) {
 }
 
 
-function zot_encapsulate($data,$sender,$pubkey) {
+// This has been superceded.
+
+function zot_encapsulate($data,$envelope,$pubkey) {
 $res = aes_encapsulate($data,$pubkey);
-openssl_public_encrypt($sender,$s,$pubkey);
-$s1 = base64url_encode($s,true);
 
 return <<< EOT
 <?xml version='1.0' encoding='UTF-8'?>
-<zot:env xmlns:zot='http://purl.org/zot/1.0'>
+<zot:msg xmlns:zot='http://purl.org/zot/1.0'>
  <zot:key>{$res['key']}</zot:key>
  <zot:iv>{$res['iv']}</zot:iv>
- <zot:sender>$s1</zot:sender>
+ <zot:env>$s1</zot:env>
+ <zot:sig key_id="$keyid">$sig</zot:sig>
  <zot:alg>AES-256-CBC</zot:alg>
  <zot:data type='application/magic-envelope+xml'>{$res['data']}</zot:data>
-</zot:env>
+</zot:msg>
 EOT;
 
 }
 
+// so has this
+
 function zot_unencapsulate($data,$prvkey) {
        $ret = array();
        $c = array();
@@ -289,4 +292,38 @@ function zot_unencapsulate($data,$prvkey) {
        $ret['sender'] = $s;
        $ret['data'] = aes_unencapsulate($x,$prvkey);
        return $ret;
-}
\ No newline at end of file
+}
+
+function new_keypair($bits) {
+
+       $openssl_options = array(
+               'digest_alg'       => 'sha1',
+               'private_key_bits' => $bits,
+               'encrypt_key'      => false 
+       );
+
+       $conf = get_config('system','openssl_conf_file');
+       if($conf)
+               $openssl_options['config'] = $conf;
+       
+       $result = openssl_pkey_new($openssl_options);
+
+       if(empty($result)) {
+               logger('new_keypair: failed');
+               return false;
+       }
+
+       // Get private key
+
+       $response = array('prvkey' => '', 'pubkey' => '');
+
+       openssl_pkey_export($result, $response['prvkey']);
+
+       // Get public key
+       $pkey = openssl_pkey_get_details($result);
+       $response['pubkey'] = $pkey["key"];
+
+       return $response;
+
+}
+