Ejemplo n.º 1
0
void test_a_dbobject::should_be_selectable()
{
    should_be_insertable();

    DBObject tokenObject(connection);
    CPPUNIT_ASSERT(tokenObject.find(1));
    CPPUNIT_ASSERT(tokenObject.isValid());
}
Ejemplo n.º 2
0
void test_a_dbobject::should_be_insertable()
{
    DBObject tokenObject(connection);
    CPPUNIT_ASSERT(!tokenObject.isValid());
    CPPUNIT_ASSERT(tokenObject.insert());
    CPPUNIT_ASSERT(tokenObject.isValid());
    CPPUNIT_ASSERT_EQUAL(tokenObject.objectId(), (long long)1);
}
Ejemplo n.º 3
0
void test_a_dbobject_with_an_object::setUp()
{
    test_a_dbobject::setUp();
    DBObject tokenObject(connection);
    CPPUNIT_ASSERT(tokenObject.startTransaction(DBObject::ReadWrite));
    CPPUNIT_ASSERT(!tokenObject.isValid());
    CPPUNIT_ASSERT(tokenObject.insert());
    CPPUNIT_ASSERT(tokenObject.isValid());
    CPPUNIT_ASSERT_EQUAL(tokenObject.objectId(), (long long)1);
    CPPUNIT_ASSERT(tokenObject.commitTransaction());

}
Ejemplo n.º 4
0
// Create a new token
/*static*/ OSToken* OSToken::createToken(const std::string basePath, const std::string tokenDir, const ByteString& label, const ByteString& serial)
{
	Directory baseDir(basePath);

	if (!baseDir.isValid())
	{
		return NULL;
	}

	// Create the token directory
	if (!baseDir.mkdir(tokenDir))
	{
		return NULL;
	}

	// Create the token object
	ObjectFile tokenObject(NULL, basePath + OS_PATHSEP + tokenDir + OS_PATHSEP + "token.object", basePath + OS_PATHSEP + tokenDir + OS_PATHSEP + "token.lock", true);

	if (!tokenObject.valid)
	{
		baseDir.rmdir(tokenDir);

		return NULL;
	}

	// Set the initial attributes
	CK_ULONG flags = 
		CKF_RNG |
		CKF_LOGIN_REQUIRED | // FIXME: check
		CKF_RESTORE_KEY_NOT_NEEDED |
		CKF_TOKEN_INITIALIZED |
		CKF_SO_PIN_LOCKED |
		CKF_SO_PIN_TO_BE_CHANGED;

	OSAttribute tokenLabel(label);
	OSAttribute tokenSerial(serial);
	OSAttribute tokenFlags(flags);

	if (!tokenObject.setAttribute(CKA_OS_TOKENLABEL, tokenLabel) ||
	    !tokenObject.setAttribute(CKA_OS_TOKENSERIAL, tokenSerial) ||
	    !tokenObject.setAttribute(CKA_OS_TOKENFLAGS, tokenFlags))
	{
		baseDir.remove(tokenDir + OS_PATHSEP + "token.object");
		baseDir.remove(tokenDir + OS_PATHSEP + "token.lock");
		baseDir.rmdir(tokenDir);

		return NULL;
	}

	DEBUG_MSG("Created new token %s", tokenDir.c_str());

	return new OSToken(basePath + OS_PATHSEP + tokenDir);
}