]> git.ozlabs.org Git - petitboot/blobdiff - lib/pb-protocol/pb-protocol.c
lib: Add AUTH_MSG_DECRYPT
[petitboot] / lib / pb-protocol / pb-protocol.c
index 5de382d2215bae22c216c1e3424a6147b308c7b2..33bd4e6e3064c5f4d393605f79d24619d42f4275 100644 (file)
@@ -204,6 +204,7 @@ int pb_protocol_boot_option_len(const struct boot_option *opt)
                4 + optional_strlen(opt->boot_args) +
                4 + optional_strlen(opt->args_sig_file) +
                sizeof(opt->is_default) +
+               sizeof(opt->is_autoboot_default) +
                sizeof(opt->type);
 }
 
@@ -323,6 +324,7 @@ int pb_protocol_config_len(const struct config *config)
        }
 
        len += 4 + 4; /* ipmi_bootdev, ipmi_bootdev_persistent */
+       len += 4; /* ipmi_bootdev_mailbox */
 
        len += 4; /* allow_writes */
 
@@ -392,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;
@@ -434,6 +440,8 @@ int pb_protocol_serialise_boot_option(const struct boot_option *opt,
 
        *(bool *)pos = opt->is_default;
        pos += sizeof(bool);
+       *(bool *)pos = opt->is_autoboot_default;
+       pos += sizeof(bool);
 
        *(uint32_t *)pos = __cpu_to_be32(opt->type);
        pos += 4;
@@ -643,6 +651,8 @@ int pb_protocol_serialise_config(const struct config *config,
        pos += 4;
        *(uint32_t *)pos = config->ipmi_bootdev_persistent;
        pos += 4;
+       *(uint32_t *)pos = config->ipmi_bootdev_mailbox;
+       pos += 4;
 
        *(uint32_t *)pos = config->allow_writes;
        pos += 4;
@@ -744,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;
@@ -925,6 +941,9 @@ int pb_protocol_deserialise_boot_option(struct boot_option *opt,
        opt->is_default = *(bool *)(pos);
        pos += sizeof(bool);
        len -= sizeof(bool);
+       opt->is_autoboot_default = *(bool *)(pos);
+       pos += sizeof(bool);
+       len -= sizeof(bool);
 
        if (read_u32(&pos, &len, &opt->type))
                return -1;
@@ -1271,6 +1290,9 @@ int pb_protocol_deserialise_config(struct config *config,
        if (read_u32(&pos, &len, &tmp))
                goto out;
        config->ipmi_bootdev_persistent = !!tmp;
+       if (read_u32(&pos, &len, &tmp))
+               goto out;
+       config->ipmi_bootdev_mailbox = !!tmp;
 
        if (read_u32(&pos, &len, &tmp))
                goto out;
@@ -1427,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;