/**
 * Create a keystore with the new default name in the old location
 */
LONGBOW_TEST_CASE(Local, ccnxKeystoreUtilities_OpenFromHomeDirectory_Newfile)
{
    char *homedir = ccnxKeystoreUtilities_GetHomeDirectory();
    char *ccnxdir = ccnxKeystoreUtilities_ConstructPath(homedir, ".ccnx");
    mkdir(ccnxdir, 0700);
    char *path = ccnxKeystoreUtilities_ConstructPath(ccnxdir, ".ccnx_keystore.p12");

    bool success = parcPkcs12KeyStore_CreateFile(path, "1234", "ccnxuser", 1024, 365);
    assertTrue(success, "parcPkcs12KeyStore_CreateFile() failed.");

    KeystoreParams *signer = ccnxKeystoreUtilities_OpenFromHomeDirectory("1234");
    assertNotNull(signer, "Signer should be non-null opening from a file we just created");
    keystoreParams_Destroy(&signer);

    parcMemory_Deallocate((void **) &path);
    parcMemory_Deallocate((void **) &ccnxdir);
    parcMemory_Deallocate((void **) &homedir);
}
Ejemplo n.º 2
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);
}