コード例 #1
0
ファイル: ospya.cpp プロジェクト: mecirt/7k2
//--------- Begin of function SpyArray::deinit ----------//
//
void SpyArray::deinit()
{
	if( size()==0 )
		return;

	// ####### begin Gilbert 22/3 #######//
	//----- delete units ------//

	for( int i=1 ; i<=size() ; i++ )
	{
		if( is_deleted(i) )
			continue;

		del_spy(i);
	}
	// ####### end Gilbert 22/3 #######//

	//-------- zap the array -----------//

	zap();
}
コード例 #2
0
ファイル: tc_Connected.cpp プロジェクト: genua/anoubis
END_TEST

START_TEST(test_signature)
{
	mark_point();
	LocalCertificate &cert = KeyCtrl::instance()->getLocalCertificate();
	struct anoubis_sig *raw_cert = cert.getCertificate();

	mark_point();
	/* Create a new file */
	wxString fileName = JobCtrl_tempfile();
	fail_if(fileName.IsEmpty(), "Failed to create file");

	mark_point();
	u_int8_t cs_in[ANOUBIS_CS_LEN];
	fail_unless(JobCtrl_calculate_checksum(fileName, cs_in, sizeof(cs_in)),
	    "Failed to calculate checksum");

	mark_point();
	/* Register signature: Success */
	TaskEventSpy add_spy(jobCtrl, anTASKEVT_CSUM_ADD);

	mark_point();
	ComCsumAddTask add_task;
	add_task.addPath(fileName);
	fail_unless(add_task.setKeyId(raw_cert->keyid, raw_cert->idlen),
	    "Failed to setup task with key-id.");
	add_task.setPrivateKey(&KeyCtrl::instance()->getPrivateKey());
	mark_point();

	jobCtrl->addTask(&add_task);
	add_spy.waitForInvocation(1);

	mark_point();
	/* Receive signature: Success */
	TaskEventSpy get_spy(jobCtrl, anTASKEVT_CSUM_GET);

	mark_point();
	ComCsumGetTask *get_task = new ComCsumGetTask;
	get_task->addPath(fileName);
	fail_unless(get_task->setKeyId(raw_cert->keyid, raw_cert->idlen),
	    "Failed to setup task with key-id.");

	mark_point();
	jobCtrl->addTask(get_task);
	get_spy.waitForInvocation(1);

	mark_point();
	fail_unless(get_task->getComTaskResult() == ComTask::RESULT_SUCCESS,
	    "Failed to get a checksum!\nComTaskResult = %i\n"
	    "ResultDetails = %i\n", get_task->getComTaskResult(),
	    get_task->getResultDetails());
	fail_unless(get_task->getResultDetails() == 0,
	    "ResultDetails: %s (%i)\n",
	    anoubis_strerror(get_task->getResultDetails()),
	    get_task->getResultDetails());
	fail_unless(get_task->haveKeyId(), "No key-id is assigned");
	size_t len = get_task->getChecksumLen(0, ANOUBIS_SIG_TYPE_SIG);
	fail_unless(len > ANOUBIS_CS_LEN, "Unexpected csum-len\nIs: %i", len);
	mark_point();

	/* Remove signature: Success */
	TaskEventSpy del_spy(jobCtrl, anTASKEVT_CSUM_DEL);
	ComCsumDelTask	*del_task = new ComCsumDelTask;
	del_task->addPath(fileName);
	fail_unless(del_task->setKeyId(raw_cert->keyid, raw_cert->idlen),
	    "Failed to setup task with key-id.");
	mark_point();

	jobCtrl->addTask(del_task);
	del_spy.waitForInvocation(1);
	mark_point();

	fail_unless(del_task->getComTaskResult() == ComTask::RESULT_SUCCESS,
	    "Failed to remove a checksum!\nComTaskResult = %i\n"
	    "ResultDetails = %i\n", del_task->getComTaskResult(),
	    del_task->getResultDetails());
	fail_unless(del_task->getResultDetails() == 0,
	    "ResultDetails: %s (%i)\n",
	    anoubis_strerror(del_task->getResultDetails()),
	    del_task->getResultDetails());
	fail_unless(del_task->haveKeyId(), "No key-id is assigned");
	delete del_task;

	mark_point();
	delete get_task;
	get_task = new ComCsumGetTask;
	get_task->addPath(fileName);
	mark_point();
	fail_unless(get_task->setKeyId(raw_cert->keyid, raw_cert->idlen),
	    "Failed to setup task with key-id.");
	mark_point();
	/* Fetch signature again: Failure */
	jobCtrl->addTask(get_task);
	get_spy.waitForInvocation(2);

	mark_point();
	fail_unless(get_task->getComTaskResult() == ComTask::RESULT_SUCCESS,
	    "Checksum request failed!\nComTaskResult = %i\nResultDetails = %i",
	    get_task->getComTaskResult(), get_task->getResultDetails());
	fail_unless(get_task->getSignatureError(0) == ENOENT,
	    "Signature error: %s (%i)\n",
	    anoubis_strerror(get_task->getSignatureError(0)),
	    get_task->getSignatureError(0));
	len = get_task->getChecksumLen(0, ANOUBIS_SIG_TYPE_SIG);
	fail_unless(len == 0, "Task contains a signature");
	mark_point();

	wxRemoveFile(fileName);
	mark_point();
}
コード例 #3
0
ファイル: tc_Connected.cpp プロジェクト: genua/anoubis
END_TEST

START_TEST(test_csum)
{
	size_t		len;

	mark_point();
	wxString fileName = JobCtrl_tempfile();
	fail_if(fileName.IsEmpty(), "Failed to create file");
	mark_point();

	u_int8_t cs_in[ANOUBIS_CS_LEN];
	fail_unless(JobCtrl_calculate_checksum(fileName, cs_in, sizeof(cs_in)),
	    "Failed to calculate checksum");
	mark_point();

	/* Register checksum: Success */
	TaskEventSpy add_spy(jobCtrl, anTASKEVT_CSUM_ADD);
	ComCsumAddTask add_task;
	add_task.addPath(fileName);
	mark_point();

	jobCtrl->addTask(&add_task);
	add_spy.waitForInvocation(1);
	mark_point();

	fail_unless(add_task.getComTaskResult() == ComTask::RESULT_SUCCESS,
	    "Failed to add a checksum: %i\n", add_task.getComTaskResult());
	fail_unless(add_task.getResultDetails() == 0,
	    "ResultDetails: %s (%i)\n",
	    anoubis_strerror(add_task.getResultDetails()),
	    add_task.getResultDetails());
	mark_point();

	/* Receive checksum: Success */
	TaskEventSpy get_spy(jobCtrl, anTASKEVT_CSUM_GET);
	ComCsumGetTask *get_task = new ComCsumGetTask;
	get_task->addPath(fileName);
	mark_point();

	jobCtrl->addTask(get_task);
	get_spy.waitForInvocation(1);
	mark_point();

	fail_unless(get_task->getComTaskResult() == ComTask::RESULT_SUCCESS,
	    "Failed to get a checksum!\n"
	    "ComTaskResult = %i\n"
	    "ResultDetails = %i (%s)\n",
	    get_task->getComTaskResult(), get_task->getResultDetails(),
	    anoubis_strerror(get_task->getResultDetails()));
	fail_unless(get_task->getResultDetails() == 0,
	    "ResultDetails: %s (%i)\n",
	    anoubis_strerror(get_task->getResultDetails()),
	    get_task->getResultDetails());
	fail_unless(get_task->haveKeyId() == false, "A key-id is assigned");
	mark_point();
	len = get_task->getChecksumLen(0, ANOUBIS_SIG_TYPE_CS);
	fail_unless(len == ANOUBIS_CS_LEN,
	    "Unexpected csum-len\nIs: %ld\nExpected: %d\n",
	    len, ANOUBIS_CS_LEN);
	mark_point();

	const u_int8_t *cs_out;
	bool ok = get_task->getChecksumData(0, ANOUBIS_SIG_TYPE_CS,
	    cs_out, len);
	fail_unless(ok && len == ANOUBIS_CS_LEN,
	    "Unexpected checksum received!");
	fail_unless(memcmp(cs_in, cs_out, ANOUBIS_CS_LEN) == 0,
	    "Unexpected checksum fetched from daemon");
	mark_point();

	/* Remove checksum: Success */
	TaskEventSpy del_spy(jobCtrl, anTASKEVT_CSUM_DEL);
	ComCsumDelTask	*del_task = new ComCsumDelTask();
	del_task->addPath(fileName);
	mark_point();

	jobCtrl->addTask(del_task);
	del_spy.waitForInvocation(1);
	mark_point();

	fail_unless(del_task->getComTaskResult() == ComTask::RESULT_SUCCESS,
	    "Failed to remove a checksum!\n"
	    "ComTaskResult = %i\n"
	    "ResultDetails = %i\n",
	    del_task->getComTaskResult(), del_task->getResultDetails());
	mark_point();
	fail_unless(del_task->haveKeyId() == false, "A key-id is assigned");
	fail_unless(del_task->getResultDetails() == 0,
	    "ResultDetails: %s (%i)",
	    anoubis_strerror(del_task->getResultDetails()),
	    del_task->getResultDetails());
	delete del_task;
	mark_point();

	delete get_task;
	get_task = new ComCsumGetTask;
	get_task->addPath(fileName);
	/* Fetch checksum again: Failure */
	jobCtrl->addTask(get_task);
	get_spy.waitForInvocation(2);
	mark_point();

	fail_unless(get_task->getComTaskResult() == ComTask::RESULT_SUCCESS,
	    "Checksum request failed\n"
	    "ComTaskResult = %i\n"
	    "ResultDetails = %i\n",
	    get_task->getComTaskResult(), get_task->getResultDetails());
	fail_unless(get_task->getChecksumError(0) == ENOENT,
	    "Checksum error: %s (%i)\n",
	    anoubis_strerror(get_task->getChecksumError(0)),
	    get_task->getChecksumError(0));
	fail_unless(get_task->haveKeyId() == false, "A key-id is assigned");
	mark_point();
	len = get_task->getChecksumLen(0, ANOUBIS_SIG_TYPE_CS);
	fail_unless(len == 0, "Task contains a checksum");
	ok = get_task->getChecksumData(0, ANOUBIS_SIG_TYPE_CS, cs_out, len);
	fail_unless(!ok && len == 0, "Task contains a checksum!\n");
	mark_point();

	wxRemoveFile(fileName);
	mark_point();
}