Repository Public
1#!/usr/bin/env bash2# =============================================================================3# SP BOUCHER | SOFTWARE & RESEARCH4# ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING5# =============================================================================6#7# Project : QYVORA8# File : security/audit/install-tools.sh9# Module : Security10# Repository : https://git.spboucher.ai/qyvora11# Project Website : Not specified12# Created : 2026-12-0413# Last Modified : 2026-12-0414#15# Author : Simon-Pierre Boucher16# Position : Professor of Finance17# Institution : Université du Québec en Outaouais (UQO)18# Organization : SP Boucher19# Website : https://spboucher.ai20# Git : https://git.spboucher.ai21#22# Preferred Contact: contact@spboucher.ai23# Development : dev@spboucher.ai24# Support : support@spboucher.ai25# Security/Admin : admin@spboucher.ai26#27# Copyright (c) 202628# Simon-Pierre Boucher29# All rights reserved where applicable. This file is governed by the30# applicable project license, copyright notices and relevant law.31# Existing third-party rights and notices remain unaffected.32#33# License : None specified (no license file in this repository)34#35# Do not embed credentials, private keys, access tokens,36# certificates or confidential personal information.37#38# =============================================================================39# END OF SP BOUCHER SOURCE HEADER40# =============================================================================4142# Installs the tools of the QYVORA security audit on this machine (laptop or cluster node).43# Idempotent. Everything goes under security/.tools (git-ignored); nothing is installed system-wide44# except Gitleaks through Homebrew when it is missing. Pinned versions: security/policies/tools.json.45#46# security/audit/install-tools.sh install or complete the installation47# security/audit/install-tools.sh --check print what is installed, install nothing48#49# Network use: package downloads from PyPI, rule packs (rules only, HTTP GET) from semgrep.dev.50# No file of this repository is sent anywhere.51set -euo pipefail52# Non-interactive SSH sessions on the cluster nodes have a minimal PATH.53export PATH="$HOME/.local/bin:/opt/homebrew/bin:$PATH"5455HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"56REPO="$(cd "$HERE/../.." && pwd)"57TOOLS="$REPO/security/.tools"58VENV="$TOOLS/venv"59PINS="$REPO/security/policies/tools.json"60CHECK_ONLY=061[ "${1:-}" = "--check" ] && CHECK_ONLY=16263pin() { # pin <tool> -> pinned version from tools.json64 /usr/bin/python3 -c 'import json,sys; print(json.load(open(sys.argv[1]))["tools"][sys.argv[2]]["version"])' "$PINS" "$1"65}6667say() { printf '%s\n' "$*"; }6869SEMGREP_PIN="$(pin semgrep)"70MOBSFSCAN_PIN="$(pin mobsfscan)"71GITLEAKS_PIN="$(pin gitleaks)"7273mkdir -p "$TOOLS/bin" "$TOOLS/semgrep-registry"7475# --- Python virtual environment (Semgrep, mobsfscan, Python oracles of the differential tests) --------76if [ ! -x "$VENV/bin/python3" ]; then77 if [ "$CHECK_ONLY" = 1 ]; then78 say "venv: MISSING ($VENV)"79 elif command -v uv >/dev/null 2>&1; then80 uv venv --python 3.12 "$VENV"81 else82 PY="$(command -v python3.12 || command -v python3.13 || command -v python3)"83 "$PY" -m venv "$VENV"84 fi85fi8687pip_install() {88 if command -v uv >/dev/null 2>&1; then89 uv pip install --python "$VENV/bin/python3" "$@"90 else91 "$VENV/bin/python3" -m pip install --disable-pip-version-check "$@"92 fi93}9495if [ -x "$VENV/bin/python3" ] && [ "$CHECK_ONLY" = 0 ]; then96 have_semgrep="$("$VENV/bin/semgrep" --version 2>/dev/null | tail -1 || true)"97 have_mobsfscan="$("$VENV/bin/python3" -c 'import importlib.metadata as m; print(m.version("mobsfscan"))' 2>/dev/null || true)"98 if [ "$have_semgrep" != "$SEMGREP_PIN" ] || [ "$have_mobsfscan" != "$MOBSFSCAN_PIN" ]; then99 pip_install "semgrep==$SEMGREP_PIN" "mobsfscan==$MOBSFSCAN_PIN"100 fi101 REQ="$REPO/security/tests/oracles/requirements.txt"102 if [ -f "$REQ" ]; then103 pip_install -r "$REQ"104 else105 say "oracles: $REQ not present, Python oracles not installed"106 fi107fi108109# --- Semgrep registry packs: rules only, fetched once and then used offline -----------------------------110# The packs are under the Semgrep Rules License v1.0 (internal use): they are cached here, not committed.111# References of the multi-chain differential tests (solders, PyNaCl, cryptography, tronpy, eth-account, bip-utils,112# bitcash): a separate environment, because some of them pin older versions of the packages of the first one.113VENV_MC="$TOOLS/venv-mc"114REQ_MC="$REPO/security/tests/oracles/requirements-multichain.txt"115if [ "$CHECK_ONLY" = 0 ] && [ -f "$REQ_MC" ]; then116 if [ ! -x "$VENV_MC/bin/python3" ]; then117 if command -v uv >/dev/null 2>&1; then118 uv venv --python 3.12 "$VENV_MC"119 else120 PY="$(command -v python3.12 || command -v python3.13 || command -v python3)"121 "$PY" -m venv "$VENV_MC"122 fi123 fi124 if command -v uv >/dev/null 2>&1; then125 uv pip install --python "$VENV_MC/bin/python3" -r "$REQ_MC"126 else127 "$VENV_MC/bin/python3" -m pip install --disable-pip-version-check -r "$REQ_MC"128 fi129fi130131for pack in swift secrets; do132 dest="$TOOLS/semgrep-registry/$pack.yaml"133 if [ ! -s "$dest" ] && [ "$CHECK_ONLY" = 0 ]; then134 if curl -fsSL -A "semgrep-rules-fetch" -o "$dest.tmp" "https://semgrep.dev/c/p/$pack"; then135 mv "$dest.tmp" "$dest"136 date -u +%Y-%m-%dT%H:%M:%SZ > "$dest.fetched"137 else138 rm -f "$dest.tmp"139 say "semgrep registry pack p/$pack: download failed (the runner will record it as NOT RUN)"140 fi141 fi142done143144# --- Gitleaks (Homebrew) -----------------------------------------------------------------------------------145if ! command -v gitleaks >/dev/null 2>&1; then146 if [ "$CHECK_ONLY" = 0 ] && command -v brew >/dev/null 2>&1; then147 brew install gitleaks148 fi149fi150151# --- spbqc: command-line tool of the owner's Rust library spb-quantum-crypto (independent oracle) ----------152# Copied from an existing release build; the source repository is never modified.153SPBQC_SRC="${QY_SPBQC_SRC:-$HOME/Desktop/Cluster/projets/SP/spb-quantum-crypto/target/release/spbqc}"154if [ ! -x "$TOOLS/bin/spbqc" ] && [ -x "$SPBQC_SRC" ] && [ "$CHECK_ONLY" = 0 ]; then155 cp "$SPBQC_SRC" "$TOOLS/bin/spbqc"156fi157# The dynamic library of the same build: the differential tests call its C interface (seeded operations).158SPB_DYLIB_SRC="$(dirname "$SPBQC_SRC")/libspb_pqc.dylib"159if [ ! -f "$TOOLS/lib/libspb_pqc.dylib" ] && [ -f "$SPB_DYLIB_SRC" ] && [ "$CHECK_ONLY" = 0 ]; then160 mkdir -p "$TOOLS/lib"161 cp "$SPB_DYLIB_SRC" "$TOOLS/lib/libspb_pqc.dylib"162fi163164# --- Summary -----------------------------------------------------------------------------------------------165say "--- installed tools ---"166if [ -x "$VENV/bin/semgrep" ]; then167 v="$("$VENV/bin/semgrep" --disable-version-check --version 2>/dev/null | tail -1)"168 say "semgrep $v (pinned $SEMGREP_PIN)"169else170 say "semgrep MISSING"171fi172if [ -x "$VENV/bin/mobsfscan" ]; then173 v="$("$VENV/bin/python3" -c 'import importlib.metadata as m; print(m.version("mobsfscan"))' 2>/dev/null)"174 say "mobsfscan $v (pinned $MOBSFSCAN_PIN)"175else176 say "mobsfscan MISSING"177fi178if [ -x "$TOOLS/venv-mc/bin/python3" ]; then179 say "venv-mc present (multi-chain references: $("$TOOLS/venv-mc/bin/python3" -I -c 'import importlib.metadata as m; print(", ".join(n+" "+m.version(n) for n in ("solders","pynacl","cryptography","tronpy","eth-account","bip-utils","bitcash")))' 2>/dev/null || echo "packages missing"))"180else181 say "venv-mc MISSING (multi-chain differential tests will be NOT RUN)"182fi183if command -v gitleaks >/dev/null 2>&1; then184 say "gitleaks $(gitleaks version) (pinned $GITLEAKS_PIN) at $(command -v gitleaks)"185else186 say "gitleaks MISSING"187fi188for pack in swift secrets; do189 f="$TOOLS/semgrep-registry/$pack.yaml"190 if [ -s "$f" ]; then191 say "registry p/$pack sha256=$(shasum -a 256 "$f" | cut -d' ' -f1) fetched=$(cat "$f.fetched" 2>/dev/null || echo unknown)"192 else193 say "registry p/$pack MISSING"194 fi195done196if [ -x "$TOOLS/bin/spbqc" ]; then197 say "spbqc sha256=$(shasum -a 256 "$TOOLS/bin/spbqc" | cut -d' ' -f1)"198else199 say "spbqc MISSING (differential tests against the Rust library will be NOT RUN)"200fi201