Ejemplo n.º 1
0
int main(int argc, char** argv)
{
	// Usage: rsa_make_key <private key file> <public key file>
	const char* private_key = ARGV(1);
	const char* public_key = ARGV(2);

	ltc_mp = ltm_desc;

	// Register PRNG algorithm.
	const int prng_idx = register_prng(&sprng_desc);
	if (prng_idx < 0) return error(CRYPT_INVALID_PRNG);

	// Generate key.
	rsa_key key;
	const int bitsize = 2048;
	int err = rsa_make_key(NULL, prng_idx, bitsize/8, 65537, &key);
	if (err != CRYPT_OK) return error(err);

	// Export private key.
	unsigned char out[bitsize * 5 / 8]; // guesstimate
	unsigned long outlen = sizeof(out);
	err = rsa_export(out, &outlen, PK_PRIVATE, &key);
	if (err != CRYPT_OK) return error(err, &key);

	// Save private key.
	FILE* f = fopen(private_key, "wb");
	if (!f) return error(CRYPT_FILE_NOTFOUND, &key);
	outlen = (unsigned long)fwrite(out, 1, outlen, f);
	fclose(f);
	if (!outlen) return error(CRYPT_ERROR, &key);

	// Export public key.
	outlen = sizeof(out);
	err = rsa_export(out, &outlen, PK_PUBLIC, &key);
	if (err != CRYPT_OK) return error(err, &key);

	// Save public key.
	f = fopen(public_key, "wb");
	if (!f) return error(CRYPT_FILE_NOTFOUND, &key);
	outlen = (unsigned long)fwrite(out, 1, outlen, f);
	fclose(f);
	if (!outlen) return error(CRYPT_ERROR, &key);

	rsa_free(&key);
	return 0;
}
Ejemplo n.º 2
0
static void
compile_dex_with_dexopt(const char* dex_file_name,
                        const char* odex_file_name)
{
    SCOPED_RESLIST(rl);

    int dex_file = xopen(dex_file_name, O_RDONLY, 0);
    const char* odex_temp_filename = xaprintf(
        "%s.tmp.%s",
        odex_file_name,
        gen_hex_random(ENOUGH_ENTROPY));
    cleanup_commit(cleanup_allocate(), cleanup_tmpfile, odex_temp_filename);
    int odex_temp_file = xopen(odex_temp_filename,
                               O_RDWR | O_CREAT | O_EXCL,
                               0644);

    allow_inherit(dex_file);
    allow_inherit(odex_temp_file);

    struct child_start_info csi = {
        .io[0] = CHILD_IO_DEV_NULL,
        .io[1] = CHILD_IO_PIPE,
        .io[2] = CHILD_IO_DUP_TO_STDOUT,
        .exename = "dexopt",
        .argv = ARGV(
            "dexopt",
            "--zip",
            xaprintf("%d", dex_file),
            xaprintf("%d", odex_temp_file),
            dex_file_name,
            "v=ao=fm=y"),
    };

    struct child* dexopt = child_start(&csi);
    struct growable_buffer output = slurp_fd_buf(dexopt->fd[1]->fd);
    int status = child_status_to_exit_code(child_wait(dexopt));
    if (status != 0)
        die(EINVAL,
            "dexopt failed: %s",
            massage_output_buf(output));

    xrename(odex_temp_filename, odex_file_name);
}

static void
compile_dex(const char* dex_file_name,
            const char* odex_file_name)
{
    if (api_level() < 21)
        compile_dex_with_dexopt(dex_file_name, odex_file_name);
}

int
rdex_main(const struct cmd_rdex_info* info)
{
    const char* dex_file_name = info->dexfile;
    struct stat dex_stat = xstat(dex_file_name);
    const char* odex_file_name = make_odex_name(dex_file_name);

    bool need_recompile = true;

    struct stat odex_stat;
    if (stat(odex_file_name, &odex_stat) == 0 &&
        dex_stat.st_mtime <= odex_stat.st_mtime)
    {
        need_recompile = false;
    }

    (void) need_recompile;
    (void) odex_file_name;
    (void) compile_dex;

    if (need_recompile)
        compile_dex(dex_file_name, odex_file_name);

    if (setenv("CLASSPATH", dex_file_name, 1) == -1)
        die_errno("setenv");

    if (info->classname[0] == '-')
        die(EINVAL, "class name cannot begin with '-'");

    execvp("app_process",
           (char* const*)
           ARGV_CONCAT(
               ARGV("app_process",
                    xdirname(dex_file_name),
                    info->classname),
               info->args ?: empty_argv));
    die_errno("execvp(\"app_process\", ...");
}
Ejemplo n.º 3
0
			{"dlna_sort", "", NULL, EVM_RESTART_DMS},
			{"dlna_src1", "", NULL, EVM_RESTART_DMS},
			{"dlna_src2", "", NULL, EVM_RESTART_DMS},
			{"dlna_src3", "", NULL, EVM_RESTART_DMS},
			{"dlna_rescan", "", NULL, EVM_RESTART_DMS},
			{"apps_itunes", "", NULL, EVM_RESTART_ITUNES},
			{"trmd_enable", "", NULL,EVM_RESTART_TRMD},
			{"trmd_pport", "", NULL, EVM_RESTART_TRMD},
			{"trmd_rport", "", NULL, EVM_RESTART_TRMD},
			{"aria_enable", "", NULL,EVM_RESTART_ARIA},
			{"aria_pport", "", NULL, EVM_RESTART_ARIA},
			{"aria_rport", "", NULL, EVM_RESTART_ARIA},
#if (BOARD_NUM_UPHY_USB3 > 0)
			{"usb3_disable", "", NULL, EVM_RESTART_REBOOT},
#endif
			{"Storage_UserList", "Group", ARGV((char*)variables_Storage_UserList, "16", "79", "acc_num"), EVM_RESTART_FTPD|EVM_RESTART_SMBD},
			{0,0,0,0}
		};

	struct variable variables_Layer3Forwarding[] = {
			{"x_DHCPClient", "", NULL, EVM_RESTART_WAN},
			{"wan_proto", "", NULL, EVM_RESTART_WAN},
			{"wan_stb_x", "", NULL, EVM_RESTART_SWITCH_VLAN},
			{"wan_src_phy", "", NULL, FALSE},
			{"wan_stb_iso", "", NULL, EVM_RESTART_SWITCH_VLAN},
			{"vlan_filter", "", NULL, EVM_RESTART_WAN},
			{"vlan_vid_cpu", "", NULL, EVM_RESTART_WAN},
			{"vlan_pri_cpu", "", NULL, EVM_RESTART_WAN},
			{"vlan_vid_iptv", "", NULL, EVM_RESTART_WAN},
			{"vlan_pri_iptv", "", NULL, EVM_RESTART_WAN},
			{"vlan_vid_lan1", "", NULL, EVM_RESTART_SWITCH_VLAN},