mirror of
https://github.com/XTLS/Xray-core.git
synced 2025-04-30 09:18:34 +00:00
Refactor log (#3446)
* Refactor log * Add new log methods * Fix logger test * Change all logging code * Clean up pathObj * Rebase to latest main * Remove invoking method name after the dot
This commit is contained in:
parent
8320732743
commit
079d0bd8a9
291 changed files with 1837 additions and 2368 deletions
|
@ -1,9 +0,0 @@
|
|||
package ocsp
|
||||
|
||||
import "github.com/xtls/xray-core/common/errors"
|
||||
|
||||
type errPathObjHolder struct{}
|
||||
|
||||
func newError(values ...interface{}) *errors.Error {
|
||||
return errors.New(values...).WithPathObj(errPathObjHolder{})
|
||||
}
|
|
@ -8,6 +8,7 @@ import (
|
|||
"net/http"
|
||||
"os"
|
||||
|
||||
"github.com/xtls/xray-core/common/errors"
|
||||
"github.com/xtls/xray-core/common/platform/filesystem"
|
||||
"golang.org/x/crypto/ocsp"
|
||||
)
|
||||
|
@ -63,26 +64,26 @@ func GetOCSPForCert(cert [][]byte) ([]byte, error) {
|
|||
}
|
||||
issuedCert := certificates[0]
|
||||
if len(issuedCert.OCSPServer) == 0 {
|
||||
return nil, newError("no OCSP server specified in cert")
|
||||
return nil, errors.New("no OCSP server specified in cert")
|
||||
}
|
||||
if len(certificates) == 1 {
|
||||
if len(issuedCert.IssuingCertificateURL) == 0 {
|
||||
return nil, newError("no issuing certificate URL")
|
||||
return nil, errors.New("no issuing certificate URL")
|
||||
}
|
||||
resp, errC := http.Get(issuedCert.IssuingCertificateURL[0])
|
||||
if errC != nil {
|
||||
return nil, newError("no issuing certificate URL")
|
||||
return nil, errors.New("no issuing certificate URL")
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
issuerBytes, errC := io.ReadAll(resp.Body)
|
||||
if errC != nil {
|
||||
return nil, newError(errC)
|
||||
return nil, errors.New(errC)
|
||||
}
|
||||
|
||||
issuerCert, errC := x509.ParseCertificate(issuerBytes)
|
||||
if errC != nil {
|
||||
return nil, newError(errC)
|
||||
return nil, errors.New(errC)
|
||||
}
|
||||
|
||||
certificates = append(certificates, issuerCert)
|
||||
|
@ -96,12 +97,12 @@ func GetOCSPForCert(cert [][]byte) ([]byte, error) {
|
|||
reader := bytes.NewReader(ocspReq)
|
||||
req, err := http.Post(issuedCert.OCSPServer[0], "application/ocsp-request", reader)
|
||||
if err != nil {
|
||||
return nil, newError(err)
|
||||
return nil, errors.New(err)
|
||||
}
|
||||
defer req.Body.Close()
|
||||
ocspResBytes, err := io.ReadAll(req.Body)
|
||||
if err != nil {
|
||||
return nil, newError(err)
|
||||
return nil, errors.New(err)
|
||||
}
|
||||
return ocspResBytes, nil
|
||||
}
|
||||
|
@ -128,7 +129,7 @@ func parsePEMBundle(bundle []byte) ([]*x509.Certificate, error) {
|
|||
}
|
||||
|
||||
if len(certificates) == 0 {
|
||||
return nil, newError("no certificates were found while parsing the bundle")
|
||||
return nil, errors.New("no certificates were found while parsing the bundle")
|
||||
}
|
||||
|
||||
return certificates, nil
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue