Skip to content

Commit

Permalink
Add: possibility to add C encapsuled functionality
Browse files Browse the repository at this point in the history
Adds possibility to add nasl-functions written in C.

---------

Co-authored-by: Philipp Eder <philipp.eder@greenbone.net>
  • Loading branch information
Kraemii and nichtsfrei authored Sep 7, 2023
1 parent aac7ce8 commit eb2ca34
Show file tree
Hide file tree
Showing 31 changed files with 491 additions and 49 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,7 @@ testsuiterun.nasl
assets/
*.rsa
*.pem
rust/nasl-c-lib/include
rust/nasl-c-lib/bin
rust/nasl-c-lib/share
rust/nasl-c-lib/lib
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

## DESCRIPTION

aes_mac_gcm encrypts given data with given key by using AES in CBC mode.
aes_mac_cbc encrypts given data with given key by using AES in CBC mode.
The according aes algorithm is dependent on the key size (if the key is 128 bit than AES128 is used, 256 and 512 are supported.)


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@

## SYNOPSIS

*str* **aes_mac_gcm**(key: str, data: str);
*str* **aes_mac_gcm**(key: str, data: str, iv: str);

**aes_mac_gcm** It takes four named arguments key, data.
**aes_mac_gcm** It takes three named arguments key, data, iv.

## DESCRIPTION

Expand Down
3 changes: 3 additions & 0 deletions rust/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
target/
libsrc/
nasl-c-lib/libsrc/
nasl-c-lib/lib/
77 changes: 45 additions & 32 deletions rust/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion rust/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,16 @@ members = [
"nasl-syntax",
"nasl-interpreter",
"nasl-cli",
"nasl-c-lib",
"nasl-c-lib/libgcrypt-sys",
"storage",
"redis-storage",
"json-storage",
"feed",
"feed-verifier",
"models",
"osp",
"openvasd",
"openvasd",
"scanconfig",
"infisto",
]
Expand Down
2 changes: 2 additions & 0 deletions rust/Cross.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
[build.env]
passthrough = ["IN_CROSS=1", "CLEAN=1"]
[target.aarch64-unknown-linux-gnu]
dockerfile = "cross_aarch64.Dockerfile"
[target.x86_64-unknown-linux-gnu]
Expand Down
5 changes: 1 addition & 4 deletions rust/cross.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ WORKDIR /tmp
RUN tar xvf pcap.tar.gz
RUN ls -las
WORKDIR /tmp/libpcap-1.10.3
ENV CHOST=amd64
ENV CC=x86_64-linux-gnu-gcc
ENV CFLAGS='-Os'
RUN ./configure --host=x86_64-unknown-linux-gnu --with-pcap=linux
Expand All @@ -20,8 +21,6 @@ RUN curl --output /tmp/zlib.tar.gz https://www.zlib.net/zlib-1.3.tar.gz
WORKDIR /tmp
RUN tar xvf zlib.tar.gz
WORKDIR /tmp/zlib-1.3
ENV CC=x86_64-linux-gnu-gcc
ENV CHOST=amd64
RUN ./configure
RUN make install
RUN ldconfig
Expand All @@ -31,8 +30,6 @@ WORKDIR /tmp
RUN tar xvf openssl.tar.gz
RUN ls -las
WORKDIR /tmp/openssl-1.1.1
ENV CC=x86_64-linux-gnu-gcc
ENV CFLAGS='-Os'
RUN ./Configure linux-x86_64 --prefix=/usr/local/ssl --openssldir=/usr/local/ssl shared zlib
ENV LD_LIBRARY_PATH=/usr/local/ssl/lib:${LD_LIBRARY_PATH}
RUN ldconfig
Expand Down
10 changes: 4 additions & 6 deletions rust/cross_aarch64.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@ RUN apt-get update && apt-get install -y \
curl \
zlib1g-dev
RUN curl -o /tmp/pcap.tar.gz https://www.tcpdump.org/release/libpcap-1.10.3.tar.gz
ENV CC=aarch64-linux-gnu-gcc
ENV CFLAGS='-Os'
ENV CHOST=arm64

WORKDIR /tmp
RUN tar xvf pcap.tar.gz
RUN ls -las
WORKDIR /tmp/libpcap-1.10.3
ENV CC=aarch64-linux-gnu-gcc
ENV CFLAGS='-Os'
RUN ./configure --host=aarch64-unknown-linux-gnu --with-pcap=linux
RUN cat config.log
RUN make install
Expand All @@ -24,8 +26,6 @@ RUN curl --output /tmp/zlib.tar.gz https://www.zlib.net/zlib-1.3.tar.gz
WORKDIR /tmp
RUN tar xvzf zlib.tar.gz
WORKDIR /tmp/zlib-1.3
ENV CC=aarch64-linux-gnu-gcc
ENV CHOST=arm64
RUN ./configure
RUN make install
RUN ldconfig
Expand All @@ -35,8 +35,6 @@ WORKDIR /tmp
RUN tar xvf openssl.tar.gz
RUN ls -las
WORKDIR /tmp/openssl-1.1.1
ENV CC=aarch64-linux-gnu-gcc
ENV CFLAGS='-Os'
RUN ./Configure linux-aarch64 --prefix=/usr/local/ssl --openssldir=/usr/local/ssl shared zlib
ENV LD_LIBRARY_PATH=/usr/local/ssl/lib:${LD_LIBRARY_PATH}
RUN ldconfig
Expand Down
3 changes: 3 additions & 0 deletions rust/nasl-builtin-cryptographic/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,8 @@ ripemd = "0.1.3"
sha1 = "0.10.5"
sha2 = "0.10.6"

# depend on c libraries and are considered unstable for now
nasl-c-lib = {path = "../nasl-c-lib", optional = true}

[dev-dependencies]
nasl-interpreter = {path = "../nasl-interpreter"}
Loading

0 comments on commit eb2ca34

Please sign in to comment.