diff --git a/.github/workflows/control.yml b/.github/workflows/control.yml index 5bb81e204..a94cb7a39 100644 --- a/.github/workflows/control.yml +++ b/.github/workflows/control.yml @@ -90,7 +90,7 @@ jobs: dockerhub_token: ${{ secrets.DOCKERHUB_TOKEN}} cosign_key_opensight: ${{ secrets.COSIGN_KEY_OPENSIGHT }} cosign_password_opensight: ${{ secrets.COSIGN_KEY_PASSWORD_OPENSIGHT }} - greenbone_registry: ${{ secrets.GREENBONE_REGISTRY }} + greenbone_registry: ${{ vars.GREENBONE_REGISTRY }} greenbone_registry_user: ${{ secrets.GREENBONE_REGISTRY_USER }} greenbone_registry_token: ${{ secrets.GREENBONE_REGISTRY_TOKEN }} mattermost_webhook_url: ${{ secrets.MATTERMOST_WEBHOOK_URL }} diff --git a/rust/Cargo.lock b/rust/Cargo.lock index 2ba732341..6d596400b 100644 --- a/rust/Cargo.lock +++ b/rust/Cargo.lock @@ -2465,6 +2465,12 @@ dependencies = [ "universal-hash", ] +[[package]] +name = "portable-atomic" +version = "1.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cc9c68a3f6da06753e9335d63e27f6b9754dd1920d941135b7ea8224f141adb2" + [[package]] name = "powerfmt" version = "0.2.0" diff --git a/rust/README.md b/rust/README.md index eb33df00f..d958f59a7 100644 --- a/rust/README.md +++ b/rust/README.md @@ -4,8 +4,7 @@ This is the rust scanner implementation with the goal to replace the current sca (openvas-scanner, ospd-openvas, notus-scanner), including the Open Scanner Protocol (OSP). The rust implementation of the new [HTTP scanner API](https://greenbone.github.io/scanner-api/) is called **openvasd**. It provides an interface to manage scans for vulnerability testing. It currently utilizes the **openvas-scanner** to perform tasks. -This project also consist of a collection of tools called [**scannerctl**](scannerctl/README.md). It contains variety of utilities for different tasks. For more information look into [**scannerctl**](scannerctl/README.md). - +This project also consist of a collection of tools called [**scannerctl**](./src/scannerctl/README.md). It contains variety of utilities for different tasks. For more information look into [**scannerctl**](./src/scannerctl/README.md). # Implementation of the NASL Attack Scripting Language @@ -17,7 +16,6 @@ The decision to rewrite certain parts in rust was mainly to have an easier way t The implementation is split into multiple parts that are reflected in the directory layout. - # Requirements - rust toolchain diff --git a/rust/crates/nasl-function-proc-macro/src/codegen.rs b/rust/crates/nasl-function-proc-macro/src/codegen.rs index c7cbd4b74..df8b350f3 100644 --- a/rust/crates/nasl-function-proc-macro/src/codegen.rs +++ b/rust/crates/nasl-function-proc-macro/src/codegen.rs @@ -120,7 +120,9 @@ impl<'a> ArgsStruct<'a> { let fn_args_names = self.get_fn_args_names(); let call_expr = match self.receiver_type { ReceiverType::None => quote! { #mangled_ident(#fn_args_names) }, - ReceiverType::RefSelf => quote! { self.#mangled_ident(#fn_args_names) }, + ReceiverType::RefSelf | ReceiverType::RefMutSelf => { + quote! { self.#mangled_ident(#fn_args_names) } + } }; let await_ = match asyncness { Some(_) => quote! { .await }, @@ -176,6 +178,7 @@ impl<'a> ArgsStruct<'a> { let self_arg = match self.receiver_type { ReceiverType::None => quote! {}, ReceiverType::RefSelf => quote! {&self,}, + ReceiverType::RefMutSelf => quote! {&mut self,}, }; let inputs = quote! { #self_arg diff --git a/rust/crates/nasl-function-proc-macro/src/error.rs b/rust/crates/nasl-function-proc-macro/src/error.rs index e2049f0b0..1145e1926 100644 --- a/rust/crates/nasl-function-proc-macro/src/error.rs +++ b/rust/crates/nasl-function-proc-macro/src/error.rs @@ -14,7 +14,6 @@ pub enum ErrorKind { OnlyNormalArgumentsAllowed, WrongArgumentOrder, MovedReceiverType, - MutableRefReceiverType, TypedRefReceiverType, } @@ -41,9 +40,6 @@ impl Error { ErrorKind::MovedReceiverType => { "Receiver argument is of type `self`. Currently, only `&self` receiver types are supported." } - ErrorKind::MutableRefReceiverType => { - "Receiver argument is of type `&mut self`. Currently, only `&self` receiver types are supported." - } ErrorKind::TypedRefReceiverType => { "Specific type specified in receiver argument. Currently, only `&self` is supported." } diff --git a/rust/crates/nasl-function-proc-macro/src/parse.rs b/rust/crates/nasl-function-proc-macro/src/parse.rs index 72b234f5b..2c4d669cd 100644 --- a/rust/crates/nasl-function-proc-macro/src/parse.rs +++ b/rust/crates/nasl-function-proc-macro/src/parse.rs @@ -152,13 +152,13 @@ impl ReceiverType { if rec.reference.is_none() { return make_err(ErrorKind::MovedReceiverType); } - // `&mut self` - else if rec.mutability.is_some() { - return make_err(ErrorKind::MutableRefReceiverType); - } // e.g. `self: Box` else if rec.colon_token.is_some() { return make_err(ErrorKind::TypedRefReceiverType); + } + // `&mut self` + else if rec.mutability.is_some() { + ReceiverType::RefMutSelf } else { ReceiverType::RefSelf } diff --git a/rust/crates/nasl-function-proc-macro/src/types.rs b/rust/crates/nasl-function-proc-macro/src/types.rs index 4ee93372e..8e1b25baf 100644 --- a/rust/crates/nasl-function-proc-macro/src/types.rs +++ b/rust/crates/nasl-function-proc-macro/src/types.rs @@ -23,6 +23,7 @@ pub struct ArgsStruct<'a> { pub enum ReceiverType { None, RefSelf, + RefMutSelf, } pub struct Arg<'a> { diff --git a/rust/crates/smoketest/README.md b/rust/crates/smoketest/README.md index 503b5ed94..07337a001 100644 --- a/rust/crates/smoketest/README.md +++ b/rust/crates/smoketest/README.md @@ -7,11 +7,11 @@ To build and run the tests a Makefile is provided: - make run - runs a scan against an scanner API listening on http://127.0.0.1:3000. ## Configuration -Usage of api-key is optional. For details on how to configure it, see the [openvasd documentation](../openvasd/README.md). +Usage of api-key is optional. For details on how to configure it, see the [openvasd documentation](../../src/openvasd/README.md). -In case of running the test against a mTLS enabled `openvasd`, you need to configure the client key and cert as well in the smoke test environment. For details on how to configure it, see the [openvasd documentation](../openvasd/README.md). +In case of running the test against a mTLS enabled `openvasd`, you need to configure the client key and cert as well in the smoke test environment. For details on how to configure it, see the [openvasd documentation](../../src/openvasd/README.md). -For creation of the key/cert pair for mTLS authentication, see the tls section in the [openvasd documentation](../openvasd/README.md). Also, you find certificate generators in the [examples](../examples/tls) +For creation of the key/cert pair for mTLS authentication, see the tls section in the [openvasd documentation](../../src/openvasd/README.md). Also, you find certificate generators in the [examples](../../examples/tls/) For authenticated scans, you can set a custom target (default is 127.0.0.1), username and password. diff --git a/rust/doc/misc/progress-calculation-details.md b/rust/doc/misc/progress-calculation-details.md index 8fa6ee8c9..f027c0dfa 100644 --- a/rust/doc/misc/progress-calculation-details.md +++ b/rust/doc/misc/progress-calculation-details.md @@ -74,7 +74,7 @@ scan_progress = (12 + 75 + 100 * 1) / (12 - 2) = 18.7 % ## Special case for resume task -When a resume task, the finished hosts should not be scanned again. Therefore they are sent in the list of excluded hosts. Please read the documentation for [resume scan](resume-scan.md). +When a resume task, the finished hosts should not be scanned again. Therefore they are sent in the list of excluded hosts. Please read the documentation for [resume scan](../faq/resume-scan.md). In this case, a resume scan with some finished hosts, should not start with a progress with 0%, but a progress according with the already finished hosts. Then, imagine that the scan of example above, with an initial target of 15 hosts, was stopped/interrupted and you want to resume it. It has an already finished hosts. This hosts is added to the list of `excluded hosts`. @@ -111,4 +111,3 @@ Then, the scan progress for a resume task will start from: ``` scan_progress = (0 + 100 * (0 + 1) / (11 + 1 - 2) = 10 % ``` - diff --git a/rust/doc/openvasd-osp-cmd-equivalence.md b/rust/doc/openvasd-osp-cmd-equivalence.md index 14b9619ce..eb8df3aa3 100644 --- a/rust/doc/openvasd-osp-cmd-equivalence.md +++ b/rust/doc/openvasd-osp-cmd-equivalence.md @@ -2,33 +2,33 @@ This document shows the migration of OSP commands (implemented by ospd-openvas) to the new scanner API (implemented by openvasd). It only provides the XML for the command and its corresponding JSON counterpart, as well as the endpoint of the HTTP API. For further information of the commands either see [OSP](https://docs.greenbone.net/API/OSP/osp-22.4.html) or [Scanner API](https://greenbone.github.io/scanner-api/). -# Table of contents -1. [Help command](#Help-command) -2. [Get memory usage command](#Get-memory-usage-command) -3. [Start a scan](#Start-a-scan) -4. [Stop a scan](#Stop-a-scan) -5. [Delete a scan](#Delete-a-scan) -6. [Fetching results](#Fetching-results) -7. [Scan status and progress](#Scan-status-and-progress) -8. [Feed check](#Feed-check) -9. [Get VTs](#Get-VTs) -10. [Get Version](#Get-Version) -11. [Get scanner details](#Get-scanner-details) -12. [Get sensor performance](#Get-sensor-performance) - -### Help command +- [Migration Guide for API usage of previous OSP commands](#migration-guide-for-api-usage-of-previous-osp-commands) + - [Help command](#help-command) + - [Get memory usage command](#get-memory-usage-command) + - [Start a scan](#start-a-scan) + - [Stop a scan](#stop-a-scan) + - [Delete a scan](#delete-a-scan) + - [Fetching results](#fetching-results) + - [Scan status and progress](#scan-status-and-progress) + - [Feed check](#feed-check) + - [Get VTs](#get-vts) + - [Get Version](#get-version) + - [Get scanner details](#get-scanner-details) + - [Get sensor performance](#get-sensor-performance) + +## Help command there is a help command which includes all supported OSP commands and details. There is no equivalent command for Scanner API. Just refer to the Scanner API ``` xml ``` -### Get memory usage command +## Get memory usage command This command shows RSS, VMS and shared current memory usage. It is a debugging purpose command. There is no equivalent command for Scanner API. ``` xml ``` -### Start a scan +## Start a scan ***With OSP*** @@ -123,7 +123,7 @@ Json body: {"action": "start"} ``` -### Stop a scan +## Stop a scan As explained in the subsection above, you know the scan ID for OSP, because it is necessary for starting a new scan, while the scan ID is created by Openvasd when using Scanner API. Then the scan_id is necessary for both protocols. @@ -143,7 +143,7 @@ Json body: {"action": "stop"} ``` -### Delete a scan +## Delete a scan With the known scan_id, a scan can be deleted. The scan must not be running. So it must be either stopped before or finished. In case of the new scanner API it could also be in the stored status. @@ -162,7 +162,7 @@ Endpoint: /scans/{scan_id} Parameter scan_id: is de Scan ID ``` -### Fetching results +## Fetching results Knowing the scan id, it is possible to fetch results. This command allows some options, like fetching just an amount of results. @@ -186,7 +186,7 @@ Parameter scan_id: is de Scan ID. Optional Query: ?range=start-end, where end is optional as well. ``` -### Scan status and progress +## Scan status and progress ***With OSP*** @@ -205,7 +205,7 @@ Endpoint: /scans/{scan_id}/status Parameter scan_id: is de Scan ID ``` -### Feed check +## Feed check ***With OSP*** @@ -223,7 +223,7 @@ Endpoint: /health/ready or /health/alive or /health/started ``` -### Get VTs +## Get VTs Get a list of Vulnerability test present in the current feed. This includes Notus and NASL tests. @@ -249,7 +249,7 @@ Optional Query: ?information=bool shows the whole feed metadata. ``` -### Get Version +## Get Version ***With Osp*** @@ -266,7 +266,7 @@ Only the feed version and the HTTP version are available. Method: HEAD ``` -### Get scanner details +## Get scanner details Return details about the scanner @@ -285,7 +285,7 @@ Method: GET Entrypoint: scans/preferences ``` -### Get sensor performance +## Get sensor performance Return system report. There is currently no equivalent command for Scanner API @@ -295,5 +295,3 @@ More information about this command GOS GVMCG ``` xml ``` - - diff --git a/rust/src/feed/README.md b/rust/src/feed/README.md index d1835ed27..63b36f5f7 100644 --- a/rust/src/feed/README.md +++ b/rust/src/feed/README.md @@ -16,12 +16,12 @@ FEED_NAME = "short name of the feed"; ``` ## Verify -[Implements](./src/verify/mod.rs) a [HashSumNameLoader](./src/verify/mod.rs#L93) that loads the filenames defined in the sha256sums and verifies the corresponding hashsum. -Also, implements a [signature verifier](./src/verify/mod.rs#L163) for checking the signature of the sha256sums file. +[Implements](./verify/mod.rs) a `HashSumNameLoader` that loads the filenames defined in the sha256sums and verifies the corresponding hashsum. +Also, implements a `signature verifier` for checking the signature of the sha256sums file. ### Example -```no_run +```rs,no_run use scannerlib::nasl::FSPluginLoader; // needs to be path that contains a sha256sums file otherwise // it will throw an exception. diff --git a/rust/src/nasl/builtin/README.md b/rust/src/nasl/builtin/README.md index c86a160d7..cbd3d3e13 100644 --- a/rust/src/nasl/builtin/README.md +++ b/rust/src/nasl/builtin/README.md @@ -2,7 +2,7 @@ Contains functions that are within the std library of nasl. -To use the std functions it is recommended to use the defined [ContextFactory] as it sets the function register to the one created in [nasl_std_functions] automatically. +To use the std functions it is recommended to use the defined `ContextFactory` as it sets the function register to the one created in `nasl_std_functions` automatically. All you have to do as a user is to create the builder @@ -29,7 +29,7 @@ To add a function to std you have to add function crate to the Cargo.toml nasl-builtin-string = {path = "../nasl-builtin-string"} ``` -and then extend the builder within [nasl_std_functions] with the implementation of [nasl_builtin_utils::NaslFunctionExecuter] of those functions: +and then extend the builder within `nasl_std_functions` with the implementation of `nasl_builtin_utils::NaslFunctionExecuter` of those functions: ```text builder = builder.push_register(nasl_builtin_string::NaslString) diff --git a/rust/src/nasl/interpreter/README.md b/rust/src/nasl/interpreter/README.md index 64be1f116..6d5ee1aaf 100644 --- a/rust/src/nasl/interpreter/README.md +++ b/rust/src/nasl/interpreter/README.md @@ -1,11 +1,10 @@ # nasl-interpreter +Is a library that is utilizing [nasl-syntax](../syntax/) and [storage](../../openvasd/storage/) to execute statements. -Is a library that is utilizing [nasl-syntax](../nasl-syntax/) and [storage](../storage/) to execute statements. +The core part is written in [interpreter.rs](./interpreter.rs) and is separated into various extensions to execute a given `Statement` when `resolve` is called. -The core part is written in [interpreter.rs](./src/interpreter.rs) and is separated into various extensions to execute a given `Statement` when `resolve` is called. - -Each resolve call will result in a [NaslValue](./src/naslvalue.rs) or an [InterpretError](./src/error.rs) return value. +Each resolve call will result in a [NaslValue](../syntax/naslvalue.rs) or an [InterpretError](../syntax/error.rs) return value. An interpreter requires: @@ -16,7 +15,6 @@ An interpreter requires: - `loader: &'a dyn Loader` - is used to load script dependencies on `include`, - `logger: Box` - the default logger - ## Example ``` @@ -30,10 +28,9 @@ let code = "display('hi');"; let mut parser = CodeInterpreter::new(code, register, &context); ``` - ## Built in functions -It provides a set of builtin functionality within [built_in_functions](./src/built_in_functions/) to add a new functionality you have to enhance the lookup function within [lib.rs](./src/lib.rs). +It provides a set of builtin functionality within [built_in_functions](../builtin/) to add a new functionality you have to enhance the lookup function within [lib.rs](../../lib.rs). Each builtin function follow the syntax of: @@ -41,7 +38,7 @@ Each builtin function follow the syntax of: fn(&str, &dyn storage, &Register) -> Result ``` -An example of how to write a new builtin function can be found in [misc](./src/built_in_functions/misc.rs). +An example of how to write a new builtin function can be found in [misc](../builtin/misc/). ## Build diff --git a/rust/src/nasl/mod.rs b/rust/src/nasl/mod.rs index 9ac2dfe6b..a399cbcb9 100644 --- a/rust/src/nasl/mod.rs +++ b/rust/src/nasl/mod.rs @@ -31,6 +31,7 @@ pub use prelude::*; pub mod test_prelude { pub use super::prelude::*; pub use super::test_utils::check_code_result; + pub use super::test_utils::DefaultTestBuilder; pub use super::test_utils::TestBuilder; pub use crate::check_code_result_matches; pub use crate::check_err_matches; diff --git a/rust/src/nasl/syntax/README.md b/rust/src/nasl/syntax/README.md index 051a94cbe..a5ecad448 100644 --- a/rust/src/nasl/syntax/README.md +++ b/rust/src/nasl/syntax/README.md @@ -2,7 +2,7 @@ `nasl-syntax` is a library to provide structured representation of NASL code. -It will return an Iterator with either a [statement](./src/statement.rs) for further execution or an [error](./src/error.rs) if the given code was incorrect. +It will return an Iterator with either a [statement](./statement.rs) for further execution or an [error](./error.rs) if the given code was incorrect. Each statement is self contained and it is expected to be executed iteratively and therefore there is no visitor implementation. diff --git a/rust/src/nasl/test_utils.rs b/rust/src/nasl/test_utils.rs index 0e559f01f..d82c19644 100644 --- a/rust/src/nasl/test_utils.rs +++ b/rust/src/nasl/test_utils.rs @@ -13,7 +13,7 @@ use crate::{ }, storage::{DefaultDispatcher, Storage}, }; -use futures::StreamExt; +use futures::{Stream, StreamExt}; use super::{ builtin::ContextFactory, @@ -95,8 +95,14 @@ impl From for TracedTestResult { /// NASL code. #[derive(Clone)] enum TestResult { + /// Expect the Result to be `Ok(val)` and compare `val` against a + /// given `NaslValue` Ok(NaslValue), - GenericCheck(Box), + /// Performs a check described by the closure. To still provide + /// decent error messages, the second argument may contain a + /// String describing the expected result. + GenericCheck(Box, Option), + /// Do not perform any check. None, } @@ -116,6 +122,8 @@ pub struct TestBuilder { should_verify: bool, } +pub type DefaultTestBuilder = TestBuilder; + impl Default for TestBuilder { fn default() -> Self { Self { @@ -145,8 +153,8 @@ where S: Storage, { #[track_caller] - fn add_line(&mut self, line: &str, val: TestResult) -> &mut Self { - self.lines.push(line.to_string()); + fn add_line(&mut self, line: impl Into, val: TestResult) -> &mut Self { + self.lines.push(line.into()); self.results.push(val.into()); self } @@ -158,7 +166,7 @@ where /// t.ok("x = 3;", 3); /// ``` #[track_caller] - pub fn ok(&mut self, line: &str, val: impl ToNaslResult) -> &mut Self { + pub fn ok(&mut self, line: impl Into, val: impl ToNaslResult) -> &mut Self { self.add_line(line, TestResult::Ok(val.to_nasl_result().unwrap())) } @@ -175,15 +183,19 @@ where #[track_caller] pub fn check( &mut self, - line: &str, + line: impl Into, f: impl Fn(NaslResult) -> bool + 'static + Clone, + expected: Option>, ) -> &mut Self { - self.add_line(line, TestResult::GenericCheck(Box::new(f))) + self.add_line( + line, + TestResult::GenericCheck(Box::new(f), expected.map(|s| s.into())), + ) } /// Run a `line` of NASL code without checking its result. #[track_caller] - pub fn run(&mut self, line: &str) -> &mut Self { + pub fn run(&mut self, line: impl Into) -> &mut Self { self.add_line(line, TestResult::None) } @@ -201,27 +213,37 @@ where /// Return the list of results returned by all the lines of /// code. pub fn results(&self) -> Vec { - let code = self.lines.join("\n"); + futures::executor::block_on(async { + self.results_stream(&self.code(), &self.context()) + .collect() + .await + }) + } + + fn code(&self) -> String { + self.lines.join("\n") + } + + pub fn results_stream<'a>( + &'a self, + code: &'a str, + context: &'a Context, + ) -> impl Stream + 'a { let variables: Vec<_> = self .variables .iter() .map(|(k, v)| (k.clone(), ContextType::Value(v.clone()))) .collect(); let register = Register::root_initial(&variables); - let context = self.context(); + // let code = self.lines.join("\n"); + // let context = self.context(); let parser = CodeInterpreter::new(&code, register, &context); - futures::executor::block_on(async { - parser - .stream() - .map(|res| { - res.map_err(|e| match e.kind { - InterpretErrorKind::FunctionCallError(f) => f.kind, - e => panic!("Unknown error: {}", e), - }) - }) - .collect() - .await + parser.stream().map(|res| { + res.map_err(|e| match e.kind { + InterpretErrorKind::FunctionCallError(f) => f.kind, + e => panic!("Unknown error: {}", e), + }) }) } @@ -241,14 +263,18 @@ where } fn verify(&mut self) { - let results = self.results(); if self.should_verify { - assert_eq!(results.len(), self.results.len()); - for (line_count, (result, reference)) in - (results.iter().zip(self.results.iter())).enumerate() - { - self.check_result(result, reference, line_count); - } + let mut references_iter = self.results.iter().enumerate(); + let code = self.code(); + let context = self.context(); + let mut results = self.results_stream(&code, &context); + futures::executor::block_on(async { + while let Some(result) = results.next().await { + let (line_count, reference) = references_iter.next().unwrap(); + self.check_result(&result, reference, line_count); + } + }); + assert!(references_iter.next().is_none()); } else { // Make sure the user did not add requirements to this test // since we wont verify them. Panic if they did @@ -279,12 +305,16 @@ where result, ); } - TestResult::GenericCheck(_) => { - panic!( - "Check failed at {}.\nIn code \"{}\".", - reference.location, self.lines[line_count] - ); - } + TestResult::GenericCheck(_, expected) => match expected { + Some(expected) => panic!( + "Mismatch at {}.\nIn code \"{}\":\nExpected: {}\nFound: {:?}", + reference.location, self.lines[line_count], expected, result + ), + None => panic!( + "Check failed at {}.\nIn code \"{}\". Found result: {:?}", + reference.location, self.lines[line_count], result + ), + }, TestResult::None => unreachable!(), } } @@ -297,7 +327,7 @@ where ) -> bool { match reference { TestResult::Ok(val) => result.as_ref() == Ok(val), - TestResult::GenericCheck(f) => f(result.clone()), + TestResult::GenericCheck(f, _) => f(result.clone()), TestResult::None => true, } } @@ -359,12 +389,12 @@ pub fn check_code_result(code: &str, expected: impl ToNaslResult) { /// perform a check on the line of code using a new `TestBuilder`. #[macro_export] macro_rules! check_err_matches { - ($t: ident, $code: literal, $pat: pat $(,)?) => { - $t.check($code, |e| matches!(e, Err($pat))); + ($t: ident, $code: expr, $pat: pat $(,)?) => { + $t.check($code, |e| matches!(e, Err($pat)), Some(stringify!($pat))); }; - ($code: literal, $pat: pat $(,)?) => { + ($code: expr, $pat: pat $(,)?) => { let mut t = $crate::nasl::test_utils::TestBuilder::default(); - t.check($code, |e| matches!(e, Err($pat))); + t.check($code, |e| matches!(e, Err($pat)), Some(stringify!($pat))); }; } @@ -372,8 +402,8 @@ macro_rules! check_err_matches { /// and that the inner value matches a pattern. #[macro_export] macro_rules! check_code_result_matches { - ($code: literal, $pat: pat) => { + ($code: expr, $pat: pat) => { let mut t = $crate::nasl::test_utils::TestBuilder::default(); - t.check($code, |val| matches!(val, Ok($pat))); + t.check($code, |val| matches!(val, Ok($pat)), Some(stringify!($pat))); }; } diff --git a/rust/src/nasl/utils/function/from_nasl_value.rs b/rust/src/nasl/utils/function/from_nasl_value.rs index 2da41b42b..a36dbeacc 100644 --- a/rust/src/nasl/utils/function/from_nasl_value.rs +++ b/rust/src/nasl/utils/function/from_nasl_value.rs @@ -101,9 +101,10 @@ macro_rules! impl_from_nasl_value_for_numeric_type { NaslValue::Number(num) => Ok(<$ty>::try_from(*num).map_err(|_| { FunctionErrorKind::WrongArgument("Expected positive number.".into()) })?), - _ => Err(FunctionErrorKind::WrongArgument( - "Expected a number.".to_string(), - )), + e => Err(FunctionErrorKind::WrongArgument(format!( + "Expected a number, found '{}'.", + e + ))), } } } diff --git a/rust/src/openvasd/README.md b/rust/src/openvasd/README.md index 10eeaafcc..569210d48 100644 --- a/rust/src/openvasd/README.md +++ b/rust/src/openvasd/README.md @@ -4,6 +4,21 @@ Is the implementation for [scanner-api](https://greenbone.github.io/scanner-api/ Currently it is utilizing ospd-openvas. +- [OpenVAS Daemon](#openvas-daemon) +- [Requirements](#requirements) +- [Configuration](#configuration) + - [Authentication](#authentication) + - [API Key](#api-key) + - [Certificates](#certificates) + - [How does mTLS works?](#how-does-mtls-works) + - [Certificate Authority for PKI mTLS Method](#certificate-authority-for-pki-mtls-method) + - [mTLS with self-signed client certificates.](#mtls-with-self-signed-client-certificates) + - [Mode](#mode) +- [Usage](#usage) + - [Feed signature check.](#feed-signature-check) +- [Options](#options) +- [Migration from previous OSP commands](#migration-from-previous-osp-commands) + # Requirements It requires a running ospd-openvas instance. @@ -17,7 +32,7 @@ Create a configuration file under either: or provide the `-c` flag when starting openvasd. -An example can be found [here](../examples/openvasd/config.example.toml) +An example can be found [here](../../examples/openvasd/config.example.toml) ## Authentication @@ -118,7 +133,6 @@ As can be seen, no CA certificate is used, since instead the client certificate Openvasd currently supports two operation modes. The `service` mode supports all available endpoints, where the `service_notus` mode only supports the notus related endpoints. - # Usage ``` @@ -218,4 +232,4 @@ If the signature check is enabled, it is also required to set the the `GNUPGHOME # Migration from previous OSP commands -In this [page](doc/osp-cmd-equivalence.md) you can find a guide for API usage of previous OSP commands +In this [page](../../doc/openvasd-osp-cmd-equivalence.md) you can find a guide for API usage of previous OSP commands diff --git a/rust/src/scannerctl/README.md b/rust/src/scannerctl/README.md index 7d08c0eb1..b2b7cb14c 100644 --- a/rust/src/scannerctl/README.md +++ b/rust/src/scannerctl/README.md @@ -224,7 +224,7 @@ Options: On `feed transform` it will first read the `sha256sums` file within the feed directory and verify each file with the corresponding sha256sums. When the hash is correct it will execute each mentioned `*.nasl` script within that dir with `description = 1`. Optionally, it is possible to perform a signature verification of the sha256sums file before the transformation. To enable the signature check, the environment variable `GNUPGHOME` must be set with the gnupg home directory, where the `pubring.kbx` file is stored. -It will produce a json array in stdout in the format described within [json-storage](../json-storage/README.md). +It will produce a json array in stdout in the format described within [json-storage](../storage/json/README.md) #### transpile @@ -238,7 +238,7 @@ Options: - `-r`, `--rules `: Path to transpiler rules. - `-h`, `--help`: Print help -An example can be found in [examples](../examples/scannerctl/transpile.toml) folder. This example demonstrates how to +An example can be found in [examples](../../examples/scannerctl/transpile.toml) folder. This example demonstrates how to - rename service `www` to `word-wide-web` in register_product - `register_host_detail` to `add_host_detail` diff --git a/rust/src/storage/README.md b/rust/src/storage/README.md index f3e838b7a..beb452bab 100644 --- a/rust/src/storage/README.md +++ b/rust/src/storage/README.md @@ -1,18 +1,23 @@ # storage +``` + +``` + + Is a specialized library to handle data from the nasl-interpreter to the storage / distribution implementation. -To be able to introduce new distribution implementations the [Dispatcher](src/lib.rs#L80) must be implement. +To be able to introduce new distribution implementations the `Dispatcher` must be implement. -The [Field](src/lib.rs#L21) enum required by `dispatch` method describes fields to be distributed. +The `Field` enum required by `dispatch` method describes fields to be distributed. The reason that it uses field descriptions rather than structs are two fold: 1. it allows the usage of streaming distribution 2. it makes it easier to store information immediately on execution -Since we sometimes have the requirement to just store when all information is available the [on_exit](src/lib.rs#L93) must be called when the interpreter finishes. +Since we sometimes have the requirement to just store when all information is available the `on_exit` must be called when the interpreter finishes. -A simplified example on how to write a storage implementation can be found in [DefaultDispatcher](src/lib.rs#L116) +A simplified example on how to write a storage implementation can be found in `DefaultDispatcher` ## Build diff --git a/rust/src/storage/redis/README.md b/rust/src/storage/redis/README.md index 9fcde16ca..1dfab7c96 100644 --- a/rust/src/storage/redis/README.md +++ b/rust/src/storage/redis/README.md @@ -1,5 +1,5 @@ # redis-storage -Is the redis implementation for [storage](../storage/). +Is the redis implementation for [storage](../../storage/). It is written in a downwards compatible way so that `ospd-openvas` is capable of reading and writing the data.