[pve-devel] [PATCH manager v2 4/9] introduce hardware rng scanning api

Filip Schauer f.schauer at proxmox.com
Wed Jan 29 16:53:34 CET 2025


Signed-off-by: Filip Schauer <f.schauer at proxmox.com>
---
 PVE/API2/Hardware.pm       |  7 ++++++
 PVE/API2/Hardware/HWRNG.pm | 47 ++++++++++++++++++++++++++++++++++++++
 PVE/API2/Hardware/Makefile |  1 +
 3 files changed, 55 insertions(+)
 create mode 100644 PVE/API2/Hardware/HWRNG.pm

diff --git a/PVE/API2/Hardware.pm b/PVE/API2/Hardware.pm
index 1c6fd8f5..02503b22 100644
--- a/PVE/API2/Hardware.pm
+++ b/PVE/API2/Hardware.pm
@@ -6,11 +6,17 @@ use warnings;
 use PVE::JSONSchema qw(get_standard_option);
 use PVE::RESTHandler;
 
+use PVE::API2::Hardware::HWRNG;
 use PVE::API2::Hardware::PCI;
 use PVE::API2::Hardware::USB;
 
 use base qw(PVE::RESTHandler);
 
+__PACKAGE__->register_method ({
+    subclass => "PVE::API2::Hardware::HWRNG",
+    path => 'hwrng',
+});
+
 __PACKAGE__->register_method ({
     subclass => "PVE::API2::Hardware::PCI",
     path => 'pci',
@@ -47,6 +53,7 @@ __PACKAGE__->register_method ({
 	my ($param) = @_;
 
 	my $res = [
+	    { type => 'hwrng' },
 	    { type => 'pci' },
 	    { type => 'usb' },
 	];
diff --git a/PVE/API2/Hardware/HWRNG.pm b/PVE/API2/Hardware/HWRNG.pm
new file mode 100644
index 00000000..1c3ac240
--- /dev/null
+++ b/PVE/API2/Hardware/HWRNG.pm
@@ -0,0 +1,47 @@
+package PVE::API2::Hardware::HWRNG;
+
+use strict;
+use warnings;
+
+use PVE::JSONSchema qw(get_standard_option);
+
+use PVE::QemuServer::RNG qw(check_rng_source);
+
+use base qw(PVE::RESTHandler);
+
+__PACKAGE__->register_method({
+    name => 'hwrngscan',
+    path => '',
+    method => 'GET',
+    description => "List local Hardware RNG devices.",
+    protected => 1,
+    proxyto => "node",
+    permissions => {
+	check => ['perm', '/', ['Sys.Audit']],
+    },
+    parameters => {
+	additionalProperties => 0,
+	properties => {
+	    node => get_standard_option('pve-node'),
+	},
+    },
+    returns => {
+	type => 'array',
+	items => {
+	    type => "object",
+	    properties => {
+		path => { type => 'string'},
+	    },
+	},
+    },
+    code => sub {
+	my ($param) = @_;
+
+	eval { PVE::QemuServer::RNG::check_rng_source('/dev/hwrng') };
+	if (my $err = $@) {
+	    return [];
+	}
+
+	return [ { path => '/dev/hwrng' } ];
+    }
+});
diff --git a/PVE/API2/Hardware/Makefile b/PVE/API2/Hardware/Makefile
index 026a8dd6..1e552864 100644
--- a/PVE/API2/Hardware/Makefile
+++ b/PVE/API2/Hardware/Makefile
@@ -1,6 +1,7 @@
 include ../../../defines.mk
 
 PERLSOURCE=			\
+	HWRNG.pm		\
 	PCI.pm			\
 	USB.pm			\
 
-- 
2.39.5





More information about the pve-devel mailing list