move issetup to pcryptofolder
This commit is contained in:
parent
c81c4deba8
commit
93fc7ec815
|
|
@ -357,6 +357,11 @@ setup_upload(const unsigned char *rsapriv, size_t rsaprivlen,
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int pcryptofolder_issetup() {
|
||||||
|
return psync_sql_cellint("SELECT value FROM setting WHERE id='cryptosetup'", 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* generate 64 byte (512 bit) salt for PBKDF2
|
* generate 64 byte (512 bit) salt for PBKDF2
|
||||||
* generate AES key and IV with PBKDF2
|
* generate AES key and IV with PBKDF2
|
||||||
|
|
@ -364,7 +369,6 @@ setup_upload(const unsigned char *rsapriv, size_t rsaprivlen,
|
||||||
* upload to server salt, encrypted private and public
|
* upload to server salt, encrypted private and public
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
int pcryptofolder_setup(const char *password, const char *hint) {
|
int pcryptofolder_setup(const char *password, const char *hint) {
|
||||||
unsigned char salt[PSYNC_CRYPTO_PBKDF2_SALT_LEN];
|
unsigned char salt[PSYNC_CRYPTO_PBKDF2_SALT_LEN];
|
||||||
char publicsha1[PSYNC_SHA1_DIGEST_HEXLEN + 2],
|
char publicsha1[PSYNC_SHA1_DIGEST_HEXLEN + 2],
|
||||||
|
|
@ -719,7 +723,7 @@ int pcryptofolder_reset() {
|
||||||
binresult *res;
|
binresult *res;
|
||||||
uint32_t result;
|
uint32_t result;
|
||||||
int tries;
|
int tries;
|
||||||
if (!psync_crypto_issetup())
|
if (!pcryptofolder_issetup())
|
||||||
return PRINT_RETURN_CONST(PSYNC_CRYPTO_RESET_NOT_SETUP);
|
return PRINT_RETURN_CONST(PSYNC_CRYPTO_RESET_NOT_SETUP);
|
||||||
debug(D_NOTICE, "resetting crypto");
|
debug(D_NOTICE, "resetting crypto");
|
||||||
tries = 0;
|
tries = 0;
|
||||||
|
|
|
||||||
|
|
@ -77,6 +77,7 @@ int pcryptofolder_mkdir(psync_folderid_t folderid, const char *name, const char
|
||||||
int pcryptofolder_reset();
|
int pcryptofolder_reset();
|
||||||
int pcryptofolder_setup(const char *password, const char *hint);
|
int pcryptofolder_setup(const char *password, const char *hint);
|
||||||
int pcryptofolder_unlock(const char *password);
|
int pcryptofolder_unlock(const char *password);
|
||||||
|
int pcryptofolder_issetup();
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2195,11 +2195,6 @@ int psync_crypto_mkdir(psync_folderid_t folderid, const char *name,
|
||||||
return pcryptofolder_mkdir(folderid, name, err, newfolderid);
|
return pcryptofolder_mkdir(folderid, name, err, newfolderid);
|
||||||
}
|
}
|
||||||
|
|
||||||
int psync_crypto_issetup() {
|
|
||||||
return psync_sql_cellint("SELECT value FROM setting WHERE id='cryptosetup'",
|
|
||||||
0);
|
|
||||||
}
|
|
||||||
|
|
||||||
int psync_crypto_hassubscription() {
|
int psync_crypto_hassubscription() {
|
||||||
return psync_sql_cellint(
|
return psync_sql_cellint(
|
||||||
"SELECT value FROM setting WHERE id='cryptosubscription'", 0);
|
"SELECT value FROM setting WHERE id='cryptosubscription'", 0);
|
||||||
|
|
|
||||||
|
|
@ -1327,7 +1327,6 @@ char *psync_derive_password_from_passphrase(const char *username,
|
||||||
int psync_crypto_get_hint(char **hint);
|
int psync_crypto_get_hint(char **hint);
|
||||||
int psync_crypto_mkdir(psync_folderid_t folderid, const char *name,
|
int psync_crypto_mkdir(psync_folderid_t folderid, const char *name,
|
||||||
const char **err, psync_folderid_t *newfolderid);
|
const char **err, psync_folderid_t *newfolderid);
|
||||||
int psync_crypto_issetup();
|
|
||||||
int psync_crypto_hassubscription();
|
int psync_crypto_hassubscription();
|
||||||
int psync_crypto_isexpired();
|
int psync_crypto_isexpired();
|
||||||
time_t psync_crypto_expires();
|
time_t psync_crypto_expires();
|
||||||
|
|
|
||||||
|
|
@ -208,7 +208,7 @@ static int lib_setup_cripto() {
|
||||||
return PSYNC_CRYPTO_CANT_CONNECT;
|
return PSYNC_CRYPTO_CANT_CONNECT;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!psync_crypto_issetup()) {
|
if(!pcryptofolder_issetup()) {
|
||||||
std::cout << "crypto is not setup, setting it up now..." << std::endl;
|
std::cout << "crypto is not setup, setting it up now..." << std::endl;
|
||||||
if(int ret = pcryptofolder_setup(pwd, "no hint") != PSYNC_CRYPTO_SETUP_SUCCESS) {
|
if(int ret = pcryptofolder_setup(pwd, "no hint") != PSYNC_CRYPTO_SETUP_SUCCESS) {
|
||||||
std::cout << "crypto setup failed, error code was " << ret << std::endl;
|
std::cout << "crypto setup failed, error code was " << ret << std::endl;
|
||||||
|
|
@ -342,34 +342,34 @@ static void status_change(pstatus_t *status) {
|
||||||
psync_free(err);
|
psync_free(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
int clib::pclsync_lib::start_crypto(const char *pass) {
|
int clib::pclsync_lib::start_crypto(const char *pwd) {
|
||||||
get_lib().crypto_pass_ = pass;
|
get_lib().crypto_pass_ = pwd;
|
||||||
return lib_setup_cripto();
|
return lib_setup_cripto();
|
||||||
}
|
}
|
||||||
|
|
||||||
int clib::pclsync_lib::stop_crypto(const char *path) {
|
int clib::pclsync_lib::stop_crypto(const char *unused) {
|
||||||
(void)path;
|
(void)unused;
|
||||||
|
|
||||||
pcryptofolder_lock();
|
pcryptofolder_lock();
|
||||||
get_lib().crypto_on_ = false;
|
get_lib().crypto_on_ = false;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int clib::pclsync_lib::finalize(const char *path) {
|
int clib::pclsync_lib::finalize(const char *unused) {
|
||||||
(void)path;
|
(void)unused;
|
||||||
|
|
||||||
psync_destroy();
|
psync_destroy();
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
// path is the local and remote path delimited by '|'
|
// path is the local and remote path delimited by '|'
|
||||||
int clib::pclsync_lib::add_sync_folder(const char *path) {
|
int clib::pclsync_lib::add_sync_folder(const char *combined_path) {
|
||||||
if (path == nullptr) {
|
if (combined_path == nullptr) {
|
||||||
std::cerr << "Error: path is nullptr" << std::endl;
|
std::cerr << "Error: path is nullptr" << std::endl;
|
||||||
return -255;
|
return -255;
|
||||||
}
|
}
|
||||||
const char delimiter = '|';
|
const char delimiter = '|';
|
||||||
std::string combined(path);
|
std::string combined(combined_path);
|
||||||
size_t delimiter_pos = combined.find(delimiter);
|
size_t delimiter_pos = combined.find(delimiter);
|
||||||
if (delimiter_pos == std::string::npos) {
|
if (delimiter_pos == std::string::npos) {
|
||||||
std::cerr << "Error: Invalid path format. Expected 'localpath|remotepath'"
|
std::cerr << "Error: Invalid path format. Expected 'localpath|remotepath'"
|
||||||
|
|
@ -395,15 +395,15 @@ int clib::pclsync_lib::add_sync_folder(const char *path) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// path is the folderid to remove
|
// path is the folderid to remove
|
||||||
int clib::pclsync_lib::remove_sync_folder(const char *path) {
|
int clib::pclsync_lib::remove_sync_folder(const char *fid) {
|
||||||
psync_folderid_t folderid;
|
psync_folderid_t folderid;
|
||||||
folderid = static_cast<psync_folderid_t>(std::stoull(path, nullptr, 10));
|
folderid = static_cast<psync_folderid_t>(std::stoull(fid, nullptr, 10));
|
||||||
return psync_delete_sync_by_folderid(folderid);
|
return psync_delete_sync_by_folderid(folderid);
|
||||||
}
|
}
|
||||||
|
|
||||||
// path is not used
|
// path is not used
|
||||||
int clib::pclsync_lib::list_sync_folders(const char *path) {
|
int clib::pclsync_lib::list_sync_folders(const char *unused) {
|
||||||
(void)path;
|
(void)unused;
|
||||||
|
|
||||||
psync_folder_list_t *folders;
|
psync_folder_list_t *folders;
|
||||||
size_t folderssz;
|
size_t folderssz;
|
||||||
|
|
@ -459,12 +459,12 @@ int clib::pclsync_lib::init() {
|
||||||
psync_free(username_old);
|
psync_free(username_old);
|
||||||
}
|
}
|
||||||
|
|
||||||
prpc_register(STARTCRYPTO, &clib::pclsync_lib::start_crypto);
|
prpc_register(STARTCRYPTO, &start_crypto);
|
||||||
prpc_register(STOPCRYPTO, &clib::pclsync_lib::stop_crypto);
|
prpc_register(STOPCRYPTO, &stop_crypto);
|
||||||
prpc_register(FINALIZE, &clib::pclsync_lib::finalize);
|
prpc_register(FINALIZE, &finalize);
|
||||||
prpc_register(LISTSYNC, &clib::pclsync_lib::list_sync_folders);
|
prpc_register(LISTSYNC, &list_sync_folders);
|
||||||
prpc_register(ADDSYNC, &clib::pclsync_lib::add_sync_folder);
|
prpc_register(ADDSYNC, &add_sync_folder);
|
||||||
prpc_register(STOPSYNC, &clib::pclsync_lib::remove_sync_folder);
|
prpc_register(STOPSYNC, &remove_sync_folder);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue