Exemplo n.º 1
0
void fileio_menu (void)
{
  char inbuf[10];

  /*
   * Wait for characters from console terminal
   */
  for (;;) {
    printf(" =========================\n");
    printf(" RTEMS FILE I/O Test Menu \n");
    printf(" =========================\n");
    printf("   p -> part_table_initialize\n");
    printf("   f -> mount all disks in fs_table\n");
    printf("   l -> list  file\n");
    printf("   r -> read  file\n");
    printf("   w -> write file\n");
#ifdef USE_SHELL
    printf("   s -> start shell\n");
#endif
    printf("   Enter your selection ==>");
    fflush(stdout);

    inbuf[0] = '\0';
    fgets(inbuf,sizeof(inbuf),stdin);
    switch (inbuf[0]) {
    case 'l':
      fileio_list_file ();
      break;
    case 'r':
      fileio_read_file ();
      break;
    case 'w':
      fileio_write_file ();
      break;
    case 'p':
      fileio_part_table_initialize ();
      break;
    case 'f':
      fileio_fsmount ();
      break;
#ifdef USE_SHELL
    case 's':
      fileio_start_shell ();
      break;
#endif
    default:
      printf("Selection `%c` not implemented\n",inbuf[0]);
      break;
    }

  }
  exit (0);
}
Exemplo n.º 2
0
static int attach_sig(struct image *image, const char *image_filename,
		const char *sig_filename)
{
	const uint8_t *tmp_buf;
	uint8_t *sigbuf;
	size_t size;
	PKCS7 *p7;
	int rc;

	rc = fileio_read_file(image, sig_filename, &sigbuf, &size);
	if (rc)
		goto out;

	image_add_signature(image, sigbuf, size);

	rc = -1;
	tmp_buf = sigbuf;
	p7 = d2i_PKCS7(NULL, &tmp_buf, size);
	if (!p7) {
		fprintf(stderr, "Unable to parse signature data in file: %s\n",
				sig_filename);
		ERR_print_errors_fp(stderr);
		goto out;
	}
	rc = PKCS7_verify(p7, NULL, NULL, NULL, NULL,
				PKCS7_BINARY | PKCS7_NOVERIFY | PKCS7_NOSIGS);
	if (!rc) {
		fprintf(stderr, "PKCS7 verification failed for file %s\n",
				sig_filename);
		ERR_print_errors_fp(stderr);
		goto out;
	}

	rc = image_write(image, image_filename);
	if (rc)
		fprintf(stderr, "Error writing %s: %s\n", image_filename,
				strerror(errno));

out:
	talloc_free(sigbuf);
	return rc;
}
Exemplo n.º 3
0
int main(int argc, char **argv)
{
	const char *guid_str;
    const char *attr_str;
    const char *varname;
	const char *keyfilename;
    const char *certfilename;
	varsign_context *ctx;
	bool include_attrs;
	int c = 0;
    	unsigned char no_signing = 0;
	unsigned char no_repack = 0;

	ctx = talloc_zero(NULL, varsign_context);

	keyfilename = NULL;
	certfilename = NULL;
	guid_str = NULL;
	attr_str= NULL;
	include_attrs = false;

	for (;;) {
		int idx;

		c = getopt_long(argc, argv, "o:g:a:k:c:n:ivVh", options, &idx);

		if (c == -1) {
			break;
        }

		switch (c) {
	case 'o':
			ctx->outfilename = optarg;
			break;

        case 'g':
			guid_str = optarg;
			break;

        case 'a':
			attr_str = optarg;
			break;

        case 'k':
			keyfilename = optarg;
			break;

        case 'c':
			certfilename = optarg;
			break;

        case 'i':
			include_attrs = true;
			break;

        case 'v':
			ctx->verbose = 1;
			break;

        case 'V':
			version();
			return EXIT_SUCCESS;

        case 'n':
            no_signing = 1;
            break;

        case 'N':
            no_signing = 1;
            break;

        case 'r':
            no_repack = 1;
            do_direct = 1;
            break;

        case 'R':
            no_repack = 1;
            do_direct = 1;
            break;

        case 'h':
			usage();
			return EXIT_SUCCESS;
		}
	}

	if (argc != (optind + 2)) {
		usage();

		return EXIT_FAILURE;
	}

	if ((!keyfilename) && (!no_signing)) {
		fprintf(stderr, "No signing key specified\n");

		return EXIT_FAILURE;
	}

	if ((!certfilename) && (!no_signing)) {
		fprintf(stderr, "No signing certificate specified\n");

		return EXIT_FAILURE;
	}

	/* initialise openssl */
	OpenSSL_add_all_digests();
	OpenSSL_add_all_ciphers();
	ERR_load_crypto_strings();

	/* set up the variable signing context */
	varname = argv[optind];
	set_varname(ctx, varname);
	ctx->infilename = argv[optind+1];

	if (!ctx->outfilename) {
		set_default_outfilename(ctx);
    }

	if (attr_str) {
		ctx->var_attrs = parse_attrs(attr_str);

		if (ctx->var_attrs == attr_invalid) {
			return EXIT_FAILURE;
        }
	} else {
		ctx->var_attrs = default_attrs;
	}

	if (guid_str) {
		if (parse_guid(guid_str, &ctx->var_guid)) {
			fprintf(stderr, "Invalid GUID '%s'\n", guid_str);

			return EXIT_FAILURE;
		}
	} else {
		set_default_guid(ctx, varname);
	}

	if (fileio_read_file(ctx, ctx->infilename, &ctx->data, &ctx->data_len)) {
		return EXIT_FAILURE;
    }

    if (!no_signing)
    {
        ctx->key = fileio_read_pkey(keyfilename);
        if (!ctx->key) {
            return EXIT_FAILURE;
        }
        
        ctx->cert = fileio_read_cert(certfilename);
        if (!ctx->cert) {
            return EXIT_FAILURE;
        }
    }

	/* do the signing */
	if (add_auth_descriptor(ctx, no_signing)) {
		return EXIT_FAILURE;
    }

	/* write the resulting image */
	if (write_signed(ctx, include_attrs, no_repack)) {
		return EXIT_FAILURE;
    }

	return EXIT_SUCCESS;
}