removed asserts and did proper error handling in crypto.c

git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@7061 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
csoler 2014-01-27 19:55:43 +00:00
parent a8feff606e
commit 257d865804

View file

@ -57,10 +57,20 @@ int ops_decrypt_and_unencode_mpi(unsigned char *buf, unsigned buflen,
mpisize=BN_num_bytes(encmpi);
/* MPI can't be more than 65,536 */
assert(mpisize <= sizeof encmpibuf);
if(!(mpisize <= sizeof encmpibuf)) // ASSERT(mpisize <= sizeof encmpibuf);
{
fprintf(stderr,"ops_decrypt_and_unencode_mpi: number size too large (%d bytes!).\n",mpisize) ;
return -1 ;
}
BN_bn2bin(encmpi, encmpibuf);
assert(skey->public_key.algorithm == OPS_PKA_RSA);
if(!(skey->public_key.algorithm == OPS_PKA_RSA)) // ASSERT(skey->public_key.algorithm == OPS_PKA_RSA);
{
fprintf(stderr,"ops_decrypt_and_unencode_mpi: encryption algorithm %02x is not supported. Sorry.\n",skey->public_key.algorithm) ;
return -1 ;
}
/*
fprintf(stderr,"\nDECRYPTING\n");
@ -72,7 +82,9 @@ int ops_decrypt_and_unencode_mpi(unsigned char *buf, unsigned buflen,
n=ops_rsa_private_decrypt(mpibuf, encmpibuf, (BN_num_bits(encmpi)+7)/8,
&skey->key.rsa, &skey->public_key.key.rsa);
assert(n != -1);
// if(n == -1) // assert(n != -1);
// return ops_false ;
/*
fprintf(stderr,"decrypted encoded m buf : ");
@ -128,15 +140,17 @@ ops_boolean_t ops_rsa_encrypt_mpi(const unsigned char *encoded_m_buf,
const size_t sz_encoded_m_buf,
const ops_public_key_t *pkey,
ops_pk_session_key_parameters_t *skp)
{
assert(sz_encoded_m_buf==(size_t) BN_num_bytes(pkey->key.rsa.n));
{
if(!(sz_encoded_m_buf==(size_t) BN_num_bytes(pkey->key.rsa.n))) // ASSERT(sz_encoded_m_buf==(size_t) BN_num_bytes(pkey->key.rsa.n));
return ops_false ;
unsigned char encmpibuf[8192];
int n=0;
n=ops_rsa_public_encrypt(encmpibuf, encoded_m_buf, sz_encoded_m_buf,
&pkey->key.rsa);
assert(n!=-1);
n=ops_rsa_public_encrypt(encmpibuf, encoded_m_buf, sz_encoded_m_buf, &pkey->key.rsa);
//if(!(n!=-1)) // ASSERT(n!=-1);
// return ops_false ;
if(n <= 0)
return ops_false;
@ -152,7 +166,7 @@ ops_boolean_t ops_rsa_encrypt_mpi(const unsigned char *encoded_m_buf,
*/
return ops_true;
}
}
#define MAXBUF 1024
@ -213,7 +227,9 @@ ops_boolean_t ops_encrypt_file(const char* input_filename,
n=read(fd_in, buffer, sizeof buffer);
if (!n)
break;
assert(n >= 0);
if(n < 0)
return ops_false ;
// FIXME: apparently writing can't fail.
ops_write(buffer, n, cinfo);
@ -473,7 +489,7 @@ ops_boolean_t ops_decrypt_file(const char* input_filename,
static ops_parse_cb_return_t
callback_write_parsed(const ops_parser_content_t *content_,
ops_parse_cb_info_t *cbinfo)
{
{
ops_parser_content_union_t* content
=(ops_parser_content_union_t *)&content_->content;
static ops_boolean_t skipping;
@ -481,7 +497,7 @@ callback_write_parsed(const ops_parser_content_t *content_,
OPS_USED(cbinfo);
// ops_print_packet(content_);
// ops_print_packet(content_);
if(content_->tag != OPS_PTAG_CT_UNARMOURED_TEXT && skipping)
{
@ -540,10 +556,9 @@ callback_write_parsed(const ops_parser_content_t *content_,
break;
// fprintf(stderr,"Unexpected packet tag=%d (0x%x)\n",content_->tag,
// content_->tag);
// assert(0);
}
return OPS_RELEASE_MEMORY;
}
}
// EOF