@@ -51,7 +51,7 @@ static const std::string envname[RdKafka::CERT__CNT][RdKafka::CERT_ENC__CNT] = {
51
51
{
52
52
" SSL_pkcs" ,
53
53
" SSL_ca_der" ,
54
- " SSL_ca_pem " ,
54
+ " SSL_all_cas_pem " /* Contains multiple CA certs */ ,
55
55
}};
56
56
57
57
@@ -118,26 +118,45 @@ class TestVerifyCb : public RdKafka::SslCertificateVerifyCb {
118
118
};
119
119
120
120
121
+ /* *
122
+ * @brief Set SSL PEM cert/key using configuration property.
123
+ *
124
+ * The cert/key is loadded from environment variables set up by trivup.
125
+ *
126
+ * @param loc_prop ssl.X.location property that will be cleared.
127
+ * @param pem_prop ssl.X.pem property that will be set.
128
+ * @param cert_type Certificate type.
129
+ */
121
130
static void conf_location_to_pem (RdKafka::Conf *conf,
122
131
std::string loc_prop,
123
- std::string pem_prop) {
132
+ std::string pem_prop,
133
+ RdKafka::CertificateType cert_type) {
124
134
std::string loc;
125
135
126
-
127
- if (conf->get (loc_prop, loc) != RdKafka::Conf::CONF_OK)
128
- Test::Fail (" Failed to get " + loc_prop);
129
-
130
136
std::string errstr;
131
137
if (conf->set (loc_prop, " " , errstr) != RdKafka::Conf::CONF_OK)
132
138
Test::Fail (" Failed to reset " + loc_prop + " : " + errstr);
133
139
140
+ const char *p;
141
+ p = test_getenv (envname[cert_type][RdKafka::CERT_ENC_PEM].c_str (), NULL );
142
+ if (!p)
143
+ Test::Fail (
144
+ " Invalid test environment: "
145
+ " Missing " +
146
+ envname[cert_type][RdKafka::CERT_ENC_PEM] +
147
+ " env variable: make sure trivup is up to date" );
148
+
149
+ loc = p;
150
+
151
+
134
152
/* Read file */
135
153
std::ifstream ifs (loc.c_str ());
136
154
std::string pem ((std::istreambuf_iterator<char >(ifs)),
137
155
std::istreambuf_iterator<char >());
138
156
139
- Test::Say (" Read " + loc_prop + " =" + loc +
140
- " from disk and changed to in-memory " + pem_prop + " \n " );
157
+ Test::Say (" Read env " + envname[cert_type][RdKafka::CERT_ENC_PEM] + " =" +
158
+ loc + " from disk and changed to in-memory " + pem_prop +
159
+ " string\n " );
141
160
142
161
if (conf->set (pem_prop, pem, errstr) != RdKafka::Conf::CONF_OK)
143
162
Test::Fail (" Failed to set " + pem_prop + " : " + errstr);
@@ -178,7 +197,8 @@ static void conf_location_to_setter(RdKafka::Conf *conf,
178
197
loc = p;
179
198
180
199
Test::Say (tostr () << " Reading " << loc_prop << " file " << loc << " as "
181
- << encnames[encoding] << " \n " );
200
+ << encnames[encoding] << " from env "
201
+ << envname[cert_type][encoding] << " \n " );
182
202
183
203
/* Read file */
184
204
std::ifstream ifs (loc.c_str (), std::ios::binary | std::ios::ate);
@@ -200,8 +220,8 @@ static void conf_location_to_setter(RdKafka::Conf *conf,
200
220
201
221
202
222
typedef enum {
203
- USE_LOCATION, /* use ssl.key .location */
204
- USE_CONF, /* use ssl.key .pem */
223
+ USE_LOCATION, /* use ssl.X .location */
224
+ USE_CONF, /* use ssl.X .pem */
205
225
USE_SETTER, /* use conf->set_ssl_cert(), this supports multiple formats */
206
226
} cert_load_t ;
207
227
@@ -245,20 +265,22 @@ static void do_test_verify(const int line,
245
265
/* Get ssl.key.location, read its contents, and replace with
246
266
* ssl.key.pem. Same with ssl.certificate.location -> ssl.certificate.pem. */
247
267
if (load_key == USE_CONF)
248
- conf_location_to_pem (conf, " ssl.key.location" , " ssl.key.pem" );
268
+ conf_location_to_pem (conf, " ssl.key.location" , " ssl.key.pem" ,
269
+ RdKafka::CERT_PRIVATE_KEY);
249
270
else if (load_key == USE_SETTER)
250
271
conf_location_to_setter (conf, " ssl.key.location" , RdKafka::CERT_PRIVATE_KEY,
251
272
key_enc);
252
273
253
274
if (load_pub == USE_CONF)
254
275
conf_location_to_pem (conf, " ssl.certificate.location" ,
255
- " ssl.certificate.pem" );
276
+ " ssl.certificate.pem" , RdKafka::CERT_PUBLIC_KEY );
256
277
else if (load_pub == USE_SETTER)
257
278
conf_location_to_setter (conf, " ssl.certificate.location" ,
258
279
RdKafka::CERT_PUBLIC_KEY, pub_enc);
259
280
260
281
if (load_ca == USE_CONF)
261
- conf_location_to_pem (conf, " ssl.ca.location" , " ssl.ca.pem" );
282
+ conf_location_to_pem (conf, " ssl.ca.location" , " ssl.ca.pem" ,
283
+ RdKafka::CERT_CA);
262
284
else if (load_ca == USE_SETTER)
263
285
conf_location_to_setter (conf, " ssl.ca.location" , RdKafka::CERT_CA, ca_enc);
264
286
@@ -391,6 +413,12 @@ int main_0097_ssl_verify(int argc, char **argv) {
391
413
do_test_verify (__LINE__, true , USE_LOCATION, RdKafka::CERT_ENC_PEM,
392
414
USE_SETTER, RdKafka::CERT_ENC_DER, USE_SETTER,
393
415
RdKafka::CERT_ENC_DER);
416
+ do_test_verify (__LINE__, true , USE_LOCATION, RdKafka::CERT_ENC_PEM,
417
+ USE_SETTER, RdKafka::CERT_ENC_DER, USE_SETTER,
418
+ RdKafka::CERT_ENC_PEM); /* env: SSL_all_cas_pem */
419
+ do_test_verify (__LINE__, true , USE_LOCATION, RdKafka::CERT_ENC_PEM,
420
+ USE_SETTER, RdKafka::CERT_ENC_DER, USE_CONF,
421
+ RdKafka::CERT_ENC_PEM); /* env: SSL_all_cas_pem */
394
422
do_test_verify (__LINE__, true , USE_SETTER, RdKafka::CERT_ENC_PKCS12,
395
423
USE_SETTER, RdKafka::CERT_ENC_PKCS12, USE_SETTER,
396
424
RdKafka::CERT_ENC_PKCS12);
0 commit comments