示例#1
0
ops_parse_cb_return_t
callback_pk_session_key(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;
    
    OPS_USED(cbinfo);

    //    ops_print_packet(content_);
    
    // Read data from packet into static buffer
    switch(content_->tag)
        {
    case OPS_PTAG_CT_PK_SESSION_KEY:
		//	printf ("OPS_PTAG_CT_PK_SESSION_KEY\n");
        assert(cbinfo->cryptinfo.keyring);
        cbinfo->cryptinfo.keydata=ops_keyring_find_key_by_id(cbinfo->cryptinfo.keyring,
                                             content->pk_session_key.key_id);
        if(!cbinfo->cryptinfo.keydata)
            break;
        break;

    default:
        //        return callback_general(content_,cbinfo);
        break;
        }

    return OPS_RELEASE_MEMORY;
    }
示例#2
0
ops_parse_cb_return_t
callback_data_signature(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;

    OPS_USED(cbinfo);

    //    ops_print_packet(content_);

    switch(content_->tag)
        {
    case OPS_PTAG_CT_SIGNED_CLEARTEXT_HEADER:
    case OPS_PTAG_CT_SIGNED_CLEARTEXT_BODY:
    case OPS_PTAG_CT_SIGNED_CLEARTEXT_TRAILER:

    case OPS_PTAG_CT_ONE_PASS_SIGNATURE:
    case OPS_PTAG_CT_SIGNATURE_HEADER:
    case OPS_PTAG_CT_SIGNATURE_FOOTER:

    case OPS_PTAG_CT_LITERAL_DATA_HEADER:
    case OPS_PTAG_CT_LITERAL_DATA_BODY:

    case OPS_PTAG_CT_SIGNATURE:
        return validate_data_cb(content_, cbinfo);
        break;

    default:
        return callback_general(content_, cbinfo);
        }

    return OPS_RELEASE_MEMORY;
    }
示例#3
0
ops_parse_cb_return_t
callback_cmd_get_secret_key(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;
	const ops_secret_key_t *secret;
	ops_parser_content_t pc;

	OPS_USED(cbinfo);

	//    ops_print_packet(content_);

	switch(content_->tag)
	{
		case OPS_PARSER_CMD_GET_SECRET_KEY:
			cbinfo->cryptinfo.keydata=ops_keyring_find_key_by_id(cbinfo->cryptinfo.keyring,content->get_secret_key.pk_session_key->key_id);
			if (!cbinfo->cryptinfo.keydata || !ops_is_key_secret(cbinfo->cryptinfo.keydata))
				return 0;

			/* now get the key from the data */
			secret=ops_get_secret_key_from_data(cbinfo->cryptinfo.keydata);
			int tag_to_use = OPS_PARSER_CMD_GET_SK_PASSPHRASE ;
			int nbtries = 0 ;

			while( (!secret) && nbtries++ < 3)
			{
				if (!cbinfo->cryptinfo.passphrase)
				{
					memset(&pc,'\0',sizeof pc);
					pc.content.secret_key_passphrase.passphrase=&cbinfo->cryptinfo.passphrase;
					CB(cbinfo,tag_to_use,&pc);
					if (!cbinfo->cryptinfo.passphrase)
					{
						fprintf(stderr,"can't get passphrase\n");
						assert(0);
					}
				}
				/* then it must be encrypted */
				secret=ops_decrypt_secret_key_from_data(cbinfo->cryptinfo.keydata,cbinfo->cryptinfo.passphrase);

				free(cbinfo->cryptinfo.passphrase) ;
				cbinfo->cryptinfo.passphrase = NULL ;
				tag_to_use = OPS_PARSER_CMD_GET_SK_PASSPHRASE_PREV_WAS_BAD ;
			}

			if(!secret)
				return 0 ;

			*content->get_secret_key.secret_key=secret;
			break;

		default:
			//        return callback_general(content_,cbinfo);
			break;
	}

	return OPS_RELEASE_MEMORY;
}
示例#4
0
static ops_boolean_t error_writer(const unsigned char *src,
                                  unsigned length,
                                  ops_error_t **errors,
                                  ops_writer_info_t *winfo)
    {
    OPS_USED(src);
    OPS_USED(length);
    error_arg_t *arg=ops_writer_get_arg(winfo);
    arg->times_called++;
    CU_ASSERT(arg->times_called <= arg->count);
    if (arg->times_called == arg->count)
        {
        OPS_ERROR(errors, arg->code, arg->msg);
        return ops_false;
        }
    else
        {
        return ops_true;
        }
    }
示例#5
0
ops_parse_cb_return_t
callback_general(const ops_parser_content_t *content_,ops_parse_cb_info_t *cbinfo)
    {
    int debug=0;

    const ops_parser_content_union_t* content=&content_->content;
    
    OPS_USED(cbinfo);
    
    //    ops_print_packet(content_);
    
    switch(content_->tag)
        {
    case OPS_PARSER_PTAG:
    case OPS_PTAG_CT_COMPRESSED: 
        // ignore
        break;
        
    case OPS_PARSER_PACKET_END:
        // print raw packet

        if (debug)
            {
            unsigned i=0;
            fprintf(stderr,"***\n***Raw Packet:\n");
            for (i=0 ; i < content_->content.packet.length ; i++)
                {
                fprintf(stderr,"0x%02x ", content_->content.packet.raw[i]);
                if (!((i+1) % 16))
                    fprintf(stderr, "\n");
                else if (!((i+1) % 8))
                    fprintf(stderr, "  ");
                }
            fprintf(stderr, "\n");
            }
        break;

    case OPS_PARSER_ERROR:
        printf("parse error: %s\n", content->error.error);
        break;
        
    case OPS_PARSER_ERRCODE:
        printf("parse error: %s\n", ops_errcode(content->errcode.errcode));
        break;
        
    default:
        fprintf(stderr,"Unexpected packet tag=%d (0x%x)\n",content_->tag,
                content_->tag);
        assert(0);
        }
    
    return OPS_RELEASE_MEMORY;
    }
示例#6
0
ops_boolean_t write_literal_header(ops_create_info_t *info,
				   void *header_data)
    {
    OPS_USED(header_data);
    // \todo add the literal type as a header_data argument
    // \todo add filename 
    // \todo add date
    // \todo do we need to check text data for <cr><lf> line endings ?

    ops_write_scalar(OPS_LDT_BINARY, 1, info); // data type
    ops_write_scalar(0, 1, info);    // Filename (length = 0)
    ops_write_scalar(0, 4, info);    // Date (unspecified)
    return ops_true;
    }
示例#7
0
ops_parse_cb_return_t
callback_literal_data(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;

    OPS_USED(cbinfo);

    //    ops_print_packet(content_);

    // Read data from packet into static buffer
    switch(content_->tag)
        {
    case OPS_PTAG_CT_LITERAL_DATA_BODY:
        // if writer enabled, use it
        if (cbinfo->cinfo)
            {
            ops_write(content->literal_data_body.data,
                      content->literal_data_body.length,
                      cbinfo->cinfo);
            }
        /*
        ops_memory_add(mem_literal_data,
                       content->literal_data_body.data,
                       content->literal_data_body.length);
        */
        break;

    case OPS_PTAG_CT_LITERAL_DATA_HEADER:
        // ignore
        break;

    default:
        //        return callback_general(content_,cbinfo);
        break;
        }

    return OPS_RELEASE_MEMORY;
    }
示例#8
0
static ops_parse_cb_return_t
cb_keyring_read(const ops_parser_content_t *content_,
		ops_parse_cb_info_t *cbinfo)
{
	OPS_USED(cbinfo);

	switch(content_->tag)
	{
		case OPS_PARSER_PTAG:
		case OPS_PTAG_CT_ENCRYPTED_SECRET_KEY: // we get these because we didn't prompt
		case OPS_PTAG_CT_SIGNATURE_HEADER:
		case OPS_PTAG_CT_SIGNATURE_FOOTER:
		case OPS_PTAG_CT_SIGNATURE:
		case OPS_PTAG_CT_TRUST:
		case OPS_PARSER_ERRCODE:
			break;

		default:
			;
	}

	return OPS_RELEASE_MEMORY;
}
示例#9
0
/**
 \ingroup HighLevel_Callbacks
 \brief Callback to use when you need to prompt user for passphrase
 \param content_
 \param cbinfo
*/
ops_parse_cb_return_t
callback_cmd_get_passphrase_from_cmdline(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;

    OPS_USED(cbinfo);

//    ops_print_packet(content_);

    switch(content_->tag)
        {
    case OPS_PARSER_CMD_GET_SK_PASSPHRASE:
        *(content->secret_key_passphrase.passphrase)=ops_get_passphrase();
        return OPS_KEEP_MEMORY;
        break;
        
    default:
        //        return callback_general(content_,cbinfo);
        break;
	}
    
    return OPS_RELEASE_MEMORY;
    }
示例#10
0
ops_parse_cb_return_t
test_cb_get_passphrase(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;
    char *passphrase=NULL;

    OPS_USED(cbinfo);

//    ops_print_packet(content_);

    switch(content_->tag)
        {
    case OPS_PARSER_CMD_GET_SK_PASSPHRASE:
        /*
          Doing this so the test can be automated.
        */
        
        if (cbinfo->cryptinfo.keydata==alpha_sec_keydata)
            passphrase=alpha_passphrase;
        else if (cbinfo->cryptinfo.keydata==bravo_sec_keydata)
            passphrase=bravo_passphrase;
        else
            assert(0);
        //        *(content->secret_key_passphrase.passphrase)=ops_malloc_passphrase(no_passphrase);
        cbinfo->cryptinfo.passphrase=ops_malloc_passphrase(passphrase);
        return OPS_KEEP_MEMORY;
        break;
        
    default:
        //        return callback_general(content_,cbinfo);
        break;
	}
    
    return OPS_RELEASE_MEMORY;
    }
示例#11
0
static ops_parse_cb_return_t decrypt_cb(const ops_parser_content_t *content_,
					ops_parse_cb_info_t *cbinfo)
    {
    const ops_parser_content_union_t *content=&content_->content;
    decrypt_arg_t *arg=ops_parse_cb_get_arg(cbinfo);

    OPS_USED(cbinfo);

    switch(content_->tag)
	{
    case OPS_PARSER_PTAG:
    case OPS_PTAG_CT_USER_ID:
    case OPS_PTAG_CT_SIGNATURE:
    case OPS_PTAG_CT_SIGNATURE_HEADER:
    case OPS_PTAG_CT_SIGNATURE_FOOTER:
    case OPS_PTAG_CT_TRUST:
	break;

    case OPS_PARSER_CMD_GET_SK_PASSPHRASE:
	*content->secret_key_passphrase.passphrase=arg->pphrase;
	return OPS_KEEP_MEMORY;

    case OPS_PARSER_ERRCODE:
	switch(content->errcode.errcode)
	    {
	case OPS_E_P_MPI_FORMAT_ERROR:
	    /* Generally this means a bad passphrase */
	    fprintf(stderr,"Bad passphrase!\n");
	    goto done;

	case OPS_E_P_PACKET_CONSUMED:
	    /* And this is because of an error we've accepted */
	    goto done;

	default:
	    fprintf(stderr,"parse error: %s\n",
		    ops_errcode(content->errcode.errcode));
	    assert(0);
	    break;
	    }

	break;

    case OPS_PARSER_ERROR:
	printf("parse error: %s\n",content->error.error);
	assert(0);
	break;

    case OPS_PTAG_CT_SECRET_KEY:
	arg->skey=malloc(sizeof *arg->skey);
	*arg->skey=content->secret_key;
	return OPS_KEEP_MEMORY;

 case OPS_PARSER_PACKET_END:
     // nothing to do
     break;

    default:
	fprintf(stderr,"Unexpected tag %d (0x%x)\n",content_->tag,
		content_->tag);
	assert(0);
	}

 done:
    return OPS_RELEASE_MEMORY;
    }
示例#12
0
文件: crypto.c 项目: MrKID/RetroShare
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;
	//    ops_boolean_t write=ops_true;

	OPS_USED(cbinfo);

	//    ops_print_packet(content_);

	if(content_->tag != OPS_PTAG_CT_UNARMOURED_TEXT && skipping)
	{
		puts("...end of skip");
		skipping=ops_false;
	}

	switch(content_->tag)
	{
		case OPS_PTAG_CT_UNARMOURED_TEXT:
			printf("OPS_PTAG_CT_UNARMOURED_TEXT\n");
			if(!skipping)
			{
				puts("Skipping...");
				skipping=ops_true;
			}
			fwrite(content->unarmoured_text.data, 1,
					content->unarmoured_text.length, stdout);
			break;

		case OPS_PTAG_CT_PK_SESSION_KEY:
			return callback_pk_session_key(content_, cbinfo);
			break;

		case OPS_PARSER_CMD_GET_SECRET_KEY:
			return callback_cmd_get_secret_key(content_, cbinfo);
			break;

		case OPS_PARSER_CMD_GET_SK_PASSPHRASE:
		case OPS_PARSER_CMD_GET_SK_PASSPHRASE_PREV_WAS_BAD:
			//        return callback_cmd_get_secret_key_passphrase(content_,cbinfo);
			return cbinfo->cryptinfo.cb_get_passphrase(content_, cbinfo);
			break;

		case OPS_PTAG_CT_LITERAL_DATA_BODY:
			return callback_literal_data(content_, cbinfo);
			break;

		case OPS_PTAG_CT_ARMOUR_HEADER:
		case OPS_PTAG_CT_ARMOUR_TRAILER:
		case OPS_PTAG_CT_ENCRYPTED_PK_SESSION_KEY:
		case OPS_PTAG_CT_COMPRESSED:
		case OPS_PTAG_CT_LITERAL_DATA_HEADER:
		case OPS_PTAG_CT_SE_IP_DATA_BODY:
		case OPS_PTAG_CT_SE_IP_DATA_HEADER:
		case OPS_PTAG_CT_SE_DATA_BODY:
		case OPS_PTAG_CT_SE_DATA_HEADER:

			// Ignore these packets 
			// They're handled in ops_parse_one_packet()
			// and nothing else needs to be done
			break;

		default:
			//        return callback_general(content_,cbinfo);
			break;
			//	fprintf(stderr,"Unexpected packet tag=%d (0x%x)\n",content_->tag,
			//		content_->tag);
	}

	return OPS_RELEASE_MEMORY;
}