80
}
81
83
>
if temporalTls == nil || !temporalTls.Enabled {
84
return nil, nil
85
}
87
>
if err != nil {
88
return nil, err
89
}
90
92
>
InsecureSkipVerify: !temporalTls.EnableHostVerification,
93
>
}
94
>
if temporalTls.ServerName != "" {
95
tlsConfig.ServerName = temporalTls.ServerName
96
}
97
98
// Load CA cert
100
>
if err != nil {
101
return nil, err
102
}
105
>
}
106
107
// Load client cert
109
>
if err != nil {
110
return nil, err
111
}
114
>
}
115
117
}
118
120
>
if temporalTls.CertData != "" && temporalTls.CertFile != "" {
121
return fmt.Errorf("%w: %s", ErrTLSConfig, "only one of certData or certFile properties should be specified")
122
}
123
125
return fmt.Errorf("%w: %s", ErrTLSConfig, "only one of keyData or keyFile properties should be specified")
126
}
127
129
>
keyProvided := temporalTls.KeyData != "" || temporalTls.KeyFile != ""
130
>
if certProvided != keyProvided {
131
return fmt.Errorf("%w: %s", ErrTLSConfig, "cert or key is missing")
132
}
133
135
return fmt.Errorf("%w: %s", ErrTLSConfig, "only one of caData or caFile properties should be specified")
136
}
138
}
139
141
>
var caBytes []byte
142
>
var err error
143
>
if temporalTls.CaFile != "" {
144
caBytes, err = os.ReadFile(temporalTls.CaFile)
145
if err != nil {
146
return nil, fmt.Errorf("%w: %s (%w)", ErrTLSConfig, "unable to read client ca file", err)
147
}
150
>
if err != nil {
151
return nil, fmt.Errorf("%w: %s (%w)", ErrTLSConfig, "unable to decode client ca data", err)
152
}
153
}
156
>
caCerts, err := parseCertsFromPEM(caBytes)
157
>
if len(caCerts) == 0 {
158
return nil, fmt.Errorf("%w: %s (%w)", ErrTLSConfig, "unable to parse certs as PEM", err)
159
}
161
>
caCertPool.AddCert(cert)
162
>
}
163
>
if err != nil {
164
return nil, fmt.Errorf("%w: %s (%w)", ErrTLSConfig, "unable to load decoded CA Cert as PEM", err)
165
}
167
}
168
return nil, nil
169
}
170
172
>
for len(pemCerts) > 0 {
173
>
var block *pem.Block
174
>
block, pemCerts = pem.Decode(pemCerts)
175
>
if block == nil {
176
break
177
}
179
continue
180
}
181
183
>
return x509.ParseCertificates(certBytes)
184
}
185
return nil, nil
186
}
187
189
>
var certBytes []byte
190
>
var keyBytes []byte
191
>
var err error
192
>
if temporalTls.CertFile != "" {
194
>
if err != nil {
195
return nil, fmt.Errorf("%w: %s (%w)", ErrTLSConfig, "unable to read client certificate file", err)
196
}