Beispiel #1
0
CwController::CwController(std::ifstream *ifile, CwLabelList *label_list, std::string name)
{
	label = name;
	int i;

	for (i=0; i<128; i++)
	{
		ctrl_names[i] = CwDefaults::initial_items[i];
	}

	add_names(ifile, label_list, name);
}
Beispiel #2
0
static int add_names(
    char *curr_file,
    char *c,
    struct Manifest *manp,
    int num)
{
    FILE *str;
    char *a;
    if (!(str = fopen(&c[1], "r")))
        FATAL(MSG_OPEN, &c[1]);
    while ((fgets(c, (CURR_FILE_SIZE - (c - curr_file)), str)))
    {
        if (strlen(curr_file) >= CURR_FILE_SIZE - 1)
            FATAL(MSG_FN_LONG, c);
        for (a = c; *a > ' '; a++);
        *a = 0;
        if (*c == '-')
            num = add_names(curr_file, c, manp, num);
        else
            num += add_name(curr_file, manp, num);
    }
    fclose(str);
    return num;
}
Beispiel #3
0
void CwController::add_names(std::ifstream *ifile, CwLabelList *label_list, std::string name)
{
	int i;
	const std::string based_on = "BasedOn=";
	const int len_based_on = based_on.length();
	based_on_name = "";

	char line[256];
	std::string str_line;

	unsigned char ch;
	bool is_error = false;
	long pos = label_list->label_pos(name);

	if (pos == -1)
	{
//		MIDIFile::message("No Label %s",name.c_str());
		return;
	}

	long initial_pos = ifile->tellg();
	ifile->clear();
	ifile->seekg(pos);

	// look for controller names 

	while (true)
	{
		ifile->getline(line,256);
	
		is_error = false;

		if (ifile->eof())
		{
			ifile->clear();
			break;
		}

		if (line[0] == '[')
		{
			break;
		}

		str_line = line;

		if (str_line.substr(0,len_based_on)==based_on)
		{
			based_on_name = str_line.substr(len_based_on);
			continue;
		}

		ch = line[0];
		if ((ch<'0')||(ch>'9'))
		{
			continue;
		}

		int last = str_line.find("=");

		if (last < 0)
		{
			continue;
		}

		int no = 0;
		
		for (i=0; i<last; i++)
		{
			ch = line[i];
			if ((ch<'0')||(ch>'9'))
			{
				MIDIFile::message("error CW Controller, line %s",line);
				is_error = true;
				break;
			}
			no = 10*no+(ch-'0');
		}

		if (is_error) 
		{
			break;
		}

		if (no>128)
		{
			MIDIFile::message("error CW Controller number");
			break;
		}

		if (ctrl_names[no] == CwDefaults::initial_items[no])
		{
			ctrl_names[no] = str_line.substr(last+1);
		}
	}
	if (based_on_name != "")
	{
		add_names(ifile, label_list,based_on_name);
	}

	ifile->seekg(initial_pos);
}
Beispiel #4
0
int main(
    int argc,
    char **argv)
{
    char *c,
        curr_file[CURR_FILE_SIZE],
        locbuf[20];
    struct CMS cms;
    struct AlgorithmIdentifier *algidp;
    int man_num;

    if (argc < 4)
    {
        printf
            ("Args needed: output file, certificate file, key file, optional directory\n");
        return 0;
    }
    CMS(&cms, 0);
    write_objid(&cms.contentType, id_signedData);
    write_casn_num(&cms.content.signedData.version.self, (long)3);
    inject_casn(&cms.content.signedData.digestAlgorithms.self, 0);
    algidp =
        (struct AlgorithmIdentifier *)member_casn(&cms.content.
                                                  signedData.digestAlgorithms.
                                                  self, 0);
    write_objid(&algidp->algorithm, id_sha256);
    write_casn(&algidp->parameters.sha256, (uchar *) "", 0);
    write_objid(&cms.content.signedData.encapContentInfo.eContentType,
                id_roa_pki_manifest);
    struct Manifest *manp =
        &cms.content.signedData.encapContentInfo.eContent.manifest;
    printf("What manifest number? ");
    fgets(locbuf, sizeof(locbuf), stdin);
    sscanf(locbuf, "%d", &man_num);
    write_casn_num(&manp->manifestNumber, (long)man_num);
    getDate(&manp->thisUpdate, "This");
    getDate(&manp->nextUpdate, "Next");
    write_objid(&manp->fileHashAlg, id_sha256);

    // now get the files
    memset(curr_file, 0, CURR_FILE_SIZE);
    if (argc > 4)
    {
        if (strlen(argv[4]) > CURR_FILE_SIZE - 8)
            FATAL(MSG_FN_LONG, argv[4]);
        strcpy(curr_file, argv[4]);
        for (c = curr_file; *c > ' '; c++);
        if (c > curr_file && c[-1] != '/')
            *c++ = '/';
    }
    else
        c = curr_file;
    int num;
    printf("Now give the names of the files to go in the manifest\n");
    printf("Terminate with a null name\n");
    printf
        ("If a name begins with '-', the remainder of the name is considered\n");
    printf("to be the full path to a file containing a list of file names.\n");
    for (num = 0; 1;)
    {
        char *a;

        printf("File[%d]? ", num);
        fgets(c, (CURR_FILE_SIZE - (c - curr_file)), stdin);
        if (strlen(curr_file) > CURR_FILE_SIZE - 1)
            FATAL(MSG_FN_LONG, curr_file);
        if (*c < ' ')
            break;
        for (a = c; *a > ' '; a++);
        *a = 0;                 // remove carriage return
        if (*c != '-')
            num += add_name(curr_file, manp, num);
        else
            num = add_names(curr_file, c, manp, num);
    }
    if (!inject_casn(&cms.content.signedData.certificates.self, 0))
        FATAL(MSG_INSERTING, "signedData");
    struct Certificate *certp =
        (struct Certificate *)member_casn(&cms.content.signedData.certificates.
                                          self, 0);
    if (get_casn_file(&certp->self, argv[2], 0) < 0)
        FATAL(MSG_READING, argv[2]);
    if (!inject_casn(&cms.content.signedData.signerInfos.self, 0))
        FATAL(MSG_INSERTING, "signerInfo");
    struct SignerInfo *sigInfop =
        (struct SignerInfo *)member_casn(&cms.content.signedData.signerInfos.
                                         self, 0);
    write_casn_num(&sigInfop->version.v3, 3);
    write_objid(&sigInfop->digestAlgorithm.algorithm, id_sha256);
    write_objid(&sigInfop->signatureAlgorithm.algorithm,
                id_rsadsi_rsaEncryption);

    const char *msg;
    if ((msg = signCMS(&cms, argv[3], 0)))
        FATAL(MSG_CREATING_SIG, msg);
    if (put_casn_file(&cms.self, argv[1], 0) < 0)
        FATAL(MSG_WRITING, argv[1]);
    printf("What readable file, if any? ");
    fgets(curr_file, CURR_FILE_SIZE, stdin);
    curr_file[strlen(curr_file) - 1] = 0;
    if (*curr_file > ' ')
    {
        int dsize = dump_size(&cms.self);
        c = (char *)calloc(1, dsize + 2);
        dump_casn(&cms.self, c);
        FILE *str = fopen(curr_file, "w");
        fprintf(str, "%s", c);
        fclose(str);
    }
    DONE(MSG_OK);
    return 0;
}