示例#1
0
int ops_setup_file_read(ops_parse_info_t **pinfo, const char *filename,
                        void* arg,
                        ops_parse_cb_return_t callback(const ops_parser_content_t *, ops_parse_cb_info_t *),
                        ops_boolean_t accumulate)
    {
    int fd=0;
    /*
     * initialise needed structures for reading
     */

    fd=open(filename,O_RDONLY | O_BINARY);

    if (fd < 0)
        {
        perror(filename);
        return fd;
        }

    *pinfo=ops_parse_info_new();
    ops_parse_cb_set(*pinfo,callback,arg);
    ops_reader_set_fd(*pinfo,fd);

    if (accumulate)
        (*pinfo)->rinfo.accumulate=ops_true;

    return fd;
    }
示例#2
0
ops_boolean_t ops_keyring_read_from_file(ops_keyring_t *keyring, const ops_boolean_t armour, const char *filename)
    {
    ops_parse_info_t *pinfo;
    int fd;
    ops_boolean_t res = ops_true;

    pinfo=ops_parse_info_new();

    // add this for the moment,
    // \todo need to fix the problems with reading signature subpackets later

    //    ops_parse_options(pinfo,OPS_PTAG_SS_ALL,OPS_PARSE_RAW);
    ops_parse_options(pinfo,OPS_PTAG_SS_ALL,OPS_PARSE_PARSED);

    fd=open(filename,O_RDONLY | O_BINARY);

    if(fd < 0)
        {
        ops_parse_info_delete(pinfo);
        perror(filename);
        return ops_false;
        }

    ops_reader_set_fd(pinfo,fd);

    ops_parse_cb_set(pinfo,cb_keyring_read,NULL);

    if (armour)
        { ops_reader_push_dearmour(pinfo); }

    if ( ops_parse_and_accumulate(keyring,pinfo) == 0 ) {
        res = ops_false; 
    }
    else
        {
        res = ops_true;
        }
    ops_print_errors(ops_parse_info_get_errors(pinfo));

    if (armour)
        ops_reader_pop_dearmour(pinfo);

    close(fd);

    ops_parse_info_delete(pinfo);

    return res;
    }
示例#3
0
/**
   \ingroup Core_Readers
   \brief Create parse_info and sets to read from memory
   \param pinfo Address where new parse_info will be set
   \param mem Memory to read from
   \param arg Reader-specific arg
   \param callback Callback to use with reader
   \param accumulate Set if we need to accumulate as we read. (Usually false unless doing signature verification)
   \note It is the caller's responsiblity to free parse_info
   \sa ops_teardown_memory_read()
*/
void ops_setup_memory_read(ops_parse_info_t **pinfo, ops_memory_t *mem,
                           void* arg,
                           ops_parse_cb_return_t callback(const ops_parser_content_t *, ops_parse_cb_info_t *),
                           ops_boolean_t accumulate)
    {
    /*
     * initialise needed uctures for reading
     */

    *pinfo=ops_parse_info_new();
    ops_parse_cb_set(*pinfo,callback,arg);
    ops_reader_set_memory(*pinfo,
                          ops_memory_get_data(mem),
                          ops_memory_get_length(mem));

    if (accumulate)
        (*pinfo)->rinfo.accumulate=ops_true;
    }
示例#4
0
/**
\ingroup Core_Keys
\brief Decrypts secret key from given keydata with given passphrase
\param key Key from which to get secret key
\param pphrase Passphrase to use to decrypt secret key
\return secret key
*/
ops_secret_key_t *ops_decrypt_secret_key_from_data(const ops_keydata_t *key,
						   const char *pphrase)
    {
    ops_parse_info_t *pinfo;
    decrypt_arg_t arg;

    memset(&arg,'\0',sizeof arg);
    arg.key=key;
    arg.pphrase=strdup(pphrase);

    pinfo=ops_parse_info_new();

    ops_keydata_reader_set(pinfo,key);
    ops_parse_cb_set(pinfo,decrypt_cb,&arg);
    pinfo->rinfo.accumulate=ops_true;

    ops_parse(pinfo);

    ops_parse_info_delete(pinfo);

    return arg.skey;
    }
示例#5
0
void check_sig_with_ops(const char *signed_file, ops_boolean_t use_armour)
    {
    validate_data_cb_arg_t validate_arg;
    int fd=0;
    ops_parse_info_t *pinfo=NULL;
    
    // open signed file
    fd=open(signed_file, O_RDONLY | O_BINARY);
    if(fd < 0)
        {
        perror(signed_file);
        exit(2);
        }
    
    // Set verification reader and handling options
    pinfo=ops_parse_info_new();
    ops_reader_set_fd(pinfo, fd);
    ops_parse_cb_set(pinfo, callback_verify, &validate_arg);

    check_sig_with_ops_core(pinfo, use_armour, &validate_arg);

    close(fd);
    }