Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PYTHON-4818 Add OCSP Helper Scripts #517

Merged
merged 3 commits into from
Oct 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions .evergreen/ocsp/README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,30 @@
# Usage

We provide convenience setup and teardown scripts to manage the OSCP server.

```bash
OCSP_ALGORITHM=rsa SERVER_TYPE=valid bash ${DRIVERS_TOOLS}/.evergreen/ocsp/setup.sh
```

```bash
bash ${DRIVERS_TOOLS}/.evergreen/ocsp/teardown.sh
```

The server should typically be run in the background, e.g.

```yaml
run-revoked-delegate-ocsp-server:
- command: subprocess.exec
params:
binary: bash
background: true
env:
SERVER_TYPE: revoked-delegate
include_expansions_in_env: [OCSP_ALGORITHM]
args:
- ${DRIVERS_TOOLS}/.evergreen/ocsp/setup.sh
```

# Generating Test Certificates

The test certificates here were generating using a fork of the server
Expand Down
5 changes: 5 additions & 0 deletions .evergreen/ocsp/ocsp_mock.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,12 @@ def main():

mock_ocsp_responder.init(port=args.port, debug=args.verbose, host=args.bind_ip)

# Write the pid file.
with open(os.path.join(os.getcwd(), 'ocsp.pid'), 'w') as fid:
fid.write(str(os.getpid()))

print('Mock OCSP Responder is running on port %s' % (str(args.port)))


if __name__ == '__main__':
main()
55 changes: 55 additions & 0 deletions .evergreen/ocsp/setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#!/usr/bin/env bash
# Start an ocsp server.
set -o errexit # Exit on first command error.

SCRIPT_DIR=$(dirname ${BASH_SOURCE[0]})
. $SCRIPT_DIR/../handle-paths.sh

pushd $SCRIPT_DIR

VARLIST=(
OCSP_ALGORITHM
SERVER_TYPE
)

# Ensure that all variables required to run the test are set, otherwise throw
# an error.
for VARNAME in "${VARLIST[@]}"; do
[[ -z "${!VARNAME:-}" ]] && echo "ERROR: $VARNAME not set" && exit 1;
done

. ./activate-ocspvenv.sh

CA_FILE="${OCSP_ALGORITHM}/ca.pem"
ARGS="-p 8100 -v"

case $SERVER_TYPE in
valid)
CERT="${OCSP_ALGORITHM}/ca.crt"
KEY="${OCSP_ALGORITHM}/ca.key"
;;
revoked)
CERT="${OCSP_ALGORITHM}/ca.crt"
KEY="${OCSP_ALGORITHM}/ca.key"
ARGS="$ARGS --fault revoked"
;;
valid-delegate)
CERT="${OCSP_ALGORITHM}/ocsp-responder.crt"
KEY="${OCSP_ALGORITHM}/ocsp-responder.key"
;;
revoked-delegate)
CERT="${OCSP_ALGORITHM}/ocsp-responder.crt"
KEY="${OCSP_ALGORITHM}/ocsp-responder.key"
ARGS="$ARGS --fault revoked"
;;
*)
echo "Invalid SERVER_TYPE: $SERVER_TYPE"
exit 1
;;
esac

python ocsp_mock.py \
--ca_file $CA_FILE \
--ocsp_responder_cert $CERT \
--ocsp_responder_key $KEY \
$ARGS
13 changes: 13 additions & 0 deletions .evergreen/ocsp/teardown.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/usr/bin/env bash

# Clean up oscp server
set -e

SCRIPT_DIR=$(dirname ${BASH_SOURCE[0]})
. $SCRIPT_DIR/../handle-paths.sh
pushd $SCRIPT_DIR
if [ -f "ocsp.pid" ]; then
< ocsp.pid xargs kill -9 || true
rm ocsp.pid
fi
popd
Loading