Skip to content

Commit 122796d

Browse files
committedAug 24, 2022
pki: Additional pki.scep options for strongswan.conf
1 parent 93f2901 commit 122796d

File tree

5 files changed

+45
-49
lines changed

5 files changed

+45
-49
lines changed
 

‎conf/options/pki.opt

+6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
pki.load =
22
Plugins to load in the pki tool.
33

4+
pki.scep.http_bind
5+
Source IP address to bind for HTTP operations.
6+
7+
pki.scep.http_timeout = 30s
8+
Timeout for HTTP operations.
9+
410
pki.scep.renewal_via_pkcs_req = no
511
Some SCEP servers (e.g. openxpki) are incorrectly doing certificate renewal
612
via messageType PKCSReq (19) instead of RenewalReq (17).

‎src/pki/commands/scep.c

+7-12
Original file line numberDiff line numberDiff line change
@@ -76,11 +76,7 @@ static int scep()
7676
linked_list_t *san;
7777
enumerator_t *enumerator;
7878
int status = 1;
79-
bool ok, stored = FALSE;
80-
81-
scep_http_params_t http_params = {
82-
.get_request = FALSE, .timeout = 30, .bind = NULL
83-
};
79+
bool ok, http_post = FALSE, stored = FALSE;
8480

8581
bool pss = lib->settings->get_bool(lib->settings,
8682
"%s.rsa_pss", FALSE, lib->ns);
@@ -273,7 +269,7 @@ static int scep()
273269
public = private->get_public_key(private);
274270

275271
/* Request capabilities from SCEP server */
276-
if (!scep_http_request(url, chunk_empty, SCEP_GET_CA_CAPS, &http_params,
272+
if (!scep_http_request(url, chunk_empty, SCEP_GET_CA_CAPS, FALSE,
277273
&scep_response))
278274
{
279275
DBG1(DBG_APP, "did not receive a valid scep response");
@@ -338,10 +334,9 @@ static int scep()
338334
if ((caps_flags & SCEP_CAPS_POSTPKIOPERATION) ||
339335
(caps_flags & SCEP_CAPS_SCEPSTANDARD))
340336
{
341-
http_params.get_request = FALSE;
337+
http_post = TRUE;
342338
}
343-
DBG2(DBG_APP, "HTTP POST %ssupported",
344-
http_params.get_request ? "not " : "");
339+
DBG2(DBG_APP, "HTTP POST %ssupported", http_post ? "" : "not ");
345340

346341
scheme = get_signature_scheme(private, digest_alg, pss);
347342
if (!scheme)
@@ -467,7 +462,7 @@ static int scep()
467462
goto end;
468463
}
469464

470-
if (!scep_http_request(url, pkcs7_req, SCEP_PKI_OPERATION, &http_params,
465+
if (!scep_http_request(url, pkcs7_req, SCEP_PKI_OPERATION, http_post,
471466
&scep_response))
472467
{
473468
DBG1(DBG_APP, "did not receive a valid SCEP response");
@@ -526,8 +521,8 @@ static int scep()
526521
DBG1(DBG_APP, "failed to build SCEP certPoll request");
527522
goto end;
528523
}
529-
if (!scep_http_request(url, certPoll, SCEP_PKI_OPERATION,
530-
&http_params, &scep_response))
524+
if (!scep_http_request(url, certPoll, SCEP_PKI_OPERATION, http_post,
525+
&scep_response))
531526
{
532527
DBG1(DBG_APP, "did not receive a valid SCEP response");
533528
goto end;

‎src/pki/commands/scepca.c

+1-5
Original file line numberDiff line numberDiff line change
@@ -248,10 +248,6 @@ static int scepca()
248248

249249
int cert_type_count[] = { 0, 0, 0 };
250250

251-
scep_http_params_t http_params = {
252-
.get_request = TRUE, .timeout = 30, .bind = NULL
253-
};
254-
255251
while (TRUE)
256252
{
257253
switch (command_getopt(&arg))
@@ -289,7 +285,7 @@ static int scepca()
289285
return command_usage("--url is required");
290286
}
291287

292-
if (!scep_http_request(url, chunk_empty, SCEP_GET_CA_CERT, &http_params,
288+
if (!scep_http_request(url, chunk_empty, SCEP_GET_CA_CERT, FALSE,
293289
&scep_response))
294290
{
295291
DBG1(DBG_APP, "did not receive a valid scep response");

‎src/pki/scep/scep.c

+29-23
Original file line numberDiff line numberDiff line change
@@ -334,29 +334,50 @@ static char* escape_http_request(chunk_t req)
334334
* Send a SCEP request via HTTP and wait for a response
335335
*/
336336
bool scep_http_request(const char *url, chunk_t msg, scep_op_t op,
337-
scep_http_params_t *http_params, chunk_t *response)
337+
bool http_post, chunk_t *response)
338338
{
339339
int len;
340340
status_t status;
341341
char *complete_url = NULL;
342342
const char *operation;
343343
host_t *srcip = NULL;
344344

345-
/* initialize response */
346-
*response = chunk_empty;
345+
uint32_t http_timeout = lib->settings->get_time(lib->settings,
346+
"%s.scep.http_timeout", 30, lib->ns);
347347

348-
if (http_params->bind)
348+
char *http_bind = lib->settings->get_str(lib->settings,
349+
"%s.scep.http_bind", NULL, lib->ns);
350+
351+
if (http_bind)
349352
{
350-
srcip = host_create_from_string(http_params->bind, 0);
353+
srcip = host_create_from_string(http_bind, 0);
351354
}
352355
DBG2(DBG_APP, "sending scep request to '%s'", url);
353356

357+
/* initialize response */
358+
*response = chunk_empty;
359+
354360
operation = operations[op];
355361
switch (op)
356362
{
357363
case SCEP_PKI_OPERATION:
358364
default:
359-
if (http_params->get_request)
365+
if (http_post)
366+
{
367+
/* form complete url */
368+
len = strlen(url) + 11 + strlen(operation) + 1;
369+
complete_url = malloc(len);
370+
snprintf(complete_url, len, "%s?operation=%s", url, operation);
371+
372+
status = lib->fetcher->fetch(lib->fetcher, complete_url, response,
373+
FETCH_TIMEOUT, http_timeout,
374+
FETCH_REQUEST_DATA, msg,
375+
FETCH_REQUEST_TYPE, "",
376+
FETCH_REQUEST_HEADER, "Expect:",
377+
FETCH_SOURCEIP, srcip,
378+
FETCH_END);
379+
}
380+
else /* HTTP_GET */
360381
{
361382
char *escaped_req = escape_http_request(msg);
362383

@@ -369,28 +390,13 @@ bool scep_http_request(const char *url, chunk_t msg, scep_op_t op,
369390
free(escaped_req);
370391

371392
status = lib->fetcher->fetch(lib->fetcher, complete_url, response,
372-
FETCH_TIMEOUT, http_params->timeout,
393+
FETCH_TIMEOUT, http_timeout,
373394
FETCH_REQUEST_HEADER, "Pragma:",
374395
FETCH_REQUEST_HEADER, "Host:",
375396
FETCH_REQUEST_HEADER, "Accept:",
376397
FETCH_SOURCEIP, srcip,
377398
FETCH_END);
378399
}
379-
else /* HTTP_POST */
380-
{
381-
/* form complete url */
382-
len = strlen(url) + 11 + strlen(operation) + 1;
383-
complete_url = malloc(len);
384-
snprintf(complete_url, len, "%s?operation=%s", url, operation);
385-
386-
status = lib->fetcher->fetch(lib->fetcher, complete_url, response,
387-
FETCH_TIMEOUT, http_params->timeout,
388-
FETCH_REQUEST_DATA, msg,
389-
FETCH_REQUEST_TYPE, "",
390-
FETCH_REQUEST_HEADER, "Expect:",
391-
FETCH_SOURCEIP, srcip,
392-
FETCH_END);
393-
}
394400
break;
395401
case SCEP_GET_CA_CERT:
396402
case SCEP_GET_CA_CAPS:
@@ -401,7 +407,7 @@ bool scep_http_request(const char *url, chunk_t msg, scep_op_t op,
401407
snprintf(complete_url, len, "%s?operation=%s", url, operation);
402408

403409
status = lib->fetcher->fetch(lib->fetcher, complete_url, response,
404-
FETCH_TIMEOUT, http_params->timeout,
410+
FETCH_TIMEOUT, http_timeout,
405411
FETCH_SOURCEIP, srcip,
406412
FETCH_END);
407413
}

‎src/pki/scep/scep.h

+2-9
Original file line numberDiff line numberDiff line change
@@ -68,13 +68,6 @@ typedef struct {
6868
chunk_t recipientNonce;
6969
} scep_attributes_t;
7070

71-
/* SCEP http parameters */
72-
typedef struct {
73-
bool get_request;
74-
u_int timeout;
75-
char *bind;
76-
} scep_http_params_t;
77-
7871
/* SCEP CA Capabilities */
7972
typedef enum {
8073
SCEP_CAPS_AES = 0,
@@ -108,8 +101,8 @@ chunk_t scep_build_request(chunk_t data, chunk_t transID, scep_msg_t msg,
108101
size_t key_size, certificate_t *signer_cert,
109102
hash_algorithm_t digest_alg, private_key_t *private_key);
110103

111-
bool scep_http_request(const char *url, chunk_t msg, scep_op_t op,
112-
scep_http_params_t *http_params, chunk_t *response);
104+
bool scep_http_request(const char *url, chunk_t msg, scep_op_t op, bool use_post,
105+
chunk_t *response);
113106

114107
bool scep_parse_response(chunk_t response, chunk_t transID, container_t **out,
115108
scep_attributes_t *attrs);

0 commit comments

Comments
 (0)
Please sign in to comment.