examples/provider-http/auth-signature-pfx/README.md
You can run this example with:
npx promptfoo@latest init --example provider-http/auth-signature-pfx
cd provider-http/auth-signature-pfx
This example demonstrates how to setup authentication with an HTTP provider using certificates for cryptographic signature validation. You can use either:
npm install
# First, create a private key and certificate
openssl req -x509 -newkey rsa:2048 -keyout private.key -out certificate.crt \
-days 365 -nodes -subj "/CN=PromptFoo Test/O=Test/C=US"
# Then, create a PFX file from the key and certificate
openssl pkcs12 -export -out certificate.pfx -inkey private.key -in certificate.crt \
-passout pass:password
# Clean up temporary files
rm private.key certificate.crt
# Create a private key and certificate (keep both files)
openssl req -x509 -newkey rsa:2048 -keyout private.key -out certificate.crt \
-days 365 -nodes -subj "/CN=PromptFoo Test/O=Test/C=US"
# No cleanup needed - both files are used directly
npm start
The example includes two configuration files demonstrating different certificate formats:
promptfooconfig.yaml)signatureAuth:
type: pfx
pfxPath: ./certificate.pfx
pfxPassword: password
signatureAlgorithm: SHA256
signatureValidityMs: 300000
signatureDataTemplate: 'promptfoo-app{{signatureTimestamp}}'
promptfooconfig-crt-key.yaml)signatureAuth:
type: pfx
certPath: ./certificate.crt
keyPath: ./private.key
signatureAlgorithm: SHA256
signatureValidityMs: 300000
signatureDataTemplate: 'promptfoo-app{{signatureTimestamp}}'
Important: In production, use environment variables for passwords and secure key management practices.
Note, for this example to work, you will need to set the environment variable NODE_TLS_REJECT_UNAUTHORIZED=0, as this cert is self-signed.
# Run test cases with PFX certificate
NODE_TLS_REJECT_UNAUTHORIZED=0 promptfoo eval --no-cache
# Or run with separate CRT/KEY files
NODE_TLS_REJECT_UNAUTHORIZED=0 promptfoo eval -c promptfooconfig-crt-key.yaml --no-cache
# View results
promptfoo view
IMPORTANT: Be sure to run with --no-cache when testing! Otherwise it may cache responses from good signatures.
signature, timestamp, client-id)This example uses hardcoded values for simplicity. In production, you should use:
PROMPTFOO_PFX_PASSWORD - Password for the PFX certificate file (when using PFX option)PFX (Personal Information Exchange) is a binary format for storing cryptographic objects. It's commonly used on Windows systems and can contain:
This format is password-protected and provides a convenient way to transport certificates and private keys together.
Alternatively, you can use separate certificate and key files:
This approach is common in Unix/Linux environments and provides flexibility in managing certificates and keys separately.
Both formats are supported by the promptfoo HTTP provider for cryptographic signature generation and verification.