X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=include%2Fcrypto.php;h=f5163a9dacbeb2bb8ccf8b3be23ff6de27a62546;hb=1c93729c4624c7c8c27344f3c5139ff1c4e08d65;hp=0feb45c2474b58edbb0f27e066d7c382eaf2e992;hpb=ef1b99aa44031662187be878485be14edf35b42b;p=friendica.git diff --git a/include/crypto.php b/include/crypto.php index 0feb45c247..f5163a9dac 100644 --- a/include/crypto.php +++ b/include/crypto.php @@ -187,6 +187,7 @@ function salmon_key($pubkey) { if(! function_exists('aes_decrypt')) { +// DEPRECATED IN 3.4.1 function aes_decrypt($val,$ky) { $key="\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"; @@ -200,6 +201,7 @@ function aes_decrypt($val,$ky) if(! function_exists('aes_encrypt')) { +// DEPRECATED IN 3.4.1 function aes_encrypt($val,$ky) { $key="\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"; @@ -211,7 +213,6 @@ function aes_encrypt($val,$ky) return mcrypt_encrypt($enc, $key, $val, $mode, mcrypt_create_iv( mcrypt_get_iv_size($enc, $mode), MCRYPT_DEV_URANDOM)); }} - function pkcs5_pad ($text, $blocksize) { $pad = $blocksize - (strlen($text) % $blocksize); @@ -226,70 +227,37 @@ function pkcs5_unpad($text) return substr($text, 0, -1 * $pad); } -function AES256CBC_encrypt($data,$key,$iv) { - return mcrypt_encrypt( - MCRYPT_RIJNDAEL_128, - str_pad($key,32,"\0"), - pkcs5_pad($data,16), - MCRYPT_MODE_CBC, - str_pad($iv,16,"\0")); -} -function AES256CBC_decrypt($data,$key,$iv) { - return pkcs5_unpad(mcrypt_decrypt( - MCRYPT_RIJNDAEL_128, - str_pad($key,32,"\0"), - $data, - MCRYPT_MODE_CBC, - str_pad($iv,16,"\0"))); -} +function new_keypair($bits) { -function aes_encapsulate($data,$pubkey) { - $key = random_string(32,RANDOM_STRING_TEXT); - $iv = random_string(16,RANDOM_STRING_TEXT); - $result['data'] = base64url_encode(AES256CBC_encrypt($data,$key,$iv),true); - openssl_public_encrypt($key,$k,$pubkey); - $result['key'] = base64url_encode($k,true); - openssl_public_encrypt($iv,$i,$pubkey); - $result['iv'] = base64url_encode($i,true); - return $result; -} + $openssl_options = array( + 'digest_alg' => 'sha1', + 'private_key_bits' => $bits, + 'encrypt_key' => false + ); -function aes_unencapsulate($data,$prvkey) { - openssl_private_decrypt(base64url_decode($data['key']),$k,$prvkey); - openssl_private_decrypt(base64url_decode($data['iv']),$i,$prvkey); - return AES256CBC_decrypt(base64url_decode($data['data']),$k,$i); -} + $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' => ''); -// This has been superceded. + openssl_pkey_export($result, $response['prvkey']); -function zot_encapsulate($data,$envelope,$pubkey) { -$res = aes_encapsulate($data,$pubkey); + // Get public key + $pkey = openssl_pkey_get_details($result); + $response['pubkey'] = $pkey["key"]; -return <<< EOT - - - {$res['key']} - {$res['iv']} - $s1 - $sig - AES-256-CBC - {$res['data']} - -EOT; + return $response; } -// so has this - -function zot_unencapsulate($data,$prvkey) { - $ret = array(); - $c = array(); - $x = parse_xml_string($data); - $c = array('key' => $x->key,'iv' => $x->iv,'data' => $x->data); - openssl_private_decrypt(base64url_decode($x->sender),$s,$prvkey); - $ret['sender'] = $s; - $ret['data'] = aes_unencapsulate($x,$prvkey); - return $ret; -} \ No newline at end of file