Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
8 changes: 8 additions & 0 deletions common/platform/filesystem/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package filesystem
import (
"io"
"os"
"path/filepath"

"github.com/xtls/xray-core/common/buf"
"github.com/xtls/xray-core/common/platform"
Expand All @@ -28,6 +29,13 @@ func ReadAsset(file string) ([]byte, error) {
return ReadFile(platform.GetAssetLocation(file))
}

func ReadCertificate(file string) ([]byte, error) {
Comment thread
RPRX marked this conversation as resolved.
Outdated
if filepath.IsAbs(file) {
return ReadFile(file)
}
return ReadFile(platform.GetCertLocation(file))
}

func CopyFile(dst string, src string) error {
bytes, err := ReadFile(src)
if err != nil {
Expand Down
5 changes: 5 additions & 0 deletions common/platform/others.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,8 @@ func GetAssetLocation(file string) string {
// asset not found, let the caller throw out the error
return defPath
}

func GetCertLocation(file string) string {
certificatePath := NewEnvFlag(CertLocation).GetValue(getExecutableDir)
Comment thread
RPRX marked this conversation as resolved.
Outdated
return filepath.Join(certificatePath, file)
}
1 change: 1 addition & 0 deletions common/platform/platform.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const (
ConfdirLocation = "xray.location.confdir"
ToolLocation = "xray.location.tool"
AssetLocation = "xray.location.asset"
CertLocation = "xray.location.cert"

UseReadV = "xray.buf.readv"
UseFreedomSplice = "xray.buf.splice"
Expand Down
5 changes: 5 additions & 0 deletions common/platform/windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,8 @@ func GetAssetLocation(file string) string {
assetPath := NewEnvFlag(AssetLocation).GetValue(getExecutableDir)
return filepath.Join(assetPath, file)
}

func GetCertLocation(file string) string {
certificatePath := NewEnvFlag(CertLocation).GetValue(getExecutableDir)
Comment thread
RPRX marked this conversation as resolved.
Outdated
return filepath.Join(certificatePath, file)
}
2 changes: 1 addition & 1 deletion infra/conf/transport_internet.go
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ func (c *SplitHTTPConfig) Build() (proto.Message, error) {

func readFileOrString(f string, s []string) ([]byte, error) {
if len(f) > 0 {
return filesystem.ReadFile(f)
return filesystem.ReadCertificate(f)
}
if len(s) > 0 {
return []byte(strings.Join(s, "\n")), nil
Expand Down
4 changes: 2 additions & 2 deletions transport/internet/tls/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,12 +109,12 @@ func setupOcspTicker(entry *Certificate, callback func(isReloaded, isOcspstaplin
for {
var isReloaded bool
if entry.CertificatePath != "" && entry.KeyPath != "" {
newCert, err := filesystem.ReadFile(entry.CertificatePath)
newCert, err := filesystem.ReadCertificate(entry.CertificatePath)
if err != nil {
errors.LogErrorInner(context.Background(), err, "failed to parse certificate")
return
}
newKey, err := filesystem.ReadFile(entry.KeyPath)
newKey, err := filesystem.ReadCertificate(entry.KeyPath)
if err != nil {
errors.LogErrorInner(context.Background(), err, "failed to parse key")
return
Expand Down