Skip to main content

Overview

The Certificate type represents an x509 certificate used to authenticate WebRTC communications. Certificates are used by DTLS to encrypt data sent over the wire.

Type Definition

certificate.go

Certificate Generation

GenerateCertificate

Generates a new X.509 compliant certificate with a default template.
certificate.go
crypto.PrivateKey
required
Private key to use for the certificate. Supports RSA and ECDSA keys.
*Certificate, error
Returns a new Certificate or an error if generation fails
Example:

NewCertificate

Generates a new certificate with a custom X.509 template.
certificate.go
crypto.PrivateKey
required
Private key to use (RSA or ECDSA)
x509.Certificate
required
X.509 certificate template with custom parameters
*Certificate, error
Returns a new Certificate or an error if creation fails
Example:

CertificateFromX509

Creates a Certificate from an existing private key and X.509 certificate.
certificate.go
crypto.PrivateKey
required
The private key associated with the certificate
*x509.Certificate
required
The X.509 certificate
Certificate
Returns a Certificate instance
Example:

PEM Encoding/Decoding

CertificateFromPEM

Creates a certificate from PEM-encoded strings.
certificate.go
string
required
String containing PEM blocks for the private key and X.509 certificate
*Certificate, error
Returns a Certificate or an error if parsing fails
Example:

PEM

Encodes the certificate as PEM blocks.
certificate.go
string, error
Returns PEM-encoded certificate and private key, or an error
Example:

Methods

GetFingerprints

Returns the certificate fingerprints used for DTLS verification.
certificate.go
[]DTLSFingerprint, error
Returns a list of fingerprints (currently SHA-256) or an error
Example:

Expires

Returns the timestamp after which the certificate is no longer valid.
certificate.go
time.Time
Returns the expiration timestamp, or zero time if not set
Example:

Equals

Determines if two certificates are identical.
certificate.go
Certificate
required
Certificate to compare against
bool
Returns true if certificates are identical (same key and X.509 cert)
Example:

Key Types

Pion WebRTC supports the following private key types:

RSA

ECDSA with P-256 is recommended for WebRTC as it provides good security with better performance than RSA.

Usage Examples

Security Best Practices

Always transmit certificate fingerprints over a secure, authenticated signaling channel to prevent man-in-the-middle attacks.

Certificate Storage

  • Store private keys securely with appropriate file permissions (e.g., 0600)
  • Consider using hardware security modules (HSMs) for production deployments
  • Rotate certificates periodically

Fingerprint Verification

  • Always verify the remote peer’s certificate fingerprint
  • Use SHA-256 or stronger hash algorithms
  • Implement fingerprint pinning for additional security

Certificate Lifetime

  • Default generated certificates are valid for 1 month
  • For production, consider longer validity periods (but not too long)
  • Implement monitoring for certificate expiration
  • Have a certificate rotation strategy

Error Handling

Common errors when working with certificates:

See Also