boxdd: Add insecure mode

This commit is contained in:
世界
2026-08-30 17:41:43 +08:00
parent b4600dd4f7
commit 0a4e4c8061
60 changed files with 1055 additions and 285 deletions
+10 -6
View File
@@ -2,6 +2,7 @@ package certificate
import (
"bytes"
"context"
"crypto/x509"
"io/fs"
"os"
@@ -15,11 +16,13 @@ import (
"github.com/sagernet/sing-box/option"
E "github.com/sagernet/sing/common/exceptions"
"github.com/sagernet/sing/common/logger"
"github.com/sagernet/sing/service/filemanager"
)
var _ adapter.CertificateStore = (*Store)(nil)
type Store struct {
ctx context.Context
access sync.RWMutex
storeType string
systemPool *x509.CertPool
@@ -32,7 +35,7 @@ type Store struct {
platform storePlatform
}
func NewStore(logger logger.Logger, options option.CertificateOptions) (*Store, error) {
func NewStore(ctx context.Context, logger logger.Logger, options option.CertificateOptions) (*Store, error) {
storeType := options.Store
if storeType == "" {
storeType = C.CertificateStoreSystem
@@ -59,6 +62,7 @@ func NewStore(logger logger.Logger, options option.CertificateOptions) (*Store,
return nil, E.New("unknown certificate store: ", options.Store)
}
store := &Store{
ctx: ctx,
storeType: storeType,
systemPool: systemPool,
certificate: strings.Join(options.Certificate, "\n"),
@@ -165,7 +169,7 @@ func (s *Store) update() error {
appendPEMBlock(pemBuffer, s.certificate)
}
for _, path := range s.certificatePaths {
pemContent, err := os.ReadFile(path)
pemContent, err := filemanager.ReadFile(s.ctx, path)
if err != nil {
return err
}
@@ -176,7 +180,7 @@ func (s *Store) update() error {
}
var firstErr error
for _, directoryPath := range s.certificateDirectoryPaths {
directoryEntries, err := readUniqueDirectoryEntries(directoryPath)
directoryEntries, err := readUniqueDirectoryEntries(s.ctx, directoryPath)
if err != nil {
if firstErr == nil && !os.IsNotExist(err) {
firstErr = E.Cause(err, "invalid certificate directory: ", directoryPath)
@@ -184,7 +188,7 @@ func (s *Store) update() error {
continue
}
for _, directoryEntry := range directoryEntries {
pemContent, err := os.ReadFile(filepath.Join(directoryPath, directoryEntry.Name()))
pemContent, err := filemanager.ReadFile(s.ctx, filepath.Join(directoryPath, directoryEntry.Name()))
if err == nil && currentPool.AppendCertsFromPEM(pemContent) {
appendPEMBlock(pemBuffer, string(pemContent))
}
@@ -223,8 +227,8 @@ func (s *Store) newBasePool() (*x509.CertPool, error) {
}
}
func readUniqueDirectoryEntries(dir string) ([]fs.DirEntry, error) {
files, err := os.ReadDir(dir)
func readUniqueDirectoryEntries(ctx context.Context, dir string) ([]fs.DirEntry, error) {
files, err := filemanager.ReadDir(ctx, dir)
if err != nil {
return nil, err
}