Fix Android certificate initialize

This commit is contained in:
世界 2025-02-13 09:09:26 +08:00
parent c57bbcb68a
commit 44177b9e58
No known key found for this signature in database
GPG Key ID: CD109927C34A63C4

View File

@ -33,16 +33,14 @@ func NewStore(ctx context.Context, logger logger.Logger, options option.Certific
var systemPool *x509.CertPool var systemPool *x509.CertPool
switch options.Store { switch options.Store {
case C.CertificateStoreSystem, "": case C.CertificateStoreSystem, "":
platformInterface := service.FromContext[platform.Interface](ctx) systemPool = x509.NewCertPool()
systemCertificates := platformInterface.SystemCertificates() var systemValid bool
if len(systemCertificates) > 0 { for _, cert := range service.FromContext[platform.Interface](ctx).SystemCertificates() {
systemPool = x509.NewCertPool() if systemPool.AppendCertsFromPEM([]byte(cert)) {
for _, cert := range systemCertificates { systemValid = true
if !systemPool.AppendCertsFromPEM([]byte(cert)) {
return nil, E.New("invalid system certificate PEM: ", cert)
}
} }
} else { }
if !systemValid {
certPool, err := x509.SystemCertPool() certPool, err := x509.SystemCertPool()
if err != nil { if err != nil {
return nil, err return nil, err