mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-05-02 06:06:10 -04:00
- added encryption / decryption of files and memory
- started implementation of new AuthGPG git-svn-id: http://svn.code.sf.net/p/retroshare/code/branches/v0.5-OpenPGP@5084 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
c27f695a37
commit
b43fb7e8b3
14 changed files with 862 additions and 1372 deletions
|
@ -269,6 +269,91 @@ extern void ops_encrypt_stream(ops_create_info_t* cinfo,
|
|||
ops_writer_push_literal(cinfo);
|
||||
}
|
||||
|
||||
/**
|
||||
\ingroup HighLevel_Crypto
|
||||
\brief Decrypt a chunk of memory, containing a encrypted stream.
|
||||
\param input_filename Name of file to be decrypted
|
||||
\param output_filename Name of file to write to. If NULL, the filename is constructed from the input filename, following GPG conventions.
|
||||
\param keyring Keyring to use
|
||||
\param use_armour Expect armoured text, if set
|
||||
\param allow_overwrite Allow output file to overwritten, if set.
|
||||
\param cb_get_passphrase Callback to use to get passphrase
|
||||
*/
|
||||
|
||||
ops_boolean_t ops_decrypt_memory(const unsigned char *encrypted_memory,int em_length,
|
||||
unsigned char **decrypted_memory,int *out_length,
|
||||
ops_keyring_t* keyring,
|
||||
const ops_boolean_t use_armour,
|
||||
ops_parse_cb_t* cb_get_passphrase)
|
||||
{
|
||||
int fd_in=0;
|
||||
int fd_out=0;
|
||||
char* myfilename=NULL;
|
||||
|
||||
//
|
||||
ops_parse_info_t *pinfo=NULL;
|
||||
|
||||
// setup for reading from given input file
|
||||
|
||||
ops_memory_t *input_mem = ops_memory_new() ;
|
||||
ops_memory_add(input_mem,encrypted_memory,em_length) ;
|
||||
|
||||
ops_setup_memory_read(&pinfo, input_mem, NULL, callback_write_parsed, ops_false);
|
||||
|
||||
if (pinfo == NULL)
|
||||
{
|
||||
perror("cannot create memory read");
|
||||
return ops_false;
|
||||
}
|
||||
|
||||
// setup memory chunk
|
||||
|
||||
ops_memory_t *output_mem = ops_memory_new() ;
|
||||
|
||||
ops_setup_memory_write(&pinfo->cbinfo.cinfo, &output_mem,0) ;
|
||||
|
||||
if (output_mem == NULL)
|
||||
{
|
||||
perror("Cannot create output memory");
|
||||
ops_teardown_memory_read(pinfo, input_mem);
|
||||
return ops_false;
|
||||
}
|
||||
|
||||
// \todo check for suffix matching armour param
|
||||
|
||||
// setup keyring and passphrase callback
|
||||
pinfo->cbinfo.cryptinfo.keyring=keyring;
|
||||
pinfo->cbinfo.cryptinfo.cb_get_passphrase=cb_get_passphrase;
|
||||
|
||||
// Set up armour/passphrase options
|
||||
|
||||
if (use_armour)
|
||||
ops_reader_push_dearmour(pinfo);
|
||||
|
||||
// Do it
|
||||
|
||||
ops_parse_and_print_errors(pinfo);
|
||||
|
||||
// Unsetup
|
||||
|
||||
if (use_armour)
|
||||
ops_reader_pop_dearmour(pinfo);
|
||||
|
||||
ops_boolean_t res = ops_true ;
|
||||
|
||||
// copy output memory to supplied buffer.
|
||||
//
|
||||
*out_length = ops_memory_get_length(output_mem) ;
|
||||
*decrypted_memory = ops_mallocz(*out_length) ;
|
||||
memcpy(*decrypted_memory,ops_memory_get_data(output_mem),*out_length) ;
|
||||
|
||||
ops_decrypt_memory_ABORT:
|
||||
ops_teardown_memory_write(pinfo->cbinfo.cinfo, output_mem);
|
||||
ops_teardown_memory_read(pinfo, input_mem);
|
||||
|
||||
return res ;
|
||||
}
|
||||
|
||||
/**
|
||||
\ingroup HighLevel_Crypto
|
||||
\brief Decrypt a file.
|
||||
|
@ -286,7 +371,7 @@ ops_boolean_t ops_decrypt_file(const char* input_filename,
|
|||
const ops_boolean_t use_armour,
|
||||
const ops_boolean_t allow_overwrite,
|
||||
ops_parse_cb_t* cb_get_passphrase)
|
||||
{
|
||||
{
|
||||
int fd_in=0;
|
||||
int fd_out=0;
|
||||
char* myfilename=NULL;
|
||||
|
@ -379,8 +464,7 @@ ops_boolean_t ops_decrypt_file(const char* input_filename,
|
|||
// \todo cleardown crypt
|
||||
|
||||
return ops_true;
|
||||
}
|
||||
|
||||
}
|
||||
static ops_parse_cb_return_t
|
||||
callback_write_parsed(const ops_parser_content_t *content_,
|
||||
ops_parse_cb_info_t *cbinfo)
|
||||
|
|
|
@ -34,7 +34,7 @@
|
|||
|
||||
static int debug=0;
|
||||
|
||||
#define LINE_LENGTH 75
|
||||
#define LINE_LENGTH 63
|
||||
|
||||
static const char newline[] = "\r\n";
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue