summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon Rettberg2018-05-29 15:02:22 +0200
committerSimon Rettberg2018-05-29 15:02:22 +0200
commit8bfa8171cfba14c97dd90c0a0c70b9449c9f2f49 (patch)
treefd442c0530d547dc4ad68174f59be3004f4989fb
parent[vesafb] Fix resetting console to text mode by passing NULL config (diff)
downloadipxe-8bfa8171cfba14c97dd90c0a0c70b9449c9f2f49.tar.gz
ipxe-8bfa8171cfba14c97dd90c0a0c70b9449c9f2f49.tar.xz
ipxe-8bfa8171cfba14c97dd90c0a0c70b9449c9f2f49.zip
[settings] Add md5 encoding type for doing ${foo:md5}
This obviously only works for formatting, not parsing. This makes it possible to implement client side password checks without giving the password away too easily. Not super secure as it's md5, but enough for basic protection.
-rw-r--r--src/core/settings.c47
-rw-r--r--src/include/ipxe/settings.h1
2 files changed, 48 insertions, 0 deletions
diff --git a/src/core/settings.c b/src/core/settings.c
index 3e5d416e..df4fe9fc 100644
--- a/src/core/settings.c
+++ b/src/core/settings.c
@@ -45,6 +45,7 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
#include <ipxe/init.h>
#include <ipxe/version.h>
#include <ipxe/settings.h>
+#include <ipxe/md5.h>
/** @file
*
@@ -2132,6 +2133,46 @@ static int format_hex_raw_setting ( const struct setting_type *type __unused,
return hex_encode ( 0, raw, raw_len, buf, len );
}
+/**
+ * Parsing md5 setting doesn't make any sense
+ *
+ * @v type Setting type
+ * @v value Formatted setting value
+ * @v buf Buffer to contain raw value
+ * @v len Length of buffer
+ * @v size Integer size, in bytes
+ * @ret len Length of raw value, or negative error
+ */
+static int parse_md5_setting ( const struct setting_type *type __unused,
+ const char *value __unused, void *buf __unused,
+ size_t len __unused ) {
+ return -ENOTSUP;
+}
+
+/**
+ * Format setting value as md5 hash (hex representation)
+ *
+ * @v type Setting type
+ * @v raw Raw setting value
+ * @v raw_len Length of raw setting value
+ * @v buf Buffer to contain formatted value
+ * @v len Length of buffer
+ * @ret len Length of formatted value, or negative error
+ */
+static int format_md5_setting ( const struct setting_type *type __unused,
+ const void *raw, size_t raw_len,
+ char *buf, size_t len ) {
+ struct md5_context ctx;
+ uint8_t digest[MD5_DIGEST_SIZE];
+
+ if ( len < MD5_DIGEST_SIZE )
+ return -ENOSPC;
+ digest_init ( &md5_algorithm, &ctx );
+ digest_update ( &md5_algorithm, &ctx, raw, raw_len );
+ digest_final ( &md5_algorithm, &ctx, digest );
+ return hex_encode ( 0, digest, sizeof(digest), buf, len );
+}
+
/** A hex-string setting (colon-delimited) */
const struct setting_type setting_type_hex __setting_type = {
.name = "hex",
@@ -2153,6 +2194,12 @@ const struct setting_type setting_type_hexraw __setting_type = {
.format = format_hex_raw_setting,
};
+const struct setting_type setting_type_md5 __setting_type = {
+ .name = "md5",
+ .parse = parse_md5_setting,
+ .format = format_md5_setting,
+};
+
/**
* Parse Base64-encoded setting value
*
diff --git a/src/include/ipxe/settings.h b/src/include/ipxe/settings.h
index f463e667..2bffe2fb 100644
--- a/src/include/ipxe/settings.h
+++ b/src/include/ipxe/settings.h
@@ -424,6 +424,7 @@ extern const struct setting_type setting_type_uint32 __setting_type;
extern const struct setting_type setting_type_hex __setting_type;
extern const struct setting_type setting_type_hexhyp __setting_type;
extern const struct setting_type setting_type_hexraw __setting_type;
+extern const struct setting_type setting_type_md5 __setting_type;
extern const struct setting_type setting_type_base64 __setting_type;
extern const struct setting_type setting_type_uuid __setting_type;
extern const struct setting_type setting_type_busdevfn __setting_type;