Skip to content

Certz-2: Changes to create certificates and uploading the certificates - #6094

Open
priyaranjannanda wants to merge 1 commit into
openconfig:mainfrom
priyaranjannanda:certz2_1
Open

priyaranjannanda wants to merge 1 commit into
openconfig:mainfrom
priyaranjannanda:certz2_1

Conversation

@priyaranjannanda

Copy link
Copy Markdown
Contributor

mk_cas.sh

  • Resolves its own directory with SCRIPT_DIR, so certificate config files work regardless of the current working directory.
    Supports:
    ./mk_cas.sh
    ./mk_cas.sh /tmp/output
    ./mk_cas.sh "01,02,10" /tmp/output

  • Resolves OUTDIR to an absolute path.

  • Uses absolute paths for client/server OpenSSL config and extension files.

  • Restores proper CA extensions:

basicConstraints=critical,CA:TRUE
keyUsage=critical,keyCertSign,cRLSign

  • Generates valid server/client certificates and trust bundles in the requested output directory.

  • Uses the selected CA list instead of always generating every default set.

@priyaranjannanda
priyaranjannanda requested a review from a team as a code owner September 25, 2026 12:05
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request improves the reliability and portability of the certificate generation script used for test data. By enforcing absolute paths, removing dependencies on system-level OpenSSL configurations, and explicitly defining certificate extensions, the script now produces consistent and valid test certificates across different environments.

Highlights

  • Robust Path Resolution: Updated the script to resolve its own directory using SCRIPT_DIR and convert the output directory to an absolute path, ensuring certificate configuration files are correctly located regardless of the execution context.
  • Improved OpenSSL Certificate Generation: Refactored the certificate generation process to avoid reliance on system-default openssl.cnf files by explicitly defining extensions and using absolute paths for configuration files.
  • Enhanced CA Extensions: Restored critical CA extensions (basicConstraints and keyUsage) to ensure generated certificates meet security requirements.
  • Flexible CLI Arguments: Enhanced the command-line interface to support more flexible input patterns for specifying directories and output locations.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize the Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counterproductive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩

@OpenConfigBot

Copy link
Copy Markdown

Pull Request Functional Test Report for #6094 / f0a938c

No tests identified for validation.

Help

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request refactors the mk_cas.sh script to improve argument parsing, enforce safer shell options (set -eu), and cleanly generate CA certificates using explicit OpenSSL configurations rather than relying on system defaults. The review feedback recommends quoting all instances of ${OUTDIR} to prevent word splitting issues with paths containing spaces, and suggests defining an EXT_FILE variable to simplify the certificate generation logic and avoid spawning unnecessary subshells.

Comment on lines +73 to +85
openssl req -new -nodes \
-key ${OUTDIR}/ca-${d}/ca-${OFFSET}-${t}-key.pem \
-out ${OUTDIR}/ca-${d}/ca-${OFFSET}-${t}-cert.pem \
-out ${OUTDIR}/ca-${d}/ca-${OFFSET}-${t}-req.pem \
-subj "/CN=CA ${OFFSET}/C=AQ/ST=NZ/L=NZ/O=OpenConfigFeatureProfiles"

openssl x509 -req -days ${LIFETIME} \
-in ${OUTDIR}/ca-${d}/ca-${OFFSET}-${t}-req.pem \
-signkey ${OUTDIR}/ca-${d}/ca-${OFFSET}-${t}-key.pem \
-out ${OUTDIR}/ca-${d}/ca-${OFFSET}-${t}-cert.pem \
-sha256 \
-extfile <(printf "basicConstraints=critical,CA:TRUE\nkeyUsage=critical,keyCertSign,cRLSign")

rm -f ${OUTDIR}/ca-${d}/ca-${OFFSET}-${t}-req.pem

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The variable ${OUTDIR} is not quoted in several places within this block. If the output directory path contains spaces, the script will fail due to word splitting. Quoting all instances of ${OUTDIR} ensures robustness.

Suggested change
openssl req -new -nodes \
-key ${OUTDIR}/ca-${d}/ca-${OFFSET}-${t}-key.pem \
-out ${OUTDIR}/ca-${d}/ca-${OFFSET}-${t}-cert.pem \
-out ${OUTDIR}/ca-${d}/ca-${OFFSET}-${t}-req.pem \
-subj "/CN=CA ${OFFSET}/C=AQ/ST=NZ/L=NZ/O=OpenConfigFeatureProfiles"
openssl x509 -req -days ${LIFETIME} \
-in ${OUTDIR}/ca-${d}/ca-${OFFSET}-${t}-req.pem \
-signkey ${OUTDIR}/ca-${d}/ca-${OFFSET}-${t}-key.pem \
-out ${OUTDIR}/ca-${d}/ca-${OFFSET}-${t}-cert.pem \
-sha256 \
-extfile <(printf "basicConstraints=critical,CA:TRUE\nkeyUsage=critical,keyCertSign,cRLSign")
rm -f ${OUTDIR}/ca-${d}/ca-${OFFSET}-${t}-req.pem
openssl req -new -nodes \
-key "${OUTDIR}/ca-${d}/ca-${OFFSET}-${t}-key.pem" \
-out "${OUTDIR}/ca-${d}/ca-${OFFSET}-${t}-req.pem" \
-subj "/CN=CA ${OFFSET}/C=AQ/ST=NZ/L=NZ/O=OpenConfigFeatureProfiles"
openssl x509 -req -days ${LIFETIME} \
-in "${OUTDIR}/ca-${d}/ca-${OFFSET}-${t}-req.pem" \
-signkey "${OUTDIR}/ca-${d}/ca-${OFFSET}-${t}-key.pem" \
-out "${OUTDIR}/ca-${d}/ca-${OFFSET}-${t}-cert.pem" \
-sha256 \
-extfile <(printf "basicConstraints=critical,CA:TRUE\nkeyUsage=critical,keyCertSign,cRLSign")
rm -f "${OUTDIR}/ca-${d}/ca-${OFFSET}-${t}-req.pem"

Comment on lines +133 to +141
if [ "${cs}" = "client" ]; then
openssl req -new -key ${OUTDIR}/ca-${d}/${cs}-${t}-${g}-key.pem \
-out ${OUTDIR}/ca-${d}/${cs}-${t}-${g}-req.pem \
-config "${CLIENT_CNF}"
else
openssl req -new -key ${OUTDIR}/ca-${d}/${cs}-${t}-${g}-key.pem \
-out ${OUTDIR}/ca-${d}/${cs}-${t}-${g}-req.pem \
-config "${SERVER_CNF}"
fi

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

To improve readability and avoid spawning a subshell inside the openssl x509 arguments, we can define an EXT_FILE variable within this if/else block. Additionally, quoting the path variables prevents potential issues with spaces in the output directory path.

Suggested change
if [ "${cs}" = "client" ]; then
openssl req -new -key ${OUTDIR}/ca-${d}/${cs}-${t}-${g}-key.pem \
-out ${OUTDIR}/ca-${d}/${cs}-${t}-${g}-req.pem \
-config "${CLIENT_CNF}"
else
openssl req -new -key ${OUTDIR}/ca-${d}/${cs}-${t}-${g}-key.pem \
-out ${OUTDIR}/ca-${d}/${cs}-${t}-${g}-req.pem \
-config "${SERVER_CNF}"
fi
if [ "${cs}" = "client" ]; then
EXT_FILE="${CLIENT_EXT}"
openssl req -new -key "${OUTDIR}/ca-${d}/${cs}-${t}-${g}-key.pem" \
-out "${OUTDIR}/ca-${d}/${cs}-${t}-${g}-req.pem" \
-config "${CLIENT_CNF}"
else
EXT_FILE="${SERVER_EXT}"
openssl req -new -key "${OUTDIR}/ca-${d}/${cs}-${t}-${g}-key.pem" \
-out "${OUTDIR}/ca-${d}/${cs}-${t}-${g}-req.pem" \
-config "${SERVER_CNF}"
fi

-days ${LIFETIME} \
-sha256 \
-extfile ${cs}_cert_ext.cnf
-extfile "$( [ "${cs}" = "client" ] && printf '%s' "${CLIENT_EXT}" || printf '%s' "${SERVER_EXT}" )"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Using the EXT_FILE variable defined in the previous block simplifies this command and avoids spawning a subshell.

Suggested change
-extfile "$( [ "${cs}" = "client" ] && printf '%s' "${CLIENT_EXT}" || printf '%s' "${SERVER_EXT}" )"
-extfile "${EXT_FILE}"

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants