|
|
|
@ -42,11 +42,10 @@ GRUB_MOD_LICENSE ("GPLv3+");
|
|
|
|
|
|
|
|
|
|
char g_arch_mode_suffix[64];
|
|
|
|
|
static char g_iso_disk_name[128];
|
|
|
|
|
static grub_uint8_t g_boot_pwd = 0;
|
|
|
|
|
static grub_uint8_t g_boot_sha256[32];
|
|
|
|
|
static vtoy_password g_boot_pwd;
|
|
|
|
|
static install_template *g_install_template_head = NULL;
|
|
|
|
|
static dud *g_dud_head = NULL;
|
|
|
|
|
static vtoy_password *g_pwd_head = NULL;
|
|
|
|
|
static menu_password *g_pwd_head = NULL;
|
|
|
|
|
static persistence_config *g_persistence_head = NULL;
|
|
|
|
|
static menu_alias *g_menu_alias_head = NULL;
|
|
|
|
|
static menu_class *g_menu_class_head = NULL;
|
|
|
|
@ -700,18 +699,120 @@ static int ventoy_plugin_dud_entry(VTOY_JSON *json, const char *isodisk)
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int ventoy_plugin_parse_pwdstr(char *pwdstr, vtoy_password *pwd)
|
|
|
|
|
{
|
|
|
|
|
int i;
|
|
|
|
|
int len;
|
|
|
|
|
char ch;
|
|
|
|
|
char *pos;
|
|
|
|
|
char bytes[3];
|
|
|
|
|
vtoy_password tmpPwd;
|
|
|
|
|
|
|
|
|
|
len = (int)grub_strlen(pwdstr);
|
|
|
|
|
if (len > 64)
|
|
|
|
|
{
|
|
|
|
|
if (NULL == pwd) grub_printf("Password too long %d\n", len);
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
grub_memset(&tmpPwd, 0, sizeof(tmpPwd));
|
|
|
|
|
|
|
|
|
|
if (grub_strncmp(pwdstr, "txt#", 4) == 0)
|
|
|
|
|
{
|
|
|
|
|
tmpPwd.type = VTOY_PASSWORD_TXT;
|
|
|
|
|
grub_snprintf(tmpPwd.text, sizeof(tmpPwd.text), "%s", pwdstr + 4);
|
|
|
|
|
}
|
|
|
|
|
else if (grub_strncmp(pwdstr, "md5#", 4) == 0)
|
|
|
|
|
{
|
|
|
|
|
if ((len - 4) == 32)
|
|
|
|
|
{
|
|
|
|
|
for (i = 0; i < 16; i++)
|
|
|
|
|
{
|
|
|
|
|
bytes[0] = pwdstr[4 + i * 2];
|
|
|
|
|
bytes[1] = pwdstr[4 + i * 2 + 1];
|
|
|
|
|
bytes[2] = 0;
|
|
|
|
|
|
|
|
|
|
if (grub_isxdigit(bytes[0]) && grub_isxdigit(bytes[1]))
|
|
|
|
|
{
|
|
|
|
|
tmpPwd.md5[i] = (grub_uint8_t)grub_strtoul(bytes, NULL, 16);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (NULL == pwd) grub_printf("Invalid md5 hex format %s %d\n", pwdstr, i);
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
tmpPwd.type = VTOY_PASSWORD_MD5;
|
|
|
|
|
}
|
|
|
|
|
else if ((len - 4) > 32)
|
|
|
|
|
{
|
|
|
|
|
pos = grub_strchr(pwdstr + 4, '#');
|
|
|
|
|
if (!pos)
|
|
|
|
|
{
|
|
|
|
|
if (NULL == pwd) grub_printf("Invalid md5 password format %s\n", pwdstr);
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (len - 1 - (int)(long)(pos - pwdstr) != 32)
|
|
|
|
|
{
|
|
|
|
|
if (NULL == pwd) grub_printf("Invalid md5 salt password format %s\n", pwdstr);
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ch = *pos;
|
|
|
|
|
*pos = 0;
|
|
|
|
|
grub_snprintf(tmpPwd.salt, sizeof(tmpPwd.salt), "%s", pwdstr + 4);
|
|
|
|
|
*pos = ch;
|
|
|
|
|
|
|
|
|
|
pos++;
|
|
|
|
|
for (i = 0; i < 16; i++)
|
|
|
|
|
{
|
|
|
|
|
bytes[0] = pos[i * 2];
|
|
|
|
|
bytes[1] = pos[i * 2 + 1];
|
|
|
|
|
bytes[2] = 0;
|
|
|
|
|
|
|
|
|
|
if (grub_isxdigit(bytes[0]) && grub_isxdigit(bytes[1]))
|
|
|
|
|
{
|
|
|
|
|
tmpPwd.md5[i] = (grub_uint8_t)grub_strtoul(bytes, NULL, 16);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (NULL == pwd) grub_printf("Invalid md5 hex format %s %d\n", pwdstr, i);
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
tmpPwd.type = VTOY_PASSWORD_SALT_MD5;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (NULL == pwd) grub_printf("Invalid md5 password format %s\n", pwdstr);
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (NULL == pwd) grub_printf("Invalid password format %s\n", pwdstr);
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (pwd)
|
|
|
|
|
{
|
|
|
|
|
grub_memcpy(pwd, &tmpPwd, sizeof(tmpPwd));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int ventoy_plugin_pwd_entry(VTOY_JSON *json, const char *isodisk)
|
|
|
|
|
{
|
|
|
|
|
int i = 0;
|
|
|
|
|
int len = 0;
|
|
|
|
|
const char *iso = NULL;
|
|
|
|
|
const char *pwd = NULL;
|
|
|
|
|
VTOY_JSON *pNode = NULL;
|
|
|
|
|
VTOY_JSON *pCNode = NULL;
|
|
|
|
|
vtoy_password *node = NULL;
|
|
|
|
|
vtoy_password *tail = NULL;
|
|
|
|
|
vtoy_password *next = NULL;
|
|
|
|
|
char bytes[3];
|
|
|
|
|
menu_password *node = NULL;
|
|
|
|
|
menu_password *tail = NULL;
|
|
|
|
|
menu_password *next = NULL;
|
|
|
|
|
|
|
|
|
|
(void)isodisk;
|
|
|
|
|
|
|
|
|
@ -736,18 +837,7 @@ static int ventoy_plugin_pwd_entry(VTOY_JSON *json, const char *isodisk)
|
|
|
|
|
{
|
|
|
|
|
if (pNode->pcName && grub_strcmp("bootpwd", pNode->pcName) == 0)
|
|
|
|
|
{
|
|
|
|
|
len = (int)grub_strlen(pNode->unData.pcStrVal);
|
|
|
|
|
if (len == 64)
|
|
|
|
|
{
|
|
|
|
|
g_boot_pwd = 1;
|
|
|
|
|
for (i = 0; i < 32; i++)
|
|
|
|
|
{
|
|
|
|
|
bytes[0] = pNode->unData.pcStrVal[i * 2];
|
|
|
|
|
bytes[1] = pNode->unData.pcStrVal[i * 2 + 1];
|
|
|
|
|
bytes[2] = 0;
|
|
|
|
|
g_boot_sha256[i] = (grub_uint8_t)grub_strtoul(bytes, NULL, 16);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
ventoy_plugin_parse_pwdstr(pNode->unData.pcStrVal, &g_boot_pwd);
|
|
|
|
|
}
|
|
|
|
|
else if (pNode->pcName && grub_strcmp("menupwd", pNode->pcName) == 0)
|
|
|
|
|
{
|
|
|
|
@ -762,24 +852,16 @@ static int ventoy_plugin_pwd_entry(VTOY_JSON *json, const char *isodisk)
|
|
|
|
|
pwd = vtoy_json_get_string_ex(pCNode->pstChild, "pwd");
|
|
|
|
|
if (iso && pwd && iso[0] == '/')
|
|
|
|
|
{
|
|
|
|
|
node = grub_zalloc(sizeof(vtoy_password));
|
|
|
|
|
node = grub_zalloc(sizeof(menu_password));
|
|
|
|
|
if (node)
|
|
|
|
|
{
|
|
|
|
|
node->pathlen = grub_snprintf(node->isopath, sizeof(node->isopath), "%s", iso);
|
|
|
|
|
len = (int)grub_strlen(pwd);
|
|
|
|
|
if (len != 64)
|
|
|
|
|
|
|
|
|
|
if (ventoy_plugin_parse_pwdstr((char *)pwd, &(node->password)))
|
|
|
|
|
{
|
|
|
|
|
grub_free(node);
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < 32; i++)
|
|
|
|
|
{
|
|
|
|
|
bytes[0] = pwd[i * 2];
|
|
|
|
|
bytes[1] = pwd[i * 2 + 1];
|
|
|
|
|
bytes[2] = 0;
|
|
|
|
|
node->sha256[i] = (grub_uint8_t)grub_strtoul(bytes, NULL, 16);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (g_pwd_head)
|
|
|
|
|
{
|
|
|
|
@ -801,7 +883,6 @@ static int ventoy_plugin_pwd_entry(VTOY_JSON *json, const char *isodisk)
|
|
|
|
|
|
|
|
|
|
static int ventoy_plugin_pwd_check(VTOY_JSON *json, const char *isodisk)
|
|
|
|
|
{
|
|
|
|
|
int len = 0;
|
|
|
|
|
const char *iso = NULL;
|
|
|
|
|
const char *pwd = NULL;
|
|
|
|
|
VTOY_JSON *pNode = NULL;
|
|
|
|
@ -817,18 +898,18 @@ static int ventoy_plugin_pwd_check(VTOY_JSON *json, const char *isodisk)
|
|
|
|
|
{
|
|
|
|
|
if (pNode->pcName && grub_strcmp("bootpwd", pNode->pcName) == 0)
|
|
|
|
|
{
|
|
|
|
|
len = (int)grub_strlen(pNode->unData.pcStrVal);
|
|
|
|
|
if (len != 64)
|
|
|
|
|
if (0 == ventoy_plugin_parse_pwdstr(pNode->unData.pcStrVal, NULL))
|
|
|
|
|
{
|
|
|
|
|
grub_printf("Invalid bootpwd len :%d\n", len);
|
|
|
|
|
grub_printf("bootpwd:<%s>\n", pNode->unData.pcStrVal);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
grub_printf("bootpwd:<%s>\n", pNode->unData.pcStrVal);
|
|
|
|
|
grub_printf("Invalid bootpwd.\n");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (pNode->pcName && grub_strcmp("menupwd", pNode->pcName) == 0)
|
|
|
|
|
{
|
|
|
|
|
grub_printf("\n");
|
|
|
|
|
for (pCNode = pNode->pstChild; pCNode; pCNode = pCNode->pstNext)
|
|
|
|
|
{
|
|
|
|
|
if (pCNode->enDataType != JSON_TYPE_OBJECT)
|
|
|
|
@ -844,21 +925,24 @@ static int ventoy_plugin_pwd_check(VTOY_JSON *json, const char *isodisk)
|
|
|
|
|
{
|
|
|
|
|
pwd = vtoy_json_get_string_ex(pCNode->pstChild, "pwd");
|
|
|
|
|
|
|
|
|
|
len = (int)grub_strlen(pwd);
|
|
|
|
|
if (len != 64)
|
|
|
|
|
if (0 == ventoy_plugin_parse_pwdstr((char *)pwd, NULL))
|
|
|
|
|
{
|
|
|
|
|
grub_printf("Invalid sha256 len <%d>\n", len);
|
|
|
|
|
grub_printf("file:<%s> [OK]\n", iso);
|
|
|
|
|
grub_printf("pwd:<%s>\n\n", pwd);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
grub_printf("file:<%s> [OK]\n", iso);
|
|
|
|
|
grub_printf("pwd:<%s>\n\n", pwd);
|
|
|
|
|
grub_printf("Invalid password for <%s>\n", iso);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
grub_printf("<%s%s> not found\n", isodisk, iso);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
grub_printf("No file found\n");
|
|
|
|
|
grub_printf("No file item found in json.\n");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -1385,7 +1469,7 @@ static int ventoy_plugin_conf_replace_check(VTOY_JSON *json, const char *isodisk
|
|
|
|
|
{
|
|
|
|
|
grub_printf("iso:<%s> [OK]\n", isof);
|
|
|
|
|
|
|
|
|
|
grub_snprintf(cmd, sizeof(cmd), "loopback vtisocheck %s%s", isodisk, isof);
|
|
|
|
|
grub_snprintf(cmd, sizeof(cmd), "loopback vtisocheck \"%s%s\"", isodisk, isof);
|
|
|
|
|
grub_script_execute_sourcecode(cmd);
|
|
|
|
|
|
|
|
|
|
file = ventoy_grub_file_open(VENTOY_FILE_TYPE, "(vtisocheck)/%s", orgf);
|
|
|
|
@ -1695,10 +1779,10 @@ grub_err_t ventoy_cmd_load_plugin(grub_extcmd_context_t ctxt, int argc, char **a
|
|
|
|
|
|
|
|
|
|
grub_free(buf);
|
|
|
|
|
|
|
|
|
|
if (g_boot_pwd)
|
|
|
|
|
{
|
|
|
|
|
grub_printf("\n\n\n\n");
|
|
|
|
|
if (ventoy_check_password(g_boot_sha256, 3))
|
|
|
|
|
if (g_boot_pwd.type)
|
|
|
|
|
{
|
|
|
|
|
grub_printf("\n\n======= %s ======\n\n", grub_env_get("VTOY_TEXT_MENU_VER"));
|
|
|
|
|
if (ventoy_check_password(&g_boot_pwd, 3))
|
|
|
|
|
{
|
|
|
|
|
grub_printf("\n!!! Password check failed, will exit after 5 seconds. !!!\n");
|
|
|
|
|
grub_refresh();
|
|
|
|
@ -2105,10 +2189,10 @@ int ventoy_plugin_load_dud(dud *node, const char *isopart)
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static const grub_uint8_t * ventoy_plugin_get_password(const char *isopath)
|
|
|
|
|
static const vtoy_password * ventoy_plugin_get_password(const char *isopath)
|
|
|
|
|
{
|
|
|
|
|
int len;
|
|
|
|
|
vtoy_password *node = NULL;
|
|
|
|
|
menu_password *node = NULL;
|
|
|
|
|
|
|
|
|
|
if ((!g_pwd_head) || (!isopath))
|
|
|
|
|
{
|
|
|
|
@ -2120,54 +2204,25 @@ static const grub_uint8_t * ventoy_plugin_get_password(const char *isopath)
|
|
|
|
|
{
|
|
|
|
|
if (node->pathlen == len && grub_strncmp(isopath, node->isopath, len) == 0)
|
|
|
|
|
{
|
|
|
|
|
return node->sha256;
|
|
|
|
|
return &(node->password);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int ventoy_check_password(const grub_uint8_t *pwdsha256, int retry)
|
|
|
|
|
{
|
|
|
|
|
char input[128];
|
|
|
|
|
grub_uint8_t sha256[32];
|
|
|
|
|
|
|
|
|
|
while (retry--)
|
|
|
|
|
{
|
|
|
|
|
grub_memset(input, 0, sizeof(input));
|
|
|
|
|
|
|
|
|
|
grub_printf("Enter password: ");
|
|
|
|
|
grub_refresh();
|
|
|
|
|
grub_password_get(input, sizeof(input));
|
|
|
|
|
|
|
|
|
|
grub_crypto_hash(GRUB_MD_SHA256, sha256, input, grub_strlen(input));
|
|
|
|
|
|
|
|
|
|
if (grub_memcmp(pwdsha256, sha256, 32) == 0)
|
|
|
|
|
{
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
grub_printf("Invalid password!\n\n");
|
|
|
|
|
grub_refresh();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
grub_err_t ventoy_cmd_check_password(grub_extcmd_context_t ctxt, int argc, char **args)
|
|
|
|
|
{
|
|
|
|
|
int ret;
|
|
|
|
|
const grub_uint8_t *sha256 = NULL;
|
|
|
|
|
const vtoy_password *pwd = NULL;
|
|
|
|
|
|
|
|
|
|
(void)ctxt;
|
|
|
|
|
(void)argc;
|
|
|
|
|
|
|
|
|
|
sha256 = ventoy_plugin_get_password(args[0]);
|
|
|
|
|
if (sha256)
|
|
|
|
|
pwd = ventoy_plugin_get_password(args[0]);
|
|
|
|
|
if (pwd)
|
|
|
|
|
{
|
|
|
|
|
if (0 == ventoy_check_password(sha256, 1))
|
|
|
|
|
if (0 == ventoy_check_password(pwd, 1))
|
|
|
|
|
{
|
|
|
|
|
ret = 1;
|
|
|
|
|
}
|
|
|
|
|