-
Notifications
You must be signed in to change notification settings - Fork 120
udisks2: fix LUKS2 auto-unlock failure with TPM2 pin #550
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,133 @@ | ||
| /* vim: set tabstop=8 shiftwidth=4 softtabstop=4 expandtab smarttab colorcolumn=80: */ | ||
| /* | ||
| * Copyright (c) 2026 Red Hat, Inc. | ||
| * Author: Sergio Correia <scorreia@redhat.com> | ||
| * | ||
| * This program is free software: you can redistribute it and/or modify | ||
| * it under the terms of the GNU General Public License as published by | ||
| * the Free Software Foundation, either version 3 of the License, or | ||
| * (at your option) any later version. | ||
| * | ||
| * This program is distributed in the hope that it will be useful, | ||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| * GNU General Public License for more details. | ||
| * | ||
| * You should have received a copy of the GNU General Public License | ||
| * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| */ | ||
|
|
||
| #include "token-to-jwe.h" | ||
|
|
||
| #include <assert.h> | ||
| #include <stdio.h> | ||
| #include <stdlib.h> | ||
| #include <string.h> | ||
|
|
||
| static const char valid_token[] = | ||
| "{" | ||
| " \"type\": \"clevis\"," | ||
| " \"keyslots\": [\"1\"]," | ||
| " \"jwe\": {" | ||
| " \"protected\": \"eyJhbGciOiJkaXIiLCJlbmMiOiJBMjU2R0NNIn0\"," | ||
| " \"encrypted_key\": \"\"," | ||
| " \"iv\": \"oB2uB6_a2LCQnhNk\"," | ||
| " \"ciphertext\": \"Gss774jh5EcnMA5NacAxuX8\"," | ||
| " \"tag\": \"6L9KBrn6-R1---wTikJTrA\"" | ||
| " }" | ||
| "}"; | ||
|
|
||
| static void | ||
| test_basic_conversion(void) | ||
| { | ||
| pkt_t pkt = {}; | ||
| const char *expected = | ||
| "eyJhbGciOiJkaXIiLCJlbmMiOiJBMjU2R0NNIn0" | ||
| "." | ||
| "." | ||
| "oB2uB6_a2LCQnhNk" | ||
| "." | ||
| "Gss774jh5EcnMA5NacAxuX8" | ||
| "." | ||
| "6L9KBrn6-R1---wTikJTrA"; | ||
|
|
||
| assert(token_to_jwe(valid_token, &pkt)); | ||
| assert(strcmp(pkt.data, expected) == 0); | ||
| fprintf(stderr, "test_basic_conversion: PASS\n"); | ||
| } | ||
|
|
||
| static void | ||
| test_used_equals_strlen(void) | ||
| { | ||
| pkt_t pkt = {}; | ||
|
|
||
| assert(token_to_jwe(valid_token, &pkt)); | ||
| assert(pkt.used == (ssize_t) strlen(pkt.data)); | ||
| fprintf(stderr, "test_used_equals_strlen: PASS\n"); | ||
| } | ||
|
|
||
| static void | ||
| test_invalid_json(void) | ||
| { | ||
| pkt_t pkt = {}; | ||
|
|
||
| assert(!token_to_jwe(NULL, &pkt)); | ||
| assert(!token_to_jwe("not json", &pkt)); | ||
| assert(!token_to_jwe("{}", &pkt)); | ||
| assert(!token_to_jwe("{\"jwe\":{}}", &pkt)); | ||
| assert(!token_to_jwe("{\"jwe\":{\"protected\":\"a\"}}", &pkt)); | ||
| fprintf(stderr, "test_invalid_json: PASS\n"); | ||
| } | ||
|
|
||
| static void | ||
| test_empty_components(void) | ||
| { | ||
| const char *json = | ||
| "{\"jwe\":{" | ||
| "\"protected\":\"\"," | ||
| "\"encrypted_key\":\"\"," | ||
| "\"iv\":\"\"," | ||
| "\"ciphertext\":\"\"," | ||
| "\"tag\":\"\"" | ||
| "}}"; | ||
| pkt_t pkt = {}; | ||
|
|
||
| assert(token_to_jwe(json, &pkt)); | ||
| assert(strcmp(pkt.data, "....") == 0); | ||
| assert(pkt.used == 4); | ||
| assert(pkt.used == (ssize_t) strlen(pkt.data)); | ||
| fprintf(stderr, "test_empty_components: PASS\n"); | ||
| } | ||
|
|
||
| static void | ||
| test_single_char_components(void) | ||
| { | ||
| const char *json = | ||
| "{\"jwe\":{" | ||
| "\"protected\":\"a\"," | ||
| "\"encrypted_key\":\"b\"," | ||
| "\"iv\":\"c\"," | ||
| "\"ciphertext\":\"d\"," | ||
| "\"tag\":\"e\"" | ||
| "}}"; | ||
| pkt_t pkt = {}; | ||
|
|
||
| assert(token_to_jwe(json, &pkt)); | ||
| assert(strcmp(pkt.data, "a.b.c.d.e") == 0); | ||
| assert(pkt.used == 9); | ||
| assert(pkt.used == (ssize_t) strlen(pkt.data)); | ||
| fprintf(stderr, "test_single_char_components: PASS\n"); | ||
| } | ||
|
|
||
| int | ||
| main(void) | ||
| { | ||
| test_basic_conversion(); | ||
| test_used_equals_strlen(); | ||
| test_invalid_json(); | ||
| test_empty_components(); | ||
| test_single_char_components(); | ||
|
|
||
| fprintf(stderr, "All tests passed.\n"); | ||
| return EXIT_SUCCESS; | ||
| } | ||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| /* vim: set tabstop=8 shiftwidth=4 softtabstop=4 expandtab smarttab colorcolumn=80: */ | ||
| /* | ||
| * Copyright (c) 2015 Red Hat, Inc. | ||
| * Author: Nathaniel McCallum <npmccallum@redhat.com> | ||
| * | ||
| * This program is free software: you can redistribute it and/or modify | ||
| * it under the terms of the GNU General Public License as published by | ||
| * the Free Software Foundation, either version 3 of the License, or | ||
| * (at your option) any later version. | ||
| * | ||
| * This program is distributed in the hope that it will be useful, | ||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| * GNU General Public License for more details. | ||
| * | ||
| * You should have received a copy of the GNU General Public License | ||
| * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| */ | ||
|
|
||
| #include "token-to-jwe.h" | ||
|
|
||
| #include <jansson.h> | ||
| #include <stdio.h> | ||
| #include <string.h> | ||
|
|
||
| bool | ||
| token_to_jwe(const char *json, pkt_t *pkt) | ||
| { | ||
| json_auto_t *tokn = NULL; | ||
| const json_t *jwe = NULL; | ||
| const char *prt = NULL; | ||
| const char *key = NULL; | ||
| const char *tag = NULL; | ||
| const char *iv = NULL; | ||
| const char *ct = NULL; | ||
|
|
||
| if (!json) | ||
| return false; | ||
|
|
||
| tokn = json_loads(json, 0, NULL); | ||
| if (!tokn) | ||
| return false; | ||
|
|
||
| jwe = json_object_get(tokn, "jwe"); | ||
| if (!jwe) | ||
| return false; | ||
|
|
||
| if (json_unpack((json_t *) jwe, "{s:s,s:s,s:s,s:s,s:s}", | ||
| "protected", &prt, "encrypted_key", &key, "iv", &iv, | ||
| "ciphertext", &ct, "tag", &tag) < 0) | ||
| return false; | ||
|
|
||
| pkt->used = snprintf(pkt->data, sizeof(pkt->data), | ||
| "%s.%s.%s.%s.%s", prt, key, iv, ct, tag); | ||
| if (pkt->used < 0 || (size_t) pkt->used >= sizeof(pkt->data)) | ||
| return false; | ||
|
|
||
| return true; | ||
| } |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| /* vim: set tabstop=8 shiftwidth=4 softtabstop=4 expandtab smarttab colorcolumn=80: */ | ||
| /* | ||
| * Copyright (c) 2015 Red Hat, Inc. | ||
| * Author: Nathaniel McCallum <npmccallum@redhat.com> | ||
| * | ||
| * This program is free software: you can redistribute it and/or modify | ||
| * it under the terms of the GNU General Public License as published by | ||
| * the Free Software Foundation, either version 3 of the License, or | ||
| * (at your option) any later version. | ||
| * | ||
| * This program is distributed in the hope that it will be useful, | ||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| * GNU General Public License for more details. | ||
| * | ||
| * You should have received a copy of the GNU General Public License | ||
| * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| */ | ||
|
|
||
| #ifndef TOKEN_TO_JWE_H | ||
| #define TOKEN_TO_JWE_H | ||
|
|
||
| #include <stdbool.h> | ||
| #include <sys/types.h> | ||
|
|
||
| #define MAX_UDP 65507 | ||
|
|
||
| typedef struct { | ||
| ssize_t used; | ||
| char data[MAX_UDP]; | ||
| } pkt_t; | ||
|
|
||
| bool token_to_jwe(const char *json, pkt_t *pkt); | ||
|
|
||
| #endif /* TOKEN_TO_JWE_H */ |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.