| 1 |
/* |
| 2 |
* Copyright 1999-2025 The OpenSSL Project Authors. All Rights Reserved. |
| 3 |
* |
| 4 |
* Licensed under the Apache License 2.0 (the "License"). You may not use |
| 5 |
* this file except in compliance with the License. You can obtain a copy |
| 6 |
* in the file LICENSE in the source distribution or at |
| 7 |
* https://www.openssl.org/source/license.html |
| 8 |
*/ |
| 9 |
|
| 10 |
#include <stdio.h> |
| 11 |
#include "internal/cryptlib.h" |
| 12 |
#include <openssl/conf.h> |
| 13 |
#include <openssl/asn1.h> |
| 14 |
#include <openssl/asn1t.h> |
| 15 |
#include <openssl/x509v3.h> |
| 16 |
|
| 17 |
#include "crypto/x509.h" |
| 18 |
#include "ext_dat.h" |
| 19 |
#include "x509_local.h" |
| 20 |
|
| 21 |
static void *v2i_crld(const X509V3_EXT_METHOD *method, |
| 22 |
X509V3_CTX *ctx, STACK_OF(CONF_VALUE) *nval); |
| 23 |
static int i2r_crldp(const X509V3_EXT_METHOD *method, void *pcrldp, BIO *out, |
| 24 |
int indent); |
| 25 |
|
| 26 |
const X509V3_EXT_METHOD ossl_v3_crld = { |
| 27 |
NID_crl_distribution_points, 0, ASN1_ITEM_ref(CRL_DIST_POINTS), |
| 28 |
0, 0, 0, 0, |
| 29 |
0, 0, |
| 30 |
0, |
| 31 |
v2i_crld, |
| 32 |
i2r_crldp, 0, |
| 33 |
NULL |
| 34 |
}; |
| 35 |
|
| 36 |
const X509V3_EXT_METHOD ossl_v3_freshest_crl = { |
| 37 |
NID_freshest_crl, 0, ASN1_ITEM_ref(CRL_DIST_POINTS), |
| 38 |
0, 0, 0, 0, |
| 39 |
0, 0, |
| 40 |
0, |
| 41 |
v2i_crld, |
| 42 |
i2r_crldp, 0, |
| 43 |
NULL |
| 44 |
}; |
| 45 |
|
| 46 |
static STACK_OF(GENERAL_NAME) *gnames_from_sectname(X509V3_CTX *ctx, |
| 47 |
char *sect) |
| 48 |
{ |
| 49 |
STACK_OF(CONF_VALUE) *gnsect; |
| 50 |
STACK_OF(GENERAL_NAME) *gens; |
| 51 |
if (*sect == '@') |
| 52 |
gnsect = X509V3_get_section(ctx, sect + 1); |
| 53 |
else |
| 54 |
gnsect = X509V3_parse_list(sect); |
| 55 |
if (!gnsect) { |
| 56 |
ERR_raise(ERR_LIB_X509V3, X509V3_R_SECTION_NOT_FOUND); |
| 57 |
return NULL; |
| 58 |
} |
| 59 |
gens = v2i_GENERAL_NAMES(NULL, ctx, gnsect); |
| 60 |
if (*sect == '@') |
| 61 |
X509V3_section_free(ctx, gnsect); |
| 62 |
else |
| 63 |
sk_CONF_VALUE_pop_free(gnsect, X509V3_conf_free); |
| 64 |
return gens; |
| 65 |
} |
| 66 |
|
| 67 |
static int set_dist_point_name(DIST_POINT_NAME **pdp, X509V3_CTX *ctx, |
| 68 |
CONF_VALUE *cnf) |
| 69 |
{ |
| 70 |
STACK_OF(GENERAL_NAME) *fnm = NULL; |
| 71 |
STACK_OF(X509_NAME_ENTRY) *rnm = NULL; |
| 72 |
|
| 73 |
if (cnf->value == NULL) { |
| 74 |
ERR_raise(ERR_LIB_X509V3, X509V3_R_MISSING_VALUE); |
| 75 |
goto err; |
| 76 |
} |
| 77 |
|
| 78 |
if (HAS_PREFIX(cnf->name, "fullname")) { |
| 79 |
fnm = gnames_from_sectname(ctx, cnf->value); |
| 80 |
if (!fnm) |
| 81 |
goto err; |
| 82 |
} else if (strcmp(cnf->name, "relativename") == 0) { |
| 83 |
int ret; |
| 84 |
STACK_OF(CONF_VALUE) *dnsect; |
| 85 |
X509_NAME *nm; |
| 86 |
nm = X509_NAME_new(); |
| 87 |
if (nm == NULL) |
| 88 |
return -1; |
| 89 |
dnsect = X509V3_get_section(ctx, cnf->value); |
| 90 |
if (!dnsect) { |
| 91 |
X509_NAME_free(nm); |
| 92 |
ERR_raise(ERR_LIB_X509V3, X509V3_R_SECTION_NOT_FOUND); |
| 93 |
return -1; |
| 94 |
} |
| 95 |
ret = X509V3_NAME_from_section(nm, dnsect, MBSTRING_ASC); |
| 96 |
X509V3_section_free(ctx, dnsect); |
| 97 |
rnm = nm->entries; |
| 98 |
nm->entries = NULL; |
| 99 |
X509_NAME_free(nm); |
| 100 |
if (!ret || sk_X509_NAME_ENTRY_num(rnm) <= 0) |
| 101 |
goto err; |
| 102 |
/* |
| 103 |
* Since its a name fragment can't have more than one RDNSequence |
| 104 |
*/ |
| 105 |
if (sk_X509_NAME_ENTRY_value(rnm, |
| 106 |
sk_X509_NAME_ENTRY_num(rnm) - 1) |
| 107 |
->set) { |
| 108 |
ERR_raise(ERR_LIB_X509V3, X509V3_R_INVALID_MULTIPLE_RDNS); |
| 109 |
goto err; |
| 110 |
} |
| 111 |
} else |
| 112 |
return 0; |
| 113 |
|
| 114 |
if (*pdp) { |
| 115 |
ERR_raise(ERR_LIB_X509V3, X509V3_R_DISTPOINT_ALREADY_SET); |
| 116 |
goto err; |
| 117 |
} |
| 118 |
|
| 119 |
*pdp = DIST_POINT_NAME_new(); |
| 120 |
if (*pdp == NULL) |
| 121 |
goto err; |
| 122 |
if (fnm) { |
| 123 |
(*pdp)->type = 0; |
| 124 |
(*pdp)->name.fullname = fnm; |
| 125 |
} else { |
| 126 |
(*pdp)->type = 1; |
| 127 |
(*pdp)->name.relativename = rnm; |
| 128 |
} |
| 129 |
|
| 130 |
return 1; |
| 131 |
|
| 132 |
err: |
| 133 |
sk_GENERAL_NAME_pop_free(fnm, GENERAL_NAME_free); |
| 134 |
sk_X509_NAME_ENTRY_pop_free(rnm, X509_NAME_ENTRY_free); |
| 135 |
return -1; |
| 136 |
} |
| 137 |
|
| 138 |
static const BIT_STRING_BITNAME reason_flags[] = { |
| 139 |
{ 0, "Unused", "unused" }, |
| 140 |
{ 1, "Key Compromise", "keyCompromise" }, |
| 141 |
{ 2, "CA Compromise", "CACompromise" }, |
| 142 |
{ 3, "Affiliation Changed", "affiliationChanged" }, |
| 143 |
{ 4, "Superseded", "superseded" }, |
| 144 |
{ 5, "Cessation Of Operation", "cessationOfOperation" }, |
| 145 |
{ 6, "Certificate Hold", "certificateHold" }, |
| 146 |
{ 7, "Privilege Withdrawn", "privilegeWithdrawn" }, |
| 147 |
{ 8, "AA Compromise", "AACompromise" }, |
| 148 |
{ -1, NULL, NULL } |
| 149 |
}; |
| 150 |
|
| 151 |
static int set_reasons(ASN1_BIT_STRING **preas, char *value) |
| 152 |
{ |
| 153 |
STACK_OF(CONF_VALUE) *rsk = NULL; |
| 154 |
const BIT_STRING_BITNAME *pbn; |
| 155 |
const char *bnam; |
| 156 |
int i, ret = 0; |
| 157 |
rsk = X509V3_parse_list(value); |
| 158 |
if (rsk == NULL) |
| 159 |
return 0; |
| 160 |
if (*preas != NULL) |
| 161 |
goto err; |
| 162 |
for (i = 0; i < sk_CONF_VALUE_num(rsk); i++) { |
| 163 |
bnam = sk_CONF_VALUE_value(rsk, i)->name; |
| 164 |
if (*preas == NULL) { |
| 165 |
*preas = ASN1_BIT_STRING_new(); |
| 166 |
if (*preas == NULL) |
| 167 |
goto err; |
| 168 |
} |
| 169 |
for (pbn = reason_flags; pbn->lname; pbn++) { |
| 170 |
if (strcmp(pbn->sname, bnam) == 0) { |
| 171 |
if (!ASN1_BIT_STRING_set_bit(*preas, pbn->bitnum, 1)) |
| 172 |
goto err; |
| 173 |
break; |
| 174 |
} |
| 175 |
} |
| 176 |
if (pbn->lname == NULL) |
| 177 |
goto err; |
| 178 |
} |
| 179 |
ret = 1; |
| 180 |
|
| 181 |
err: |
| 182 |
sk_CONF_VALUE_pop_free(rsk, X509V3_conf_free); |
| 183 |
return ret; |
| 184 |
} |
| 185 |
|
| 186 |
static int print_reasons(BIO *out, const char *rname, |
| 187 |
ASN1_BIT_STRING *rflags, int indent) |
| 188 |
{ |
| 189 |
int first = 1; |
| 190 |
const BIT_STRING_BITNAME *pbn; |
| 191 |
BIO_printf(out, "%*s%s:\n%*s", indent, "", rname, indent + 2, ""); |
| 192 |
for (pbn = reason_flags; pbn->lname; pbn++) { |
| 193 |
if (ASN1_BIT_STRING_get_bit(rflags, pbn->bitnum)) { |
| 194 |
if (first) |
| 195 |
first = 0; |
| 196 |
else |
| 197 |
BIO_puts(out, ", "); |
| 198 |
BIO_puts(out, pbn->lname); |
| 199 |
} |
| 200 |
} |
| 201 |
if (first) |
| 202 |
BIO_puts(out, "<EMPTY>\n"); |
| 203 |
else |
| 204 |
BIO_puts(out, "\n"); |
| 205 |
return 1; |
| 206 |
} |
| 207 |
|
| 208 |
static DIST_POINT *crldp_from_section(X509V3_CTX *ctx, |
| 209 |
STACK_OF(CONF_VALUE) *nval) |
| 210 |
{ |
| 211 |
int i; |
| 212 |
CONF_VALUE *cnf; |
| 213 |
DIST_POINT *point = DIST_POINT_new(); |
| 214 |
|
| 215 |
if (point == NULL) |
| 216 |
goto err; |
| 217 |
for (i = 0; i < sk_CONF_VALUE_num(nval); i++) { |
| 218 |
int ret; |
| 219 |
cnf = sk_CONF_VALUE_value(nval, i); |
| 220 |
ret = set_dist_point_name(&point->distpoint, ctx, cnf); |
| 221 |
if (ret > 0) |
| 222 |
continue; |
| 223 |
if (ret < 0) |
| 224 |
goto err; |
| 225 |
if (strcmp(cnf->name, "reasons") == 0) { |
| 226 |
if (!set_reasons(&point->reasons, cnf->value)) |
| 227 |
goto err; |
| 228 |
} else if (strcmp(cnf->name, "CRLissuer") == 0) { |
| 229 |
point->CRLissuer = gnames_from_sectname(ctx, cnf->value); |
| 230 |
if (point->CRLissuer == NULL) |
| 231 |
goto err; |
| 232 |
} |
| 233 |
} |
| 234 |
|
| 235 |
return point; |
| 236 |
|
| 237 |
err: |
| 238 |
DIST_POINT_free(point); |
| 239 |
return NULL; |
| 240 |
} |
| 241 |
|
| 242 |
static void *v2i_crld(const X509V3_EXT_METHOD *method, |
| 243 |
X509V3_CTX *ctx, STACK_OF(CONF_VALUE) *nval) |
| 244 |
{ |
| 245 |
STACK_OF(DIST_POINT) *crld; |
| 246 |
GENERAL_NAMES *gens = NULL; |
| 247 |
GENERAL_NAME *gen = NULL; |
| 248 |
CONF_VALUE *cnf; |
| 249 |
const int num = sk_CONF_VALUE_num(nval); |
| 250 |
int i; |
| 251 |
|
| 252 |
crld = sk_DIST_POINT_new_reserve(NULL, num); |
| 253 |
if (crld == NULL) { |
| 254 |
ERR_raise(ERR_LIB_X509V3, ERR_R_CRYPTO_LIB); |
| 255 |
goto err; |
| 256 |
} |
| 257 |
for (i = 0; i < num; i++) { |
| 258 |
DIST_POINT *point; |
| 259 |
|
| 260 |
cnf = sk_CONF_VALUE_value(nval, i); |
| 261 |
if (cnf->value == NULL) { |
| 262 |
STACK_OF(CONF_VALUE) *dpsect; |
| 263 |
dpsect = X509V3_get_section(ctx, cnf->name); |
| 264 |
if (!dpsect) |
| 265 |
goto err; |
| 266 |
point = crldp_from_section(ctx, dpsect); |
| 267 |
X509V3_section_free(ctx, dpsect); |
| 268 |
if (point == NULL) |
| 269 |
goto err; |
| 270 |
sk_DIST_POINT_push(crld, point); /* no failure as it was reserved */ |
| 271 |
} else { |
| 272 |
if ((gen = v2i_GENERAL_NAME(method, ctx, cnf)) == NULL) |
| 273 |
goto err; |
| 274 |
if ((gens = GENERAL_NAMES_new()) == NULL) { |
| 275 |
ERR_raise(ERR_LIB_X509V3, ERR_R_ASN1_LIB); |
| 276 |
goto err; |
| 277 |
} |
| 278 |
if (!sk_GENERAL_NAME_push(gens, gen)) { |
| 279 |
ERR_raise(ERR_LIB_X509V3, ERR_R_CRYPTO_LIB); |
| 280 |
goto err; |
| 281 |
} |
| 282 |
gen = NULL; |
| 283 |
if ((point = DIST_POINT_new()) == NULL) { |
| 284 |
ERR_raise(ERR_LIB_X509V3, ERR_R_ASN1_LIB); |
| 285 |
goto err; |
| 286 |
} |
| 287 |
sk_DIST_POINT_push(crld, point); /* no failure as it was reserved */ |
| 288 |
if ((point->distpoint = DIST_POINT_NAME_new()) == NULL) { |
| 289 |
ERR_raise(ERR_LIB_X509V3, ERR_R_ASN1_LIB); |
| 290 |
goto err; |
| 291 |
} |
| 292 |
point->distpoint->name.fullname = gens; |
| 293 |
point->distpoint->type = 0; |
| 294 |
gens = NULL; |
| 295 |
} |
| 296 |
} |
| 297 |
return crld; |
| 298 |
|
| 299 |
err: |
| 300 |
GENERAL_NAME_free(gen); |
| 301 |
GENERAL_NAMES_free(gens); |
| 302 |
sk_DIST_POINT_pop_free(crld, DIST_POINT_free); |
| 303 |
return NULL; |
| 304 |
} |
| 305 |
|
| 306 |
static int dpn_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it, |
| 307 |
void *exarg) |
| 308 |
{ |
| 309 |
DIST_POINT_NAME *dpn = (DIST_POINT_NAME *)*pval; |
| 310 |
|
| 311 |
switch (operation) { |
| 312 |
case ASN1_OP_NEW_POST: |
| 313 |
dpn->dpname = NULL; |
| 314 |
break; |
| 315 |
|
| 316 |
case ASN1_OP_FREE_POST: |
| 317 |
X509_NAME_free(dpn->dpname); |
| 318 |
break; |
| 319 |
} |
| 320 |
return 1; |
| 321 |
} |
| 322 |
|
| 323 |
ASN1_CHOICE_cb(DIST_POINT_NAME, dpn_cb) = { |
| 324 |
ASN1_IMP_SEQUENCE_OF(DIST_POINT_NAME, name.fullname, GENERAL_NAME, 0), |
| 325 |
ASN1_IMP_SET_OF(DIST_POINT_NAME, name.relativename, X509_NAME_ENTRY, 1) |
| 326 |
} ASN1_CHOICE_END_cb(DIST_POINT_NAME, DIST_POINT_NAME, type) |
| 327 |
|
| 328 |
IMPLEMENT_ASN1_FUNCTIONS(DIST_POINT_NAME) |
| 329 |
IMPLEMENT_ASN1_DUP_FUNCTION(DIST_POINT_NAME) |
| 330 |
|
| 331 |
ASN1_SEQUENCE(DIST_POINT) = { |
| 332 |
ASN1_EXP_OPT(DIST_POINT, distpoint, DIST_POINT_NAME, 0), |
| 333 |
ASN1_IMP_OPT(DIST_POINT, reasons, ASN1_BIT_STRING, 1), |
| 334 |
ASN1_IMP_SEQUENCE_OF_OPT(DIST_POINT, CRLissuer, GENERAL_NAME, 2) |
| 335 |
} ASN1_SEQUENCE_END(DIST_POINT) |
| 336 |
|
| 337 |
IMPLEMENT_ASN1_FUNCTIONS(DIST_POINT) |
| 338 |
|
| 339 |
ASN1_ITEM_TEMPLATE(CRL_DIST_POINTS) = ASN1_EX_TEMPLATE_TYPE(ASN1_TFLG_SEQUENCE_OF, 0, CRLDistributionPoints, DIST_POINT) |
| 340 |
ASN1_ITEM_TEMPLATE_END(CRL_DIST_POINTS) |
| 341 |
|
| 342 |
IMPLEMENT_ASN1_FUNCTIONS(CRL_DIST_POINTS) |
| 343 |
|
| 344 |
ASN1_SEQUENCE(ISSUING_DIST_POINT) = { |
| 345 |
ASN1_EXP_OPT(ISSUING_DIST_POINT, distpoint, DIST_POINT_NAME, 0), |
| 346 |
ASN1_IMP_OPT(ISSUING_DIST_POINT, onlyuser, ASN1_FBOOLEAN, 1), |
| 347 |
ASN1_IMP_OPT(ISSUING_DIST_POINT, onlyCA, ASN1_FBOOLEAN, 2), |
| 348 |
ASN1_IMP_OPT(ISSUING_DIST_POINT, onlysomereasons, ASN1_BIT_STRING, 3), |
| 349 |
ASN1_IMP_OPT(ISSUING_DIST_POINT, indirectCRL, ASN1_FBOOLEAN, 4), |
| 350 |
ASN1_IMP_OPT(ISSUING_DIST_POINT, onlyattr, ASN1_FBOOLEAN, 5) |
| 351 |
} ASN1_SEQUENCE_END(ISSUING_DIST_POINT) |
| 352 |
|
| 353 |
IMPLEMENT_ASN1_FUNCTIONS(ISSUING_DIST_POINT) |
| 354 |
|
| 355 |
static int i2r_idp(const X509V3_EXT_METHOD *method, void *pidp, BIO *out, |
| 356 |
int indent); |
| 357 |
static void *v2i_idp(const X509V3_EXT_METHOD *method, X509V3_CTX *ctx, |
| 358 |
STACK_OF(CONF_VALUE) *nval); |
| 359 |
|
| 360 |
const X509V3_EXT_METHOD ossl_v3_idp = { |
| 361 |
NID_issuing_distribution_point, X509V3_EXT_MULTILINE, |
| 362 |
ASN1_ITEM_ref(ISSUING_DIST_POINT), |
| 363 |
0, 0, 0, 0, |
| 364 |
0, 0, |
| 365 |
0, |
| 366 |
v2i_idp, |
| 367 |
i2r_idp, 0, |
| 368 |
NULL |
| 369 |
}; |
| 370 |
|
| 371 |
static void *v2i_idp(const X509V3_EXT_METHOD *method, X509V3_CTX *ctx, |
| 372 |
STACK_OF(CONF_VALUE) *nval) |
| 373 |
{ |
| 374 |
ISSUING_DIST_POINT *idp = NULL; |
| 375 |
CONF_VALUE *cnf; |
| 376 |
char *name, *val; |
| 377 |
int i, ret; |
| 378 |
idp = ISSUING_DIST_POINT_new(); |
| 379 |
if (idp == NULL) { |
| 380 |
ERR_raise(ERR_LIB_X509V3, ERR_R_ASN1_LIB); |
| 381 |
goto err; |
| 382 |
} |
| 383 |
for (i = 0; i < sk_CONF_VALUE_num(nval); i++) { |
| 384 |
cnf = sk_CONF_VALUE_value(nval, i); |
| 385 |
name = cnf->name; |
| 386 |
val = cnf->value; |
| 387 |
ret = set_dist_point_name(&idp->distpoint, ctx, cnf); |
| 388 |
if (ret > 0) |
| 389 |
continue; |
| 390 |
if (ret < 0) |
| 391 |
goto err; |
| 392 |
if (strcmp(name, "onlyuser") == 0) { |
| 393 |
if (!X509V3_get_value_bool(cnf, &idp->onlyuser)) |
| 394 |
goto err; |
| 395 |
} else if (strcmp(name, "onlyCA") == 0) { |
| 396 |
if (!X509V3_get_value_bool(cnf, &idp->onlyCA)) |
| 397 |
goto err; |
| 398 |
} else if (strcmp(name, "onlyAA") == 0) { |
| 399 |
if (!X509V3_get_value_bool(cnf, &idp->onlyattr)) |
| 400 |
goto err; |
| 401 |
} else if (strcmp(name, "indirectCRL") == 0) { |
| 402 |
if (!X509V3_get_value_bool(cnf, &idp->indirectCRL)) |
| 403 |
goto err; |
| 404 |
} else if (strcmp(name, "onlysomereasons") == 0) { |
| 405 |
if (!set_reasons(&idp->onlysomereasons, val)) |
| 406 |
goto err; |
| 407 |
} else { |
| 408 |
ERR_raise(ERR_LIB_X509V3, X509V3_R_INVALID_NAME); |
| 409 |
X509V3_conf_add_error_name_value(cnf); |
| 410 |
goto err; |
| 411 |
} |
| 412 |
} |
| 413 |
return idp; |
| 414 |
|
| 415 |
err: |
| 416 |
ISSUING_DIST_POINT_free(idp); |
| 417 |
return NULL; |
| 418 |
} |
| 419 |
|
| 420 |
static int print_distpoint(BIO *out, DIST_POINT_NAME *dpn, int indent) |
| 421 |
{ |
| 422 |
if (dpn->type == 0) { |
| 423 |
BIO_printf(out, "%*sFull Name:\n", indent, ""); |
| 424 |
OSSL_GENERAL_NAMES_print(out, dpn->name.fullname, indent); |
| 425 |
BIO_puts(out, "\n"); |
| 426 |
} else { |
| 427 |
X509_NAME ntmp; |
| 428 |
ntmp.entries = dpn->name.relativename; |
| 429 |
BIO_printf(out, "%*sRelative Name:\n%*s", indent, "", indent + 2, ""); |
| 430 |
X509_NAME_print_ex(out, &ntmp, 0, XN_FLAG_ONELINE); |
| 431 |
BIO_puts(out, "\n"); |
| 432 |
} |
| 433 |
return 1; |
| 434 |
} |
| 435 |
|
| 436 |
static int i2r_idp(const X509V3_EXT_METHOD *method, void *pidp, BIO *out, |
| 437 |
int indent) |
| 438 |
{ |
| 439 |
ISSUING_DIST_POINT *idp = pidp; |
| 440 |
if (idp->distpoint) |
| 441 |
print_distpoint(out, idp->distpoint, indent); |
| 442 |
if (idp->onlyuser > 0) |
| 443 |
BIO_printf(out, "%*sOnly User Certificates\n", indent, ""); |
| 444 |
if (idp->onlyCA > 0) |
| 445 |
BIO_printf(out, "%*sOnly CA Certificates\n", indent, ""); |
| 446 |
if (idp->indirectCRL > 0) |
| 447 |
BIO_printf(out, "%*sIndirect CRL\n", indent, ""); |
| 448 |
if (idp->onlysomereasons) |
| 449 |
print_reasons(out, "Only Some Reasons", idp->onlysomereasons, indent); |
| 450 |
if (idp->onlyattr > 0) |
| 451 |
BIO_printf(out, "%*sOnly Attribute Certificates\n", indent, ""); |
| 452 |
if (!idp->distpoint && (idp->onlyuser <= 0) && (idp->onlyCA <= 0) |
| 453 |
&& (idp->indirectCRL <= 0) && !idp->onlysomereasons |
| 454 |
&& (idp->onlyattr <= 0)) |
| 455 |
BIO_printf(out, "%*s<EMPTY>\n", indent, ""); |
| 456 |
|
| 457 |
return 1; |
| 458 |
} |
| 459 |
|
| 460 |
static int i2r_crldp(const X509V3_EXT_METHOD *method, void *pcrldp, BIO *out, |
| 461 |
int indent) |
| 462 |
{ |
| 463 |
STACK_OF(DIST_POINT) *crld = pcrldp; |
| 464 |
DIST_POINT *point; |
| 465 |
int i; |
| 466 |
for (i = 0; i < sk_DIST_POINT_num(crld); i++) { |
| 467 |
if (i > 0) |
| 468 |
BIO_puts(out, "\n"); |
| 469 |
point = sk_DIST_POINT_value(crld, i); |
| 470 |
if (point->distpoint) |
| 471 |
print_distpoint(out, point->distpoint, indent); |
| 472 |
if (point->reasons) |
| 473 |
print_reasons(out, "Reasons", point->reasons, indent); |
| 474 |
if (point->CRLissuer) { |
| 475 |
BIO_printf(out, "%*sCRL Issuer:\n", indent, ""); |
| 476 |
OSSL_GENERAL_NAMES_print(out, point->CRLissuer, indent); |
| 477 |
} |
| 478 |
} |
| 479 |
return 1; |
| 480 |
} |
| 481 |
|
| 482 |
static int i2r_crl_invdate(const X509V3_EXT_METHOD *method, void *date, |
| 483 |
BIO *out, int indent); |
| 484 |
static int i2r_object(const X509V3_EXT_METHOD *method, void *obj, BIO *out, |
| 485 |
int indent); |
| 486 |
|
| 487 |
const X509V3_EXT_METHOD ossl_v3_crl_invdate = { |
| 488 |
NID_invalidity_date, 0, ASN1_ITEM_ref(ASN1_GENERALIZEDTIME), |
| 489 |
0, 0, 0, 0, |
| 490 |
0, 0, |
| 491 |
0, 0, |
| 492 |
i2r_crl_invdate, 0, |
| 493 |
NULL |
| 494 |
}; |
| 495 |
|
| 496 |
const X509V3_EXT_METHOD ossl_v3_crl_hold = { |
| 497 |
NID_hold_instruction_code, 0, ASN1_ITEM_ref(ASN1_OBJECT), |
| 498 |
0, 0, 0, 0, |
| 499 |
0, 0, |
| 500 |
0, 0, |
| 501 |
i2r_object, 0, |
| 502 |
NULL |
| 503 |
}; |
| 504 |
|
| 505 |
static int i2r_crl_invdate(const X509V3_EXT_METHOD *method, void *date, |
| 506 |
BIO *bp, int ind) |
| 507 |
{ |
| 508 |
if (BIO_printf(bp, "%*s", ind, "") <= 0) |
| 509 |
return 0; |
| 510 |
if (!ASN1_GENERALIZEDTIME_print(bp, date)) |
| 511 |
return 0; |
| 512 |
return 1; |
| 513 |
} |
| 514 |
|
| 515 |
static int i2r_object(const X509V3_EXT_METHOD *method, void *oid, BIO *bp, |
| 516 |
int ind) |
| 517 |
{ |
| 518 |
if (BIO_printf(bp, "%*s", ind, "") <= 0) |
| 519 |
return 0; |
| 520 |
if (i2a_ASN1_OBJECT(bp, oid) <= 0) |
| 521 |
return 0; |
| 522 |
return 1; |
| 523 |
} |
| 524 |
|
| 525 |
/* Append any nameRelativeToCRLIssuer in dpn to iname, set in dpn->dpname */ |
| 526 |
int DIST_POINT_set_dpname(DIST_POINT_NAME *dpn, const X509_NAME *iname) |
| 527 |
{ |
| 528 |
int i; |
| 529 |
STACK_OF(X509_NAME_ENTRY) *frag; |
| 530 |
X509_NAME_ENTRY *ne; |
| 531 |
|
| 532 |
if (dpn == NULL || dpn->type != 1) |
| 533 |
return 1; |
| 534 |
frag = dpn->name.relativename; |
| 535 |
X509_NAME_free(dpn->dpname); /* just in case it was already set */ |
| 536 |
dpn->dpname = X509_NAME_dup(iname); |
| 537 |
if (dpn->dpname == NULL) |
| 538 |
return 0; |
| 539 |
for (i = 0; i < sk_X509_NAME_ENTRY_num(frag); i++) { |
| 540 |
ne = sk_X509_NAME_ENTRY_value(frag, i); |
| 541 |
if (!X509_NAME_add_entry(dpn->dpname, ne, -1, i ? 0 : 1)) |
| 542 |
goto err; |
| 543 |
} |
| 544 |
/* generate cached encoding of name */ |
| 545 |
if (i2d_X509_NAME(dpn->dpname, NULL) >= 0) |
| 546 |
return 1; |
| 547 |
|
| 548 |
err: |
| 549 |
X509_NAME_free(dpn->dpname); |
| 550 |
dpn->dpname = NULL; |
| 551 |
return 0; |
| 552 |
} |
| 553 |
|
| 554 |
ASN1_SEQUENCE(OSSL_AA_DIST_POINT) = { |
| 555 |
ASN1_EXP_OPT(OSSL_AA_DIST_POINT, distpoint, DIST_POINT_NAME, 0), |
| 556 |
ASN1_IMP_OPT(OSSL_AA_DIST_POINT, reasons, ASN1_BIT_STRING, 1), |
| 557 |
ASN1_IMP_OPT(OSSL_AA_DIST_POINT, indirectCRL, ASN1_FBOOLEAN, 2), |
| 558 |
ASN1_IMP_OPT(OSSL_AA_DIST_POINT, containsUserAttributeCerts, ASN1_TBOOLEAN, 3), |
| 559 |
ASN1_IMP_OPT(OSSL_AA_DIST_POINT, containsAACerts, ASN1_TBOOLEAN, 4), |
| 560 |
ASN1_IMP_OPT(OSSL_AA_DIST_POINT, containsSOAPublicKeyCerts, ASN1_TBOOLEAN, 5) |
| 561 |
} ASN1_SEQUENCE_END(OSSL_AA_DIST_POINT) |
| 562 |
|
| 563 |
IMPLEMENT_ASN1_FUNCTIONS(OSSL_AA_DIST_POINT) |
| 564 |
|
| 565 |
static int print_boolean(BIO *out, ASN1_BOOLEAN b) |
| 566 |
{ |
| 567 |
return BIO_puts(out, b ? "TRUE" : "FALSE"); |
| 568 |
} |
| 569 |
|
| 570 |
static OSSL_AA_DIST_POINT *aaidp_from_section(X509V3_CTX *ctx, |
| 571 |
STACK_OF(CONF_VALUE) *nval) |
| 572 |
{ |
| 573 |
int i, ret; |
| 574 |
CONF_VALUE *cnf; |
| 575 |
OSSL_AA_DIST_POINT *point = OSSL_AA_DIST_POINT_new(); |
| 576 |
|
| 577 |
if (point == NULL) |
| 578 |
goto err; |
| 579 |
for (i = 0; i < sk_CONF_VALUE_num(nval); i++) { |
| 580 |
cnf = sk_CONF_VALUE_value(nval, i); |
| 581 |
ret = set_dist_point_name(&point->distpoint, ctx, cnf); |
| 582 |
if (ret > 0) |
| 583 |
continue; |
| 584 |
if (ret < 0) |
| 585 |
goto err; |
| 586 |
if (strcmp(cnf->name, "reasons") == 0) { |
| 587 |
if (!set_reasons(&point->reasons, cnf->value)) |
| 588 |
goto err; |
| 589 |
} else if (strcmp(cnf->name, "indirectCRL") == 0) { |
| 590 |
if (!X509V3_get_value_bool(cnf, &point->indirectCRL)) |
| 591 |
goto err; |
| 592 |
} else if (strcmp(cnf->name, "containsUserAttributeCerts") == 0) { |
| 593 |
if (!X509V3_get_value_bool(cnf, &point->containsUserAttributeCerts)) |
| 594 |
goto err; |
| 595 |
} else if (strcmp(cnf->name, "containsAACerts") == 0) { |
| 596 |
if (!X509V3_get_value_bool(cnf, &point->containsAACerts)) |
| 597 |
goto err; |
| 598 |
} else if (strcmp(cnf->name, "containsSOAPublicKeyCerts") == 0) { |
| 599 |
if (!X509V3_get_value_bool(cnf, &point->containsSOAPublicKeyCerts)) |
| 600 |
goto err; |
| 601 |
} |
| 602 |
} |
| 603 |
|
| 604 |
return point; |
| 605 |
|
| 606 |
err: |
| 607 |
OSSL_AA_DIST_POINT_free(point); |
| 608 |
return NULL; |
| 609 |
} |
| 610 |
|
| 611 |
static void *v2i_aaidp(const X509V3_EXT_METHOD *method, |
| 612 |
X509V3_CTX *ctx, STACK_OF(CONF_VALUE) *nval) |
| 613 |
{ |
| 614 |
GENERAL_NAMES *gens = NULL; |
| 615 |
GENERAL_NAME *gen = NULL; |
| 616 |
CONF_VALUE *cnf; |
| 617 |
OSSL_AA_DIST_POINT *point = NULL; |
| 618 |
STACK_OF(CONF_VALUE) *dpsect; |
| 619 |
|
| 620 |
cnf = sk_CONF_VALUE_value(nval, 0); |
| 621 |
if (cnf == NULL) |
| 622 |
return NULL; |
| 623 |
if (cnf->value == NULL) { |
| 624 |
dpsect = X509V3_get_section(ctx, cnf->name); |
| 625 |
if (dpsect == NULL) |
| 626 |
goto err; |
| 627 |
point = aaidp_from_section(ctx, dpsect); |
| 628 |
X509V3_section_free(ctx, dpsect); |
| 629 |
if (point == NULL) |
| 630 |
goto err; |
| 631 |
} else { |
| 632 |
if ((gen = v2i_GENERAL_NAME(method, ctx, cnf)) == NULL) |
| 633 |
goto err; |
| 634 |
if ((gens = GENERAL_NAMES_new()) == NULL) { |
| 635 |
ERR_raise(ERR_LIB_X509V3, ERR_R_ASN1_LIB); |
| 636 |
goto err; |
| 637 |
} |
| 638 |
if (!sk_GENERAL_NAME_push(gens, gen)) { |
| 639 |
ERR_raise(ERR_LIB_X509V3, ERR_R_CRYPTO_LIB); |
| 640 |
goto err; |
| 641 |
} |
| 642 |
gen = NULL; |
| 643 |
if ((point = OSSL_AA_DIST_POINT_new()) == NULL) { |
| 644 |
ERR_raise(ERR_LIB_X509V3, ERR_R_ASN1_LIB); |
| 645 |
goto err; |
| 646 |
} |
| 647 |
if ((point->distpoint = DIST_POINT_NAME_new()) == NULL) { |
| 648 |
ERR_raise(ERR_LIB_X509V3, ERR_R_ASN1_LIB); |
| 649 |
goto err; |
| 650 |
} |
| 651 |
point->distpoint->name.fullname = gens; |
| 652 |
point->distpoint->type = 0; |
| 653 |
gens = NULL; |
| 654 |
} |
| 655 |
return point; |
| 656 |
|
| 657 |
err: |
| 658 |
OSSL_AA_DIST_POINT_free(point); |
| 659 |
GENERAL_NAME_free(gen); |
| 660 |
GENERAL_NAMES_free(gens); |
| 661 |
return NULL; |
| 662 |
} |
| 663 |
|
| 664 |
static int i2r_aaidp(const X509V3_EXT_METHOD *method, void *dp, BIO *out, |
| 665 |
int indent) |
| 666 |
{ |
| 667 |
OSSL_AA_DIST_POINT *pdp = dp; |
| 668 |
|
| 669 |
if (pdp->distpoint) |
| 670 |
if (print_distpoint(out, pdp->distpoint, indent) <= 0) |
| 671 |
return 0; |
| 672 |
if (pdp->reasons) |
| 673 |
if (print_reasons(out, "Reasons", pdp->reasons, indent) <= 0) |
| 674 |
return 0; |
| 675 |
if (pdp->indirectCRL) { |
| 676 |
if (BIO_printf(out, "%*sIndirect CRL: ", indent, "") <= 0) |
| 677 |
return 0; |
| 678 |
if (print_boolean(out, pdp->indirectCRL) <= 0) |
| 679 |
return 0; |
| 680 |
if (BIO_puts(out, "\n") <= 0) |
| 681 |
return 0; |
| 682 |
} |
| 683 |
if (pdp->containsUserAttributeCerts) { |
| 684 |
if (BIO_printf(out, "%*sContains User Attribute Certificates: ", indent, "") <= 0) |
| 685 |
return 0; |
| 686 |
if (print_boolean(out, pdp->containsUserAttributeCerts) <= 0) |
| 687 |
return 0; |
| 688 |
if (BIO_puts(out, "\n") <= 0) |
| 689 |
return 0; |
| 690 |
} |
| 691 |
if (pdp->containsAACerts) { |
| 692 |
if (BIO_printf(out, "%*sContains Attribute Authority (AA) Certificates: ", |
| 693 |
indent, "") |
| 694 |
<= 0) |
| 695 |
return 0; |
| 696 |
if (print_boolean(out, pdp->containsAACerts) <= 0) |
| 697 |
return 0; |
| 698 |
if (BIO_puts(out, "\n") <= 0) |
| 699 |
return 0; |
| 700 |
} |
| 701 |
if (pdp->containsSOAPublicKeyCerts) { |
| 702 |
if (BIO_printf(out, |
| 703 |
"%*sContains Source Of Authority (SOA) Public Key Certificates: ", |
| 704 |
indent, "") |
| 705 |
<= 0) |
| 706 |
return 0; |
| 707 |
if (print_boolean(out, pdp->containsSOAPublicKeyCerts) <= 0) |
| 708 |
return 0; |
| 709 |
if (BIO_puts(out, "\n") <= 0) |
| 710 |
return 0; |
| 711 |
} |
| 712 |
return 1; |
| 713 |
} |
| 714 |
|
| 715 |
const X509V3_EXT_METHOD ossl_v3_aa_issuing_dist_point = { |
| 716 |
NID_id_aa_issuing_distribution_point, 0, |
| 717 |
ASN1_ITEM_ref(OSSL_AA_DIST_POINT), |
| 718 |
0, 0, 0, 0, |
| 719 |
0, 0, |
| 720 |
0, |
| 721 |
v2i_aaidp, |
| 722 |
i2r_aaidp, 0, |
| 723 |
NULL |
| 724 |
}; |