MS cert template: validate argument
Update the server to validate the MS V2 certificate template option
argument when adding or updating a request.
Fixes: https://pagure.io/certmonger/issue/78
Fraser Tweedale
6 years ago
185 | 185 | tdbusm_check_LDADD = libcm.a $(CERTMONGER_LIBS) $(POPT_LIBS) |
186 | 186 | serial_check_LDADD = libcm.a $(CERTMONGER_LIBS) $(LTLIBICONV) |
187 | 187 | nl_check_LDADD = libcm.a $(CERTMONGER_LIBS) |
188 | submit_x_CFLAGS = $(AM_CFLAGS) -DCM_SUBMIT_X_MAIN | |
188 | submit_x_CFLAGS = $(AM_CFLAGS) $(NSS_CFLAGS) -DCM_SUBMIT_X_MAIN | |
189 | 189 | submit_x_SOURCES = submit-x.c submit-x.h submit-u.c submit-u.h log.c log.h \ |
190 | 190 | tm.c tm.h |
191 | 191 | submit_x_LDADD = $(XMLRPC_LIBS) $(KRB5_LIBS) $(TALLOC_LIBS) \ |
204 | 204 | pkglibexec_PROGRAMS += scep-submit |
205 | 205 | endif |
206 | 206 | noinst_PROGRAMS += submit-h submit-d |
207 | ipa_submit_CFLAGS = $(AM_CFLAGS) $(NSS_CFLAGS) | |
207 | 208 | ipa_submit_SOURCES = ipa.c srvloc.c srvloc.h store.h store-gen.c \ |
208 | 209 | submit-x.c submit-x.h submit-u.c submit-u.h \ |
209 | 210 | submit-e.h util.c util.h log.c log.h tm.c tm.h |
210 | 211 | ipa_submit_LDADD = $(XMLRPC_LIBS) $(LDAP_LIBS) $(KRB5_LIBS) $(TALLOC_LIBS) \ |
211 | 212 | $(GMP_LIBS) $(IDN_LIBS) $(OPENSSL_LIBS) $(UUID_LIBS) \ |
212 | 213 | $(RESOLV_LIBS) $(LTLIBICONV) $(POPT_LIBS) |
214 | certmaster_submit_CFLAGS = $(AM_CFLAGS) $(NSS_CFLAGS) | |
213 | 215 | certmaster_submit_SOURCES = certmaster.c submit-x.c submit-x.h \ |
214 | 216 | submit-e.h submit-u.c submit-u.h util.c util.h log.c log.h \ |
215 | 217 | tm.c tm.h |
1670 | 1670 | return SECITEM_ArenaDupItem(arena, &encoded); |
1671 | 1671 | } |
1672 | 1672 | |
1673 | /* Validate a V2 template spec */ | |
1674 | PRBool cm_ms_template_valid(char *template_spec) { | |
1675 | PLArenaPool *arena = PORT_NewArena(sizeof(double)); | |
1676 | if (arena == NULL) | |
1677 | return PR_FALSE; | |
1678 | SECItem *result = | |
1679 | cm_certext_build_certificate_template(arena, template_spec); | |
1680 | PORT_FreeArena(arena, PR_FALSE); | |
1681 | // *result has been freed, but we don't read it; | |
1682 | // we only need to know whether the parse succeeded | |
1683 | return result != NULL; | |
1684 | } | |
1685 | ||
1673 | 1686 | /* Build a Netscape certtype extension value. */ |
1674 | 1687 | static SECItem * |
1675 | 1688 | cm_certext_build_ns_certtype(struct cm_store_entry *entry, |
14 | 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
15 | 15 | */ |
16 | 16 | |
17 | #include <prtypes.h> | |
18 | ||
17 | 19 | #ifndef cmcertext_h |
18 | 20 | #define cmcertext_h |
19 | 21 | |
24 | 26 | struct NSSInitContextStr *ctx, |
25 | 27 | unsigned char **encoded, size_t *length); |
26 | 28 | |
29 | /* Validate a V2 template spec */ | |
30 | PRBool cm_ms_template_valid(char *template_spec); | |
31 | ||
27 | 32 | #endif |
31 | 31 | |
32 | 32 | #include "log.h" |
33 | 33 | #include "cm.h" |
34 | #include "certext.h" | |
34 | 35 | #include "prefs.h" |
35 | 36 | #include "store.h" |
36 | 37 | #include "store-int.h" |
1571 | 1572 | CM_DBUS_PROP_TEMPLATE_MS_CERTIFICATE_TEMPLATE, |
1572 | 1573 | cm_tdbusm_dict_s); |
1573 | 1574 | if (param != NULL) { |
1574 | // TODO check validity | |
1575 | if (param->value.s != NULL | |
1576 | && strlen(param->value.s) > 0 | |
1577 | && !cm_ms_template_valid(param->value.s)) { | |
1578 | cm_log(1, "Invalid V2 certificate template specifier: %s", param->value.s); | |
1579 | ret = send_internal_base_bad_arg_error( | |
1580 | conn, msg, | |
1581 | _("Invalid V2 certificate template specifier: %s"), | |
1582 | param->value.s, | |
1583 | CM_DBUS_PROP_TEMPLATE_MS_CERTIFICATE_TEMPLATE); | |
1584 | talloc_free(parent); | |
1585 | return ret; | |
1586 | } | |
1575 | 1587 | new_entry->cm_template_certificate_template = maybe_strdup(new_entry, |
1576 | 1588 | param->value.s); |
1577 | 1589 | } |
3367 | 3379 | } else |
3368 | 3380 | if ((param->value_type == cm_tdbusm_dict_s) && |
3369 | 3381 | (strcasecmp(param->key, CM_DBUS_PROP_TEMPLATE_MS_CERTIFICATE_TEMPLATE) == 0)) { |
3382 | if (param->value.s != NULL | |
3383 | && strlen(param->value.s) > 0 | |
3384 | && !cm_ms_template_valid(param->value.s)) { | |
3385 | cm_log(1, "Invalid V2 certificate template specifier: %s", param->value.s); | |
3386 | return send_internal_base_bad_arg_error( | |
3387 | conn, msg, | |
3388 | _("Invalid V2 certificate template specifier: %s"), | |
3389 | param->value.s, | |
3390 | CM_DBUS_PROP_TEMPLATE_MS_CERTIFICATE_TEMPLATE); | |
3391 | } | |
3370 | 3392 | talloc_free(entry->cm_template_certificate_template); |
3371 | // TODO check validity | |
3372 | 3393 | entry->cm_template_certificate_template = |
3373 | 3394 | maybe_strdup(entry, param->value.s); |
3374 | 3395 | if (n_propname + 2 < sizeof(propname) / sizeof(propname[0])) { |