]> 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 d8771fcb9493296be9b879c1f841d4aa681a6273..33bd4e6e3064c5f4d393605f79d24619d42f4275 100644 (file)
@@ -324,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 */
 
@@ -393,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;
@@ -646,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;
@@ -747,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;
@@ -1277,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;
@@ -1433,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;