예제 #1
0
LONGBOW_TEST_CASE(Global, ccnxKeyLocator_GetType)
{
    // Try FromKey
    char *hexString = "ABCDEF1234";
    PARCBuffer *keyBuffer = parcBuffer_WrapCString(hexString);
    PARCKeyId *keyId = parcKeyId_Create(keyBuffer);

    PARCKey *key = parcKey_CreateFromDerEncodedPublicKey(keyId, PARCSigningAlgorithm_RSA, keyBuffer);
    CCNxKeyLocator *keyLocator = ccnxKeyLocator_CreateFromKey(key);
    parcKeyId_Release(&keyId);
    parcBuffer_Release(&keyBuffer);

    ccnxKeyLocator_AssertValid(keyLocator);
    assertTrue(ccnxKeyLocator_GetType(keyLocator) == CCNxKeyLocatorType_Key, "Actual certificate type didn't match expected type");

    ccnxKeyLocator_Release(&keyLocator);
    parcKey_Release(&key);

    // Try KeyName
    CCNxName *keyURIName = ccnxName_CreateFromCString("lci://name/test");
    CCNxLink *keyLink = ccnxLink_Create(keyURIName, NULL, NULL);
    keyLocator = ccnxKeyLocator_CreateFromKeyLink(keyLink);

    ccnxKeyLocator_AssertValid(keyLocator);
    assertTrue(ccnxKeyLocator_GetType(keyLocator) == CCNxKeyLocatorType_Link, "Actual certificate type didn't match expected type");
    assertFalse(ccnxKeyLocator_GetType(keyLocator) == CCNxKeyLocatorType_Key, "Actual certificate type didn't match expected type");

    ccnxKeyLocator_Release(&keyLocator);
    ccnxName_Release(&keyURIName);
    ccnxLink_Release(&keyLink);
}
예제 #2
0
LONGBOW_TEST_CASE(Global, parcSigner_CreatePublicKey)
{
    _MockSigner *mock = _createSigner();
    PARCSigner *signer = parcSigner_Create(mock, _MockSignerInterface);

    PARCKey *key = parcSigner_CreatePublicKey(signer);

    // Compute the real value
    PARCCryptoHash *hash = parcKeyStore_GetVerifierKeyDigest(mock->keyStore);
    PARCKeyId *keyid = parcKeyId_Create(parcCryptoHash_GetDigest(hash));
    PARCBuffer *derEncodedKey = parcKeyStore_GetDEREncodedPublicKey(mock->keyStore);

    PARCKey *expectedKey = parcKey_CreateFromDerEncodedPublicKey(keyid,
                           parcSigner_GetSigningAlgorithm(signer),
                           derEncodedKey);

    parcBuffer_Release(&derEncodedKey);
    parcKeyId_Release(&keyid);

    parcCryptoHash_Release(&hash);

    assertTrue(parcKey_Equals(key, expectedKey), "Expected public keys to be computed equally.");

    parcKey_Release(&key);
    parcKey_Release(&expectedKey);
    parcSigner_Release(&signer);
    _mockSigner_Release(&mock);
}
예제 #3
0
LONGBOW_TEST_CASE(Global, ccnxPortalFactory_GetKeyId)
{
    const char *keystoreName = "ccnxPortalFactory_keystore";

    parcSecurity_Init();
    bool success = parcPkcs12KeyStore_CreateFile(keystoreName, "keystore_password", "consumer", 1024, 30);
    assertTrue(success, "parcPkcs12KeyStore_CreateFile('%s', 'keystore_password') failed.", keystoreName);

    PARCIdentityFile *identityFile = parcIdentityFile_Create(keystoreName, "keystore_password");
    PARCIdentity *identity = parcIdentity_Create(identityFile, PARCIdentityFileAsPARCIdentity);

    CCNxPortalFactory *factory = ccnxPortalFactory_Create(identity);

    const PARCKeyId *actual = ccnxPortalFactory_GetKeyId(factory);

    PARCSigner *signer = parcIdentity_CreateSigner(identity);
    PARCKeyId *expected = parcSigner_CreateKeyId(signer);
    parcSigner_Release(&signer);

    assertTrue(parcKeyId_Equals(expected, actual), "KeyIds not equal");

    parcKeyId_Release(&expected);

    ccnxPortalFactory_Release(&factory);
   
    parcIdentityFile_Release(&identityFile);
    parcIdentity_Release(&identity);

    parcSecurity_Fini();
}
예제 #4
0
LONGBOW_TEST_CASE(Global, ccnxKeyLocator_Copy)
{
    CCNxName *keyURIName = ccnxName_CreateFromCString("lci://name");
    CCNxLink *keyLink = ccnxLink_Create(keyURIName, NULL, NULL);
    CCNxKeyLocator *keyLocator = ccnxKeyLocator_CreateFromKeyLink(keyLink);

    ccnxKeyLocator_AssertValid(keyLocator);

    CCNxKeyLocator *copy = ccnxKeyLocator_Copy(keyLocator);
    assertTrue(ccnxKeyLocator_Equals(copy, keyLocator), "Expected orig and copy to be the same");

    ccnxKeyLocator_Release(&keyLocator);
    ccnxKeyLocator_Release(&copy);

    ccnxName_Release(&keyURIName);
    ccnxLink_Release(&keyLink);

    // Try FromHexString, too, for yucks.
    PARCBuffer *keyBuffer = parcBuffer_WrapCString("hello world");
    PARCKeyId *keyId = parcKeyId_Create(keyBuffer);
    PARCKey *key = parcKey_CreateFromDerEncodedPublicKey(keyId, PARCSigningAlgorithm_RSA, keyBuffer);
    parcKeyId_Release(&keyId);
    parcBuffer_Release(&keyBuffer);
    CCNxKeyLocator *keyLocator2 = ccnxKeyLocator_CreateFromKey(key);

    CCNxKeyLocator *copy2 = ccnxKeyLocator_Copy(keyLocator2);
    assertTrue(ccnxKeyLocator_Equals(copy, keyLocator), "Expected orig and copy to be the same");

    parcKey_Release(&key);
    ccnxKeyLocator_Release(&keyLocator2);
    ccnxKeyLocator_Release(&copy2);
}
예제 #5
0
TestData *
testData_Create(void)
{
    char keyidString[] = "the keyid";
    char keyString[] = "Memory, all alone in the moonlight";
    char certString[] = "The quick brown fox";

    TestData *data = parcMemory_AllocateAndClear(sizeof(TestData));
    assertNotNull(data, "parcMemory_AllocateAndClear(%zu) returned NULL", sizeof(TestData));

    data->keyid = bufferFromString(sizeof(keyidString), keyidString);
    data->key = bufferFromString(sizeof(keyString), keyString);
    data->cert = bufferFromString(sizeof(certString), certString);
    data->keyname = ccnxName_CreateFromURI("lci:/lazy/dog");

    PARCBuffer *bb_id = parcBuffer_Wrap("choo choo", 9, 0, 9);
    PARCKeyId *keyid = parcKeyId_Create(bb_id);
    parcBuffer_Release(&bb_id);

    PARCKey *key = parcKey_CreateFromDerEncodedPublicKey(keyid, PARCSigningAlgorithm_RSA, data->key);

    data->locatorByKey = ccnxKeyLocator_CreateFromKey(key);
    parcKey_Release(&key);
    parcKeyId_Release(&keyid);

    CCNxLink *link = ccnxLink_Create(data->keyname, NULL, NULL);
    data->locatorByName = ccnxKeyLocator_CreateFromKeyLink(link);
    ccnxLink_Release(&link);

    return data;
}
예제 #6
0
LONGBOW_TEST_CASE(Global, ccnxKeyLocator_Equals)
{
    char *hexString = "ABCDEF1234";
    PARCBuffer *keyBuffer = parcBuffer_WrapCString(hexString);
    PARCKeyId *keyId = parcKeyId_Create(keyBuffer);
    PARCKey *key1 = parcKey_CreateFromDerEncodedPublicKey(keyId, PARCSigningAlgorithm_RSA, keyBuffer);
    CCNxKeyLocator *keyLocator1 = ccnxKeyLocator_CreateFromKey(key1);
    parcKeyId_Release(&keyId);
    parcBuffer_Release(&keyBuffer);

    CCNxKeyLocator *keyLocator1Copy = ccnxKeyLocator_Copy(keyLocator1);

    PARCBuffer *keyBuffer2 = parcBuffer_WrapCString(hexString);
    PARCKeyId *keyId2 = parcKeyId_Create(keyBuffer2);
    PARCKey *key2 = parcKey_CreateFromDerEncodedPublicKey(keyId2, PARCSigningAlgorithm_RSA, keyBuffer2);
    CCNxKeyLocator *keyLocator2 = ccnxKeyLocator_CreateFromKey(key2);
    parcBuffer_Release(&keyBuffer2);
    parcKeyId_Release(&keyId2);

    CCNxName *keyURIName = ccnxName_CreateFromCString("lci://name");
    CCNxLink *keyLink = ccnxLink_Create(keyURIName, NULL, NULL);
    CCNxKeyLocator *keyLocatorDiff = ccnxKeyLocator_CreateFromKeyLink(keyLink);

    ccnxKeyLocator_AssertValid(keyLocator1);
    ccnxKeyLocator_AssertValid(keyLocator1Copy);
    ccnxKeyLocator_AssertValid(keyLocator2);
    ccnxKeyLocator_AssertValid(keyLocatorDiff);

    assertEqualsContract(ccnxKeyLocator_Equals, keyLocator1, keyLocator1Copy, keyLocator2, keyLocatorDiff);

    parcKey_Release(&key1);
    ccnxKeyLocator_Release(&keyLocator1);
    ccnxKeyLocator_Release(&keyLocator1Copy);

    parcKey_Release(&key2);
    ccnxKeyLocator_Release(&keyLocator2);

    ccnxName_Release(&keyURIName);
    ccnxLink_Release(&keyLink);
    ccnxKeyLocator_Release(&keyLocatorDiff);
}
예제 #7
0
LONGBOW_TEST_CASE(Global, parcSigner_CreateKeyId)
{
    _MockSigner *mock = _createSigner();
    PARCSigner *signer = parcSigner_Create(mock, _MockSignerInterface);
    _mockSigner_Release(&mock);

    PARCKeyId *keyId = parcSigner_CreateKeyId(signer);

    assertNotNull(keyId, "Expected non-NULL PARCKeyId");

    parcKeyId_Release(&keyId);
    parcSigner_Release(&signer);
}
예제 #8
0
LONGBOW_TEST_CASE(Global, ccnxKeyLocator_FromKey)
{
    char *hexString = "ABCDEF1234";
    PARCBuffer *keyBuffer = parcBuffer_WrapCString(hexString);
    PARCKeyId *keyId = parcKeyId_Create(keyBuffer);

    PARCKey *key = parcKey_CreateFromDerEncodedPublicKey(keyId, PARCSigningAlgorithm_RSA, keyBuffer);
    CCNxKeyLocator *keyLocator = ccnxKeyLocator_CreateFromKey(key);
    parcKeyId_Release(&keyId);
    parcBuffer_Release(&keyBuffer);

    ccnxKeyLocator_AssertValid(keyLocator);

    ccnxKeyLocator_Release(&keyLocator);
    parcKey_Release(&key);
}
예제 #9
0
LONGBOW_TEST_CASE(Global, ccnxKeyLocator_GetKey)
{
    char *hexString = "ABCDEF1234";
    PARCBuffer *keyBuffer = parcBuffer_WrapCString(hexString);
    PARCKeyId *keyId = parcKeyId_Create(keyBuffer);

    PARCKey *key = parcKey_CreateFromDerEncodedPublicKey(keyId, PARCSigningAlgorithm_RSA, keyBuffer);
    CCNxKeyLocator *keyLocator = ccnxKeyLocator_CreateFromKey(key);

    parcKeyId_Release(&keyId);
    parcBuffer_Release(&keyBuffer);

    ccnxKeyLocator_AssertValid(keyLocator);
    PARCKey *actual = ccnxKeyLocator_GetKey(keyLocator);
    assertTrue(actual == key, "Actual certificate didn't match expected");

    ccnxKeyLocator_Release(&keyLocator);
    parcKey_Release(&key);
}