Exemple #1
0
LONGBOW_TEST_CASE(Global, parcSecurity_Init_Multiple)
{
    parcSecurity_Init();
    parcSecurity_Init();
    parcSecurity_Init();
    parcSecurity_Init();
    parcSecurity_AssertIsInitialized();
    parcSecurity_Fini();
    parcSecurity_Fini();
    parcSecurity_Fini();
    parcSecurity_Fini();
    assertFalse(parcSecurity_IsInitialized(), "parcSecurity_IsInitialized should be false now");
}
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();
}
Exemple #3
0
int
main(int argc, char *argv[])
{
    char *programName = "parc_publickey";
    if (argc < 2) {
        printUsage(programName);
        exit(1);
    }

    PARCArrayList *args = parcArrayList_Create(NULL);
    parcArrayList_AddAll(args, (void **) argv, argc);

    parcSecurity_Init();

    char *arg = parcArrayList_Get(args, 1);
    if (strcmp(arg, "-h") == 0 || strcmp(arg, "--help") == 0) {
        printUsage(programName);
        return 0;
    } else if (strcmp(arg, "-c") == 0 || strcmp(arg, "--create") == 0) {
        parcPublicKey_Create(args);
    } else if (strcmp(arg, "-v") == 0 || strcmp(arg, "--validate") == 0) {
        parcPublicKey_Validate(args);
    } else {
        printUsage(programName);
        exit(1);
    }

    parcSecurity_Fini();
    return 0;
}
LONGBOW_TEST_CASE(Global, parcPkcs12KeyStore_Open)
{
    // open our test p12 file created with openssl
    parcSecurity_Init();

    PARCPkcs12KeyStore *keyStore = parcPkcs12KeyStore_Open("test_rsa.p12", "blueberry", PARC_HASH_SHA256);

    assertNotNull(keyStore, "Got null result from opening openssl pkcs12 file");

    parcPkcs12KeyStore_Release(&keyStore);
    parcSecurity_Fini();
}
int
ccnServe(const PARCIdentity *identity, const CCNxName *listenName, const char *commandString)
{
    parcSecurity_Init();

    CCNxPortalFactory *factory = ccnxPortalFactory_Create(identity);

    CCNxPortal *portal = ccnxPortalFactory_CreatePortal(factory, ccnxPortalRTA_Message);
    assertNotNull(portal, "Expected a non-null CCNxPortal pointer.");

    if (ccnxPortal_Listen(portal, listenName, 365 * 86400, CCNxStackTimeout_Never)) {
        while (true) {
            CCNxMetaMessage *request = ccnxPortal_Receive(portal, CCNxStackTimeout_Never);

            if (request == NULL) {
                break;
            }

            CCNxInterest *interest = ccnxMetaMessage_GetInterest(request);

            if (interest != NULL) {
                CCNxName *interestName = ccnxInterest_GetName(interest);

                PARCBuffer *payload = makePayload(interestName, commandString);

                CCNxContentObject *contentObject = ccnxContentObject_CreateWithDataPayload(interestName, payload);

                CCNxMetaMessage *message = ccnxMetaMessage_CreateFromContentObject(contentObject);
                if (ccnxPortal_Send(portal, message, CCNxStackTimeout_Never) == false) {
                    fprintf(stderr, "ccnxPortal_Write failed: %d\n", ccnxPortal_GetError(portal));
                }
                {
                    char *name = ccnxName_ToString(interestName);
                    time_t theTime = time(0);
                    char *time = ctime(&theTime);
                    printf("%24.24s  %s\n", time, name);
                    parcMemory_Deallocate((void **) &name);
                }

                parcBuffer_Release(&payload);
            }
            ccnxMetaMessage_Release(&request);
        }
    }

    ccnxPortal_Release(&portal);

    ccnxPortalFactory_Release(&factory);

    parcSecurity_Fini();

    return 0;
}
static TestData *
_commonSetup(void)
{
    parcSecurity_Init();

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

    sprintf(data->keystore_filename, "/tmp/alice_keystore.p12.XXXXXX");
    mktemp(data->keystore_filename);
    sprintf(data->keystore_password, "12345");

    CCNxTransportConfig *config = codecTlv_CreateParams(data->keystore_filename, data->keystore_password);
    data->mock = mockFramework_Create(config);
    ccnxTransportConfig_Destroy(&config);
    return data;
}
int
consumer(void)
{
    parcSecurity_Init();
    
    CCNxPortalFactory *factory = setupConsumerFactory();
   
    CCNxPortal *portal = ccnxPortalFactory_CreatePortal(factory, ccnxPortalRTA_Message);

    assertNotNull(portal, "Expected a non-null CCNxPortal pointer.");

    CCNxName *name = ccnxName_CreateFromCString("lci:/Hello/World");

    CCNxInterest *interest = ccnxInterest_CreateSimple(name);
    ccnxName_Release(&name);

    CCNxMetaMessage *message = ccnxMetaMessage_CreateFromInterest(interest);
    
    if (ccnxPortal_Send(portal, message,CCNxStackTimeout_Never)) {
        while (ccnxPortal_IsError(portal) == false) {
            CCNxMetaMessage *response = ccnxPortal_Receive(portal,CCNxStackTimeout_Never);
            if (response != NULL) {
                if (ccnxMetaMessage_IsContentObject(response)) {
                    CCNxContentObject *contentObject = ccnxMetaMessage_GetContentObject(response);

                    PARCBuffer *payload = ccnxContentObject_GetPayload(contentObject);

                    char *string = parcBuffer_ToString(payload);
                    printf("%s\n", string);
                    parcMemory_Deallocate((void **)&string);

                    break;
                }
            }
            ccnxMetaMessage_Release(&response);
        }
    }

    ccnxPortal_Release(&portal);

    ccnxPortalFactory_Release(&factory);
    
    parcSecurity_Fini();
    return 0;
}
static TestData *
_commonSetup(const char *name)
{
    parcSecurity_Init();

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

    sprintf(data->keystore_filename, "/tmp/keystore_%s_%d.p12", name, getpid());
    sprintf(data->keystore_password, "12345");

    unlink(data->keystore_filename);

    CCNxTransportConfig *config = createParams(data->keystore_filename, data->keystore_password);
    data->mock = mockFramework_Create(config);
    ccnxTransportConfig_Destroy(&config);
    return data;
}
LONGBOW_TEST_CASE(CreateAcquireRelease, ccnxPortalFactory_Create)
{
    const char *keystoreName = "ccnxPortalFactory_keystore";

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

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

    CCNxPortalFactory *factory = ccnxPortalFactory_Create(identity);
    parcIdentity_Release(&identity);

    ccnxPortalFactory_Release(&factory);
    parcSecurity_Fini();
}
int
ccnx_Portal_Reader(char *keystoreFileName, const char *password, const char *uri)
{
    parcSecurity_Init();

    PARCIdentity *identity = getIdentity_FromFile(keystoreFileName, password);

    if (identity != NULL) {
        CCNxPortalFactory *factory = ccnxPortalFactory_Create(identity);

        reader_writer(factory, uri);

        ccnxPortalFactory_Release(&factory);
        parcIdentity_Release(&identity);
    }

    parcSecurity_Fini();

    return 0;
}
PARCIdentity *
ccnxFileRepoCommon_CreateAndGetIdentity(const char *keystoreName,
                                        const char *keystorePassword,
                                        const char *subjectName)
{
    parcSecurity_Init();

    unsigned int keyLength = 1024;
    unsigned int validityDays = 30;

    bool success = parcPkcs12KeyStore_CreateFile(keystoreName, keystorePassword, subjectName, keyLength, validityDays);
    assertTrue(success,
               "parcPkcs12KeyStore_CreateFile('%s', '%s', '%s', %d, %d) failed.",
               keystoreName, keystorePassword, subjectName, keyLength, validityDays);

    PARCIdentityFile *identityFile = parcIdentityFile_Create(keystoreName, keystorePassword);
    PARCIdentity *result = parcIdentity_Create(identityFile, PARCIdentityFileAsPARCIdentity);
    parcIdentityFile_Release(&identityFile);

    parcSecurity_Fini();

    return result;
}
LONGBOW_TEST_CASE(Global, ccnxPortalFactory_GetIdentity)
{
    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 PARCIdentity *actual = ccnxPortalFactory_GetIdentity(factory);

    assertTrue(identity == actual, "Expected the result to be the same as provided to the constructor");
   
    parcIdentityFile_Release(&identityFile);
    parcIdentity_Release(&identity);

    ccnxPortalFactory_Release(&factory);
    parcSecurity_Fini();
}
LONGBOW_TEST_CASE(CreateAcquireRelease, ccnxPortalFactory_AcquireRelease)
{
    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);
    parcIdentityFile_Release(&identityFile);
    parcIdentity_Release(&identity);

    CCNxPortalFactory *reference = ccnxPortalFactory_Acquire(factory);
    assertTrue(factory == reference, "Expected Acquire to return its argument.");

    ccnxPortalFactory_Release(&factory);
    ccnxPortalFactory_Release(&reference);

    parcSecurity_Fini();
}
Exemple #14
0
LONGBOW_TEST_CASE(Global, parcSecurity_Init)
{
    parcSecurity_Init();
    parcSecurity_AssertIsInitialized();
    parcSecurity_Fini();
}
Exemple #15
0
int
main(int argc, char *argv[])
{
    int result;

    int ch;
    while ((ch = getopt_long(argc, argv, "a:f:p:hv", longopts, NULL)) != -1) {
        switch (ch) {
            case 'f':
                keystoreFile = optarg;
                break;

            case 'p':
                keystorePassword = optarg;
                break;

            case 'a':
                setenv(FORWARDER_CONNECTION_ENV, optarg, 1);
                break;

            case 'v':
                printf("%s\n", athenactlAbout_Version());
                exit(0);

            case 'h':
                _usage();
                athenactl_Usage();
                exit(0);

            default:
                _usage();
                exit(1);
        }
    }
    argc -= optind;
    argv += optind;

    KeystoreParams *keystoreParams;

    parcSecurity_Init();

    if (keystorePassword == NULL) {
        keystorePassword = ccnxKeystoreUtilities_ReadPassword();
    }
    keystoreParams = ccnxKeystoreUtilities_OpenFile(keystoreFile, keystorePassword);

    if (keystoreParams == NULL) {
        printf("Could not open or authenticate keystore\n");
        exit(1);
    }

    PARCIdentityFile *identityFile = parcIdentityFile_Create(ccnxKeystoreUtilities_GetFileName(keystoreParams), ccnxKeystoreUtilities_GetPassword(keystoreParams));
    if (parcIdentityFile_Exists(identityFile) == false) {
        printf("Inaccessible keystore file '%s'.\n", keystoreFile);
        exit(1);
    }
    PARCIdentity *identity = parcIdentity_Create(identityFile, PARCIdentityFileAsPARCIdentity);
    parcIdentityFile_Release(&identityFile);

    result = athenactl_Command(identity, argc, argv);

    parcIdentity_Release(&identity);
    keystoreParams_Destroy(&keystoreParams);
    parcSecurity_Fini();

    return (result);
}
/**
 * Run the consumer to fetch the specified file. Save it to disk once transferred.
 *
 * @param [in] target Name of the content to request.
 * @param [in] outFile Name of the file to which the buffer will be written.
 */
static int
_ccnxFileRepoClient_Run(char *target, char *outFile)
{
    parcSecurity_Init();

    PARCLog *log = _ccnxFileRepoClient_CreateLogger();

    CCNxPortalFactory *factory = _setupConsumerPortalFactory();
    CCNxPortal *portal = ccnxPortalFactory_CreatePortal(factory, ccnxPortalRTA_Message);
    assertNotNull(portal, "Expected a non-null CCNxPortal pointer.");

    CCNxName *name = ccnxName_CreateFromCString(target);
    CCNxInterest *interest = ccnxInterest_CreateSimple(name);
    CCNxMetaMessage *message = ccnxMetaMessage_CreateFromInterest(interest);

    if (ccnxPortal_Send(portal, message, CCNxStackTimeout_Never)) {
        while (ccnxPortal_IsError(portal) == false) {
            CCNxMetaMessage *response = ccnxPortal_Receive(portal, CCNxStackTimeout_Never);
            if (response != NULL) {
                if (ccnxMetaMessage_IsManifest(response)) {
                    parcLog_Info(log, "Received root manifest. Beginning to retrieve the content.");

                    // Extract the manifest and instantiate a new fetcher for it
                    CCNxManifest *root = ccnxMetaMessage_GetManifest(response);
                    CCNxFileRepoManifestFetcher *fetcher = ccnxFileRepoManifestFetcher_Create(portal, root);

                    // Initialize the file offset and I/O buffer
                    size_t fileOffset = 0;
                    PARCBuffer *chunkBuffer = parcBuffer_Allocate(ccnxFileRepoCommon_ClientBufferSize);

                    // Start reading from the manifest until done
                    bool done = false;
                    while (!done) {
                        // Reset the buffer information
                        parcBuffer_SetPosition(chunkBuffer, 0);
                        parcBuffer_SetLimit(chunkBuffer, ccnxFileRepoCommon_ClientBufferSize);

                        // Fill the buffer with data from the manifest
                        done = ccnxFileRepoManifestFetcher_FillBuffer(fetcher, chunkBuffer);
                        parcBuffer_Flip(chunkBuffer);

                        // Write the buffer to the file
                        size_t totalSize = parcBuffer_Remaining(chunkBuffer);
                        _ccnxFileRepoClient_AppendBufferToFile(outFile, chunkBuffer, fileOffset);
                        fileOffset += totalSize;

                        // Flip the buffer back around for writing
                        parcBuffer_Flip(chunkBuffer);
                    }
                    parcBuffer_Release(&chunkBuffer);

                    break;
                } else if (ccnxMetaMessage_IsContentObject(response)) {
                    parcLog_Info(log, "Received a content object. Dump the payload and exit.");
                    CCNxContentObject *contentObject = ccnxMetaMessage_GetContentObject(response);
                    PARCBuffer *payload = ccnxContentObject_GetPayload(contentObject);
                    _ccnxFileRepoClient_AppendBufferToFile(outFile, payload, 0);
                    break;
                }
            }
            ccnxMetaMessage_Release(&response);
        }
    }

    ccnxPortal_Release(&portal);
    ccnxPortalFactory_Release(&factory);

    parcSecurity_Fini();
    return 0;
}