@@ -1152,6 +1152,37 @@ func (c *TLSConfig) UnmarshalYAML(unmarshal func(interface{}) error) error {
11521152 return c .Validate ()
11531153}
11541154
1155+ // readCertAndKey reads the cert and key files from the disk.
1156+ func readCertAndKey (certFile , keyFile string ) ([]byte , []byte , error ) {
1157+ certData , err := ioutil .ReadFile (certFile )
1158+ if err != nil {
1159+ return nil , nil , err
1160+ }
1161+
1162+ keyData , err := ioutil .ReadFile (keyFile )
1163+ if err != nil {
1164+ return nil , nil , err
1165+ }
1166+
1167+ return certData , keyData , nil
1168+ }
1169+
1170+ // getClientCertificate reads the pair of client cert and key from disk and returns a tls.Certificate.
1171+ func (c * TLSConfig ) getClientCertificate (_ * tls.CertificateRequestInfo ) (* tls.Certificate , error ) {
1172+ certData , keyData , err := readCertAndKey (c .CertFile , c .KeyFile )
1173+ if err != nil {
1174+ return nil , fmt .Errorf ("unable to read specified client cert (%s) & key (%s): %s" , c .CertFile , c .KeyFile , err )
1175+ }
1176+
1177+ cert , err := tls .X509KeyPair (certData , keyData )
1178+ if err != nil {
1179+ return nil , fmt .Errorf ("unable to use specified client cert (%s) & key (%s): %s" , c .CertFile , c .KeyFile , err )
1180+ }
1181+
1182+ return & cert , nil
1183+ >> >> >> > 78 d22dc (Check if TLS certificate and key file have been modified (#345 ))
1184+ }
1185+
11551186// Validate validates the TLSConfig to check that only one of the inlined or
11561187// file-based fields for the TLS CA, client certificate, and client key are
11571188// used.
0 commit comments