static int
handle_update_package(const char *path, ZipArchive *zip)
{
    // Update should take the rest of the progress bar.
    ui_print("Installing update...\n");

    LOGI("Trying update-binary.\n");
    int result = try_update_binary(path, zip);

    if (result == INSTALL_UPDATE_BINARY_MISSING)
    {
        LOGI("No update-binary found.\n");
        register_package_root(NULL, NULL);  // Unregister package root
        if (register_package_root(zip, path) < 0) {
            LOGE("Can't register package root\n");
            return INSTALL_ERROR;
        }
        const ZipEntry *script_entry;
        script_entry = find_update_script(zip);
        LOGI("Trying update-script.\n");
        result = handle_update_script(zip, script_entry);
        if (result == INSTALL_UPDATE_SCRIPT_MISSING)
            result = INSTALL_ERROR;
    }

    register_package_root(NULL, NULL);  // Unregister package root
    return result;
}
static int
really_install_package(const char *path)
{
    ui_set_background(BACKGROUND_ICON_INSTALLING);
    ui_print("正在查找升级包...\n");
    ui_show_indeterminate_progress();
    LOGI("Update location: %s\n", path);

    if (ensure_path_mounted(path) != 0) {
        LOGE("Can't mount %s\n", path);
        return INSTALL_CORRUPT;
    }

    ui_print("正在打开升级包...\n");

    int err;

    if (signature_check_enabled) {
        int numKeys;
        RSAPublicKey* loadedKeys = load_keys(PUBLIC_KEYS_FILE, &numKeys);
        if (loadedKeys == NULL) {
            LOGE("Failed to load keys\n");
            return INSTALL_CORRUPT;
        }
        LOGI("%d key(s) loaded from %s\n", numKeys, PUBLIC_KEYS_FILE);

        // Give verification half the progress bar...
        ui_print("正在校验升级包...\n");
        ui_show_progress(
                VERIFICATION_PROGRESS_FRACTION,
                VERIFICATION_PROGRESS_TIME);

        err = verify_file(path, loadedKeys, numKeys);
        free(loadedKeys);
        LOGI("verify_file returned %d\n", err);
        if (err != VERIFY_SUCCESS) {
            LOGE("signature verification failed\n");
            ui_show_text(1);
            if (!confirm_selection("Install Untrusted Package?", "确认 - 安装不严格的zip卡刷包"))
                return INSTALL_CORRUPT;
        }
    }

    /* Try to open the package.
     */
    ZipArchive zip;
    err = mzOpenZipArchive(path, &zip);
    if (err != 0) {
        LOGE("Can't open %s\n(%s)\n", path, err != -1 ? strerror(err) : "bad");
        return INSTALL_CORRUPT;
    }

    /* Verify and install the contents of the package.
     */
    ui_print("正在安装更新...\n");
    return try_update_binary(path, &zip);
}
Exemple #3
0
int
install_package(const char *path)
{
    ui_set_background(BACKGROUND_ICON_INSTALLING);
    ui_print("Finding update package...\n");
    ui_show_indeterminate_progress();
    LOGI("Update location: %s\n", path);

    if (ensure_path_mounted(path) != 0) {
        LOGE("Can't mount %s\n", path);
        return INSTALL_CORRUPT;
    }

    ui_print("Opening update package...\n");

	//TODO: put this back at some point
	/*
    int numKeys;
    RSAPublicKey* loadedKeys = load_keys(PUBLIC_KEYS_FILE, &numKeys);
    if (loadedKeys == NULL) {
        LOGE("Failed to load keys\n");
        return INSTALL_CORRUPT;
    }
    LOGI("%d key(s) loaded from %s\n", numKeys, PUBLIC_KEYS_FILE);

    // Give verification half the progress bar...
    ui_print("Verifying update package...\n");
    ui_show_progress(
            VERIFICATION_PROGRESS_FRACTION,
            VERIFICATION_PROGRESS_TIME);
	*/
    int err;
	/*
    err = verify_file(path, loadedKeys, numKeys);
    free(loadedKeys);
    LOGI("verify_file returned %d\n", err);
    if (err != VERIFY_SUCCESS) {
        LOGE("signature verification failed\n");
        return INSTALL_CORRUPT;
    }
	*/
	
    /* Try to open the package.
     */
    ZipArchive zip;
    err = mzOpenZipArchive(path, &zip);
    if (err != 0) {
        LOGE("Can't open %s\n(%s)\n", path, err != -1 ? strerror(err) : "bad");
        return INSTALL_CORRUPT;
    }

    /* Verify and install the contents of the package.
     */
    ui_print("Installing update...\n");
    return try_update_binary(path, &zip);
}
Exemple #4
0
static int
handle_update_package(const char *path, ZipArchive *zip)
{
    // Update should take the rest of the progress bar.
    ui_print("Installing update...\n");

    int result = try_update_binary(path, zip);
    register_package_root(NULL, NULL);  // Unregister package root
    return result;
}
static int
really_install_package(const char *path, int* wipe_cache)
{
    ui->SetBackground(RecoveryUI::INSTALLING);
    ui->Print("Finding update package...\n");
    ui->SetProgressType(RecoveryUI::INDETERMINATE);
    LOGI("Update location: %s\n", path);

    if (ensure_path_mounted(path) != 0) {
        LOGE("Can't mount %s\n", path);
        return INSTALL_CORRUPT;
    }

    ui->Print("Opening update package...\n");

    int numKeys;
    RSAPublicKey* loadedKeys = load_keys(PUBLIC_KEYS_FILE, &numKeys);
    if (loadedKeys == NULL) {
        LOGE("Failed to load keys\n");
        return INSTALL_CORRUPT;
    }
    LOGI("%d key(s) loaded from %s\n", numKeys, PUBLIC_KEYS_FILE);

    // Give verification half the progress bar...
    ui->Print("Verifying update package...\n");
    ui->SetProgressType(RecoveryUI::DETERMINATE);
    ui->ShowProgress(VERIFICATION_PROGRESS_FRACTION, VERIFICATION_PROGRESS_TIME);

    int err;
    err = verify_file(path, loadedKeys, numKeys);
    free(loadedKeys);
    LOGI("verify_file returned %d\n", err);
    if (err != VERIFY_SUCCESS) {
        LOGE("signature verification failed\n");
        return INSTALL_CORRUPT;
    }

    /* Try to open the package.
     */
    ZipArchive zip;
    err = mzOpenZipArchive(path, &zip);
    if (err != 0) {
        LOGE("Can't open %s\n(%s)\n", path, err != -1 ? strerror(err) : "bad");
        return INSTALL_CORRUPT;
    }

    /* Verify and install the contents of the package.
     */
    ui->Print("Installing update...\n");
    return try_update_binary(path, &zip, wipe_cache);
}
static int
handle_update_package(const char *path, ZipArchive *zip)
{
/*    // Give verification half the progress bar...
    ui_print("Verifying update package...\n");
    ui_show_progress(
            VERIFICATION_PROGRESS_FRACTION,
            VERIFICATION_PROGRESS_TIME);

*//*
    if (!verify_jar_signature(zip, keys, numKeys)) {
        LOGE("Verification failed\n");
        return INSTALL_CORRUPT;
    }
*/

    // Update should take the rest of the progress bar.
    printf("Installing update...\n");

    int result = try_update_binary(path, zip);
    if (result == INSTALL_SUCCESS || result == INSTALL_ERROR) {
        register_package_root(NULL, NULL);  // Unregister package root
        return result;
    }

    // if INSTALL_CORRUPT is returned, this package doesn't have an
    // update binary.  Fall back to the older mechanism of looking for
    // an update script.

    const ZipEntry *script_entry;
    script_entry = find_update_script(zip);
    if (script_entry == NULL) {
        LOGE("Can't find update script\n");
        return INSTALL_CORRUPT;
    }

    if (register_package_root(zip, path) < 0) {
        LOGE("Can't register package root\n");
        return INSTALL_ERROR;
    }

    int ret = handle_update_script(zip, script_entry);
    register_package_root(NULL, NULL);  // Unregister package root
    return ret;
}
Exemple #7
0
static int
really_install_package(const char *path, bool* wipe_cache, bool needs_mount)
{
    ui->SetBackground(RecoveryUI::INSTALLING_UPDATE);
    ui->Print("Finding update package...\n");
    // Give verification half the progress bar...
    ui->SetProgressType(RecoveryUI::DETERMINATE);
    ui->ShowProgress(VERIFICATION_PROGRESS_FRACTION, VERIFICATION_PROGRESS_TIME);
    LOGI("Update location: %s\n", path);

    // Map the update package into memory.
    ui->Print("Opening update package...\n");

    if (path && needs_mount) {
        if (path[0] == '@') {
            ensure_path_mounted(path+1);
        } else {
            ensure_path_mounted(path);
        }
    }

    MemMapping map;
    if (sysMapFile(path, &map) != 0) {
        LOGE("failed to map file\n");
        return INSTALL_CORRUPT;
    }

    int numKeys;
    Certificate* loadedKeys = load_keys(PUBLIC_KEYS_FILE, &numKeys);
    if (loadedKeys == NULL) {
        LOGE("Failed to load keys\n");
        return INSTALL_CORRUPT;
    }
    LOGI("%d key(s) loaded from %s\n", numKeys, PUBLIC_KEYS_FILE);

    ui->Print("Verifying update package...\n");

    int err;
    err = verify_file(map.addr, map.length, loadedKeys, numKeys);
    free(loadedKeys);
    LOGI("verify_file returned %d\n", err);
    if (err != VERIFY_SUCCESS) {
        LOGE("signature verification failed\n");
        sysReleaseMap(&map);
        return INSTALL_CORRUPT;
    }

    /* Try to open the package.
     */
    ZipArchive zip;
    err = mzOpenZipArchive(map.addr, map.length, &zip);
    if (err != 0) {
        LOGE("Can't open %s\n(%s)\n", path, err != -1 ? strerror(err) : "bad");
        sysReleaseMap(&map);
        return INSTALL_CORRUPT;
    }

    /* Verify and install the contents of the package.
     */
    ui->Print("Installing update...\n");
    ui->SetEnableReboot(false);
    int result = try_update_binary(path, &zip, wipe_cache);
    ui->SetEnableReboot(true);
    ui->Print("\n");

    sysReleaseMap(&map);

    return result;
}
Exemple #8
0
static int
really_install_package(const char *path, int* wipe_cache)
{
    ui->SetBackground(RecoveryUI::INSTALLING_UPDATE);
#if 0 //wschen 2012-07-10
    ui->Print("Finding update package...\n");
#else
    LOGI("Finding update package...\n");
#endif
    ui->SetProgressType(RecoveryUI::INDETERMINATE);
    LOGI("Update location: %s\n", path);

    if (ensure_path_mounted(path) != 0) {
        LOGE("Can't mount %s\n", path);
#if 0 //wschen 2012-07-10
        return INSTALL_CORRUPT;
#else
        reset_mark_block();
        return INSTALL_NO_SDCARD;
#endif
    }

#if 0 //wschen 2012-07-10
    ui->Print("Opening update package...\n");
#else
    LOGI("Opening update package...\n");
#endif

    int numKeys;
    RSAPublicKey* loadedKeys = load_keys(PUBLIC_KEYS_FILE, &numKeys);
    if (loadedKeys == NULL) {
        LOGE("Failed to load keys\n");
#if 0 //wschen 2012-07-10
        return INSTALL_CORRUPT;
#else
        reset_mark_block();
        return INSTALL_NO_KEY;
#endif
    }
    LOGI("%d key(s) loaded from %s\n", numKeys, PUBLIC_KEYS_FILE);

    // Give verification half the progress bar...
#if 0 //wschen 2012-07-10
    ui->Print("Verifying update package...\n");
#else
    LOGI("Verifying update package...\n");
#endif
    ui->SetProgressType(RecoveryUI::DETERMINATE);
    ui->ShowProgress(VERIFICATION_PROGRESS_FRACTION, VERIFICATION_PROGRESS_TIME);

    int err;
    err = verify_file(path, loadedKeys, numKeys);
    free(loadedKeys);
    LOGI("verify_file returned %d\n", err);
    if (err != VERIFY_SUCCESS) {
        LOGE("signature verification failed\n");
#if 0 //wschen 2012-07-10
        return INSTALL_CORRUPT;
#else
        reset_mark_block();
        return INSTALL_SIGNATURE_ERROR;
#endif
    }

    /* Try to open the package.
     */
    ZipArchive zip;
    err = mzOpenZipArchive(path, &zip);
    if (err != 0) {
        LOGE("Can't open %s\n(%s)\n", path, err != -1 ? strerror(err) : "bad");
#if 1 //wschen 2012-07-10
        reset_mark_block();
#endif
        return INSTALL_CORRUPT;
    }

    /* ----------------------------- */
    /* SECURE BOOT CHECK             */    
    /* ----------------------------- */
#ifdef SUPPORT_SBOOT_UPDATE    
    if(0 != (err=sec_verify_img_info(&zip,false)))
    {
        return INSTALL_SECURE_CHECK_FAIL;
    }
    sec_mark_status(false);
#endif
    

#ifdef SUPPORT_DATA_BACKUP_RESTORE //wschen 2011-03-09 

    if (check_part_size(&zip) != 0) {
        reset_mark_block();
        return INSTALL_ERROR;
    }
#endif //SUPPORT_DATA_BACKUP_RESTORE

    /* Verify and install the contents of the package.
     */
    ui->Print("Installing update...\n");
    return try_update_binary(path, &zip, wipe_cache);
}
/**
 * install_package() 的实现主体.
 * @param path
 *      待安装的 ota_pkg 的路径字串. 
 * @param install_file
 *      传入 install 流程的 log file 的路径. 
 * @param is_ru_pkg
 *      当前待安装的 ota_pkg 是否是 ru_pkg.
 */
static int
really_install_package(const char *path, int* wipe_cache, bool needs_mount, int is_ru_pkg)
{
    int ret = INSTALL_SUCCESS;
	//by [email protected]
	//if update loader, we hope not clear misc command.
	//default not clear misc command, let the update-script of update.zip to clear misc when no update loader.
	bNeedClearMisc = false;
    ui->SetBackground(RecoveryUI::INSTALLING_UPDATE);
    ui->Print("Finding update package...\n");
    // Give verification half the progress bar...
    ui->SetProgressType(RecoveryUI::DETERMINATE);
    ui->ShowProgress(VERIFICATION_PROGRESS_FRACTION, VERIFICATION_PROGRESS_TIME);
    LOGI("Update location: %s\n", path);

    // Map the update package into memory.
    ui->Print("Opening update package...\n");

	needs_mount = true;
    if (path && needs_mount) {
        if (path[0] == '@') {
            ensure_path_mounted(path+1);
        } else {
            ensure_path_mounted(path);
        }
    }

    MemMapping map;
    if (sysMapFile(path, &map) != 0) {
        LOGE("failed to map file\n");
        return INSTALL_CORRUPT;
    }

    int numKeys;
    Certificate* loadedKeys = load_keys(PUBLIC_KEYS_FILE, &numKeys);
    if (loadedKeys == NULL) {
        LOGE("Failed to load keys\n");
        return INSTALL_CORRUPT;
    }
    LOGI("%d key(s) loaded from %s\n", numKeys, PUBLIC_KEYS_FILE);

    ui->Print("Verifying update package...\n");

    int err;
    err = verify_file(map.addr, map.length, loadedKeys, numKeys);
    free(loadedKeys);
    LOGI("verify_file returned %d\n", err);
    if (err != VERIFY_SUCCESS) {
        LOGE("signature verification failed\n");
        sysReleaseMap(&map);
        return INSTALL_CORRUPT;
    }

    /* Try to open the package.
     */
    ZipArchive zip;
    err = mzOpenZipArchive(map.addr, map.length, &zip);
    if (err != 0) {
        LOGE("Can't open %s\n(%s)\n", path, err != -1 ? strerror(err) : "bad");
        sysReleaseMap(&map);
        return INSTALL_CORRUPT;
    }

#ifdef USE_BOARD_ID
    ensure_path_mounted("/cust");
    ensure_path_mounted("/system");
    D("to restore system_partition.");
    restore();

    gIfBoardIdCustom = true;
#endif

#ifdef USE_RADICAL_UPDATE
    
    // .KP : restore_fw_in_ota_ver : 
    // 无论安装 ru_pkg 还是 original_ota_pkg 之前, 都要 restore 可能的 backup_of_fws_in_ota_ver. 
    // 这样即便连续多次安装 ru_pkg, /radical_update/backup_of_fws_in_ota_ver 中保存的都是 fws_in_ota_ver. 
    // 才能保证, 后续若安装 ota_diff_pkg, 不会失败. 

    if ( 0 != ensure_path_mounted(RU_PARTITION_MOUNT_PATH) )
    {
        SET_ERROR_AND_JUMP("fail to mount ru_partition", ret, INSTALL_ERROR, EXIT);
    }
    if ( 0 != ensure_path_mounted(SYSTEM_PARTITION_MOUNT_PATH) )
    {
        SET_ERROR_AND_JUMP("fail to mount system_partition", ret, INSTALL_ERROR, EXIT);
    }

    if ( RadicalUpdate_isApplied() )
    {
        I("a ru_pkg is applied, to restore backup_of_fws_in_ota_ver to system_partition.");
        CHECK_FUNC_CALL( RadicalUpdate_restoreFirmwaresInOtaVer() , ret, EXIT);
    }
    else 
    {
        D("no ru_pkg is applied.");
    }
    
    if ( 0 != ensure_path_unmounted(RU_PARTITION_MOUNT_PATH) )
    {
        SET_ERROR_AND_JUMP("fail to unmount ru_partition", ret, INSTALL_ERROR, EXIT);
    }
    if ( 0 != ensure_path_unmounted(SYSTEM_PARTITION_MOUNT_PATH) )
    {
        SET_ERROR_AND_JUMP("fail to unmount system_partition", ret, INSTALL_ERROR, EXIT);
    }
#endif

    /* Verify and install the contents of the package.
     */
    ui->Print("Installing update...\n");
    ui->SetEnableReboot(false);
    ret = try_update_binary(path, &zip, wipe_cache);
    ui->SetEnableReboot(true);
    ui->Print("\n");

    sysReleaseMap(&map);

EXIT:
    return ret;
}