| 6 | // |
| 7 | // https://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 |
| 15 | #include <stdio.h> |
| 16 | #include <string.h> |
| 17 |
| 18 | #include <openssl/asn1.h> |
| 19 | #include <openssl/asn1t.h> |
| 20 | #include <openssl/conf.h> |
| 21 | #include <openssl/err.h> |
| 22 | #include <openssl/mem.h> |
| 23 | #include <openssl/obj.h> |
| 24 | #include <openssl/x509.h> |
| 25 |
| 26 | #include "ext_dat.h" |
| 27 | #include "internal.h" |
| 28 |
| 29 |
| 30 | static void *v2i_crld(const X509V3_EXT_METHOD *method, const X509V3_CTX *ctx, |
| 31 | const STACK_OF(CONF_VALUE) *nval); |
| 32 | static int i2r_crldp(const X509V3_EXT_METHOD *method, void *pcrldp, BIO *out, |
| 33 | int indent); |
| 34 |
| 35 | const X509V3_EXT_METHOD v3_crld = { |
| 36 | NID_crl_distribution_points, |
| 37 | 0, |
| 38 | ASN1_ITEM_ref(CRL_DIST_POINTS), |
| 39 | 0, |
| 40 | 0, |
| 41 | 0, |
| 42 | 0, |
| 43 | 0, |
| 44 | 0, |
| 45 | 0, |
| 46 | v2i_crld, |
| 47 | i2r_crldp, |
| 48 | 0, |
| 49 | NULL, |
| 50 | }; |
| 51 |
| 52 | const X509V3_EXT_METHOD v3_freshest_crl = { |
| 53 | NID_freshest_crl, |
| 54 | 0, |
| 55 | ASN1_ITEM_ref(CRL_DIST_POINTS), |
| 56 | 0, |
| 57 | 0, |
| 58 | 0, |
| 59 | 0, |
| 60 | 0, |
| 61 | 0, |
| 62 | 0, |
| 63 | v2i_crld, |
| 64 | i2r_crldp, |
| 65 | 0, |
| 66 | NULL, |
| 67 | }; |
| 68 |
| 69 | static STACK_OF(GENERAL_NAME) *gnames_from_sectname(const X509V3_CTX *ctx, |
| 70 | char *sect) { |
| 71 | const STACK_OF(CONF_VALUE) *gnsect; |
| 72 | STACK_OF(CONF_VALUE) *gnsect_owned = NULL; |
| 73 | if (*sect == '@') { |
| 74 | gnsect = X509V3_get_section(ctx, sect + 1); |
| 75 | } else { |
| 76 | gnsect_owned = X509V3_parse_list(sect); |
| 77 | gnsect = gnsect_owned; |
| 78 | } |
| 79 | if (!gnsect) { |
| 80 | OPENSSL_PUT_ERROR(X509V3, X509V3_R_SECTION_NOT_FOUND); |
| 81 | return NULL; |
| 82 | } |
| 83 | STACK_OF(GENERAL_NAME) *gens = v2i_GENERAL_NAMES(NULL, ctx, gnsect); |
| 84 | sk_CONF_VALUE_pop_free(gnsect_owned, X509V3_conf_free); |
| 85 | return gens; |
| 86 | } |
| 87 |
| 88 | // set_dist_point_name decodes a DistributionPointName from |cnf| and writes the |
| 89 | // result in |*pdp|. It returns 1 on success, -1 on error, and 0 if |cnf| used |
| 90 | // an unrecognized input type. The zero return can be used by callers to support |
| 91 | // additional syntax. |
| 92 | static int set_dist_point_name(DIST_POINT_NAME **pdp, const X509V3_CTX *ctx, |
| 93 | const CONF_VALUE *cnf) { |
| 94 | STACK_OF(GENERAL_NAME) *fnm = NULL; |
| 95 | STACK_OF(X509_NAME_ENTRY) *rnm = NULL; |
| 96 | if (!strncmp(cnf->name, "fullname", 9)) { |
| 97 | // If |cnf| comes from |X509V3_parse_list|, which is possible for a v2i |
| 98 | // function, |cnf->value| may be NULL. |
| 99 | if (cnf->value == NULL) { |
| 100 | OPENSSL_PUT_ERROR(X509V3, X509V3_R_MISSING_VALUE); |
| 101 | return -1; |
| 102 | } |
| 103 | fnm = gnames_from_sectname(ctx, cnf->value); |
| 104 | if (!fnm) { |
| 105 | goto err; |
| 106 | } |
| 107 | } else if (!strcmp(cnf->name, "relativename")) { |
| 108 | // If |cnf| comes from |X509V3_parse_list|, which is possible for a v2i |
| 109 | // function, |cnf->value| may be NULL. |
| 110 | if (cnf->value == NULL) { |
| 111 | OPENSSL_PUT_ERROR(X509V3, X509V3_R_MISSING_VALUE); |
| 112 | return -1; |
| 113 | } |
| 114 | const STACK_OF(CONF_VALUE) *dnsect = X509V3_get_section(ctx, cnf->value); |
| 115 | if (!dnsect) { |
| 116 | OPENSSL_PUT_ERROR(X509V3, X509V3_R_SECTION_NOT_FOUND); |
| 117 | return -1; |
| 118 | } |
| 119 | X509_NAME *nm = X509_NAME_new(); |
| 120 | if (!nm) { |
| 121 | return -1; |
| 122 | } |
| 123 | int ret = X509V3_NAME_from_section(nm, dnsect, MBSTRING_ASC); |
| 124 | rnm = nm->entries; |
| 125 | nm->entries = NULL; |
| 126 | X509_NAME_free(nm); |
| 127 | if (!ret || sk_X509_NAME_ENTRY_num(rnm) <= 0) { |
| 128 | goto err; |
| 129 | } |
| 130 | // There can only be one RDN in nameRelativeToCRLIssuer. |
| 131 | if (sk_X509_NAME_ENTRY_value(rnm, sk_X509_NAME_ENTRY_num(rnm) - 1)->set) { |
| 132 | OPENSSL_PUT_ERROR(X509V3, X509V3_R_INVALID_MULTIPLE_RDNS); |
| 133 | goto err; |
| 134 | } |
| 135 | } else { |
| 136 | return 0; |
| 137 | } |
| 138 |
| 139 | if (*pdp) { |
| 140 | OPENSSL_PUT_ERROR(X509V3, X509V3_R_DISTPOINT_ALREADY_SET); |
| 141 | goto err; |
| 142 | } |
| 143 |
| 144 | *pdp = DIST_POINT_NAME_new(); |
| 145 | if (!*pdp) { |
| 146 | goto err; |
| 147 | } |
| 148 | if (fnm) { |
| 149 | (*pdp)->type = 0; |
| 150 | (*pdp)->name.fullname = fnm; |
| 151 | } else { |
| 152 | (*pdp)->type = 1; |
| 153 | (*pdp)->name.relativename = rnm; |
| 154 | } |
| 155 |
| 156 | return 1; |
| 157 |
| 158 | err: |
| 159 | sk_GENERAL_NAME_pop_free(fnm, GENERAL_NAME_free); |
| 160 | sk_X509_NAME_ENTRY_pop_free(rnm, X509_NAME_ENTRY_free); |
| 161 | return -1; |
| 162 | } |
| 163 |
| 164 | static const BIT_STRING_BITNAME reason_flags[] = { |
| 165 | {0, "Unused", "unused"}, |
| 166 | {1, "Key Compromise", "keyCompromise"}, |
| 167 | {2, "CA Compromise", "CACompromise"}, |
| 168 | {3, "Affiliation Changed", "affiliationChanged"}, |
| 169 | {4, "Superseded", "superseded"}, |
| 170 | {5, "Cessation Of Operation", "cessationOfOperation"}, |
| 171 | {6, "Certificate Hold", "certificateHold"}, |
| 172 | {7, "Privilege Withdrawn", "privilegeWithdrawn"}, |
| 173 | {8, "AA Compromise", "AACompromise"}, |
| 174 | {-1, NULL, NULL}}; |
| 175 |
| 176 | static int set_reasons(ASN1_BIT_STRING **preas, const char *value) { |
| 177 | if (*preas) { |
| 178 | // Duplicate "reasons" or "onlysomereasons" key. |
| 179 | OPENSSL_PUT_ERROR(X509V3, X509V3_R_INVALID_VALUE); |
| 180 | return 0; |
| 181 | } |
| 182 | int ret = 0; |
| 183 | STACK_OF(CONF_VALUE) *rsk = X509V3_parse_list(value); |
| 184 | if (!rsk) { |
| 185 | return 0; |
| 186 | } |
| 187 | for (size_t i = 0; i < sk_CONF_VALUE_num(rsk); i++) { |
| 188 | const char *bnam = sk_CONF_VALUE_value(rsk, i)->name; |
| 189 | if (!*preas) { |
| 190 | *preas = ASN1_BIT_STRING_new(); |
| 191 | if (!*preas) { |
| 192 | goto err; |
| 193 | } |
| 194 | } |
| 195 | const BIT_STRING_BITNAME *pbn; |
| 196 | for (pbn = reason_flags; pbn->lname; pbn++) { |
| 197 | if (!strcmp(pbn->sname, bnam)) { |
| 198 | if (!ASN1_BIT_STRING_set_bit(*preas, pbn->bitnum, 1)) { |
| 199 | goto err; |
| 200 | } |
| 201 | break; |
| 202 | } |
| 203 | } |
| 204 | if (!pbn->lname) { |
| 205 | goto err; |
| 206 | } |
| 207 | } |
| 208 | ret = 1; |
| 209 |
| 210 | err: |
| 211 | sk_CONF_VALUE_pop_free(rsk, X509V3_conf_free); |
| 212 | return ret; |
| 213 | } |
| 214 |
| 215 | static int print_reasons(BIO *out, const char *rname, ASN1_BIT_STRING *rflags, |
| 216 | int indent) { |
| 217 | int first = 1; |
| 218 | const BIT_STRING_BITNAME *pbn; |
| 219 | BIO_printf(out, "%*s%s:\n%*s", indent, "", rname, indent + 2, ""); |
| 220 | for (pbn = reason_flags; pbn->lname; pbn++) { |
| 221 | if (ASN1_BIT_STRING_get_bit(rflags, pbn->bitnum)) { |
| 222 | if (first) { |
| 223 | first = 0; |
| 224 | } else { |
| 225 | BIO_puts(out, ", "); |
| 226 | } |
| 227 | BIO_puts(out, pbn->lname); |
| 228 | } |
| 229 | } |
| 230 | if (first) { |
| 231 | BIO_puts(out, "<EMPTY>\n"); |
| 232 | } else { |
| 233 | BIO_puts(out, "\n"); |
| 234 | } |
| 235 | return 1; |
| 236 | } |
| 237 |
| 238 | static DIST_POINT *crldp_from_section(const X509V3_CTX *ctx, |
| 239 | const STACK_OF(CONF_VALUE) *nval) { |
| 240 | DIST_POINT *point = NULL; |
| 241 | point = DIST_POINT_new(); |
| 242 | if (!point) { |
| 243 | goto err; |
| 244 | } |
| 245 | for (size_t i = 0; i < sk_CONF_VALUE_num(nval); i++) { |
| 246 | const CONF_VALUE *cnf = sk_CONF_VALUE_value(nval, i); |
| 247 | int ret = set_dist_point_name(&point->distpoint, ctx, cnf); |
| 248 | if (ret > 0) { |
| 249 | continue; |
| 250 | } |
| 251 | if (ret < 0) { |
| 252 | goto err; |
| 253 | } |
| 254 | if (!strcmp(cnf->name, "reasons")) { |
| 255 | if (!set_reasons(&point->reasons, cnf->value)) { |
| 256 | goto err; |
| 257 | } |
| 258 | } else if (!strcmp(cnf->name, "CRLissuer")) { |
| 259 | GENERAL_NAMES_free(point->CRLissuer); |
| 260 | point->CRLissuer = gnames_from_sectname(ctx, cnf->value); |
| 261 | if (!point->CRLissuer) { |
| 262 | goto err; |
| 263 | } |
| 264 | } |
| 265 | } |
| 266 |
| 267 | return point; |
| 268 |
| 269 | err: |
| 270 | DIST_POINT_free(point); |
| 271 | return NULL; |
| 272 | } |
| 273 |
| 274 | static void *v2i_crld(const X509V3_EXT_METHOD *method, const X509V3_CTX *ctx, |
| 275 | const STACK_OF(CONF_VALUE) *nval) { |
| 276 | STACK_OF(DIST_POINT) *crld = NULL; |
| 277 | GENERAL_NAMES *gens = NULL; |
| 278 | GENERAL_NAME *gen = NULL; |
| 279 | if (!(crld = sk_DIST_POINT_new_null())) { |
| 280 | goto err; |
| 281 | } |
| 282 | for (size_t i = 0; i < sk_CONF_VALUE_num(nval); i++) { |
| 283 | DIST_POINT *point; |
| 284 | const CONF_VALUE *cnf = sk_CONF_VALUE_value(nval, i); |
| 285 | if (!cnf->value) { |
| 286 | const STACK_OF(CONF_VALUE) *dpsect = X509V3_get_section(ctx, cnf->name); |
| 287 | if (!dpsect) { |
| 288 | goto err; |
| 289 | } |
| 290 | point = crldp_from_section(ctx, dpsect); |
| 291 | if (!point) { |
| 292 | goto err; |
| 293 | } |
| 294 | if (!sk_DIST_POINT_push(crld, point)) { |
| 295 | DIST_POINT_free(point); |
| 296 | goto err; |
| 297 | } |
| 298 | } else { |
| 299 | if (!(gen = v2i_GENERAL_NAME(method, ctx, cnf))) { |
| 300 | goto err; |
| 301 | } |
| 302 | if (!(gens = GENERAL_NAMES_new())) { |
| 303 | goto err; |
| 304 | } |
| 305 | if (!sk_GENERAL_NAME_push(gens, gen)) { |
| 306 | goto err; |
| 307 | } |
| 308 | gen = NULL; |
| 309 | if (!(point = DIST_POINT_new())) { |
| 310 | goto err; |
| 311 | } |
| 312 | if (!sk_DIST_POINT_push(crld, point)) { |
| 313 | DIST_POINT_free(point); |
| 314 | goto err; |
| 315 | } |
| 316 | if (!(point->distpoint = DIST_POINT_NAME_new())) { |
| 317 | goto err; |
| 318 | } |
| 319 | point->distpoint->name.fullname = gens; |
| 320 | point->distpoint->type = 0; |
| 321 | gens = NULL; |
| 322 | } |
| 323 | } |
| 324 | return crld; |
| 325 |
| 326 | err: |
| 327 | GENERAL_NAME_free(gen); |
| 328 | GENERAL_NAMES_free(gens); |
| 329 | sk_DIST_POINT_pop_free(crld, DIST_POINT_free); |
| 330 | return NULL; |
| 331 | } |
| 332 |
| 333 | static int dpn_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it, |
| 334 | void *exarg) { |
| 335 | DIST_POINT_NAME *dpn = (DIST_POINT_NAME *)*pval; |
| 336 |
| 337 | switch (operation) { |
| 338 | case ASN1_OP_NEW_POST: |
| 339 | dpn->dpname = NULL; |
| 340 | break; |
| 341 |
| 342 | case ASN1_OP_FREE_POST: |
| 343 | X509_NAME_free(dpn->dpname); |
| 344 | break; |
| 345 | } |
| 346 | return 1; |
| 347 | } |
| 348 |
| 349 |
| 350 | ASN1_CHOICE_cb(DIST_POINT_NAME, dpn_cb) = { |
| 351 | ASN1_IMP_SEQUENCE_OF(DIST_POINT_NAME, name.fullname, GENERAL_NAME, 0), |
| 352 | ASN1_IMP_SET_OF(DIST_POINT_NAME, name.relativename, X509_NAME_ENTRY, 1), |
| 353 | } ASN1_CHOICE_END_cb(DIST_POINT_NAME, DIST_POINT_NAME, type) |
| 354 |
| 355 | IMPLEMENT_ASN1_ALLOC_FUNCTIONS(DIST_POINT_NAME) |
| 356 |
| 357 | ASN1_SEQUENCE(DIST_POINT) = { |
| 358 | ASN1_EXP_OPT(DIST_POINT, distpoint, DIST_POINT_NAME, 0), |
| 359 | ASN1_IMP_OPT(DIST_POINT, reasons, ASN1_BIT_STRING, 1), |
| 360 | ASN1_IMP_SEQUENCE_OF_OPT(DIST_POINT, CRLissuer, GENERAL_NAME, 2), |
| 361 | } ASN1_SEQUENCE_END(DIST_POINT) |
| 362 |
| 363 | IMPLEMENT_ASN1_ALLOC_FUNCTIONS(DIST_POINT) |
| 364 |
| 365 | ASN1_ITEM_TEMPLATE(CRL_DIST_POINTS) = ASN1_EX_TEMPLATE_TYPE( |
| 366 | ASN1_TFLG_SEQUENCE_OF, 0, CRLDistributionPoints, DIST_POINT) |
| 367 | ASN1_ITEM_TEMPLATE_END(CRL_DIST_POINTS) |
| 368 |
| 369 | IMPLEMENT_ASN1_FUNCTIONS(CRL_DIST_POINTS) |
| 370 |
| 371 | ASN1_SEQUENCE(ISSUING_DIST_POINT) = { |
| 372 | ASN1_EXP_OPT(ISSUING_DIST_POINT, distpoint, DIST_POINT_NAME, 0), |
| 373 | ASN1_IMP_OPT(ISSUING_DIST_POINT, onlyuser, ASN1_FBOOLEAN, 1), |
| 374 | ASN1_IMP_OPT(ISSUING_DIST_POINT, onlyCA, ASN1_FBOOLEAN, 2), |
| 375 | ASN1_IMP_OPT(ISSUING_DIST_POINT, onlysomereasons, ASN1_BIT_STRING, 3), |
| 376 | ASN1_IMP_OPT(ISSUING_DIST_POINT, indirectCRL, ASN1_FBOOLEAN, 4), |
| 377 | ASN1_IMP_OPT(ISSUING_DIST_POINT, onlyattr, ASN1_FBOOLEAN, 5), |
| 378 | } ASN1_SEQUENCE_END(ISSUING_DIST_POINT) |
| 379 |
| 380 | IMPLEMENT_ASN1_FUNCTIONS(ISSUING_DIST_POINT) |
| 381 |
| 382 | static int i2r_idp(const X509V3_EXT_METHOD *method, void *pidp, BIO *out, |
| 383 | int indent); |
| 384 | static void *v2i_idp(const X509V3_EXT_METHOD *method, const X509V3_CTX *ctx, |
| 385 | const STACK_OF(CONF_VALUE) *nval); |
| 386 |
| 387 | const X509V3_EXT_METHOD v3_idp = { |
| 388 | NID_issuing_distribution_point, |
| 389 | X509V3_EXT_MULTILINE, |
| 390 | ASN1_ITEM_ref(ISSUING_DIST_POINT), |
| 391 | 0, |
| 392 | 0, |
| 393 | 0, |
| 394 | 0, |
| 395 | 0, |
| 396 | 0, |
| 397 | 0, |
| 398 | v2i_idp, |
| 399 | i2r_idp, |
| 400 | 0, |
| 401 | NULL, |
| 402 | }; |
| 403 |
| 404 | static void *v2i_idp(const X509V3_EXT_METHOD *method, const X509V3_CTX *ctx, |
| 405 | const STACK_OF(CONF_VALUE) *nval) { |
| 406 | ISSUING_DIST_POINT *idp = ISSUING_DIST_POINT_new(); |
| 407 | if (!idp) { |
| 408 | goto err; |
| 409 | } |
| 410 | for (size_t i = 0; i < sk_CONF_VALUE_num(nval); i++) { |
| 411 | const CONF_VALUE *cnf = sk_CONF_VALUE_value(nval, i); |
| 412 | const char *name = cnf->name; |
| 413 | const char *val = cnf->value; |
| 414 | int ret = set_dist_point_name(&idp->distpoint, ctx, cnf); |
| 415 | if (ret > 0) { |
| 416 | continue; |
| 417 | } |
| 418 | if (ret < 0) { |
| 419 | goto err; |
| 420 | } |
| 421 | if (!strcmp(name, "onlyuser")) { |
| 422 | if (!X509V3_get_value_bool(cnf, &idp->onlyuser)) { |
| 423 | goto err; |
| 424 | } |
| 425 | } else if (!strcmp(name, "onlyCA")) { |
| 426 | if (!X509V3_get_value_bool(cnf, &idp->onlyCA)) { |
| 427 | goto err; |
| 428 | } |
| 429 | } else if (!strcmp(name, "onlyAA")) { |
| 430 | if (!X509V3_get_value_bool(cnf, &idp->onlyattr)) { |
| 431 | goto err; |
| 432 | } |
| 433 | } else if (!strcmp(name, "indirectCRL")) { |
| 434 | if (!X509V3_get_value_bool(cnf, &idp->indirectCRL)) { |
| 435 | goto err; |
| 436 | } |
| 437 | } else if (!strcmp(name, "onlysomereasons")) { |
| 438 | if (!set_reasons(&idp->onlysomereasons, val)) { |
| 439 | goto err; |
| 440 | } |
| 441 | } else { |
| 442 | OPENSSL_PUT_ERROR(X509V3, X509V3_R_INVALID_NAME); |
| 443 | X509V3_conf_err(cnf); |
| 444 | goto err; |
| 445 | } |
| 446 | } |
| 447 | return idp; |
| 448 |
| 449 | err: |
| 450 | ISSUING_DIST_POINT_free(idp); |
| 451 | return NULL; |
| 452 | } |
| 453 |
| 454 | static int print_gens(BIO *out, STACK_OF(GENERAL_NAME) *gens, int indent) { |
| 455 | size_t i; |
| 456 | for (i = 0; i < sk_GENERAL_NAME_num(gens); i++) { |
| 457 | BIO_printf(out, "%*s", indent + 2, ""); |
| 458 | GENERAL_NAME_print(out, sk_GENERAL_NAME_value(gens, i)); |
| 459 | BIO_puts(out, "\n"); |
| 460 | } |
| 461 | return 1; |
| 462 | } |
| 463 |
| 464 | static int print_distpoint(BIO *out, DIST_POINT_NAME *dpn, int indent) { |
| 465 | if (dpn->type == 0) { |
| 466 | BIO_printf(out, "%*sFull Name:\n", indent, ""); |
| 467 | print_gens(out, dpn->name.fullname, indent); |
| 468 | } else { |
| 469 | X509_NAME ntmp; |
| 470 | ntmp.entries = dpn->name.relativename; |
| 471 | BIO_printf(out, "%*sRelative Name:\n%*s", indent, "", indent + 2, ""); |
| 472 | X509_NAME_print_ex(out, &ntmp, 0, XN_FLAG_ONELINE); |
| 473 | BIO_puts(out, "\n"); |
| 474 | } |
| 475 | return 1; |
| 476 | } |
| 477 |
| 478 | static int i2r_idp(const X509V3_EXT_METHOD *method, void *pidp, BIO *out, |
| 479 | int indent) { |
| 480 | ISSUING_DIST_POINT *idp = reinterpret_cast<ISSUING_DIST_POINT *>(pidp); |
| 481 | if (idp->distpoint) { |
| 482 | print_distpoint(out, idp->distpoint, indent); |
| 483 | } |
| 484 | if (idp->onlyuser > 0) { |
| 485 | BIO_printf(out, "%*sOnly User Certificates\n", indent, ""); |
| 486 | } |
| 487 | if (idp->onlyCA > 0) { |
| 488 | BIO_printf(out, "%*sOnly CA Certificates\n", indent, ""); |
| 489 | } |
| 490 | if (idp->indirectCRL > 0) { |
| 491 | BIO_printf(out, "%*sIndirect CRL\n", indent, ""); |
| 492 | } |
| 493 | if (idp->onlysomereasons) { |
| 494 | print_reasons(out, "Only Some Reasons", idp->onlysomereasons, indent); |
| 495 | } |
| 496 | if (idp->onlyattr > 0) { |
| 497 | BIO_printf(out, "%*sOnly Attribute Certificates\n", indent, ""); |
| 498 | } |
| 499 | if (!idp->distpoint && (idp->onlyuser <= 0) && (idp->onlyCA <= 0) && |
| 500 | (idp->indirectCRL <= 0) && !idp->onlysomereasons && |
| 501 | (idp->onlyattr <= 0)) { |
| 502 | BIO_printf(out, "%*s<EMPTY>\n", indent, ""); |
| 503 | } |
| 504 |
| 505 | return 1; |
| 506 | } |
| 507 |
| 508 | static int i2r_crldp(const X509V3_EXT_METHOD *method, void *pcrldp, BIO *out, |
| 509 | int indent) { |
| 510 | STACK_OF(DIST_POINT) *crld = reinterpret_cast<STACK_OF(DIST_POINT) *>(pcrldp); |
| 511 | DIST_POINT *point; |
| 512 | size_t i; |
| 513 | for (i = 0; i < sk_DIST_POINT_num(crld); i++) { |
| 514 | BIO_puts(out, "\n"); |
| 515 | point = sk_DIST_POINT_value(crld, i); |
| 516 | if (point->distpoint) { |
| 517 | print_distpoint(out, point->distpoint, indent); |
| 518 | } |
| 519 | if (point->reasons) { |
| 520 | print_reasons(out, "Reasons", point->reasons, indent); |
| 521 | } |
| 522 | if (point->CRLissuer) { |
| 523 | BIO_printf(out, "%*sCRL Issuer:\n", indent, ""); |
| 524 | print_gens(out, point->CRLissuer, indent); |
| 525 | } |
| 526 | } |
| 527 | return 1; |
| 528 | } |
| 529 |
| 530 | int DIST_POINT_set_dpname(DIST_POINT_NAME *dpn, X509_NAME *iname) { |
| 531 | size_t i; |
| 532 | STACK_OF(X509_NAME_ENTRY) *frag; |
| 533 | X509_NAME_ENTRY *ne; |
| 534 | if (!dpn || (dpn->type != 1)) { |
| 535 | return 1; |
| 536 | } |
| 537 | frag = dpn->name.relativename; |
| 538 | dpn->dpname = X509_NAME_dup(iname); |
| 539 | if (!dpn->dpname) { |
| 540 | return 0; |
| 541 | } |
| 542 | for (i = 0; i < sk_X509_NAME_ENTRY_num(frag); i++) { |
| 543 | ne = sk_X509_NAME_ENTRY_value(frag, i); |
| 544 | if (!X509_NAME_add_entry(dpn->dpname, ne, -1, i ? 0 : 1)) { |
| 545 | X509_NAME_free(dpn->dpname); |
| 546 | dpn->dpname = NULL; |
| 547 | return 0; |
| 548 | } |
| 549 | } |
| 550 | // generate cached encoding of name |
| 551 | if (i2d_X509_NAME(dpn->dpname, NULL) < 0) { |
| 552 | X509_NAME_free(dpn->dpname); |
| 553 | dpn->dpname = NULL; |
| 554 | return 0; |
| 555 | } |
| 556 | return 1; |
| 557 | } |
| 558 |