constant name cleanup
This commit is contained in:
parent
27f6e313dc
commit
87f6a36df4
|
|
@ -182,7 +182,7 @@ pcrypto_ctr_encdec_create(pssl_symkey_t *key) {
|
|||
PSYNC_AES256_KEY_SIZE + PSYNC_AES256_BLOCK_SIZE))
|
||||
return PSYNC_CRYPTO_INVALID_ENCODER;
|
||||
enc = paes_encoder_create(key);
|
||||
if (unlikely_log(enc == PSYNC_INVALID_ENCODER))
|
||||
if (unlikely_log(enc == PAES_INVALID_ENCODER))
|
||||
return PSYNC_CRYPTO_INVALID_ENCODER;
|
||||
ret = psync_new(pcrypto_key_t);
|
||||
ret->encoder = enc;
|
||||
|
|
@ -405,7 +405,7 @@ pcrypto_textenc_create(pssl_symkey_t *key) {
|
|||
PSYNC_AES256_KEY_SIZE + PSYNC_AES256_BLOCK_SIZE))
|
||||
return PSYNC_CRYPTO_INVALID_ENCODER;
|
||||
enc = paes_encoder_create(key);
|
||||
if (unlikely_log(enc == PSYNC_INVALID_ENCODER))
|
||||
if (unlikely_log(enc == PAES_INVALID_ENCODER))
|
||||
return PSYNC_CRYPTO_INVALID_ENCODER;
|
||||
ret = (pcrypto_textenc_t)pmemlock_malloc(
|
||||
offsetof(pcrypto_key_iv_t, iv) + key->keylen -
|
||||
|
|
@ -431,7 +431,7 @@ pcrypto_textdec_create(pssl_symkey_t *key) {
|
|||
PSYNC_AES256_KEY_SIZE + PSYNC_AES256_BLOCK_SIZE))
|
||||
return PSYNC_CRYPTO_INVALID_ENCODER;
|
||||
enc = paes_decoder_create(key);
|
||||
if (unlikely_log(enc == PSYNC_INVALID_ENCODER))
|
||||
if (unlikely_log(enc == PAES_INVALID_ENCODER))
|
||||
return PSYNC_CRYPTO_INVALID_ENCODER;
|
||||
ret = (pcrypto_textenc_t)pmemlock_malloc(
|
||||
offsetof(pcrypto_key_iv_t, iv) + key->keylen -
|
||||
|
|
@ -457,10 +457,10 @@ pcrypto_sec_encdec_create(pssl_symkey_t *key) {
|
|||
if (unlikely_log(key->keylen < PSYNC_AES256_KEY_SIZE))
|
||||
return PSYNC_CRYPTO_INVALID_ENCODER;
|
||||
enc = paes_encoder_create(key);
|
||||
if (unlikely_log(enc == PSYNC_INVALID_ENCODER))
|
||||
if (unlikely_log(enc == PAES_INVALID_ENCODER))
|
||||
return PSYNC_CRYPTO_INVALID_ENCODER;
|
||||
dec = paes_decoder_create(key);
|
||||
if (unlikely_log(enc == PSYNC_INVALID_ENCODER)) {
|
||||
if (unlikely_log(enc == PAES_INVALID_ENCODER)) {
|
||||
paes_encoder_free(enc);
|
||||
return PSYNC_CRYPTO_INVALID_ENCODER;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -69,8 +69,8 @@ static const char *crypto_errors[] = {"Success.",
|
|||
"Folder is not encrypted."};
|
||||
|
||||
static uint32_t crypto_started_l = 0;
|
||||
static pssl_rsapubkey_t crypto_pubkey = PSYNC_INVALID_RSA;
|
||||
static pssl_rsaprivkey_t crypto_privkey = PSYNC_INVALID_RSA;
|
||||
static pssl_rsapubkey_t crypto_pubkey = PRSA_INVALID;
|
||||
static pssl_rsaprivkey_t crypto_privkey = PRSA_INVALID;
|
||||
static pthread_rwlock_t crypto_lock = PTHREAD_RWLOCK_INITIALIZER;
|
||||
static uint32_t crypto_started_un = 0;
|
||||
|
||||
|
|
@ -392,7 +392,7 @@ int pcryptofolder_setup(const char *password, const char *hint) {
|
|||
}
|
||||
debug(D_NOTICE, "generating %d bit RSA key", (int)PSYNC_CRYPTO_RSA_SIZE);
|
||||
rsa = prsa_generate(PSYNC_CRYPTO_RSA_SIZE);
|
||||
if (unlikely(rsa == PSYNC_INVALID_RSA)) {
|
||||
if (unlikely(rsa == PRSA_INVALID)) {
|
||||
debug(D_WARNING, "RSA key generation failed");
|
||||
pcrypto_ctr_encdec_free(enc);
|
||||
return PSYNC_CRYPTO_SETUP_KEYGEN_FAILED;
|
||||
|
|
@ -401,13 +401,13 @@ int pcryptofolder_setup(const char *password, const char *hint) {
|
|||
rsaprivate = prsa_get_private(rsa);
|
||||
rsapublic = prsa_get_public(rsa);
|
||||
prsa_free(rsa);
|
||||
if (unlikely(rsaprivate == PSYNC_INVALID_RSA ||
|
||||
rsapublic == PSYNC_INVALID_RSA)) {
|
||||
if (unlikely(rsaprivate == PRSA_INVALID ||
|
||||
rsapublic == PRSA_INVALID)) {
|
||||
debug(D_WARNING,
|
||||
"psync_ssl_rsa_get_private or psync_ssl_rsa_get_public failed");
|
||||
if (rsaprivate != PSYNC_INVALID_RSA)
|
||||
if (rsaprivate != PRSA_INVALID)
|
||||
prsa_free_private(rsaprivate);
|
||||
if (rsapublic != PSYNC_INVALID_RSA)
|
||||
if (rsapublic != PRSA_INVALID)
|
||||
prsa_free_public(rsapublic);
|
||||
pcrypto_ctr_encdec_free(enc);
|
||||
return PSYNC_CRYPTO_SETUP_KEYGEN_FAILED;
|
||||
|
|
@ -416,13 +416,13 @@ int pcryptofolder_setup(const char *password, const char *hint) {
|
|||
rsapublicbin = prsa_binary_public(rsapublic);
|
||||
prsa_free_private(rsaprivate);
|
||||
prsa_free_public(rsapublic);
|
||||
if (unlikely(rsaprivatebin == PSYNC_INVALID_BIN_RSA ||
|
||||
rsapublic == PSYNC_INVALID_BIN_RSA)) {
|
||||
if (unlikely(rsaprivatebin == PRSA_INVALID_BIN_KEY ||
|
||||
rsapublic == PRSA_INVALID_BIN_KEY)) {
|
||||
debug(D_WARNING, "psync_ssl_rsa_private_to_binary or "
|
||||
"psync_ssl_rsa_public_to_binary failed");
|
||||
if (rsaprivatebin != PSYNC_INVALID_BIN_RSA)
|
||||
if (rsaprivatebin != PRSA_INVALID_BIN_KEY)
|
||||
prsa_binary_free(rsaprivatebin);
|
||||
if (rsapublicbin != PSYNC_INVALID_BIN_RSA)
|
||||
if (rsapublicbin != PRSA_INVALID_BIN_KEY)
|
||||
prsa_binary_free(rsapublicbin);
|
||||
pcrypto_ctr_encdec_free(enc);
|
||||
return PSYNC_CRYPTO_SETUP_KEYGEN_FAILED;
|
||||
|
|
@ -504,7 +504,7 @@ static int crypto_keys_match() {
|
|||
key->keylen = 64;
|
||||
pssl_random(key->key, key->keylen);
|
||||
enckey = psymkey_encrypt(crypto_pubkey, key->key, key->keylen);
|
||||
if (enckey == PSYNC_INVALID_ENC_SYM_KEY) {
|
||||
if (enckey == PSYMKEY_INVALID_ENC) {
|
||||
psync_free(key);
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -512,7 +512,7 @@ static int crypto_keys_match() {
|
|||
deckey = psymkey_decrypt_lock(&crypto_privkey, &enckey);
|
||||
|
||||
psync_free(enckey);
|
||||
if (deckey == PSYNC_INVALID_SYM_KEY) {
|
||||
if (deckey == PSYMKEY_INVALID) {
|
||||
psync_free(key);
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -606,7 +606,7 @@ retry:
|
|||
|
||||
debug(D_NOTICE, "trying to load public key");
|
||||
crypto_pubkey = prsa_load_public(rsapub, rsapublen);
|
||||
if (crypto_pubkey == PSYNC_INVALID_RSA) {
|
||||
if (crypto_pubkey == PRSA_INVALID) {
|
||||
pthread_rwlock_unlock(&crypto_lock);
|
||||
debug(D_WARNING, "could not load public key");
|
||||
psync_free(rsapriv);
|
||||
|
|
@ -634,10 +634,10 @@ retry:
|
|||
crypto_privkey = prsa_load_private(rsaprivdec, rsaprivlen);
|
||||
pssl_cleanup(rsaprivdec, rsaprivlen);
|
||||
pmemlock_free(rsaprivdec);
|
||||
if (crypto_privkey == PSYNC_INVALID_RSA) {
|
||||
if (crypto_privkey == PRSA_INVALID) {
|
||||
debug(D_NOTICE, "failed to load private key");
|
||||
prsa_free_public(crypto_pubkey);
|
||||
crypto_pubkey = PSYNC_INVALID_RSA;
|
||||
crypto_pubkey = PRSA_INVALID;
|
||||
pthread_rwlock_unlock(&crypto_lock);
|
||||
psync_free(rsapriv);
|
||||
psync_free(rsapub);
|
||||
|
|
@ -649,9 +649,9 @@ retry:
|
|||
debug(D_NOTICE, "verify matching public and private key");
|
||||
if (!crypto_keys_match()) {
|
||||
prsa_free_public(crypto_pubkey);
|
||||
crypto_pubkey = PSYNC_INVALID_RSA;
|
||||
crypto_pubkey = PRSA_INVALID;
|
||||
prsa_free_private(crypto_privkey);
|
||||
crypto_privkey = PSYNC_INVALID_RSA;
|
||||
crypto_privkey = PRSA_INVALID;
|
||||
pthread_rwlock_unlock(&crypto_lock);
|
||||
debug(D_ERROR, "keys don't match");
|
||||
psync_free(rsapriv);
|
||||
|
|
@ -697,9 +697,9 @@ int pcryptofolder_lock() {
|
|||
}
|
||||
crypto_started_l = 0;
|
||||
prsa_free_public(crypto_pubkey);
|
||||
crypto_pubkey = PSYNC_INVALID_RSA;
|
||||
crypto_pubkey = PRSA_INVALID;
|
||||
prsa_free_private(crypto_privkey);
|
||||
crypto_privkey = PSYNC_INVALID_RSA;
|
||||
crypto_privkey = PRSA_INVALID;
|
||||
pthread_rwlock_unlock(&crypto_lock);
|
||||
debug(D_NOTICE, "stopped crypto");
|
||||
pcryptofolder_cache_clean();
|
||||
|
|
@ -1002,7 +1002,7 @@ static pssl_symkey_t
|
|||
symkey = psymkey_decrypt_lock(&crypto_privkey, &enckey);
|
||||
|
||||
psync_free(enckey);
|
||||
if (symkey == PSYNC_INVALID_SYM_KEY)
|
||||
if (symkey == PSYMKEY_INVALID)
|
||||
return (pssl_symkey_t *)err_to_ptr(
|
||||
PRINT_RETURN_CONST(PSYNC_CRYPTO_INVALID_KEY));
|
||||
return symkey;
|
||||
|
|
@ -1031,7 +1031,7 @@ static pssl_symkey_t
|
|||
symkey = psymkey_decrypt_lock(&crypto_privkey, &enckey);
|
||||
|
||||
psync_free(enckey);
|
||||
if (unlikely_log(symkey == PSYNC_INVALID_SYM_KEY))
|
||||
if (unlikely_log(symkey == PSYMKEY_INVALID))
|
||||
return (pssl_symkey_t *)err_to_ptr(
|
||||
PRINT_RETURN_CONST(PSYNC_CRYPTO_INVALID_KEY));
|
||||
return symkey;
|
||||
|
|
@ -1176,13 +1176,13 @@ psync_crypto_get_temp_folder_encoder_locked(psync_fsfolderid_t folderid) {
|
|||
symkey = psymkey_decrypt(crypto_privkey, enckey, enckeylen);
|
||||
psync_free(enckey);
|
||||
} else
|
||||
symkey = PSYNC_INVALID_SYM_KEY;
|
||||
symkey = PSYMKEY_INVALID;
|
||||
} else {
|
||||
psync_sql_free_result(res);
|
||||
return (pcrypto_textenc_t)err_to_ptr(
|
||||
PRINT_RETURN_CONST(PSYNC_CRYPTO_FOLDER_NOT_FOUND));
|
||||
}
|
||||
if (symkey == PSYNC_INVALID_SYM_KEY)
|
||||
if (symkey == PSYMKEY_INVALID)
|
||||
return (pcrypto_textenc_t)err_to_ptr(
|
||||
PRINT_RETURN_CONST(PSYNC_CRYPTO_INVALID_KEY));
|
||||
skv1 = (sym_key_ver1 *)symkey->key;
|
||||
|
|
@ -1233,10 +1233,10 @@ psync_crypto_get_temp_folder_decoder_locked(psync_fsfolderid_t folderid) {
|
|||
symkey = psymkey_decrypt(crypto_privkey, enckey, enckeylen);
|
||||
|
||||
psync_free(enckey);
|
||||
if (symkey == PSYNC_INVALID_SYM_KEY)
|
||||
if (symkey == PSYMKEY_INVALID)
|
||||
debug(D_WARNING, "got key from database that fails rsa decrypt");
|
||||
} else {
|
||||
symkey = PSYNC_INVALID_SYM_KEY;
|
||||
symkey = PSYMKEY_INVALID;
|
||||
debug(D_WARNING, "got key from database that fails base64_decode");
|
||||
}
|
||||
} else {
|
||||
|
|
@ -1244,7 +1244,7 @@ psync_crypto_get_temp_folder_decoder_locked(psync_fsfolderid_t folderid) {
|
|||
return (pcrypto_textdec_t)err_to_ptr(
|
||||
PRINT_RETURN_CONST(PSYNC_CRYPTO_FOLDER_NOT_FOUND));
|
||||
}
|
||||
if (symkey == PSYNC_INVALID_SYM_KEY)
|
||||
if (symkey == PSYMKEY_INVALID)
|
||||
return (pcrypto_textdec_t)err_to_ptr(
|
||||
PRINT_RETURN_CONST(PSYNC_CRYPTO_INVALID_KEY));
|
||||
skv1 = (sym_key_ver1 *)symkey->key;
|
||||
|
|
@ -1471,8 +1471,8 @@ psync_crypto_get_temp_file_encoder_locked(psync_fsfileid_t fileid,
|
|||
|
||||
psync_free(enckey);
|
||||
} else
|
||||
symkey = PSYNC_INVALID_SYM_KEY;
|
||||
if (symkey == PSYNC_INVALID_SYM_KEY)
|
||||
symkey = PSYMKEY_INVALID;
|
||||
if (symkey == PSYMKEY_INVALID)
|
||||
return (pcrypto_sector_encdec_t)err_to_ptr(
|
||||
PRINT_RETURN_CONST(PSYNC_CRYPTO_INVALID_KEY));
|
||||
skv1 = (sym_key_ver1 *)symkey->key;
|
||||
|
|
@ -1748,7 +1748,7 @@ char *pcryptofolder_filencoder_key_new(uint32_t flags, size_t *keylen) {
|
|||
encsym = psymkey_encrypt(crypto_pubkey, (unsigned char *)&sym,
|
||||
sizeof(sym));
|
||||
pthread_rwlock_unlock(&crypto_lock);
|
||||
if (encsym == PSYNC_INVALID_ENC_SYM_KEY) {
|
||||
if (encsym == PSYMKEY_INVALID_ENC) {
|
||||
debug(D_ERROR, "RSA encryption failed");
|
||||
return (char *)err_to_ptr(PRINT_RETURN_CONST(PSYNC_CRYPTO_RSA_ERROR));
|
||||
}
|
||||
|
|
@ -1777,7 +1777,7 @@ char *pcryptofolder_filencoder_key_newplain(
|
|||
encsym = psymkey_encrypt(crypto_pubkey, (unsigned char *)&sym,
|
||||
sizeof(sym));
|
||||
pthread_rwlock_unlock(&crypto_lock);
|
||||
if (encsym == PSYNC_INVALID_ENC_SYM_KEY) {
|
||||
if (encsym == PSYMKEY_INVALID_ENC) {
|
||||
debug(D_ERROR, "RSA encryption failed");
|
||||
return (char *)err_to_ptr(PRINT_RETURN_CONST(PSYNC_CRYPTO_RSA_ERROR));
|
||||
}
|
||||
|
|
@ -1814,11 +1814,11 @@ int pcryptofolder_mkdir(psync_folderid_t folderid, const char *name,
|
|||
ret = get_name_for_folder_locked(folderid, name, &ename, err);
|
||||
pthread_rwlock_unlock(&crypto_lock);
|
||||
if (ret) {
|
||||
if (encsym != PSYNC_INVALID_ENC_SYM_KEY)
|
||||
if (encsym != PSYMKEY_INVALID_ENC)
|
||||
psync_free(encsym);
|
||||
return ret;
|
||||
}
|
||||
if (encsym == PSYNC_INVALID_ENC_SYM_KEY) {
|
||||
if (encsym == PSYMKEY_INVALID_ENC) {
|
||||
psync_free(ename);
|
||||
debug(D_ERROR, "RSA encryption failed");
|
||||
return set_err(PRINT_RETURN_CONST(PSYNC_CRYPTO_RSA_ERROR), err);
|
||||
|
|
@ -1851,7 +1851,7 @@ int psync_pcloud_crypto_reencode_key(
|
|||
goto err_bk_0;
|
||||
pub = prsa_load_public(rsapub + offsetof(pub_key_ver1, key),
|
||||
rsapublen - offsetof(pub_key_ver1, key));
|
||||
if (pub == PSYNC_INVALID_RSA)
|
||||
if (pub == PRSA_INVALID)
|
||||
goto err_bk_0;
|
||||
break;
|
||||
default:
|
||||
|
|
@ -1872,7 +1872,7 @@ int psync_pcloud_crypto_reencode_key(
|
|||
aeskey = psymkey_generate_passphrase(
|
||||
oldpassphrase, PSYNC_AES256_KEY_SIZE + PSYNC_AES256_BLOCK_SIZE,
|
||||
rsapriv_struct->salt, PSYNC_CRYPTO_PBKDF2_SALT_LEN, 20000);
|
||||
if (unlikely(aeskey == PSYNC_INVALID_SYM_KEY))
|
||||
if (unlikely(aeskey == PSYMKEY_INVALID))
|
||||
goto err_nm_1;
|
||||
rsaprivlen -= offsetof(priv_key_ver1, key);
|
||||
enc = pcrypto_ctr_encdec_create(aeskey);
|
||||
|
|
@ -1899,7 +1899,7 @@ int psync_pcloud_crypto_reencode_key(
|
|||
aeskey = psymkey_generate_passphrase(
|
||||
newpassphrase, PSYNC_AES256_KEY_SIZE + PSYNC_AES256_BLOCK_SIZE,
|
||||
rsapriv_struct->salt, PSYNC_CRYPTO_PBKDF2_SALT_LEN, 20000);
|
||||
if (unlikely(aeskey == PSYNC_INVALID_SYM_KEY))
|
||||
if (unlikely(aeskey == PSYMKEY_INVALID))
|
||||
goto err_nm_1;
|
||||
// rsaprivlen-=offsetof(priv_key_ver1, key);
|
||||
enc = pcrypto_ctr_encdec_create(aeskey);
|
||||
|
|
@ -1914,7 +1914,7 @@ int psync_pcloud_crypto_reencode_key(
|
|||
priv = prsa_load_private(rsaprivdec, rsaprivlen);
|
||||
pssl_cleanup(rsaprivdec, rsaprivlen);
|
||||
psync_free(rsaprivdec);
|
||||
if (unlikely(priv == PSYNC_INVALID_RSA))
|
||||
if (unlikely(priv == PRSA_INVALID))
|
||||
goto err_ph_1;
|
||||
break;
|
||||
}
|
||||
|
|
@ -1973,7 +1973,7 @@ int psync_pcloud_crypto_encode_key(const char *newpassphrase, uint32_t flags,
|
|||
unsigned char newprivsha[PSYNC_SHA256_DIGEST_LEN];
|
||||
pssl_signature_t rsasign;
|
||||
rsapriv = prsa_binary_private(crypto_privkey);
|
||||
if (rsapriv == PSYNC_INVALID_RSA)
|
||||
if (rsapriv == PRSA_INVALID)
|
||||
goto err_nm_0;
|
||||
rsaprivlen = rsapriv->datalen;
|
||||
newpriv =
|
||||
|
|
@ -1987,7 +1987,7 @@ int psync_pcloud_crypto_encode_key(const char *newpassphrase, uint32_t flags,
|
|||
aeskey = psymkey_generate_passphrase(
|
||||
newpassphrase, PSYNC_AES256_KEY_SIZE + PSYNC_AES256_BLOCK_SIZE,
|
||||
rsapriv_struct->salt, PSYNC_CRYPTO_PBKDF2_SALT_LEN, 20000);
|
||||
if (unlikely(aeskey == PSYNC_INVALID_SYM_KEY))
|
||||
if (unlikely(aeskey == PSYMKEY_INVALID))
|
||||
goto err_nm_1;
|
||||
enc = pcrypto_ctr_encdec_create(aeskey);
|
||||
psymkey_free(aeskey);
|
||||
|
|
|
|||
|
|
@ -116,9 +116,9 @@ static const uint32_t requiredstatuses[] = {
|
|||
static struct sockaddr_storage paddr;
|
||||
static socklen_t paddrlen;
|
||||
|
||||
static pssl_rsapubkey_t pubkey = PSYNC_INVALID_RSA;
|
||||
static pssl_rsaprivkey_t privkey = PSYNC_INVALID_RSA;
|
||||
static pssl_rsabinkey_t pubkeybin = PSYNC_INVALID_BIN_RSA;
|
||||
static pssl_rsapubkey_t pubkey = PRSA_INVALID;
|
||||
static pssl_rsaprivkey_t privkey = PRSA_INVALID;
|
||||
static pssl_rsabinkey_t pubkeybin = PRSA_INVALID_BIN_KEY;
|
||||
|
||||
PSYNC_PURE static const char *get_addr(void *addr) {
|
||||
if (((struct sockaddr_in *)addr)->sin_family == AF_INET)
|
||||
|
|
@ -363,7 +363,7 @@ static void psync_p2p_tcphandler(void *ptr) {
|
|||
psync_free(token);
|
||||
pubrsa = prsa_load_public(binpubrsa->data, binpubrsa->datalen);
|
||||
psync_free(binpubrsa);
|
||||
if (unlikely_log(pubrsa == PSYNC_INVALID_RSA))
|
||||
if (unlikely_log(pubrsa == PRSA_INVALID))
|
||||
goto err0;
|
||||
localpath = pfolder_lpath_lfile(localfileid, NULL);
|
||||
if (unlikely_log(!localpath))
|
||||
|
|
@ -383,13 +383,13 @@ static void psync_p2p_tcphandler(void *ptr) {
|
|||
psymkey_free(aeskey);
|
||||
keylen = encaeskey->datalen;
|
||||
enctype = P2P_ENCTYPE_RSA_AES;
|
||||
if (unlikely_log(encaeskey == PSYNC_INVALID_ENC_SYM_KEY) ||
|
||||
if (unlikely_log(encaeskey == PSYMKEY_INVALID_ENC) ||
|
||||
unlikely_log(encoder == PSYNC_CRYPTO_INVALID_ENCODER) ||
|
||||
unlikely_log(
|
||||
socket_write_all(sock, &keylen, sizeof(keylen)) ||
|
||||
socket_write_all(sock, &enctype, sizeof(enctype)) ||
|
||||
socket_write_all(sock, encaeskey->data, encaeskey->datalen))) {
|
||||
if (encaeskey != PSYNC_INVALID_ENC_SYM_KEY)
|
||||
if (encaeskey != PSYMKEY_INVALID_ENC)
|
||||
psync_free(encaeskey);
|
||||
if (encoder != PSYNC_CRYPTO_INVALID_ENCODER)
|
||||
pcrypto_ctr_encdec_free(encoder);
|
||||
|
|
@ -569,7 +569,7 @@ void pp2p_change() {
|
|||
static int psync_p2p_check_rsa() {
|
||||
static pthread_mutex_t rsa_lock = PTHREAD_MUTEX_INITIALIZER;
|
||||
pthread_mutex_lock(&rsa_lock);
|
||||
if (privkey == PSYNC_INVALID_RSA) {
|
||||
if (privkey == PRSA_INVALID) {
|
||||
pssl_context_t rsa;
|
||||
pssl_rsaprivkey_t rsapriv;
|
||||
pssl_rsapubkey_t rsapub;
|
||||
|
|
@ -577,28 +577,28 @@ static int psync_p2p_check_rsa() {
|
|||
debug(D_NOTICE, "generating %ubit RSA key", PSYNC_P2P_RSA_SIZE);
|
||||
rsa = prsa_generate(PSYNC_P2P_RSA_SIZE);
|
||||
debug(D_NOTICE, "key generated");
|
||||
if (unlikely_log(rsa == PSYNC_INVALID_RSA))
|
||||
if (unlikely_log(rsa == PRSA_INVALID))
|
||||
goto rete;
|
||||
rsapriv = prsa_get_private(rsa);
|
||||
rsapub = prsa_get_public(rsa);
|
||||
if (likely_log(rsapub != PSYNC_INVALID_RSA))
|
||||
if (likely_log(rsapub != PRSA_INVALID))
|
||||
rsapubbin = prsa_binary_public(rsapub);
|
||||
else
|
||||
rsapubbin = PSYNC_INVALID_BIN_RSA;
|
||||
rsapubbin = PRSA_INVALID_BIN_KEY;
|
||||
prsa_free(rsa);
|
||||
if (likely_log(rsapriv != PSYNC_INVALID_RSA &&
|
||||
rsapub != PSYNC_INVALID_RSA &&
|
||||
rsapubbin != PSYNC_INVALID_BIN_RSA)) {
|
||||
if (likely_log(rsapriv != PRSA_INVALID &&
|
||||
rsapub != PRSA_INVALID &&
|
||||
rsapubbin != PRSA_INVALID_BIN_KEY)) {
|
||||
pubkey = rsapriv;
|
||||
privkey = rsapub;
|
||||
pubkeybin = rsapubbin;
|
||||
goto ret0;
|
||||
} else {
|
||||
if (rsapriv != PSYNC_INVALID_RSA)
|
||||
if (rsapriv != PRSA_INVALID)
|
||||
prsa_free_private(rsapriv);
|
||||
if (rsapub != PSYNC_INVALID_RSA)
|
||||
if (rsapub != PRSA_INVALID)
|
||||
prsa_free_public(rsapub);
|
||||
if (rsapubbin != PSYNC_INVALID_BIN_RSA)
|
||||
if (rsapubbin != PRSA_INVALID_BIN_KEY)
|
||||
prsa_binary_free(rsapubbin);
|
||||
goto rete;
|
||||
}
|
||||
|
|
@ -676,7 +676,7 @@ static int psync_p2p_download(int sock, psync_fileid_t fileid,
|
|||
ekey = psymkey_alloc(keylen);
|
||||
if (unlikely_log(socket_read_all(sock, ekey->data, keylen)) ||
|
||||
unlikely_log((key = psymkey_decrypt_lock(
|
||||
&privkey, &ekey)) == PSYNC_INVALID_SYM_KEY)) {
|
||||
&privkey, &ekey)) == PSYMKEY_INVALID)) {
|
||||
psync_free(ekey);
|
||||
return PSYNC_NET_TEMPFAIL;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -112,11 +112,11 @@ static int wait_ssl_ready(int sock) {
|
|||
int res;
|
||||
FD_ZERO(&fds);
|
||||
FD_SET(sock, &fds);
|
||||
if (psync_ssl_errno == PSYNC_SSL_ERR_WANT_READ) {
|
||||
if (psync_ssl_errno == PSSL_ERR_WANT_READ) {
|
||||
rfds = &fds;
|
||||
wfds = NULL;
|
||||
tv.tv_sec = PSYNC_SOCK_READ_TIMEOUT;
|
||||
} else if (psync_ssl_errno == PSYNC_SSL_ERR_WANT_WRITE) {
|
||||
} else if (psync_ssl_errno == PSSL_ERR_WANT_WRITE) {
|
||||
rfds = NULL;
|
||||
wfds = &fds;
|
||||
tv.tv_sec = PSYNC_SOCK_WRITE_TIMEOUT;
|
||||
|
|
@ -387,9 +387,9 @@ int psock_try_write_buffer(psock_t *sock) {
|
|||
if (sock->ssl) {
|
||||
cw = pssl_write(sock->ssl, b->buff + b->roffset,
|
||||
b->woffset - b->roffset);
|
||||
if (cw == PSYNC_SSL_FAIL) {
|
||||
if (likely_log(psync_ssl_errno == PSYNC_SSL_ERR_WANT_READ ||
|
||||
psync_ssl_errno == PSYNC_SSL_ERR_WANT_WRITE))
|
||||
if (cw == PSSL_FAIL) {
|
||||
if (likely_log(psync_ssl_errno == PSSL_ERR_WANT_READ ||
|
||||
psync_ssl_errno == PSSL_ERR_WANT_WRITE))
|
||||
break;
|
||||
else {
|
||||
if (!wrt)
|
||||
|
|
@ -468,14 +468,14 @@ psock_t *psock_connect(const char *host, int unsigned port, int ssl) {
|
|||
|
||||
if (ssl) {
|
||||
ssl = pssl_open(sock, &sslc, host);
|
||||
while (ssl == PSYNC_SSL_NEED_FINISH) {
|
||||
while (ssl == PSSL_NEED_FINISH) {
|
||||
if (wait_ssl_ready(sock)) {
|
||||
pssl_free(sslc);
|
||||
break;
|
||||
}
|
||||
ssl = pssl_finish(sslc, host);
|
||||
}
|
||||
if (unlikely_log(ssl != PSYNC_SSL_SUCCESS)) {
|
||||
if (unlikely_log(ssl != PSSL_SUCCESS)) {
|
||||
close(sock);
|
||||
return NULL;
|
||||
}
|
||||
|
|
@ -496,7 +496,7 @@ int psock_wait_write_timeout(int sock) {
|
|||
|
||||
void psock_close(psock_t *sock) {
|
||||
if (sock->ssl)
|
||||
while (pssl_close(sock->ssl) == PSYNC_SSL_NEED_FINISH)
|
||||
while (pssl_close(sock->ssl) == PSSL_NEED_FINISH)
|
||||
if (wait_ssl_ready(sock->sock)) {
|
||||
pssl_free(sock->ssl);
|
||||
break;
|
||||
|
|
@ -613,9 +613,9 @@ static int psync_socket_read_ssl(psock_t *sock, void *buff, int num) {
|
|||
while (1) {
|
||||
psock_try_write_buffer(sock);
|
||||
r = pssl_read(sock->ssl, buff, num);
|
||||
if (r == PSYNC_SSL_FAIL) {
|
||||
if (likely_log(psync_ssl_errno == PSYNC_SSL_ERR_WANT_READ ||
|
||||
psync_ssl_errno == PSYNC_SSL_ERR_WANT_WRITE)) {
|
||||
if (r == PSSL_FAIL) {
|
||||
if (likely_log(psync_ssl_errno == PSSL_ERR_WANT_READ ||
|
||||
psync_ssl_errno == PSSL_ERR_WANT_WRITE)) {
|
||||
if (wait_ssl_ready(sock->sock)) {
|
||||
if (sock->buffer)
|
||||
debug(D_WARNING, "timeouted on socket with pending buffers");
|
||||
|
|
@ -663,10 +663,10 @@ int psock_read(psock_t *sock, void *buff, int num) {
|
|||
static int psync_socket_read_noblock_ssl(psock_t *sock, void *buff, int num) {
|
||||
int r;
|
||||
r = pssl_read(sock->ssl, buff, num);
|
||||
if (r == PSYNC_SSL_FAIL) {
|
||||
if (r == PSSL_FAIL) {
|
||||
sock->pending = 0;
|
||||
if (likely_log(psync_ssl_errno == PSYNC_SSL_ERR_WANT_READ ||
|
||||
psync_ssl_errno == PSYNC_SSL_ERR_WANT_WRITE))
|
||||
if (likely_log(psync_ssl_errno == PSSL_ERR_WANT_READ ||
|
||||
psync_ssl_errno == PSSL_ERR_WANT_WRITE))
|
||||
return PSYNC_SOCKET_WOULDBLOCK;
|
||||
else {
|
||||
errno = (ECONNRESET);
|
||||
|
|
@ -711,9 +711,9 @@ static int psync_socket_read_ssl_thread(psock_t *sock, void *buff, int num) {
|
|||
psock_try_write_buffer(sock);
|
||||
r = pssl_read(sock->ssl, buff, num);
|
||||
pthread_mutex_unlock(&mutex);
|
||||
if (r == PSYNC_SSL_FAIL) {
|
||||
if (likely_log(psync_ssl_errno == PSYNC_SSL_ERR_WANT_READ ||
|
||||
psync_ssl_errno == PSYNC_SSL_ERR_WANT_WRITE)) {
|
||||
if (r == PSSL_FAIL) {
|
||||
if (likely_log(psync_ssl_errno == PSSL_ERR_WANT_READ ||
|
||||
psync_ssl_errno == PSSL_ERR_WANT_WRITE)) {
|
||||
if (wait_ssl_ready(sock->sock))
|
||||
return -1;
|
||||
else
|
||||
|
|
@ -802,9 +802,9 @@ int psock_write(psock_t *sock, const void *buff, int num) {
|
|||
return -1;
|
||||
if (sock->ssl) {
|
||||
r = pssl_write(sock->ssl, buff, num);
|
||||
if (r == PSYNC_SSL_FAIL) {
|
||||
if (likely_log(psync_ssl_errno == PSYNC_SSL_ERR_WANT_READ ||
|
||||
psync_ssl_errno == PSYNC_SSL_ERR_WANT_WRITE))
|
||||
if (r == PSSL_FAIL) {
|
||||
if (likely_log(psync_ssl_errno == PSSL_ERR_WANT_READ ||
|
||||
psync_ssl_errno == PSSL_ERR_WANT_WRITE))
|
||||
return 0;
|
||||
else
|
||||
return -1;
|
||||
|
|
@ -839,9 +839,9 @@ static int psync_socket_readall_ssl(psock_t *sock, void *buff, int num) {
|
|||
|
||||
r = pssl_read(sock->ssl, (char *)buff + br, num - br);
|
||||
|
||||
if (r == PSYNC_SSL_FAIL) {
|
||||
if (likely_log(psync_ssl_errno == PSYNC_SSL_ERR_WANT_READ ||
|
||||
psync_ssl_errno == PSYNC_SSL_ERR_WANT_WRITE)) {
|
||||
if (r == PSSL_FAIL) {
|
||||
if (likely_log(psync_ssl_errno == PSSL_ERR_WANT_READ ||
|
||||
psync_ssl_errno == PSSL_ERR_WANT_WRITE)) {
|
||||
if (wait_ssl_ready(sock->sock))
|
||||
return -1;
|
||||
else
|
||||
|
|
@ -897,9 +897,9 @@ static int psync_socket_writeall_ssl(psock_t *sock, const void *buff, int num) {
|
|||
br = 0;
|
||||
while (br < num) {
|
||||
r = pssl_write(sock->ssl, (char *)buff + br, num - br);
|
||||
if (r == PSYNC_SSL_FAIL) {
|
||||
if (psync_ssl_errno == PSYNC_SSL_ERR_WANT_READ ||
|
||||
psync_ssl_errno == PSYNC_SSL_ERR_WANT_WRITE) {
|
||||
if (r == PSSL_FAIL) {
|
||||
if (psync_ssl_errno == PSSL_ERR_WANT_READ ||
|
||||
psync_ssl_errno == PSSL_ERR_WANT_WRITE) {
|
||||
if (wait_ssl_ready(sock->sock))
|
||||
return -1;
|
||||
else
|
||||
|
|
@ -959,9 +959,9 @@ static int psync_socket_readall_ssl_thread(psock_t *sock, void *buff, int num) {
|
|||
psock_try_write_buffer(sock);
|
||||
r = pssl_read(sock->ssl, (char *)buff + br, num - br);
|
||||
pthread_mutex_unlock(&mutex);
|
||||
if (r == PSYNC_SSL_FAIL) {
|
||||
if (likely_log(psync_ssl_errno == PSYNC_SSL_ERR_WANT_READ ||
|
||||
psync_ssl_errno == PSYNC_SSL_ERR_WANT_WRITE)) {
|
||||
if (r == PSSL_FAIL) {
|
||||
if (likely_log(psync_ssl_errno == PSSL_ERR_WANT_READ ||
|
||||
psync_ssl_errno == PSSL_ERR_WANT_WRITE)) {
|
||||
if (wait_ssl_ready(sock->sock))
|
||||
return -1;
|
||||
else
|
||||
|
|
@ -1025,9 +1025,9 @@ static int psync_socket_writeall_ssl_thread(psock_t *sock, const void *buff,
|
|||
else
|
||||
r = pssl_write(sock->ssl, (char *)buff + br, num - br);
|
||||
pthread_mutex_unlock(&mutex);
|
||||
if (r == PSYNC_SSL_FAIL) {
|
||||
if (psync_ssl_errno == PSYNC_SSL_ERR_WANT_READ ||
|
||||
psync_ssl_errno == PSYNC_SSL_ERR_WANT_WRITE) {
|
||||
if (r == PSSL_FAIL) {
|
||||
if (psync_ssl_errno == PSSL_ERR_WANT_READ ||
|
||||
psync_ssl_errno == PSSL_ERR_WANT_WRITE) {
|
||||
if (wait_ssl_ready(sock->sock))
|
||||
return -1;
|
||||
else
|
||||
|
|
|
|||
|
|
@ -201,11 +201,11 @@ static void save_session(ssl_connection_t *conn) {
|
|||
|
||||
static void set_errno(ssl_connection_t *conn, int err) {
|
||||
if (err == MBEDTLS_ERR_SSL_WANT_READ)
|
||||
psync_ssl_errno = PSYNC_SSL_ERR_WANT_READ;
|
||||
psync_ssl_errno = PSSL_ERR_WANT_READ;
|
||||
else if (err == MBEDTLS_ERR_SSL_WANT_WRITE)
|
||||
psync_ssl_errno = PSYNC_SSL_ERR_WANT_WRITE;
|
||||
psync_ssl_errno = PSSL_ERR_WANT_WRITE;
|
||||
else {
|
||||
psync_ssl_errno = PSYNC_SSL_ERR_UNKNOWN;
|
||||
psync_ssl_errno = PSSL_ERR_UNKNOWN;
|
||||
conn->isbroken = 1;
|
||||
if (err == MBEDTLS_ERR_NET_RECV_FAILED)
|
||||
debug(D_NOTICE, "got MBEDTLS_ERR_NET_RECV_FAILED");
|
||||
|
|
@ -289,11 +289,11 @@ pssl_rsabinkey_t prsa_binary_private(pssl_rsaprivkey_t rsa) {
|
|||
mbedtls_pk_init(&ctx);
|
||||
if (mbedtls_pk_setup(&ctx, mbedtls_pk_info_from_type(MBEDTLS_PK_RSA)) ||
|
||||
mbedtls_rsa_copy(mbedtls_pk_rsa(ctx), rsa))
|
||||
return PSYNC_INVALID_BIN_RSA;
|
||||
return PRSA_INVALID_BIN_KEY;
|
||||
len = mbedtls_pk_write_key_der(&ctx, buff, sizeof(buff));
|
||||
mbedtls_pk_free(&ctx);
|
||||
if (len <= 0)
|
||||
return PSYNC_INVALID_BIN_RSA;
|
||||
return PRSA_INVALID_BIN_KEY;
|
||||
ret =
|
||||
pmemlock_malloc(offsetof(pssl_enc_data_t, data) + len);
|
||||
ret->datalen = len;
|
||||
|
|
@ -310,12 +310,12 @@ pssl_rsabinkey_t prsa_binary_public(pssl_rsapubkey_t rsa) {
|
|||
mbedtls_pk_init(&ctx);
|
||||
if (mbedtls_pk_setup(&ctx, mbedtls_pk_info_from_type(MBEDTLS_PK_RSA)) ||
|
||||
mbedtls_rsa_copy(mbedtls_pk_rsa(ctx), rsa))
|
||||
return PSYNC_INVALID_BIN_RSA;
|
||||
return PRSA_INVALID_BIN_KEY;
|
||||
p = buff + sizeof(buff);
|
||||
len = mbedtls_pk_write_pubkey(&p, buff, &ctx);
|
||||
mbedtls_pk_free(&ctx);
|
||||
if (len <= 0)
|
||||
return PSYNC_INVALID_BIN_RSA;
|
||||
return PRSA_INVALID_BIN_KEY;
|
||||
ret =
|
||||
pmemlock_malloc(offsetof(pssl_enc_data_t, data) + len);
|
||||
ret->datalen = len;
|
||||
|
|
@ -345,7 +345,7 @@ pssl_context_t prsa_generate(int bits) {
|
|||
65537)) {
|
||||
mbedtls_rsa_free(ctx);
|
||||
psync_free(ctx);
|
||||
return PSYNC_INVALID_RSA;
|
||||
return PRSA_INVALID;
|
||||
} else
|
||||
return ctx;
|
||||
}
|
||||
|
|
@ -358,7 +358,7 @@ pssl_rsaprivkey_t prsa_get_private(pssl_context_t rsa) {
|
|||
if (unlikely(mbedtls_rsa_copy(ctx, rsa))) {
|
||||
mbedtls_rsa_free(ctx);
|
||||
psync_free(ctx);
|
||||
return PSYNC_INVALID_RSA;
|
||||
return PRSA_INVALID;
|
||||
} else
|
||||
return ctx;
|
||||
}
|
||||
|
|
@ -367,8 +367,8 @@ pssl_rsapubkey_t prsa_get_public(pssl_context_t rsa) {
|
|||
pssl_rsabinkey_t bin;
|
||||
pssl_rsapubkey_t ret;
|
||||
bin = prsa_binary_public(rsa);
|
||||
if (bin == PSYNC_INVALID_BIN_RSA)
|
||||
return PSYNC_INVALID_RSA;
|
||||
if (bin == PRSA_INVALID_BIN_KEY)
|
||||
return PRSA_INVALID;
|
||||
ret = prsa_load_public(bin->data, bin->datalen);
|
||||
prsa_binary_free(bin);
|
||||
return ret;
|
||||
|
|
@ -385,7 +385,7 @@ pssl_rsaprivkey_t prsa_load_private(const unsigned char *keydata, size_t keylen)
|
|||
char ebuf[100];
|
||||
mbedtls_strerror(ret, ebuf, sizeof(ebuf));
|
||||
debug(D_WARNING, "failed to parse private key: %s (-0x%04x)", ebuf, (unsigned int) -ret);
|
||||
return PSYNC_INVALID_RSA;
|
||||
return PRSA_INVALID;
|
||||
}
|
||||
|
||||
rsactx = psync_new(mbedtls_rsa_context);
|
||||
|
|
@ -397,7 +397,7 @@ pssl_rsaprivkey_t prsa_load_private(const unsigned char *keydata, size_t keylen)
|
|||
debug(D_WARNING, "rsa_copy failed with code %d", ret);
|
||||
mbedtls_rsa_free(rsactx);
|
||||
psync_free(rsactx);
|
||||
return PSYNC_INVALID_RSA;
|
||||
return PRSA_INVALID;
|
||||
} else {
|
||||
return rsactx;
|
||||
}
|
||||
|
|
@ -412,7 +412,7 @@ pssl_rsapubkey_t prsa_load_public(const unsigned char *keydata, size_t keylen) {
|
|||
ret = mbedtls_pk_parse_public_key(&ctx, keydata, keylen);
|
||||
if (unlikely(ret)) {
|
||||
debug(D_ERROR, "failed to parse public key with code %d", ret);
|
||||
return PSYNC_INVALID_RSA;
|
||||
return PRSA_INVALID;
|
||||
}
|
||||
|
||||
rsa = psync_new(mbedtls_rsa_context);
|
||||
|
|
@ -424,7 +424,7 @@ pssl_rsapubkey_t prsa_load_public(const unsigned char *keydata, size_t keylen) {
|
|||
debug(D_WARNING, "rsa_copy failed with code %d", ret);
|
||||
mbedtls_rsa_free(rsa);
|
||||
psync_free(rsa);
|
||||
return PSYNC_INVALID_RSA;
|
||||
return PRSA_INVALID;
|
||||
} else {
|
||||
mbedtls_rsa_set_padding(rsa, MBEDTLS_RSA_PKCS_V21, MBEDTLS_MD_SHA1);
|
||||
return rsa;
|
||||
|
|
@ -478,11 +478,11 @@ int pssl_close(ssl_connection_t *sslconn) {
|
|||
set_errno(conn, ret);
|
||||
if (likely_log(ret == MBEDTLS_ERR_SSL_WANT_READ ||
|
||||
ret == MBEDTLS_ERR_SSL_WANT_WRITE))
|
||||
return PSYNC_SSL_NEED_FINISH;
|
||||
return PSSL_NEED_FINISH;
|
||||
noshutdown:
|
||||
mbedtls_ssl_free(&conn->ssl);
|
||||
psync_free(conn);
|
||||
return PSYNC_SSL_SUCCESS;
|
||||
return PSSL_SUCCESS;
|
||||
}
|
||||
|
||||
void pssl_debug_cb(psync_ssl_debug_callback_t cb, void *ctx) {
|
||||
|
|
@ -501,18 +501,18 @@ int pssl_finish(ssl_connection_t *sslconn, const char *hostname) {
|
|||
goto fail;
|
||||
}
|
||||
save_session(conn);
|
||||
return PSYNC_SSL_SUCCESS;
|
||||
return PSSL_SUCCESS;
|
||||
} else {
|
||||
debug(D_ERROR, "handshake failed, return code was %d", ret);
|
||||
}
|
||||
set_errno(conn, ret);
|
||||
if (likely_log(ret == MBEDTLS_ERR_SSL_WANT_READ ||
|
||||
ret == MBEDTLS_ERR_SSL_WANT_WRITE))
|
||||
return PSYNC_SSL_NEED_FINISH;
|
||||
return PSSL_NEED_FINISH;
|
||||
fail:
|
||||
mbedtls_ssl_free(&conn->ssl);
|
||||
psync_free(conn);
|
||||
return PRINT_RETURN_CONST(PSYNC_SSL_FAIL);
|
||||
return PRINT_RETURN_CONST(PSSL_FAIL);
|
||||
}
|
||||
|
||||
void pssl_free(ssl_connection_t *sslconn) {
|
||||
|
|
@ -634,13 +634,13 @@ int pssl_open(int sock, ssl_connection_t **sslconn, const char *hostname) {
|
|||
|
||||
save_session(conn);
|
||||
debug(D_NOTICE, "SSL connection established successfully");
|
||||
return PSYNC_SSL_SUCCESS;
|
||||
return PSSL_SUCCESS;
|
||||
}
|
||||
|
||||
set_errno(conn, ret);
|
||||
if (likely_log(ret == MBEDTLS_ERR_SSL_WANT_READ || ret == MBEDTLS_ERR_SSL_WANT_WRITE)) {
|
||||
*sslconn = conn;
|
||||
return PSYNC_SSL_NEED_FINISH;
|
||||
return PSSL_NEED_FINISH;
|
||||
}
|
||||
debug(D_ERROR, "SSL handshake failed with error code %d", ret);
|
||||
|
||||
|
|
@ -648,7 +648,7 @@ err1:
|
|||
mbedtls_ssl_free(&conn->ssl);
|
||||
err0:
|
||||
psync_free(conn);
|
||||
return PRINT_RETURN_CONST(PSYNC_SSL_FAIL);
|
||||
return PRINT_RETURN_CONST(PSSL_FAIL);
|
||||
}
|
||||
|
||||
void pssl_random(unsigned char *buf, int num) {
|
||||
|
|
@ -666,7 +666,7 @@ int pssl_read(ssl_connection_t *sslconn, void *buf, int num) {
|
|||
if (res >= 0)
|
||||
return res;
|
||||
set_errno(conn, res);
|
||||
return PSYNC_SSL_FAIL;
|
||||
return PSSL_FAIL;
|
||||
}
|
||||
|
||||
int pssl_write(ssl_connection_t *sslconn, const void *buf, int num) {
|
||||
|
|
@ -677,7 +677,7 @@ int pssl_write(ssl_connection_t *sslconn, const void *buf, int num) {
|
|||
if (res >= 0)
|
||||
return res;
|
||||
set_errno(conn, res);
|
||||
return PSYNC_SSL_FAIL;
|
||||
return PSSL_FAIL;
|
||||
}
|
||||
|
||||
pssl_enc_symkey_t psymkey_alloc(size_t len) {
|
||||
|
|
@ -703,7 +703,7 @@ pssl_symkey_t *psymkey_decrypt(pssl_rsaprivkey_t rsa, const unsigned char *data,
|
|||
if (mbedtls_rsa_rsaes_oaep_decrypt(rsa, drbg_random_safe,
|
||||
&psync_mbed_rng, NULL,
|
||||
0, &len, data, buff, sizeof(buff)))
|
||||
return PSYNC_INVALID_SYM_KEY;
|
||||
return PSYMKEY_INVALID;
|
||||
ret = (pssl_symkey_t *)pmemlock_malloc(
|
||||
offsetof(pssl_symkey_t, key) + len);
|
||||
ret->keylen = len;
|
||||
|
|
@ -768,7 +768,7 @@ pssl_enc_symkey_t psymkey_encrypt(pssl_rsapubkey_t rsa, const unsigned char *dat
|
|||
D_WARNING,
|
||||
"rsa_rsaes_oaep_encrypt failed with error=%d, datalen=%lu, rsasize=%d",
|
||||
code, (unsigned long)datalen, (int)rsalen);
|
||||
return PSYNC_INVALID_ENC_SYM_KEY;
|
||||
return PSYMKEY_INVALID_ENC;
|
||||
}
|
||||
ret->datalen = rsalen;
|
||||
debug(D_NOTICE, "datalen=%lu", (unsigned long)ret->datalen);
|
||||
|
|
|
|||
|
|
@ -84,17 +84,17 @@
|
|||
// externs
|
||||
extern PSYNC_THREAD int psync_ssl_errno;
|
||||
|
||||
#define PSYNC_INVALID_RSA NULL
|
||||
#define PSYNC_INVALID_SYM_KEY NULL
|
||||
#define PSYNC_INVALID_ENC_SYM_KEY NULL
|
||||
#define PSYNC_INVALID_ENCODER NULL
|
||||
#define PSYNC_INVALID_BIN_RSA NULL
|
||||
#define PSYNC_SSL_ERR_WANT_READ 1
|
||||
#define PSYNC_SSL_ERR_WANT_WRITE 2
|
||||
#define PSYNC_SSL_ERR_UNKNOWN 3
|
||||
#define PSYNC_SSL_NEED_FINISH -2
|
||||
#define PSYNC_SSL_FAIL -1
|
||||
#define PSYNC_SSL_SUCCESS 0
|
||||
#define PAES_INVALID_ENCODER NULL
|
||||
#define PRSA_INVALID NULL
|
||||
#define PRSA_INVALID_BIN_KEY NULL
|
||||
#define PSSL_ERR_UNKNOWN 3
|
||||
#define PSSL_ERR_WANT_READ 1
|
||||
#define PSSL_ERR_WANT_WRITE 2
|
||||
#define PSSL_FAIL -1
|
||||
#define PSSL_NEED_FINISH -2
|
||||
#define PSSL_SUCCESS 0
|
||||
#define PSYMKEY_INVALID NULL
|
||||
#define PSYMKEY_INVALID_ENC NULL
|
||||
|
||||
typedef struct {
|
||||
size_t datalen;
|
||||
|
|
|
|||
Loading…
Reference in New Issue