feat: sign --keygen generates random key (v0.5.25)#35
Merged
Conversation
Add --keygen <path> flag to cfusa sign: generates 32 random bytes via /dev/urandom, encodes as 64 hex chars, writes to path (overwriting existing file), prints "Key written to <path> (keep this secret)". Exit 3 on write error. Parity with go-FuSa TestSignKeygen_* tests. Signed-off-by: Matt Jones <matt@jellybaby.com> Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> Signed-off-by: Matt Jones <47545907+SoundMatt@users.noreply.github.com>
| } | ||
| hex[64] = '\0'; | ||
|
|
||
| FILE *f = fopen(path, "w"); |
| snprintf(key_path, sizeof(key_path), "%s/test_keygen_overwrite.key", CLI_TEST_DIR); | ||
|
|
||
| /* Create an existing file with different content */ | ||
| FILE *pre = fopen(key_path, "w"); |
| fprintf(stderr, "cfusa sign: cannot open /dev/urandom\n"); | ||
| return 3; | ||
| } | ||
| if (fread(buf, 1, sizeof(buf), urandom) != sizeof(buf)) { |
| return 3; | ||
| } | ||
| if (fread(buf, 1, sizeof(buf), urandom) != sizeof(buf)) { | ||
| fclose(urandom); |
| fprintf(stderr, "cfusa sign: failed to read random bytes\n"); | ||
| return 3; | ||
| } | ||
| fclose(urandom); |
| return 3; | ||
| } | ||
| fprintf(f, "%s\n", hex); | ||
| fclose(f); |
| char buf[128]; | ||
| buf[0] = '\0'; | ||
| fgets(buf, sizeof(buf), f); | ||
| fclose(f); |
| char buf[128]; | ||
| buf[0] = '\0'; | ||
| fgets(buf, sizeof(buf), f); | ||
| fclose(f); |
| snprintf(key_path, sizeof(key_path), "%s/test_keygen.key", CLI_TEST_DIR); | ||
| remove(key_path); | ||
|
|
||
| char *argv[] = {"cfusa", "--keygen", key_path, NULL}; |
| FILE *pre = fopen(key_path, "w"); | ||
| if (pre) { fputs("old-content\n", pre); fclose(pre); } | ||
|
|
||
| char *argv[] = {"cfusa", "--keygen", key_path, NULL}; |
| //cfusa:test REQ-SIGN-KEYGEN001 | ||
| void test_sign_keygen_bad_path_returns_3(void) | ||
| { | ||
| char *argv[] = {"cfusa", "--keygen", "/nonexistent/dir/fusa.key", NULL}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
--keygen <path>flag tocfusa sign: generates 32-byte random key via/dev/urandom, writes 64 hex chars to path (overwrites existing file)TestSignKeygen_Success,TestSignKeygen_BadPath,TestSignKeygen_OverwriteTest plan