Allow encryption of unencrypted files with oidc-gen -u close
@@ -828,6 +828,9 @@ void gen_handleUpdateConfigFile(const char* file) {
}
char* password = NULL;
+ if (isJSONObject(fileContent)) { // file not encrypted
+ password = getEncryptionPassword(file, NULL, UINT_MAX);
+ } else { // file is encrypted
char* decrypted = NULL;
for (int i = 0; i < MAX_PASS_TRIES && decrypted == NULL; i++) {
password =
@@ -843,15 +846,18 @@ void gen_handleUpdateConfigFile(const char* file) {
oidc_perror();
exit(EXIT_FAILURE);
}
- if (encryptAndWriteUsingPassword(decrypted, password, shortname ? NULL : file,
+ fileContent = decrypted;
+ }
+ if (encryptAndWriteUsingPassword(fileContent, password,
+ shortname ? NULL : file,
shortname ? file : NULL) != OIDC_SUCCESS) {
secFree(password);
- secFree(decrypted);
+ secFree(fileContent);
oidc_perror();
exit(EXIT_FAILURE);
}
secFree(password);
- secFree(decrypted);
+ secFree(fileContent);
printNormal("Updated config file format\n");
exit(EXIT_SUCCESS);
}
