diff options
Diffstat (limited to 'src/usr.bin/openssl/asn1pars.c')
| -rw-r--r-- | src/usr.bin/openssl/asn1pars.c | 94 |
1 files changed, 47 insertions, 47 deletions
diff --git a/src/usr.bin/openssl/asn1pars.c b/src/usr.bin/openssl/asn1pars.c index 6f7fa18512..5824b0ea14 100644 --- a/src/usr.bin/openssl/asn1pars.c +++ b/src/usr.bin/openssl/asn1pars.c | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | /* $OpenBSD: asn1pars.c,v 1.12 2022/11/11 17:07:38 joshua Exp $ */ | 1 | /* $OpenBSD: asn1pars.c,v 1.13 2023/03/06 14:32:05 tb Exp $ */ |
| 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) |
| 3 | * All rights reserved. | 3 | * All rights reserved. |
| 4 | * | 4 | * |
| @@ -86,14 +86,14 @@ static struct { | |||
| 86 | int offset; | 86 | int offset; |
| 87 | char *oidfile; | 87 | char *oidfile; |
| 88 | STACK_OF(OPENSSL_STRING) *osk; | 88 | STACK_OF(OPENSSL_STRING) *osk; |
| 89 | } asn1pars_config; | 89 | } cfg; |
| 90 | 90 | ||
| 91 | static int | 91 | static int |
| 92 | asn1pars_opt_dlimit(char *arg) | 92 | asn1pars_opt_dlimit(char *arg) |
| 93 | { | 93 | { |
| 94 | const char *errstr; | 94 | const char *errstr; |
| 95 | 95 | ||
| 96 | asn1pars_config.dump = strtonum(arg, 1, INT_MAX, &errstr); | 96 | cfg.dump = strtonum(arg, 1, INT_MAX, &errstr); |
| 97 | if (errstr) { | 97 | if (errstr) { |
| 98 | fprintf(stderr, "-dlimit must be from 1 to INT_MAX: %s\n", | 98 | fprintf(stderr, "-dlimit must be from 1 to INT_MAX: %s\n", |
| 99 | errstr); | 99 | errstr); |
| @@ -107,7 +107,7 @@ asn1pars_opt_length(char *arg) | |||
| 107 | { | 107 | { |
| 108 | const char *errstr; | 108 | const char *errstr; |
| 109 | 109 | ||
| 110 | asn1pars_config.length = strtonum(arg, 1, UINT_MAX, &errstr); | 110 | cfg.length = strtonum(arg, 1, UINT_MAX, &errstr); |
| 111 | if (errstr) { | 111 | if (errstr) { |
| 112 | fprintf(stderr, "-length must be from 1 to UINT_MAX: %s\n", | 112 | fprintf(stderr, "-length must be from 1 to UINT_MAX: %s\n", |
| 113 | errstr); | 113 | errstr); |
| @@ -119,7 +119,7 @@ asn1pars_opt_length(char *arg) | |||
| 119 | static int | 119 | static int |
| 120 | asn1pars_opt_strparse(char *arg) | 120 | asn1pars_opt_strparse(char *arg) |
| 121 | { | 121 | { |
| 122 | if (sk_OPENSSL_STRING_push(asn1pars_config.osk, arg) == 0) { | 122 | if (sk_OPENSSL_STRING_push(cfg.osk, arg) == 0) { |
| 123 | fprintf(stderr, "-strparse cannot add argument\n"); | 123 | fprintf(stderr, "-strparse cannot add argument\n"); |
| 124 | return (-1); | 124 | return (-1); |
| 125 | } | 125 | } |
| @@ -132,7 +132,7 @@ static const struct option asn1pars_options[] = { | |||
| 132 | .desc = "Dump unknown data in hex form", | 132 | .desc = "Dump unknown data in hex form", |
| 133 | .type = OPTION_VALUE, | 133 | .type = OPTION_VALUE, |
| 134 | .value = -1, | 134 | .value = -1, |
| 135 | .opt.value = &asn1pars_config.dump, | 135 | .opt.value = &cfg.dump, |
| 136 | }, | 136 | }, |
| 137 | { | 137 | { |
| 138 | .name = "dlimit", | 138 | .name = "dlimit", |
| @@ -146,34 +146,34 @@ static const struct option asn1pars_options[] = { | |||
| 146 | .argname = "file", | 146 | .argname = "file", |
| 147 | .desc = "File to generate ASN.1 structure from", | 147 | .desc = "File to generate ASN.1 structure from", |
| 148 | .type = OPTION_ARG, | 148 | .type = OPTION_ARG, |
| 149 | .opt.arg = &asn1pars_config.genconf, | 149 | .opt.arg = &cfg.genconf, |
| 150 | }, | 150 | }, |
| 151 | { | 151 | { |
| 152 | .name = "genstr", | 152 | .name = "genstr", |
| 153 | .argname = "string", | 153 | .argname = "string", |
| 154 | .desc = "String to generate ASN.1 structure from", | 154 | .desc = "String to generate ASN.1 structure from", |
| 155 | .type = OPTION_ARG, | 155 | .type = OPTION_ARG, |
| 156 | .opt.arg = &asn1pars_config.genstr, | 156 | .opt.arg = &cfg.genstr, |
| 157 | }, | 157 | }, |
| 158 | { | 158 | { |
| 159 | .name = "i", | 159 | .name = "i", |
| 160 | .desc = "Indent output according to depth of structures", | 160 | .desc = "Indent output according to depth of structures", |
| 161 | .type = OPTION_FLAG, | 161 | .type = OPTION_FLAG, |
| 162 | .opt.flag = &asn1pars_config.indent, | 162 | .opt.flag = &cfg.indent, |
| 163 | }, | 163 | }, |
| 164 | { | 164 | { |
| 165 | .name = "in", | 165 | .name = "in", |
| 166 | .argname = "file", | 166 | .argname = "file", |
| 167 | .desc = "The input file (default stdin)", | 167 | .desc = "The input file (default stdin)", |
| 168 | .type = OPTION_ARG, | 168 | .type = OPTION_ARG, |
| 169 | .opt.arg = &asn1pars_config.infile, | 169 | .opt.arg = &cfg.infile, |
| 170 | }, | 170 | }, |
| 171 | { | 171 | { |
| 172 | .name = "inform", | 172 | .name = "inform", |
| 173 | .argname = "fmt", | 173 | .argname = "fmt", |
| 174 | .desc = "Input format (DER, TXT or PEM (default))", | 174 | .desc = "Input format (DER, TXT or PEM (default))", |
| 175 | .type = OPTION_ARG_FORMAT, | 175 | .type = OPTION_ARG_FORMAT, |
| 176 | .opt.value = &asn1pars_config.informat, | 176 | .opt.value = &cfg.informat, |
| 177 | }, | 177 | }, |
| 178 | { | 178 | { |
| 179 | .name = "length", | 179 | .name = "length", |
| @@ -186,28 +186,28 @@ static const struct option asn1pars_options[] = { | |||
| 186 | .name = "noout", | 186 | .name = "noout", |
| 187 | .desc = "Do not produce any output", | 187 | .desc = "Do not produce any output", |
| 188 | .type = OPTION_FLAG, | 188 | .type = OPTION_FLAG, |
| 189 | .opt.flag = &asn1pars_config.noout, | 189 | .opt.flag = &cfg.noout, |
| 190 | }, | 190 | }, |
| 191 | { | 191 | { |
| 192 | .name = "offset", | 192 | .name = "offset", |
| 193 | .argname = "num", | 193 | .argname = "num", |
| 194 | .desc = "Offset to begin parsing", | 194 | .desc = "Offset to begin parsing", |
| 195 | .type = OPTION_ARG_INT, | 195 | .type = OPTION_ARG_INT, |
| 196 | .opt.value = &asn1pars_config.offset, | 196 | .opt.value = &cfg.offset, |
| 197 | }, | 197 | }, |
| 198 | { | 198 | { |
| 199 | .name = "oid", | 199 | .name = "oid", |
| 200 | .argname = "file", | 200 | .argname = "file", |
| 201 | .desc = "File containing additional object identifiers (OIDs)", | 201 | .desc = "File containing additional object identifiers (OIDs)", |
| 202 | .type = OPTION_ARG, | 202 | .type = OPTION_ARG, |
| 203 | .opt.arg = &asn1pars_config.oidfile, | 203 | .opt.arg = &cfg.oidfile, |
| 204 | }, | 204 | }, |
| 205 | { | 205 | { |
| 206 | .name = "out", | 206 | .name = "out", |
| 207 | .argname = "file", | 207 | .argname = "file", |
| 208 | .desc = "Output file in DER format", | 208 | .desc = "Output file in DER format", |
| 209 | .type = OPTION_ARG, | 209 | .type = OPTION_ARG, |
| 210 | .opt.arg = &asn1pars_config.derfile, | 210 | .opt.arg = &cfg.derfile, |
| 211 | }, | 211 | }, |
| 212 | { | 212 | { |
| 213 | .name = "strparse", | 213 | .name = "strparse", |
| @@ -252,10 +252,10 @@ asn1parse_main(int argc, char **argv) | |||
| 252 | exit(1); | 252 | exit(1); |
| 253 | } | 253 | } |
| 254 | 254 | ||
| 255 | memset(&asn1pars_config, 0, sizeof(asn1pars_config)); | 255 | memset(&cfg, 0, sizeof(cfg)); |
| 256 | 256 | ||
| 257 | asn1pars_config.informat = FORMAT_PEM; | 257 | cfg.informat = FORMAT_PEM; |
| 258 | if ((asn1pars_config.osk = sk_OPENSSL_STRING_new_null()) == NULL) { | 258 | if ((cfg.osk = sk_OPENSSL_STRING_new_null()) == NULL) { |
| 259 | BIO_printf(bio_err, "Memory allocation failure\n"); | 259 | BIO_printf(bio_err, "Memory allocation failure\n"); |
| 260 | goto end; | 260 | goto end; |
| 261 | } | 261 | } |
| @@ -273,28 +273,28 @@ asn1parse_main(int argc, char **argv) | |||
| 273 | } | 273 | } |
| 274 | BIO_set_fp(out, stdout, BIO_NOCLOSE | BIO_FP_TEXT); | 274 | BIO_set_fp(out, stdout, BIO_NOCLOSE | BIO_FP_TEXT); |
| 275 | 275 | ||
| 276 | if (asn1pars_config.oidfile != NULL) { | 276 | if (cfg.oidfile != NULL) { |
| 277 | if (BIO_read_filename(in, asn1pars_config.oidfile) <= 0) { | 277 | if (BIO_read_filename(in, cfg.oidfile) <= 0) { |
| 278 | BIO_printf(bio_err, "problems opening %s\n", | 278 | BIO_printf(bio_err, "problems opening %s\n", |
| 279 | asn1pars_config.oidfile); | 279 | cfg.oidfile); |
| 280 | ERR_print_errors(bio_err); | 280 | ERR_print_errors(bio_err); |
| 281 | goto end; | 281 | goto end; |
| 282 | } | 282 | } |
| 283 | OBJ_create_objects(in); | 283 | OBJ_create_objects(in); |
| 284 | } | 284 | } |
| 285 | if (asn1pars_config.infile == NULL) | 285 | if (cfg.infile == NULL) |
| 286 | BIO_set_fp(in, stdin, BIO_NOCLOSE); | 286 | BIO_set_fp(in, stdin, BIO_NOCLOSE); |
| 287 | else { | 287 | else { |
| 288 | if (BIO_read_filename(in, asn1pars_config.infile) <= 0) { | 288 | if (BIO_read_filename(in, cfg.infile) <= 0) { |
| 289 | perror(asn1pars_config.infile); | 289 | perror(cfg.infile); |
| 290 | goto end; | 290 | goto end; |
| 291 | } | 291 | } |
| 292 | } | 292 | } |
| 293 | 293 | ||
| 294 | if (asn1pars_config.derfile) { | 294 | if (cfg.derfile) { |
| 295 | if (!(derout = BIO_new_file(asn1pars_config.derfile, "wb"))) { | 295 | if (!(derout = BIO_new_file(cfg.derfile, "wb"))) { |
| 296 | BIO_printf(bio_err, "problems opening %s\n", | 296 | BIO_printf(bio_err, "problems opening %s\n", |
| 297 | asn1pars_config.derfile); | 297 | cfg.derfile); |
| 298 | ERR_print_errors(bio_err); | 298 | ERR_print_errors(bio_err); |
| 299 | goto end; | 299 | goto end; |
| 300 | } | 300 | } |
| @@ -304,16 +304,16 @@ asn1parse_main(int argc, char **argv) | |||
| 304 | if (!BUF_MEM_grow(buf, BUFSIZ * 8)) | 304 | if (!BUF_MEM_grow(buf, BUFSIZ * 8)) |
| 305 | goto end; /* Pre-allocate :-) */ | 305 | goto end; /* Pre-allocate :-) */ |
| 306 | 306 | ||
| 307 | if (asn1pars_config.genstr || asn1pars_config.genconf) { | 307 | if (cfg.genstr || cfg.genconf) { |
| 308 | num = do_generate(bio_err, asn1pars_config.genstr, | 308 | num = do_generate(bio_err, cfg.genstr, |
| 309 | asn1pars_config.genconf, buf); | 309 | cfg.genconf, buf); |
| 310 | if (num < 0) { | 310 | if (num < 0) { |
| 311 | ERR_print_errors(bio_err); | 311 | ERR_print_errors(bio_err); |
| 312 | goto end; | 312 | goto end; |
| 313 | } | 313 | } |
| 314 | } else { | 314 | } else { |
| 315 | 315 | ||
| 316 | if (asn1pars_config.informat == FORMAT_PEM) { | 316 | if (cfg.informat == FORMAT_PEM) { |
| 317 | BIO *tmp; | 317 | BIO *tmp; |
| 318 | 318 | ||
| 319 | if ((b64 = BIO_new(BIO_f_base64())) == NULL) | 319 | if ((b64 = BIO_new(BIO_f_base64())) == NULL) |
| @@ -337,20 +337,20 @@ asn1parse_main(int argc, char **argv) | |||
| 337 | 337 | ||
| 338 | /* If any structs to parse go through in sequence */ | 338 | /* If any structs to parse go through in sequence */ |
| 339 | 339 | ||
| 340 | if (sk_OPENSSL_STRING_num(asn1pars_config.osk)) { | 340 | if (sk_OPENSSL_STRING_num(cfg.osk)) { |
| 341 | tmpbuf = (unsigned char *) str; | 341 | tmpbuf = (unsigned char *) str; |
| 342 | tmplen = num; | 342 | tmplen = num; |
| 343 | for (i = 0; i < sk_OPENSSL_STRING_num(asn1pars_config.osk); | 343 | for (i = 0; i < sk_OPENSSL_STRING_num(cfg.osk); |
| 344 | i++) { | 344 | i++) { |
| 345 | ASN1_TYPE *atmp; | 345 | ASN1_TYPE *atmp; |
| 346 | int typ; | 346 | int typ; |
| 347 | j = strtonum( | 347 | j = strtonum( |
| 348 | sk_OPENSSL_STRING_value(asn1pars_config.osk, i), | 348 | sk_OPENSSL_STRING_value(cfg.osk, i), |
| 349 | 1, INT_MAX, &errstr); | 349 | 1, INT_MAX, &errstr); |
| 350 | if (errstr) { | 350 | if (errstr) { |
| 351 | BIO_printf(bio_err, | 351 | BIO_printf(bio_err, |
| 352 | "'%s' is an invalid number: %s\n", | 352 | "'%s' is an invalid number: %s\n", |
| 353 | sk_OPENSSL_STRING_value(asn1pars_config.osk, | 353 | sk_OPENSSL_STRING_value(cfg.osk, |
| 354 | i), errstr); | 354 | i), errstr); |
| 355 | continue; | 355 | continue; |
| 356 | } | 356 | } |
| @@ -380,28 +380,28 @@ asn1parse_main(int argc, char **argv) | |||
| 380 | str = (char *) tmpbuf; | 380 | str = (char *) tmpbuf; |
| 381 | num = tmplen; | 381 | num = tmplen; |
| 382 | } | 382 | } |
| 383 | if (asn1pars_config.offset >= num) { | 383 | if (cfg.offset >= num) { |
| 384 | BIO_printf(bio_err, "Error: offset too large\n"); | 384 | BIO_printf(bio_err, "Error: offset too large\n"); |
| 385 | goto end; | 385 | goto end; |
| 386 | } | 386 | } |
| 387 | num -= asn1pars_config.offset; | 387 | num -= cfg.offset; |
| 388 | 388 | ||
| 389 | if ((asn1pars_config.length == 0) || | 389 | if ((cfg.length == 0) || |
| 390 | ((long)asn1pars_config.length > num)) | 390 | ((long)cfg.length > num)) |
| 391 | asn1pars_config.length = (unsigned int) num; | 391 | cfg.length = (unsigned int) num; |
| 392 | if (derout) { | 392 | if (derout) { |
| 393 | if (BIO_write(derout, str + asn1pars_config.offset, | 393 | if (BIO_write(derout, str + cfg.offset, |
| 394 | asn1pars_config.length) != (int)asn1pars_config.length) { | 394 | cfg.length) != (int)cfg.length) { |
| 395 | BIO_printf(bio_err, "Error writing output\n"); | 395 | BIO_printf(bio_err, "Error writing output\n"); |
| 396 | ERR_print_errors(bio_err); | 396 | ERR_print_errors(bio_err); |
| 397 | goto end; | 397 | goto end; |
| 398 | } | 398 | } |
| 399 | } | 399 | } |
| 400 | if (!asn1pars_config.noout && | 400 | if (!cfg.noout && |
| 401 | !ASN1_parse_dump(out, | 401 | !ASN1_parse_dump(out, |
| 402 | (unsigned char *)&(str[asn1pars_config.offset]), | 402 | (unsigned char *)&(str[cfg.offset]), |
| 403 | asn1pars_config.length, asn1pars_config.indent, | 403 | cfg.length, cfg.indent, |
| 404 | asn1pars_config.dump)) { | 404 | cfg.dump)) { |
| 405 | ERR_print_errors(bio_err); | 405 | ERR_print_errors(bio_err); |
| 406 | goto end; | 406 | goto end; |
| 407 | } | 407 | } |
| @@ -415,7 +415,7 @@ asn1parse_main(int argc, char **argv) | |||
| 415 | ERR_print_errors(bio_err); | 415 | ERR_print_errors(bio_err); |
| 416 | BUF_MEM_free(buf); | 416 | BUF_MEM_free(buf); |
| 417 | ASN1_TYPE_free(at); | 417 | ASN1_TYPE_free(at); |
| 418 | sk_OPENSSL_STRING_free(asn1pars_config.osk); | 418 | sk_OPENSSL_STRING_free(cfg.osk); |
| 419 | OBJ_cleanup(); | 419 | OBJ_cleanup(); |
| 420 | 420 | ||
| 421 | return (ret); | 421 | return (ret); |
