Skip to content

NO_REF: Experimental TFA support. #94

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,14 @@ On Ubuntu you can run the following command:
## Usage
Terminal command is pcloudcc and -h option prints short options description.
> ./pcloudcc -h
> pCloud console client v.2.0.1
> pCloud console client v.2.1.0
>Allowed options:
> -h [ --help ] produce help message
> -u [ --username ] arg pCloud account name
> -p [ --password ] pCloud account password
> -c [ --crypto ] arg Crypto password
> -y [ --passascrypto ] arg Use user password as crypto password also.
> -y [ --passascrypto ] arg Use user password as crypto password also.
> -t [ --trust ] Trust this device.
> -d [ --daemonize ] Daemonize the process.
> -o [ --commands ] Parent stays alive and processes commands.
> -m [ --mountpoint ] arg Mount point where drive to be mounted.
Expand Down
12 changes: 6 additions & 6 deletions pCloudCC/control_tools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,16 @@ enum command_ids_ {
};


int start_crypto(const char * pass) {
void start_crypto(const char * pass) {
int ret;
char* errm;
if (SendCall(STARTCRYPTO, pass, &ret, &errm))
std::cout << "Start Crypto failed. return is " << ret<< " and message is "<<errm << std::endl;
else
std::cout << "Crypto started. "<< std::endl;
free(errm);
free(errm);
}
int stop_crypto(){
void stop_crypto(){
int ret;
char* errm;
if (SendCall(STOPCRYPTO, "", &ret, &errm))
Expand All @@ -48,7 +48,7 @@ int stop_crypto(){
std::cout << "Crypto Stopped. "<< std::endl;
free(errm);
}
int finalize(){
void finalize(){
int ret;
char* errm;
if (SendCall(FINALIZE, "", &ret, &errm))
Expand Down Expand Up @@ -77,7 +77,7 @@ void process_commands()
}
}

int daemonize(bool do_commands) {
void daemonize(bool do_commands) {
pid_t pid, sid;

pid = fork();
Expand Down Expand Up @@ -112,4 +112,4 @@ int daemonize(bool do_commands) {

}

}
}
10 changes: 5 additions & 5 deletions pCloudCC/control_tools.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@
#ifndef CONTROL_TOOLS_H
#define CONTROL_TOOLS_H
namespace control_tools {
int start_crypto(const char * pass);
int stop_crypto();
int finalize();
int daemonize(bool do_commands);
void start_crypto(const char * pass);
void stop_crypto();
void finalize();
void daemonize(bool do_commands);
void process_commands();
}

#endif //CONTROL_TOOLS_H
#endif //CONTROL_TOOLS_H
6 changes: 3 additions & 3 deletions pCloudCC/lib/pclsync/gitcommit.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#ifndef _GITCOMMIT_H
#define _GITCOMMIT_H

#define GIT_PREV_COMMIT_ID "6339ebce20a8b853dd78b80e075ab25e1f413f73"
#define GIT_PREV_COMMIT_DATE "2018-03-15 15:36:43 +0200"
#define GIT_COMMIT_DATE "2018-03-26 18:43:25 +0300"
#define GIT_PREV_COMMIT_ID "1850db4446c928a8b3078cc84057c2fe88e4cbbc"
#define GIT_PREV_COMMIT_DATE "2018-04-16 19:11:00 +0200"
#define GIT_COMMIT_DATE "2019-05-09 00:45:00 +0300"

#endif
2 changes: 1 addition & 1 deletion pCloudCC/lib/pclsync/pcompat.c
Original file line number Diff line number Diff line change
Expand Up @@ -3380,7 +3380,7 @@ int64_t psync_file_size(psync_file_t fd){
}

void psync_set_software_name(const char *snm){
psync_software_name=snm;
psync_software_name=psync_strcat(snm, NULL);
}

char *psync_deviceid(){
Expand Down
2 changes: 2 additions & 0 deletions pCloudCC/lib/pclsync/pcompat.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,9 @@

#define P_OS_ID 7

#ifndef _GNU_SOURCE
#define _GNU_SOURCE
#endif

#else

Expand Down
10 changes: 5 additions & 5 deletions pCloudCC/lib/pclsync/pcompiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,23 +45,23 @@
#endif
#endif

#ifndef __has_builtin
#ifndef PSYNC_HAS_BUILTIN
#if defined(__GNUC__)
#define __has_builtin(x) 1
#define PSYNC_HAS_BUILTIN(x) 1
#else
#define __has_builtin(x) 0
#define PSYNC_HAS_BUILTIN(x) 0
#endif
#endif

#if __has_builtin(__builtin_expect)
#if PSYNC_HAS_BUILTIN(__builtin_expect)
#define likely(expr) __builtin_expect(!!(expr), 1)
#define unlikely(expr) __builtin_expect(!!(expr), 0)
#else
#define likely(expr) (expr)
#define unlikely(expr) (expr)
#endif

#if __has_builtin(__builtin_prefetch)
#if PSYNC_HAS_BUILTIN(__builtin_prefetch)
#define psync_prefetch(expr) __builtin_prefetch(expr)
#elif defined(_MSC_VER)
#define psync_prefetch(expr) _mm_prefetch((char *)(expr), _MM_HINT_T0)
Expand Down
133 changes: 87 additions & 46 deletions pCloudCC/lib/pclsync/pdiff.c
Original file line number Diff line number Diff line change
Expand Up @@ -111,22 +111,62 @@ static void delete_cached_crypto_keys(){
psync_sql_statement("DELETE FROM cryptofilekey");
}

static binresult *get_userinfo_user_digest(psync_socket *sock, const char *username, size_t userlen, const char *pwddig, const char *digest, uint32_t diglen,
const char *device){
static binresult *login_with_digest(psync_socket *sock, const char *username, size_t userlen, const char *pwddig,
const char *digest, uint32_t diglen,
const char *device) {
binparam params[]={P_STR("timeformat", "timestamp"),
P_LSTR("username", username, userlen),
P_LSTR("digest", digest, diglen),
P_LSTR("passworddigest", pwddig, PSYNC_SHA1_DIGEST_HEXLEN),
P_STR("device", device),
P_STR("deviceid", device),
P_BOOL("getauth", 1),
P_BOOL("getapiserver", 1),
P_BOOL("cryptokeyssign", 1),
P_NUM("os", P_OS_ID)};
return send_command(sock, "login", params);
}

static binresult *get_userinfo_user_pass(psync_socket *sock, const char *username, const char *password, const char *device){
binparam empty_params[]={P_STR("MS", "sucks")};
static binresult *get_userinfo_user_pass(psync_socket *sock, const char *username, const char *password,
const char *device) {
binparam params[] = {P_STR("timeformat", "timestamp"),
P_STR("username", username),
P_STR("password", password),
P_STR("device", device),
P_STR("deviceid", device),
P_BOOL("getauth", 1),
P_BOOL("cryptokeyssign", 1),
P_BOOL("getapiserver", 1),
P_NUM("os", P_OS_ID)};
return send_command(sock, "login", params);
}

static binresult *get_userinfo_auth(psync_socket *sock, const char *auth, const char *device) {
binparam params[]={P_STR("timeformat", "timestamp"),
P_STR("auth", auth),
P_STR("device", device),
P_STR("deviceid", device),
P_BOOL("getauth", 1),
P_BOOL("cryptokeyssign", 1),
P_BOOL("getapiserver", 1),
P_NUM("os", P_OS_ID)};
return send_command(sock, "userinfo", params);
}

static binresult *get_tfa_auth(psync_socket *sock, const char *token, const char *code, const char *device) {
binparam params[]={P_STR("timeformat", "timestamp"),
P_STR("token", token),
P_STR("device", device),
P_STR("deviceid", device),
P_NUM("code", atol(code)),
P_BOOL("trustdevice", psync_setting_get_bool(_PS(trusted))),
P_NUM("os", P_OS_ID)};
return send_command(sock, "tfa_login", params);
}

static binresult *get_userinfo_user_pass_digest(psync_socket *sock, const char *username, const char *password,
const char *device){
binparam empty_params[]={P_STR("NO_PARAM", "empty")};
psync_sha1_ctx ctx;
binresult *res, *ret;
const binresult *dig;
Expand Down Expand Up @@ -156,23 +196,23 @@ static binresult *get_userinfo_user_pass(psync_socket *sock, const char *usernam
psync_sha1_update(&ctx, dig->str, dig->length);
psync_sha1_final(sha1bin, &ctx);
psync_binhex(sha1hex, sha1bin, PSYNC_SHA1_DIGEST_LEN);
ret=get_userinfo_user_digest(sock, username, ul, sha1hex, dig->str, dig->length, device);
ret=login_with_digest(sock, username, ul, sha1hex, dig->str, dig->length, device);
psync_free(res);
return ret;
}

static psync_socket *get_connected_socket(){
char *auth, *user, *pass;
char *auth, *user, *pass, *tfa_pin, *tfa_token, *device;
psync_socket *sock;
binresult *res;
const binresult *cres;
psync_sql_res *q;
char *device;
uint64_t result, userid, luserid;
int saveauth, isbusiness, cryptosetup;
auth=user=pass=NULL;
auth=user=pass=tfa_pin=tfa_token=NULL;
psync_is_business = 0;
int digest = 1;
int auth_reset = 0;
while (1){
psync_free(auth);
psync_free(user);
Expand Down Expand Up @@ -202,30 +242,16 @@ static psync_socket *get_connected_socket(){
}
device=psync_deviceid();

if (user && pass && pass[0])
if (digest)
if (tfa_token && tfa_pin) {
res=get_tfa_auth(sock, tfa_token, tfa_pin, device);
} else if ((!auth || auth_reset) && user && pass && pass[0]) {
if (digest) {
res=get_userinfo_user_pass_digest(sock, user, pass, device);
} else {
res=get_userinfo_user_pass(sock, user, pass, device);
else
{
binparam params[]={P_STR("timeformat", "timestamp"),
P_STR("username", user),
P_STR("password", pass),
P_STR("device", device),
P_BOOL("getauth", 1),
P_BOOL("cryptokeyssign", 1),
P_BOOL("getapiserver", 1),
P_NUM("os", P_OS_ID)};
res=send_command(sock, "login", params);
}
else {
binparam params[]={P_STR("timeformat", "timestamp"),
P_STR("auth", auth),
P_STR("device", device),
P_BOOL("getauth", 1),
P_BOOL("cryptokeyssign", 1),
P_BOOL("getapiserver", 1),
P_NUM("os", P_OS_ID)};
res=send_command(sock, "userinfo", params);
} else {
res=get_userinfo_auth(sock, auth, device);
}
psync_free(device);
if (unlikely_log(!res)){
Expand All @@ -240,33 +266,48 @@ static psync_socket *get_connected_socket(){
if (unlikely(result)){
debug(D_NOTICE, "userinfo returned error %lu %s", (unsigned long)result, psync_find_result(res, "error", PARAM_STR)->str);
psync_socket_close(sock);
psync_free(res);
if (result==2000){
if (user && pass)
if (result == 2000) {
if (user && pass) {
psync_set_status(PSTATUS_TYPE_AUTH, PSTATUS_AUTH_BADLOGIN);
else
} else {
psync_set_status(PSTATUS_TYPE_AUTH, PSTATUS_AUTH_BADTOKEN);
}
psync_wait_status(PSTATUS_TYPE_AUTH, PSTATUS_AUTH_PROVIDED);
}
else if (result==4000)
psync_milisleep(5*60*1000);
else if (result == 2297 ){
} else if (result == 4000) {
psync_milisleep(5 * 60 * 1000);
} else if (result == 2297) {
tfa_token=psync_strdup(psync_find_result(res, "token", PARAM_STR)->str);
psync_set_status(PSTATUS_TYPE_AUTH, PSTATUS_AUTH_TFAERR);
psync_wait_status(PSTATUS_TYPE_AUTH, PSTATUS_AUTH_PROVIDED);
}
else if (result==2205 || result==2229){
tfa_pin=psync_strdup(psync_my_tfa_pin);
debug(D_NOTICE, "provided token from console: %s", tfa_pin);
} else if (result == 2064) { //Expired 'token'.
debug(D_NOTICE, "expired tfa token");
psync_free(tfa_token);
psync_free(tfa_pin);
} else if (result == 2012) { //"Invalid 'code' provided."
debug(D_NOTICE, "invalid tfa pin");
psync_free(tfa_pin);
psync_set_status(PSTATUS_TYPE_AUTH, PSTATUS_AUTH_TFAERR);
psync_wait_status(PSTATUS_TYPE_AUTH, PSTATUS_AUTH_PROVIDED);
tfa_pin=psync_strdup(psync_my_tfa_pin);
debug(D_NOTICE, "provided token from console: %s", tfa_pin);
} else if (result == 2205 || result == 2229) {
auth_reset=1;
psync_set_status(PSTATUS_TYPE_AUTH, PSTATUS_AUTH_EXPIRED);
psync_wait_status(PSTATUS_TYPE_AUTH, PSTATUS_AUTH_PROVIDED);
} else if (result == 2237)
{
digest = 0;
} else if (result == 2237) {
digest=0;
continue;
}

else
} else {
psync_milisleep(PSYNC_SLEEP_BEFORE_RECONNECT);
}
psync_free(res);
continue;
}
psync_free(tfa_pin);
psync_free(tfa_token);
auth_reset=0;
psync_my_userid=userid=psync_find_result(res, "userid", PARAM_NUM)->num;
current_quota=psync_find_result(res, "quota", PARAM_NUM)->num;
luserid=psync_sql_cellint("SELECT value FROM setting WHERE id='userid'", 0);
Expand Down
2 changes: 1 addition & 1 deletion pCloudCC/lib/pclsync/plibs.c
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ static char normalize_table[256];

const static char *psync_typenames[]={"[invalid type]", "[number]", "[string]", "[float]", "[null]", "[bool]"};

char psync_my_auth[64]="", *psync_my_user=NULL, *psync_my_pass=NULL;
char psync_my_auth[64]="", *psync_my_user=NULL, *psync_my_pass=NULL, psync_my_tfa_pin[8]="";
uint64_t psync_my_userid=0;
pthread_mutex_t psync_my_auth_mutex=PTHREAD_MUTEX_INITIALIZER;

Expand Down
2 changes: 1 addition & 1 deletion pCloudCC/lib/pclsync/plibs.h
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ typedef void (*psync_transaction_callback_t)(void *);
extern int psync_do_run;
extern int psync_recache_contacts;
extern pstatus_t psync_status;
extern char psync_my_auth[64], *psync_my_user, *psync_my_pass;
extern char psync_my_auth[64], psync_my_tfa_pin[8], *psync_my_user, *psync_my_pass;
extern uint64_t psync_my_userid;
extern pthread_mutex_t psync_my_auth_mutex;
extern PSYNC_THREAD uint32_t psync_error;
Expand Down
3 changes: 2 additions & 1 deletion pCloudCC/lib/pclsync/psettings.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ static psync_setting_t settings[]={
{"autostartfs", NULL, NULL, {PSYNC_AUTOSTARTFS_DEFAULT}, PSYNC_TBOOL},
{"fscachesize", psync_pagecache_resize_cache, NULL, {PSYNC_FS_DEFAULT_CACHE_SIZE}, PSYNC_TNUMBER},
{"fscachepath", NULL, NULL, {0}, PSYNC_TSTRING},
{"sleepstopcrypto", NULL, NULL, {PSYNC_CRYPTO_DEFAULT_STOP_ON_SLEEP}, PSYNC_TBOOL}
{"sleepstopcrypto", NULL, NULL, {PSYNC_CRYPTO_DEFAULT_STOP_ON_SLEEP}, PSYNC_TBOOL},
{"trusted", NULL, NULL, {0}, PSYNC_TBOOL}
};

void psync_settings_reset(){
Expand Down
1 change: 1 addition & 0 deletions pCloudCC/lib/pclsync/psettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,7 @@ pagefile.sys;\
#define PSYNC_SETTING_fscachesize 9
#define PSYNC_SETTING_fscachepath 10
#define PSYNC_SETTING_sleepstopcrypto 11
#define PSYNC_SETTING_trusted 12

typedef int psync_settingid_t;

Expand Down
4 changes: 4 additions & 0 deletions pCloudCC/lib/pclsync/psynclib.c
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,10 @@ void psync_set_auth(const char *auth, int save){
psync_set_status(PSTATUS_TYPE_AUTH, PSTATUS_AUTH_PROVIDED);
}

void psync_set_tfa_pin(const char *tfa_pin){
psync_strlcpy(psync_my_tfa_pin, tfa_pin, sizeof(psync_my_tfa_pin));
psync_set_status(PSTATUS_TYPE_AUTH, PSTATUS_AUTH_PROVIDED);
}

int psync_mark_notificaitons_read(uint32_t notificationid){
binparam params[]={P_STR("auth", psync_my_auth), P_NUM("notificationid", notificationid)};
Expand Down
1 change: 1 addition & 0 deletions pCloudCC/lib/pclsync/psynclib.h
Original file line number Diff line number Diff line change
Expand Up @@ -637,6 +637,7 @@ void psync_get_status(pstatus_t *status);

char *psync_get_username();
void psync_set_user_pass(const char *username, const char *password, int save);
void psync_set_tfa_pin(const char *tfa_pin);
void psync_set_pass(const char *password, int save);
void psync_set_auth(const char *auth, int save);
void psync_logout();
Expand Down
Loading