Пример #1
0
function uploadfile($filename)
{
    global $master_key, $root_id;
    $data = file_get_contents($filename);
    $size = strlen($data);
    $ul_url = api_req(array('a' => 'u', 's' => $size));
    $ul_url = $ul_url->p;
    $ul_key = array(0, 1, 2, 3, 4, 5);
    for ($i = 0; $i < 6; $i++) {
        $ul_key[$i] = rand(0, 4294967295.0);
    }
    $data_crypted = aes_ctr_encrypt($data, a32_to_str(array_slice($ul_key, 0, 4)), a32_to_str(array($ul_key[4], $ul_key[5], 0, 0)));
    $completion_handle = post($ul_url, $data_crypted);
    $data_mac = cbc_mac($data, array_slice($ul_key, 0, 4), array_slice($ul_key, 4, 2));
    $meta_mac = array($data_mac[0] ^ $data_mac[1], $data_mac[2] ^ $data_mac[3]);
    $attributes = array('n' => basename($filename));
    $enc_attributes = enc_attr($attributes, array_slice($ul_key, 0, 4));
    $key = array($ul_key[0] ^ $ul_key[4], $ul_key[1] ^ $ul_key[5], $ul_key[2] ^ $meta_mac[0], $ul_key[3] ^ $meta_mac[1], $ul_key[4], $ul_key[5], $meta_mac[0], $meta_mac[1]);
    return api_req(array('a' => 'p', 't' => $root_id, 'n' => array(array('h' => $completion_handle, 't' => 0, 'a' => base64urlencode($enc_attributes), 'k' => a32_to_base64(encrypt_key($key, $master_key))))));
}
Пример #2
0
function t8ArrToCookieArr($rsa_priv_key = 0)
{
    global $cookie, $T8;
    if (empty($cookie) || !is_array($cookie)) {
        $cookie = array();
    }
    $cookie['sid'] = $T8['sid'];
    $cookie['user_handle'] = $T8['user_handle'];
    $cookie['master_key'] = a32_to_base64($T8['master_key']);
    $cookie['root_id'] = $T8['root_id'];
    if (!empty($rsa_priv_key) && is_array($rsa_priv_key) && count($rsa_priv_key) > 2) {
        $cookie['rsa_priv_key'] = implode('/T8\\', array_slice($rsa_priv_key, 0, 3));
    }
    // For decrypt the SID we need only the first 3 elements of the priv key, so we will only save those 3 elements.
}