Debian Codegraph @

crt/s2n/tests/policy_snapshot/generate.sh

raw symbols SCIP
1 #!/bin/bashscip-shell filesystem . . `/bin/bash`.
2
3 # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
4 # SPDX-License-Identifier: Apache-2.0
5
6 set -eu
7
8 SNAPSHOTS_DIR_DEFAULT="./tests/policy_snapshot/snapshots"
9 SECURITY_POLICIES_C_DEFAULT="./tls/s2n_security_policies.c"
10
11 function display_usagescip-shell shell shell-project 0.0.0 display_usage(). {
12 echoscip-shell system . . echo. "Usage: $0 <policy_path> [snapshots_dir] [s2n_security_policies]"
13 echoscip-shell system . . echo.
14 echoscip-shell system . . echo. "Arguments:"
15 echoscip-shell system . . echo. " policy_path Path to the policy util binary"
16 echoscip-shell system . . echo. " snapshots_dir Path to the snapshots directory"
17 echoscip-shell system . . echo. " (default: $SNAPSHOTS_DIR_DEFAULT)"
18 echoscip-shell system . . echo. " s2n_security_policies Path to the s2n_security_policies.c file"
19 echoscip-shell system . . echo. " (default: $SECURITY_POLICIES_C_DEFAULT)"
20 echoscip-shell system . . echo.
21 exit 1
22 }
23
24 if [scip-shell system . . `[`. $# -lt 1 ] || [scip-shell system . . `[`. $# -gt 3 ] || [scip-shell system . . `[`. "$1" == "--help" ]; then
25 display_usagescip-shell shell shell-project 0.0.0 display_usage().
26 fi
27
28 POLICY_BINARY="$1"
29 SNAPSHOTS_DIR=${2:-$SNAPSHOTS_DIR_DEFAULT}
30 SECURITY_POLICIES_C=${3:-$SECURITY_POLICIES_C_DEFAULT}
31
32 echoscip-shell system . . echo. "Using snapshots directory: $SNAPSHOTS_DIR"
33 echoscip-shell system . . echo. "Using policy binary: $POLICY_BINARY"
34 echoscip-shell system . . echo. "Using security policy file: $SECURITY_POLICIES_C"
35
36 echoscip-shell system . . echo. "Extracting security policy names..."
37 POLICIES=$(grepscip-shell system . . grep. -o '{ .version = "[^"]*"' $SECURITY_POLICIES_C \
38 | sed 's/{ .version = "\(.*\)"/\1/' | grep -v "^null$")
39
40 COUNT=$(echoscip-shell system . . echo. "$POLICIES" | wcscip-shell system . . wc. -l)
41 echoscip-shell system . . echo. "Found $COUNT policies."
42
43 rmscip-shell system . . rm. -f $SNAPSHOTS_DIR/*
44
45 for policy in $POLICIES; do
46 $POLICY_BINARY $policy > $SNAPSHOTS_DIR/$policy
47 echoscip-shell system . . echo. "Generated snapshot for $policy..."
48 done
49
50 echoscip-shell system . . echo.
51 echoscip-shell system . . echo. "Snapshots successfully generated."
52 exit 0