Certificates and trust

When configured to accept SSL/TLS connections, all server processes (p4d, p4p, p4broker) require a valid certificate and key pair at startup.

The key and certificate files are stored in the directory specified by the P4SSLDIR environment variable.

You can:

  • Generate a self-signed certificate and key pair by using p4d -Gc.

  • Supply your own private key and certificate.

  • Use a certificate issued by a Certificate Authority (CA).

Certificate options

Before generating or installing a certificate, decide which type of certificate to use:

  • Self-signed certificates generated by P4 Server or a third-party tool.

  • Certificates issued by a trusted Certificate Authority (CA).

  • Wildcard certificates.

  • Certificates that use the Subject Alternative Name (SAN) field.

You can generate certificates with p4d -Gc or use third-party tools such as OpenSSL or PuTTY.

If you supply your own key and certificate pair, the privatekey.txt and certificate.txt files in the P4SSLDIR directory must be PEM encoded, and the private key must not be protected by a passphrase.

Prepare the P4SSLDIR directory

Before generating or installing certificates:

  • Ensure that the P4SSLDIR directory exists in a secure location.

  • Ensure that the directory is owned by the same user that:

  • Runs the P4 Server, proxy, or broker.

  • Generates the certificate and key pair.

Restrict access so that other users cannot read the directory. For example, on UNIX,:

  • To set drwx------ permissions, run chmod 0700 P4SSLDIR

  • To set dr-x------ permissions, chmod 0500 P4SSLDIR

Optional: Create a configuration file

Before running p4d -Gc, you can create a config.txt file in the P4SSLDIR directory to customize certificate values.

Copy
# C: Country Name - 2 letter code (default: US)
C =

# ST: State or Province Name - full name (default: CA)
ST =

# L: Locality or City Name (default: Alameda)
L =

# O: Organization or Company Name (default: Perforce Autogen Cert)
O =

# OU = Organization Unit - division or unit
OU =

# CN: Common Name (usually the DNS name of the server)
# (default: the current server's DNS name)
CN =

# EX: number of days from today for certificate expiration
# (default: 730, that is, 2 years)
EX =

# UNITS: unit multiplier for expiration (defaults to "days")
# Valid values: "secs", "mins", "hours"
UNITS =

Generate a self-signed certificate and key pair

Generate the certificate and key pair: p4d -Gc

If no certificate or private key exists, P4 Server creates:

  • privatekey.txt

  • certificate.txt

Both files are written to the P4SSLDIR directory and use PEM encoding. These files correspond to the private key and certificate used for the SSL/TLS connection.

If no config.txt file exists, the following defaults are used:

Copy
C=US
ST=CA
L=Alameda
O=Perforce Autogen Cert
OU=
CN=the-DNS-name-of-your-server
EX=730
UNITS=days

The generated certificate expires after 730 days (two years - excluding leap years).

Secure the certificate files

Ensure that privatekey.txt and certificate.txt:

  • Are owned by the user running the P4 Server, proxy, or broker.

  • Cannot be read by other users.

For example, on UNIX,

  • To set -rw------- permissions, run:

    chmod 0600 privatekey.txt
    chmod 0600 certificate.txt
  • To set -r-------- permissions, run:

    chmod 0400 privatekey.txt
    chmod 0400 certificate.txt

Generate and record the certificate fingerprint

To generate the server fingerprint, run p4d -Gf

Expect the following output:

Fingerprint:
CA:BE:5B:77:14:1B:2E:97:F0:5F:31:6E:33:6F:0E:1A:E9:DA:EF:E2

Record the fingerprint for your records. Store the certificate and private key in a secure location that is accessible only to the P4 Server process.

Distribute the fingerprint to users

Communicate the fingerprint to users through a secure channel.

Users can compare the fingerprint provided by the server with the fingerprint you distributed. If the values match, users can add the fingerprint to their P4TRUST file by using the p4 trust command.

If users see a different fingerprint, instruct them to contact an administrator. A different fingerprint might indicate a man-in-the-middle attack. The fingerprint changes only when a new certificate and key pair have been installed.

If you use certificates from a Certificate Authority

If you use a certificate issued by a trusted Certificate Authority (CA):

  1. Place the server certificate and any intermediate certificates in certificate.txt.

  2. Place the server certificate first.

  3. Ensure that each intermediate certificate directly certifies the previous certificate in the chain.

  4. Do not include the root certificate.

Trusted CA certificates do not require the P4TRUST mechanism.

To learn more, see SSL/TLS connections that do not require P4TRUST in the P4 CLI Reference.

If you use wildcard certificates or Subject Alternative Names

Any client application that uses the P4 API for C/C++ supports wildcard certificates and Subject Alternative Name (SAN) validation.

This includes:

  • P4V.

  • P4 CLI.

  • P4 Broker.

  • P4 API for PHP.

  • Any P4 product that is acting as a client.

  • Replica and edge servers acting as clients.

The wildcard value must appear in the certificate Subject Common Name (CN) field.

Only one wildcard is supported, and it must appear in the left-most label.

Example: *.mycompany.com

The Subject Alternative Name (SAN) field is also checked against the hostname specified in P4PORT.

Supported SAN values include:

  • DNS names.

  • IP addresses.

Wildcard DNS values in the SAN field are not supported.

Validate the installation

After configuring certificates:

  • Verify that P4SSLDIR contains the correct files.

  • Verify that file ownership and permissions are correct.

  • Verify that the certificate is valid and that the server date and time fall within the certificate validity period.

If you encounter certificate validation issues, see "Unable to connect" message in Troubleshooting certificate validation errors.