diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..dfdb8b7 --- /dev/null +++ b/.gitattributes @@ -0,0 +1 @@ +*.sh text eol=lf diff --git a/.github/workflows/trivy-analysis.yaml b/.github/workflows/trivy-analysis.yaml new file mode 100644 index 0000000..2ca6910 --- /dev/null +++ b/.github/workflows/trivy-analysis.yaml @@ -0,0 +1,49 @@ +name: Trivy Analysis + +permissions: + contents: read + actions: read + security-events: write + +on: + pull_request: + workflow_dispatch: + push: + +env: + SARIF_FILE: 'trivy-results.sarif' + +jobs: + build: + name: Scan + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v4.2.2 + + - name: Run Trivy vulnerability scanner on the cloned repository files + uses: aquasecurity/trivy-action@0.30.0 + with: + version: 'v0.61.1' + scan-type: 'fs' + scanners: 'vuln,misconfig,secret,license' + ignore-unfixed: true + format: 'sarif' + output: ${{ env.SARIF_FILE }} + severity: 'CRITICAL' + + - name: Check Trivy scan results existence + run: | + if [ ! -f "${{ env.SARIF_FILE }}" ]; then + echo "Error: ${{ env.SARIF_FILE }} does not exist." + exit 1 + fi + ls -lash ${{ env.SARIF_FILE }} + + - name: Upload Trivy scan results to GitHub Security tab + uses: github/codeql-action/upload-sarif@v3.28.16 + with: + sarif_file: ${{ env.SARIF_FILE }} + + + diff --git a/Dockerfile b/Dockerfile index 08c8130..06f5df5 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,13 +1,25 @@ -FROM n0madic/alpine-gcc:9.2.0 -RUN apk add --quiet --no-cache libressl-dev +FROM frolvlad/alpine-gcc:latest +RUN apk add --quiet --no-cache libressl-dev make + +# Create non-root user and group +RUN addgroup -S appgroup && adduser -S appuser -G appgroup + COPY ./*.h /opt/src/ COPY ./*.c /opt/src/ COPY Makefile /opt/src/ COPY entrypoint.sh / -#RUN apt-get install libssl-dev + WORKDIR /opt/src RUN make RUN make OPENSSL=/usr/local/opt/openssl/include OPENSSL_LIB=-L/usr/local/opt/openssl/lib RUN ["chmod", "+x", "/entrypoint.sh"] RUN ["chmod", "+x", "/opt/src/jwtcrack"] + +# Change ownership to non-root user +RUN chown -R appuser:appgroup /opt/src /entrypoint.sh + +USER appuser + +HEALTHCHECK --interval=30s --timeout=5s --start-period=5s --retries=3 CMD ["/opt/src/jwtcrack", "--version"] || exit 1 + ENTRYPOINT ["/entrypoint.sh"] diff --git a/Makefile b/Makefile index cede5e9..1d5e2ed 100644 --- a/Makefile +++ b/Makefile @@ -3,7 +3,7 @@ CC = gcc OPENSSL = /usr/include/openssl OPENSSL_LIB = -lssl -CFLAGS += -I $(OPENSSL) -g -std=gnu99 -O3 +CFLAGS += -I $(OPENSSL) -g -std=gnu99 -O3 -march=native -mtune=native LDFLAGS += $(OPENSSL_LIB) -lcrypto -lpthread NAME = jwtcrack diff --git a/entrypoint.sh b/entrypoint.sh index 6408e37..8df664b 100644 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -1,2 +1,2 @@ -#!/bin/bash +#!/bin/sh /opt/src/jwtcrack $@ diff --git a/main.c b/main.c index 228b495..677a460 100644 --- a/main.c +++ b/main.c @@ -169,6 +169,11 @@ void usage(const char *cmd, const char *alphabet, const size_t max_len, const ch int main(int argc, char **argv) { + if (argc > 1 && strcmp(argv[1], "--version") == 0) { + printf("jwtcrack version 1.0.0\n"); + return 0; + } + const EVP_MD *evp_md; size_t max_len = 6;