Skip to content

Commit

Permalink
Merge pull request #30990 from poettering/more-mime
Browse files Browse the repository at this point in the history
register mime types for some of our data files according to the shared mime spec
  • Loading branch information
bluca committed Jan 18, 2024
2 parents 75f8b0f + 16d4aed commit 73a994c
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 0 deletions.
30 changes: 30 additions & 0 deletions mime/io.systemd.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,34 @@
<comment>Configuration Extension DDI</comment>
<glob pattern="*.confext.raw"/>
</mime-type>
<mime-type type="application/x.systemd-journal">
<comment>Journal Log File</comment>
<magic>
<match type="string" value="LPKSHHRH" offset="0"/>
</magic>
</mime-type>
<mime-type type="application/x.systemd-catalog">
<comment>Journal Message Catalog</comment>
<magic>
<match type="string" value="RHHHKSLP" offset="0"/>
</magic>
</mime-type>
<mime-type type="application/x.systemd-hwdb">
<comment>Hardware Database</comment>
<magic>
<match type="string" value="KSLPHHRH" offset="0"/>
</magic>
</mime-type>
<mime-type type="application/x.systemd-credential">
<comment>Encrypted Credential</comment>
<generic-icon name="security-high"/>
<magic>
<match type="string" value="Whxqht+dQJax1aZeCGLxm" offset="0"/>
<match type="string" value="DHzAexF2RZGcSwvqCLwg/" offset="0"/>
<match type="string" value="+vfrk0HjQSyhpDb5Wik2L" offset="0"/>
<match type="string" value="k6iUCUh0RJCQyvL8k8q1U" offset="0"/>
<match type="string" value="r0lQqEkTTrGnOEYwT/MMB" offset="0"/>
<match type="string" value="BYRp2vb1QySABUnaD46i+" offset="0"/>
</magic>
</mime-type>
</mime-info>
28 changes: 28 additions & 0 deletions src/test/test-creds.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

#include "creds-util.h"
#include "fileio.h"
#include "format-util.h"
#include "hexdecoct.h"
#include "id128-util.h"
#include "iovec-util.h"
#include "path-util.h"
Expand Down Expand Up @@ -213,7 +215,33 @@ TEST(credential_encrypt_decrypt) {

if (ec)
assert_se(setenv("SYSTEMD_CREDENTIAL_SECRET", ec, true) >= 0);
}

TEST(mime_type_matches) {

static const sd_id128_t tags[] = {
CRED_AES256_GCM_BY_HOST,
CRED_AES256_GCM_BY_TPM2_HMAC,
CRED_AES256_GCM_BY_TPM2_HMAC_WITH_PK,
CRED_AES256_GCM_BY_HOST_AND_TPM2_HMAC,
CRED_AES256_GCM_BY_HOST_AND_TPM2_HMAC_WITH_PK,
CRED_AES256_GCM_BY_NULL,
};

/* Generates the right <match/> expressions for these credentials according to the shared mime-info spec */
FOREACH_ARRAY(t, tags, ELEMENTSOF(tags)) {
_cleanup_free_ char *encoded = NULL;

assert_se(base64mem(t, sizeof(sd_id128_t), &encoded) >= 0);

/* Validate that the size matches expectations for the 4/3 factor size increase (rounding up) */
assert_se(strlen(encoded) == DIV_ROUND_UP((128U / 8U), 3U) * 4U);

/* Cut off rounded string where the ID ends, but now round down to get rid of characters that might contain follow-up data */
encoded[128 / 6] = 0;

printf("<match type=\"string\" value=\"%s\" offset=\"0\"/>\n", encoded);
}
}

DEFINE_TEST_MAIN(LOG_INFO);

0 comments on commit 73a994c

Please sign in to comment.