[GH-ISSUE #4915] [Feature Request] Random serial number in certificate template #3879

Closed
opened 2026-05-05 14:28:42 -06:00 by gitea-mirror · 0 comments
Owner

Originally created by @XlabAITeam on GitHub (Aug 7, 2025).
Original GitHub issue: https://github.com/fatedier/frp/issues/4915

Describe the feature request

The newRandomTLSKeyPair function in pkg/transport/tls.go generates TLS certificates with a hardcoded serial number of 1 instead of using cryptographically random values. This violates TLS PKI best practices where certificate serial numbers must be unique and unpredictable with at least 64-bit entropy.

func newRandomTLSKeyPair() *tls.Certificate 
{
	key, err := rsa.GenerateKey(rand.Reader, 2048)
	if err != nil {
		panic(err)
	}
	template := x509.Certificate{SerialNumber: big.NewInt(1)} // fixed to 1
	certDER, err := x509.CreateCertificate(rand.Reader, &template, &template, &key.PublicKey, key)
	if err != nil {
		panic(err)
	}
	......
}

This fixed certificate field lay the foundation of further exploitation on certificate forgery. It has been proven that the overall overhead of finding certificate collision is acceptable under certain chosen prefix conditions. It is recommended generating the serial number by a cryptographically secure random number generator as the CA/B forum requested. Constructing the template with at least a subject (CN) and validity period is also appreciated in practice.

Describe alternatives you've considered

No response

Affected area

  • Docs
  • Installation
  • Performance and Scalability
  • Security
  • User Experience
  • Test and Release
  • Developer Infrastructure
  • Client Plugin
  • Server Plugin
  • Extensions
  • Others
Originally created by @XlabAITeam on GitHub (Aug 7, 2025). Original GitHub issue: https://github.com/fatedier/frp/issues/4915 ### Describe the feature request The `newRandomTLSKeyPair` function in `pkg/transport/tls.go generates` TLS certificates with a hardcoded serial number of `1` instead of using cryptographically random values. This violates TLS PKI best practices where certificate serial numbers must be unique and unpredictable with at least 64-bit entropy. ```golang func newRandomTLSKeyPair() *tls.Certificate { key, err := rsa.GenerateKey(rand.Reader, 2048) if err != nil { panic(err) } template := x509.Certificate{SerialNumber: big.NewInt(1)} // fixed to 1 certDER, err := x509.CreateCertificate(rand.Reader, &template, &template, &key.PublicKey, key) if err != nil { panic(err) } ...... } ``` This fixed certificate field lay the foundation of further exploitation on certificate forgery. It has been proven that the overall overhead of finding certificate collision is acceptable under certain [chosen prefix conditions](https://www.usenix.org/system/files/sec20-leurent.pdf). It is recommended generating the serial number by a cryptographically secure random number generator as the CA/B forum requested. Constructing the template with at least a subject (CN) and validity period is also appreciated in practice. ### Describe alternatives you've considered _No response_ ### Affected area - [ ] Docs - [ ] Installation - [ ] Performance and Scalability - [x] Security - [ ] User Experience - [ ] Test and Release - [ ] Developer Infrastructure - [ ] Client Plugin - [ ] Server Plugin - [ ] Extensions - [ ] Others
gitea-mirror 2026-05-05 14:28:42 -06:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: github-starred/frp#3879
No description provided.