mirror of
https://github.com/Rain-kl/OpenFlare.git
synced 2026-09-30 06:16:37 +08:00
2cbaf95eae
- Implemented TLS certificate model and service for managing certificates. - Added API endpoints for creating, importing, listing, and deleting TLS certificates. - Enhanced proxy route configuration to support HTTPS with certificate selection. - Updated frontend to include TLS certificate management UI with manual and file import options. - Added validation for HTTPS routes to ensure certificates are selected. - Implemented tests for TLS certificate creation and proxy route validation.
35 lines
672 B
Go
35 lines
672 B
Go
package service
|
|
|
|
import (
|
|
"crypto/x509"
|
|
"encoding/pem"
|
|
"errors"
|
|
"io"
|
|
"mime/multipart"
|
|
)
|
|
|
|
func parseLeafCertificate(certPEM string) (*x509.Certificate, error) {
|
|
certPEMBlock, _ := pem.Decode([]byte(certPEM))
|
|
if certPEMBlock == nil {
|
|
return nil, errors.New("证书 PEM 内容不合法")
|
|
}
|
|
leaf, err := x509.ParseCertificate(certPEMBlock.Bytes)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return leaf, nil
|
|
}
|
|
|
|
func readMultipartFile(fileHeader *multipart.FileHeader) (string, error) {
|
|
file, err := fileHeader.Open()
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
defer file.Close()
|
|
data, err := io.ReadAll(file)
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
return string(data), nil
|
|
}
|