MCPcopy Create free account
hub / github.com/prometheus/common / getTLSDataWithHash

Method getTLSDataWithHash

config/http_config.go:1068–1115  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

1066}
1067
1068func (t *tlsRoundTripper) getTLSDataWithHash() ([]byte, []byte, []byte, []byte, error) {
1069 var (
1070 caBytes, certBytes, keyBytes []byte
1071
1072 err error
1073 )
1074
1075 if t.settings.CAFile != "" {
1076 caBytes, err = os.ReadFile(t.settings.CAFile)
1077 if err != nil {
1078 return nil, nil, nil, nil, err
1079 }
1080 } else if t.settings.CA != "" {
1081 caBytes = []byte(t.settings.CA)
1082 }
1083
1084 if t.settings.CertFile != "" {
1085 certBytes, err = os.ReadFile(t.settings.CertFile)
1086 if err != nil {
1087 return nil, nil, nil, nil, err
1088 }
1089 } else if t.settings.Cert != "" {
1090 certBytes = []byte(t.settings.Cert)
1091 }
1092
1093 if t.settings.KeyFile != "" {
1094 keyBytes, err = os.ReadFile(t.settings.KeyFile)
1095 if err != nil {
1096 return nil, nil, nil, nil, err
1097 }
1098 } else if t.settings.Key != "" {
1099 keyBytes = []byte(t.settings.Key)
1100 }
1101
1102 var caHash, certHash, keyHash [32]byte
1103
1104 if len(caBytes) > 0 {
1105 caHash = sha256.Sum256(caBytes)
1106 }
1107 if len(certBytes) > 0 {
1108 certHash = sha256.Sum256(certBytes)
1109 }
1110 if len(keyBytes) > 0 {
1111 keyHash = sha256.Sum256(keyBytes)
1112 }
1113
1114 return caBytes, caHash[:], certHash[:], keyHash[:], nil
1115}
1116
1117// RoundTrip implements the http.RoundTrip interface.
1118func (t *tlsRoundTripper) RoundTrip(req *http.Request) (*http.Response, error) {

Callers 2

NewTLSRoundTripperFunction · 0.95
RoundTripMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected