[PATCH 3/5] lib: Add AUTH_MSG_DECRYPT

Samuel Mendoza-Jonas sam at mendozajonas.com
Fri Feb 15 11:36:01 AEDT 2019


Extend the auth_message struct to support the AUTH_MSG_DECRYPT
operation, allowing the existing authentications methods to be used for
passing a disk password from the UI to pb-discover.
In addition add DEVICE_TYPE_LUKS to identify encrypted disk devices.

Signed-off-by: Samuel Mendoza-Jonas <sam at mendozajonas.com>
---
 lib/pb-protocol/pb-protocol.c | 17 +++++++++++++++++
 lib/pb-protocol/pb-protocol.h |  5 +++++
 lib/types/types.c             |  6 ++++++
 lib/types/types.h             |  1 +
 ui/test/discover-test.c       |  2 ++
 5 files changed, 31 insertions(+)

diff --git a/lib/pb-protocol/pb-protocol.c b/lib/pb-protocol/pb-protocol.c
index b4138bbf..33bd4e6e 100644
--- a/lib/pb-protocol/pb-protocol.c
+++ b/lib/pb-protocol/pb-protocol.c
@@ -394,6 +394,10 @@ int pb_protocol_authenticate_len(struct auth_message *msg)
 		/* enum + password + password */
 		return 4 + 4 + optional_strlen(msg->set_password.password) +
 			4 + optional_strlen(msg->set_password.new_password);
+	case AUTH_MSG_DECRYPT:
+		/* enum + password + device id */
+		return 4 + 4 + optional_strlen(msg->decrypt_dev.password) +
+			4 + optional_strlen(msg->decrypt_dev.device_id);
 	default:
 		pb_log("%s: invalid input\n", __func__);
 		return 0;
@@ -750,6 +754,12 @@ int pb_protocol_serialise_authenticate(struct auth_message *msg,
 		pos += pb_protocol_serialise_string(pos,
 				msg->set_password.new_password);
 		break;
+	case AUTH_MSG_DECRYPT:
+		pos += pb_protocol_serialise_string(pos,
+				msg->decrypt_dev.password);
+		pos += pb_protocol_serialise_string(pos,
+				msg->decrypt_dev.device_id);
+		break;
 	default:
 		pb_log("%s: invalid msg\n", __func__);
 		return -1;
@@ -1439,6 +1449,13 @@ int pb_protocol_deserialise_authenticate(struct auth_message *msg,
 					&msg->set_password.new_password))
 			return -1;
 		break;
+	case AUTH_MSG_DECRYPT:
+		if (read_string(msg, &pos, &len, &msg->decrypt_dev.password))
+			return -1;
+		if (read_string(msg, &pos, &len,
+					&msg->decrypt_dev.device_id))
+			return -1;
+		break;
 	default:
 		pb_log("%s: unable to parse\n", __func__);
 		return -1;
diff --git a/lib/pb-protocol/pb-protocol.h b/lib/pb-protocol/pb-protocol.h
index 1d6c0485..f4975bc8 100644
--- a/lib/pb-protocol/pb-protocol.h
+++ b/lib/pb-protocol/pb-protocol.h
@@ -40,6 +40,7 @@ enum auth_msg_type {
 	AUTH_MSG_REQUEST,
 	AUTH_MSG_RESPONSE,
 	AUTH_MSG_SET,
+	AUTH_MSG_DECRYPT,
 };
 
 struct auth_message {
@@ -51,6 +52,10 @@ struct auth_message {
 			char	*password;
 			char	*new_password;
 		} set_password;
+		struct {
+			char	*password;
+			char	*device_id;
+		} decrypt_dev;
 	};
 };
 
diff --git a/lib/types/types.c b/lib/types/types.c
index d7f4ead7..f4510e10 100644
--- a/lib/types/types.c
+++ b/lib/types/types.c
@@ -35,6 +35,8 @@ const char *device_type_display_name(enum device_type type)
 		return _("Network");
 	case DEVICE_TYPE_ANY:
 		return _("Any");
+	case DEVICE_TYPE_LUKS:
+		return _("Encrypted Device");
 	case DEVICE_TYPE_UNKNOWN:
 	default:
 		return _("Unknown");
@@ -54,6 +56,8 @@ const char *device_type_name(enum device_type type)
 		return "network";
 	case DEVICE_TYPE_ANY:
 		return "any";
+	case DEVICE_TYPE_LUKS:
+		return "encrypted";
 	case DEVICE_TYPE_UNKNOWN:
 	default:
 		return "unknown";
@@ -72,6 +76,8 @@ enum device_type find_device_type(const char *str)
 		return DEVICE_TYPE_NETWORK;
 	if (!strncmp(str, "any", strlen("any")))
 		return DEVICE_TYPE_ANY;
+	if (!strncmp(str, "encrypted", strlen("encrypted")))
+		return DEVICE_TYPE_LUKS;
 
 	return DEVICE_TYPE_UNKNOWN;
 }
diff --git a/lib/types/types.h b/lib/types/types.h
index 9d83d87d..433a37b2 100644
--- a/lib/types/types.h
+++ b/lib/types/types.h
@@ -11,6 +11,7 @@ enum device_type {
 	DEVICE_TYPE_USB,
 	DEVICE_TYPE_OPTICAL,
 	DEVICE_TYPE_ANY,
+	DEVICE_TYPE_LUKS,
 	DEVICE_TYPE_UNKNOWN,
 };
 
diff --git a/ui/test/discover-test.c b/ui/test/discover-test.c
index f3e7dd8c..6fb14dec 100644
--- a/ui/test/discover-test.c
+++ b/ui/test/discover-test.c
@@ -16,6 +16,8 @@ static const char *device_type_string(enum device_type type)
 		return "optical";
 	case DEVICE_TYPE_ANY:
 		return "any";
+	case DEVICE_TYPE_LUKS:
+		return "encrypted";
 	case DEVICE_TYPE_UNKNOWN:
 		return "unknown";
 	}
-- 
2.20.1



More information about the Petitboot mailing list