Debian Codegraph @

crt/s2n/tests/policy_snapshot/generate.sh

raw symbols SCIP
1 #!/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_usage {
12 echo "Usage: $0 <policy_path> [snapshots_dir] [s2n_security_policies]"
13 echo
14 echo "Arguments:"
15 echo " policy_path Path to the policy util binary"
16 echo " snapshots_dir Path to the snapshots directory"
17 echo " (default: $SNAPSHOTS_DIR_DEFAULT)"
18 echo " s2n_security_policies Path to the s2n_security_policies.c file"
19 echo " (default: $SECURITY_POLICIES_C_DEFAULT)"
20 echo
21 exit 1
22 }
23
24 if [ $# -lt 1 ] || [ $# -gt 3 ] || [ "$1" == "--help" ]; then
25 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 echo "Using snapshots directory: $SNAPSHOTS_DIR"
33 echo "Using policy binary: $POLICY_BINARY"
34 echo "Using security policy file: $SECURITY_POLICIES_C"
35
36 echo "Extracting security policy names..."
37 POLICIES=$(grep -o '{ .version = "[^"]*"' $SECURITY_POLICIES_C \
38 | sed 's/{ .version = "\(.*\)"/\1/' | grep -v "^null$")
39
40 COUNT=$(echo "$POLICIES" | wc -l)
41 echo "Found $COUNT policies."
42
43 rm -f $SNAPSHOTS_DIR/*
44
45 for policy in $POLICIES; do
46 $POLICY_BINARY $policy > $SNAPSHOTS_DIR/$policy
47 echo "Generated snapshot for $policy..."
48 done
49
50 echo
51 echo "Snapshots successfully generated."
52 exit 0