Skip to content
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

Get vts #13

Closed
wants to merge 13 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
607 changes: 329 additions & 278 deletions rust/Cargo.lock

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions rust/cross.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ RUN ./configure --host=x86_64-unknown-linux-gnu --with-pcap=linux
RUN cat config.log
RUN make install

RUN curl --output /tmp/zlib.tar.gz https://www.zlib.net/zlib-1.3.tar.gz
RUN curl --output /tmp/zlib.tar.gz https://www.zlib.net/zlib-1.3.1.tar.gz
WORKDIR /tmp
RUN tar xvf zlib.tar.gz
WORKDIR /tmp/zlib-1.3
WORKDIR /tmp/zlib-1.3.1
RUN ./configure
RUN make install
RUN ldconfig
Expand Down
4 changes: 2 additions & 2 deletions rust/cross_aarch64.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ RUN ./configure --host=aarch64-unknown-linux-gnu --with-pcap=linux
RUN cat config.log
RUN make install

RUN curl --output /tmp/zlib.tar.gz https://www.zlib.net/zlib-1.3.tar.gz
RUN curl --output /tmp/zlib.tar.gz https://www.zlib.net/zlib-1.3.1.tar.gz
WORKDIR /tmp
RUN tar xvzf zlib.tar.gz
WORKDIR /tmp/zlib-1.3
WORKDIR /tmp/zlib-1.3.1
RUN ./configure
RUN make install
RUN ldconfig
Expand Down
2 changes: 1 addition & 1 deletion rust/feed-verifier/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ fn main() {
};
let (ncd, nasl_cli) = run_get(
&mut kb,
&format!("{} feed update", nasl_cli.to_str().unwrap_or_default()),
&format!("{} feed update --vts-only", nasl_cli.to_str().unwrap_or_default()),
)
.expect("results");
let mut errors = 0;
Expand Down
10 changes: 5 additions & 5 deletions rust/feed/src/update/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ use nasl_interpreter::{
logger::DefaultLogger, AsBufReader, Context, ContextType, Interpreter, Loader, NaslValue,
Register,
};
use storage::{nvt::NVTField, Dispatcher, NoOpRetriever};
use storage::{item::NVTField, Dispatcher, NoOpRetriever};

use crate::verify::{self, SignatureChecker, HashSumFileItem};
use crate::verify::{self, HashSumFileItem, SignatureChecker};

pub use self::error::ErrorKind;

Expand Down Expand Up @@ -69,16 +69,16 @@ pub fn feed_version<K: Default + AsRef<str>>(
Ok(feed_version)
}


impl<'a, R, S, L, V, K> SignatureChecker for Update<S, L, V, K>
where
S: Sync + Send + Dispatcher<K>,
K: AsRef<str> + Display + Default + From<String>,
L: Sync + Send + Loader + AsBufReader<File>,
V: Iterator<Item = Result<HashSumFileItem<'a, R>, verify::Error>>,
R: Read + 'a,
{}

{
}

impl<'a, S, L, V, K, R> Update<S, L, V, K>
where
S: Sync + Send + Dispatcher<K>,
Expand Down
41 changes: 21 additions & 20 deletions rust/json-storage/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use std::{
sync::{Arc, Mutex},
};

use storage::{self, nvt::PerNVTDispatcher, Kb, StorageError};
use storage::{self, item::PerItemDispatcher, Kb, StorageError};

/// Wraps write calls of json elements to be as list.
///
Expand Down Expand Up @@ -66,14 +66,14 @@ where
}

/// It will transform a Nvt to json and write it into the given Writer.
pub struct NvtDispatcher<W>
pub struct ItemDispatcher<W>
where
W: Write,
{
w: Arc<Mutex<W>>,
kbs: Arc<Mutex<Vec<Kb>>>,
}
impl<S> NvtDispatcher<S>
impl<S> ItemDispatcher<S>
where
S: Write,
{
Expand All @@ -87,26 +87,26 @@ where
}

/// Returns a new instance as a Dispatcher
pub fn as_dispatcher<K>(w: S) -> PerNVTDispatcher<Self, K>
pub fn as_dispatcher<K>(w: S) -> PerItemDispatcher<Self, K>
where
K: AsRef<str>,
{
PerNVTDispatcher::new(Self::new(w))
PerItemDispatcher::new(Self::new(w))
}

fn as_json(&self, nvt: storage::nvt::Nvt) -> Result<(), storage::StorageError> {
fn as_json(&self, nvt: storage::item::Nvt) -> Result<(), storage::StorageError> {
let mut context = self.w.lock().map_err(StorageError::from)?;
serde_json::to_vec(&nvt)
.map_err(|e| StorageError::Dirty(format!("{e:?}")))
.and_then(|x| context.write_all(&x).map_err(StorageError::from))
}
}

impl<S, K> storage::nvt::NvtDispatcher<K> for NvtDispatcher<S>
impl<S, K> storage::item::ItemDispatcher<K> for ItemDispatcher<S>
where
S: Write,
{
fn dispatch_nvt(&self, nvt: storage::nvt::Nvt) -> Result<(), storage::StorageError> {
fn dispatch_nvt(&self, nvt: storage::item::Nvt) -> Result<(), storage::StorageError> {
self.as_json(nvt)
}

Expand All @@ -126,7 +126,7 @@ where
}
}

impl<S, K> storage::Retriever<K> for NvtDispatcher<S>
impl<S, K> storage::Retriever<K> for ItemDispatcher<S>
where
S: Write,
{
Expand All @@ -138,6 +138,7 @@ where
Ok(match scope {
// currently not supported
storage::Retrieve::NVT(_) => Vec::new(),
storage::Retrieve::NOTUS(_) => Vec::new(),
storage::Retrieve::KB(s) => {
let kbs = self.kbs.lock().map_err(StorageError::from)?;
kbs.iter()
Expand All @@ -162,7 +163,7 @@ where
mod tests {
use std::collections::BTreeMap;

use storage::nvt::{Nvt, ACT};
use storage::item::{Nvt, ACT};

use super::*;

Expand All @@ -174,9 +175,9 @@ mod tests {
.join(".")
}

fn generate_tags() -> BTreeMap<storage::nvt::TagKey, storage::nvt::TagValue> {
use storage::nvt::TagKey::*;
use storage::nvt::TagValue;
fn generate_tags() -> BTreeMap<storage::item::TagKey, storage::item::TagValue> {
use storage::item::TagKey::*;
use storage::item::TagValue;
let ts = "2012-09-23 02:15:34 -0400";
BTreeMap::from([
(Affected, TagValue::parse(Affected, "Affected").unwrap()),
Expand Down Expand Up @@ -221,9 +222,9 @@ mod tests {
(Vuldetect, TagValue::parse(Vuldetect, "Vuldetect").unwrap()),
])
}
fn generate_preferences() -> Vec<storage::nvt::NvtPreference> {
use storage::nvt::NvtPreference;
use storage::nvt::PreferenceType;
fn generate_preferences() -> Vec<storage::item::NvtPreference> {
use storage::item::NvtPreference;
use storage::item::PreferenceType;
[
PreferenceType::CheckBox,
PreferenceType::Entry,
Expand Down Expand Up @@ -261,8 +262,8 @@ mod tests {
}
}

fn generate_references() -> Vec<storage::nvt::NvtRef> {
use storage::nvt::NvtRef;
fn generate_references() -> Vec<storage::item::NvtRef> {
use storage::item::NvtRef;
vec![NvtRef {
class: "URL".to_owned(),
id: "unix:///var/lib/really.sock".to_owned(),
Expand All @@ -273,7 +274,7 @@ mod tests {
fn single_json() {
let nvt = generate_nvt("test", ACT::DestructiveAttack);
let mut buf = Vec::with_capacity(1208);
let dispatcher = super::NvtDispatcher::new(&mut buf);
let dispatcher = super::ItemDispatcher::new(&mut buf);
dispatcher.as_json(nvt.clone()).unwrap();
let single_json = String::from_utf8(buf).unwrap();
let result: Nvt = serde_json::from_str(&single_json).unwrap();
Expand All @@ -284,7 +285,7 @@ mod tests {
fn array_wrapper() {
let mut buf = Vec::with_capacity(1208 * 11);
let mut ja = ArrayWrapper::new(&mut buf);
let dispatcher = super::NvtDispatcher::new(&mut ja);
let dispatcher = super::ItemDispatcher::new(&mut ja);
for nvt in [
ACT::Init,
ACT::Scanner,
Expand Down
1 change: 0 additions & 1 deletion rust/models/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ license = "GPL-2.0-or-later"
serde = {version = "1", features = ["derive"], optional = true}
bincode = {version = "2.0.0-rc.3", optional = true }


[features]
default = ["serde_support", "bincode_support"]
serde_support = ["serde"]
Expand Down
Loading
Loading