Build the tls-creds-psk object with the following params: id, dir,
endpoint, and username.

Note: username is an optional parameter; if not provided, it defaults
to the value "qemu".

Suggested-by: Tejus GK <[email protected]>
Signed-off-by: Abhisek Panda <[email protected]>
---
 src/qemu/qemu_command.c | 29 +++++++++++++++++++++++++++++
 src/qemu/qemu_command.h |  8 ++++++++
 2 files changed, 37 insertions(+)

diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index a4445ef17a..69324a523f 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -1332,6 +1332,35 @@ qemuBuildTLSx509CommandLine(virCommand *cmd,
 }
 
 
+/* qemuBuildTLSPSKBackendProps:
+ * @tlsPSKpath: path to the TLS-PSK credentials file
+ * @listen: boolean listen for client or server setting
+ * @username: identifier to find the secret key of a client at the server
+ * @alias: alias for the TLS-PSK object
+ * @propsret: json properties to return
+ *
+ * Create a backend string for the tls-creds-psk object.
+ *
+ * Returns 0 on success, -1 on failure with error set.
+ */
+int
+qemuBuildTLSPSKBackendProps(const char *tlsPSKpath,
+                            bool isListen,
+                            const char *username,
+                            const char *alias,
+                            virJSONValue **propsret)
+{
+    if (qemuMonitorCreateObjectProps(propsret, "tls-creds-psk", alias,
+                                     "s:dir", tlsPSKpath,
+                                     "s:endpoint", (isListen ? "server": 
"client"),
+                                     "S:username", (isListen ? NULL: username),
+                                     NULL) < 0)
+        return -1;
+
+    return 0;
+}
+
+
 static int
 qemuBuildChardevCommand(virCommand *cmd,
                         const virDomainChrSourceDef *dev,
diff --git a/src/qemu/qemu_command.h b/src/qemu/qemu_command.h
index 028d002ef9..b6c6403e07 100644
--- a/src/qemu/qemu_command.h
+++ b/src/qemu/qemu_command.h
@@ -72,6 +72,14 @@ qemuBuildTLSx509BackendProps(const char *tlspath,
                              const char *secalias,
                              virJSONValue **propsret);
 
+/* Generate the object properties for a tls-creds-psk */
+int
+qemuBuildTLSPSKBackendProps(const char *tlsPSKpath,
+                             bool isListen,
+                             const char *username,
+                             const char *alias,
+                             virJSONValue **propsret);
+
 /* Open a UNIX socket for chardev FD passing */
 int
 qemuOpenChrChardevUNIXSocket(const virDomainChrSourceDef *dev)
-- 
2.39.3

Reply via email to