RRID: generate keys for old profiles

Bump PROFILEVER to 3
This commit is contained in:
James R 2023-03-28 01:08:21 -07:00
parent 3c561c564e
commit 4413939e85
2 changed files with 25 additions and 12 deletions

View file

@ -30,6 +30,13 @@ INT32 PR_GetNumProfiles(void)
return numprofiles;
}
static void PR_GenerateProfileKeys(profile_t *new)
{
static uint8_t seed[32];
csprng(seed, 32);
crypto_eddsa_key_pair(new->secret_key, new->public_key, seed);
}
profile_t* PR_MakeProfile(
const char *prname,
const char *pname,
@ -43,17 +50,12 @@ profile_t* PR_MakeProfile(
new->version = PROFILEVER;
uint8_t secret_key[64];
uint8_t public_key[32];
memset(new->secret_key, 0, sizeof(secret_key));
memset(new->public_key, 0, sizeof(public_key));
memset(new->secret_key, 0, sizeof(new->secret_key));
memset(new->public_key, 0, sizeof(new->public_key));
if (!guest)
{
static uint8_t seed[32];
csprng(seed, 32);
crypto_eddsa_key_pair(new->secret_key, new->public_key, seed);
PR_GenerateProfileKeys(new);
}
strcpy(new->profilename, prname);
@ -348,8 +350,19 @@ void PR_LoadProfiles(void)
// Names and keys, all the identity stuff up front
READSTRINGN(save.p, profilesList[i]->profilename, PROFILENAMELEN);
READMEM(save.p, profilesList[i]->public_key, sizeof(((profile_t *)0)->public_key));
READMEM(save.p, profilesList[i]->secret_key, sizeof(((profile_t *)0)->secret_key));
// Profile update 2-->3: Add profile keys.
if (version < 3)
{
// Generate missing keys.
PR_GenerateProfileKeys(profilesList[i]);
}
else
{
READMEM(save.p, profilesList[i]->public_key, sizeof(((profile_t *)0)->public_key));
READMEM(save.p, profilesList[i]->secret_key, sizeof(((profile_t *)0)->secret_key));
}
READSTRINGN(save.p, profilesList[i]->playername, MAXPLAYERNAME);
// Character and colour.
@ -605,4 +618,4 @@ char *GetPrettyRRID(const unsigned char *bin, boolean brief)
out[len*2] = '\0';
return out;
}
}

View file

@ -31,7 +31,7 @@ extern "C" {
#define SKINNAMESIZE 16
#define PROFILENAMELEN 6
#define PROFILEVER 2
#define PROFILEVER 3
#define MAXPROFILES 16
#define PROFILESFILE "ringprofiles.prf"
#define PROFILE_GUEST 0