8000 fix: the trustcerts not add to globalCerts after ca.ResetCertificate. change the custom-certificates to use PEM format instead of DER by achenging · Pull Request #1801 · MetaCubeX/mihomo · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

fix: the trustcerts not add to globalCerts after ca.ResetCertificate. change the custom-certificates to use PEM format instead of DER #1801

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion component/ca/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ import (
"crypto/x509"
_ "embed"
"encoding/hex"
"encoding/pem"
"errors"
"fmt"
"log"
"os"
"strconv"
"strings"
Expand All @@ -33,8 +35,16 @@ func AddCertificate(certificate string) error {
if certificate == "" {
return fmt.Errorf("certificate is empty")
}
if cert, err := x509.ParseCertificate([]byte(certificate)); err == nil {

block, _ := pem.Decode([]byte(certificate))
if block == nil {
log.Fatalln("failed to parse PEM block containing the certificate")
return fmt.Errorf("decode certificate failed")
}

if cert, err := x509.ParseCertificate(block.Bytes); err == nil {
trustCerts = append(trustCerts, cert)
globalCertPool.AddCert(cert)
return nil
} else {
return fmt.Errorf("add certificate failed")
Expand Down
0