-
Notifications
You must be signed in to change notification settings - Fork 163
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
jwt-verify, jwt-generate: Added option to output JSON to command
Updated man pages as well. Pulled in a few tweaks as well. Signed-off-by: Ben Collins <[email protected]>
- Loading branch information
1 parent
ba95a07
commit 797d10d
Showing
7 changed files
with
195 additions
and
86 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
/* Copyright (C) 2024-2025 maClara, LLC <[email protected]> | ||
This file is part of the JWT C Library | ||
This Source Code Form is subject to the terms of the Mozilla Public | ||
License, v. 2.0. If a copy of the MPL was not distributed with this | ||
file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
static char *pipe_cmd; | ||
|
||
static FILE *json_fp; | ||
|
||
static void write_json(const char *title, const char *str) | ||
{ | ||
char *argv[4] = { "/bin/sh", "-c", NULL, NULL }; | ||
int pipe_fd[2]; | ||
int myfd = 0; | ||
pid_t pid; | ||
int status; | ||
|
||
if (json_fp == NULL) | ||
json_fp = stdout; | ||
|
||
if (pipe_cmd) { | ||
pipe(pipe_fd); | ||
|
||
argv[2] = pipe_cmd; | ||
pid = fork(); | ||
|
||
if (pid == 0) { | ||
close(pipe_fd[1]); | ||
|
||
if (json_fp == stderr) | ||
dup2(STDERR_FILENO, STDOUT_FILENO); | ||
dup2(pipe_fd[0], STDIN_FILENO); | ||
close(pipe_fd[0]); | ||
|
||
execvp(argv[0], argv); | ||
|
||
perror("execvp"); | ||
exit(EXIT_FAILURE); | ||
} else { | ||
close(pipe_fd[0]); | ||
myfd = pipe_fd[1]; | ||
} | ||
} | ||
|
||
fprintf(json_fp, "\033[0;95m[%s]\033[0m\n", title); | ||
|
||
if (myfd) { | ||
write(myfd, str, strlen(str)); | ||
} else { | ||
fprintf(json_fp, "\033[0;96m%s\033[0m\n", str); | ||
} | ||
|
||
if (myfd) { | ||
close(myfd); | ||
waitpid(pid, &status, 0); | ||
} | ||
} | ||
|
||
static int __jwt_wcb(jwt_t *jwt, jwt_config_t *config) | ||
{ | ||
jwt_value_t jval; | ||
int ret; | ||
|
||
if (config == NULL) | ||
return 1; | ||
|
||
jwt_set_GET_JSON(&jval, NULL); | ||
jval.pretty = 1; | ||
ret = jwt_header_get(jwt, &jval); | ||
if (!ret) { | ||
write_json("HEADER", jval.json_val); | ||
free(jval.json_val); | ||
} | ||
|
||
jwt_set_GET_JSON(&jval, NULL); | ||
jval.pretty = 1; | ||
ret = jwt_grant_get(jwt, &jval); | ||
if (!ret) { | ||
write_json("PAYLOAD", jval.json_val); | ||
free(jval.json_val); | ||
} | ||
|
||
return 0; | ||
} |
This file contains 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
This file contains 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
Oops, something went wrong.