Skip to content

Commit 6fd5853

Browse files
authored
Merge pull request systemd#34548 from SimonPilkington/fix-creds-cat
creds: fix cat with encrypted credentials
2 parents e996663 + bb322e4 commit 6fd5853

File tree

3 files changed

+13
-4
lines changed

3 files changed

+13
-4
lines changed

NEWS

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,12 @@ CHANGES WITH 257 in spe:
1111
be updated accordingly. This change has been made to make it harder
1212
to accidentally delete too many files when using --purge incorrectly.
1313

14-
Announcements of Future Feature Removals and Incompatible Changes:
14+
* The systemd-creds 'cat' verb now expects base64-encoded encrypted
15+
credentials for consistency with the 'decrypt' verb and the
16+
LoadCredentialEncrypted= service setting. Previously it could only
17+
read raw binary data.
18+
19+
Announcements of Future Feature Removals and Incompatible Changes:
1520

1621
* Support for automatic flushing of the nscd user/group database caches
1722
has been dropped.

src/creds/creds.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -434,10 +434,14 @@ static int verb_cat(int argc, char **argv, void *userdata) {
434434
if (!d) /* Not set */
435435
continue;
436436

437+
ReadFullFileFlags flags = READ_FULL_FILE_SECURE|READ_FULL_FILE_WARN_WORLD_READABLE;
438+
if (encrypted)
439+
flags |= READ_FULL_FILE_UNBASE64;
440+
437441
r = read_full_file_full(
438442
dirfd(d), *cn,
439443
UINT64_MAX, SIZE_MAX,
440-
READ_FULL_FILE_SECURE|READ_FULL_FILE_WARN_WORLD_READABLE,
444+
flags,
441445
NULL,
442446
(char**) &data, &size);
443447
if (r == -ENOENT) /* Not found */

test/units/TEST-54-CREDS.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ CRED_DIR="$(mktemp -d)"
4343
ENC_CRED_DIR="$(mktemp -d)"
4444
echo foo >"$CRED_DIR/secure-or-weak"
4545
echo foo >"$CRED_DIR/insecure"
46-
echo foo | systemd-creds --name="encrypted" encrypt - - | base64 -d >"$ENC_CRED_DIR/encrypted"
47-
echo foo | systemd-creds encrypt - - | base64 -d >"$ENC_CRED_DIR/encrypted-unnamed"
46+
echo foo | systemd-creds --name="encrypted" encrypt - "$ENC_CRED_DIR/encrypted"
47+
echo foo | systemd-creds encrypt - "$ENC_CRED_DIR/encrypted-unnamed"
4848
chmod -R 0400 "$CRED_DIR" "$ENC_CRED_DIR"
4949
chmod -R 0444 "$CRED_DIR/insecure"
5050
mkdir /tmp/empty/

0 commit comments

Comments
 (0)