-
Notifications
You must be signed in to change notification settings - Fork 589
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Change: make async the methods for preference handling. #1572
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Also, improve the creating the RedisHelper, since at this point the nvti cache and a main kb for the scan should have been created. Usage example. (Needs a running redis instance with an up-to-date nvticache) ``` ```use std::sync::{Arc, Mutex}; use models::{AliveTestMethods, Credential, PortRange, Port, Scan, Parameter}; use openvas::{pref_handler::PreferenceHandler, openvas_redis::RedisHelper}; use redis_storage::{NameSpaceSelector, RedisCtx}; async fn main() -> Result<(), std::fmt::Error> { // Create an scan config let mut scan = Scan::default(); scan.scan_id = Some("123-456".to_string()); scan.target.alive_test_methods = vec![AliveTestMethods::Icmp, AliveTestMethods::TcpSyn]; scan.target.credentials = vec![Credential { service: models::Service::SSH, port: Some(22), credential_type: models::CredentialType::UP { username: "user".to_string(), password: "pass".to_string(), privilege_credential: None, }, }]; scan.vts.push(models::VT { oid: "1.3.6.1.4.1.25623.1.0.112771".to_string(), parameters: vec![Parameter { id: 1, value: "llala".to_string() }] }); scan.target.excluded_hosts = vec!["127.0.0.1".to_string()]; scan.target.hosts = vec!["127.0.0.2".to_string()]; scan.target.ports = vec![Port { protocol: Some(models::Protocol::TCP), range: vec![ PortRange { start: 22, end: Some(25), }, PortRange { start: 80, end: None, }, ], }]; let redis_url = "unix:///run/redis-openvas/redis.sock"; // In this example, a fix db is taken,but the next free can be taken, using the name space selector NameSpaceSelector::Free let mut rctx = RedisCtx::open(redis_url, &[NameSpaceSelector::Fix(6)]).unwrap(); rctx.delete_namespace().unwrap(); // Create a redis connection to the nvticache, and a connection to the mainkb(). let cache = RedisCtx::open(redis_url, &[NameSpaceSelector::Key("nvticache")]).unwrap(); // New redis helper with access to the main kb for storing the preferences, and access to the nvticache // for getting info to build preferences. let rc = RedisHelper::<RedisCtx>::init(Arc::new(Mutex::new(cache)),Arc::new(Mutex::new(rctx))).unwrap(); let mut p = PreferenceHandler::new(scan, rc); Ok(p.prepare_preferences_for_openvas().await.expect("aaa")) }
jjnicola
force-pushed
the
async-prefs-handler
branch
from
February 16, 2024 14:28
e33c642
to
40feae3
Compare
nichtsfrei
approved these changes
Feb 20, 2024
nichtsfrei
reviewed
Feb 20, 2024
nichtsfrei
reviewed
Feb 20, 2024
nichtsfrei
reviewed
Feb 20, 2024
nichtsfrei
reviewed
Feb 20, 2024
nichtsfrei
requested changes
Feb 20, 2024
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some minor things.
nichtsfrei
approved these changes
Feb 20, 2024
Kraemii
approved these changes
Feb 21, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What:
Jira: SC-1026
Also, improve the init of RedisHelper, since at this point the nvti cache and a main kb for the scan should have been created.
Usage example. (Needs a running redis instance with an up-to-date nvticache)
Why:
How:
Checklist: