version 1.11, 2022/11/11 17:07:39 |
version 1.12, 2023/03/06 14:32:06 |
|
|
char *outfile; |
char *outfile; |
int outformat; |
int outformat; |
int text; |
int text; |
} sess_id_config; |
} cfg; |
|
|
static const struct option sess_id_options[] = { |
static const struct option sess_id_options[] = { |
{ |
{ |
.name = "cert", |
.name = "cert", |
.desc = "Output certificate if present in session", |
.desc = "Output certificate if present in session", |
.type = OPTION_FLAG, |
.type = OPTION_FLAG, |
.opt.flag = &sess_id_config.cert, |
.opt.flag = &cfg.cert, |
}, |
}, |
{ |
{ |
.name = "context", |
.name = "context", |
.argname = "id", |
.argname = "id", |
.desc = "Set the session ID context for output", |
.desc = "Set the session ID context for output", |
.type = OPTION_ARG, |
.type = OPTION_ARG, |
.opt.arg = &sess_id_config.context, |
.opt.arg = &cfg.context, |
}, |
}, |
{ |
{ |
.name = "in", |
.name = "in", |
.argname = "file", |
.argname = "file", |
.desc = "Input file (default stdin)", |
.desc = "Input file (default stdin)", |
.type = OPTION_ARG, |
.type = OPTION_ARG, |
.opt.arg = &sess_id_config.infile, |
.opt.arg = &cfg.infile, |
}, |
}, |
{ |
{ |
.name = "inform", |
.name = "inform", |
.argname = "format", |
.argname = "format", |
.desc = "Input format (DER or PEM (default))", |
.desc = "Input format (DER or PEM (default))", |
.type = OPTION_ARG_FORMAT, |
.type = OPTION_ARG_FORMAT, |
.opt.value = &sess_id_config.informat, |
.opt.value = &cfg.informat, |
}, |
}, |
{ |
{ |
.name = "noout", |
.name = "noout", |
.desc = "Do not output the encoded session info", |
.desc = "Do not output the encoded session info", |
.type = OPTION_FLAG, |
.type = OPTION_FLAG, |
.opt.flag = &sess_id_config.noout, |
.opt.flag = &cfg.noout, |
}, |
}, |
{ |
{ |
.name = "out", |
.name = "out", |
.argname = "file", |
.argname = "file", |
.desc = "Output file (default stdout)", |
.desc = "Output file (default stdout)", |
.type = OPTION_ARG, |
.type = OPTION_ARG, |
.opt.arg = &sess_id_config.outfile, |
.opt.arg = &cfg.outfile, |
}, |
}, |
{ |
{ |
.name = "outform", |
.name = "outform", |
.argname = "format", |
.argname = "format", |
.desc = "Output format (DER or PEM (default))", |
.desc = "Output format (DER or PEM (default))", |
.type = OPTION_ARG_FORMAT, |
.type = OPTION_ARG_FORMAT, |
.opt.value = &sess_id_config.outformat, |
.opt.value = &cfg.outformat, |
}, |
}, |
{ |
{ |
.name = "text", |
.name = "text", |
.desc = "Print various public or private key components in" |
.desc = "Print various public or private key components in" |
" plain text", |
" plain text", |
.type = OPTION_FLAG, |
.type = OPTION_FLAG, |
.opt.flag = &sess_id_config.text, |
.opt.flag = &cfg.text, |
}, |
}, |
{ NULL } |
{ NULL } |
}; |
}; |
|
|
exit(1); |
exit(1); |
} |
} |
|
|
memset(&sess_id_config, 0, sizeof(sess_id_config)); |
memset(&cfg, 0, sizeof(cfg)); |
|
|
sess_id_config.informat = FORMAT_PEM; |
cfg.informat = FORMAT_PEM; |
sess_id_config.outformat = FORMAT_PEM; |
cfg.outformat = FORMAT_PEM; |
|
|
if (options_parse(argc, argv, sess_id_options, NULL, NULL) != 0) { |
if (options_parse(argc, argv, sess_id_options, NULL, NULL) != 0) { |
sess_id_usage(); |
sess_id_usage(); |
return (1); |
return (1); |
} |
} |
|
|
x = load_sess_id(sess_id_config.infile, sess_id_config.informat); |
x = load_sess_id(cfg.infile, cfg.informat); |
if (x == NULL) { |
if (x == NULL) { |
goto end; |
goto end; |
} |
} |
peer = SSL_SESSION_get0_peer(x); |
peer = SSL_SESSION_get0_peer(x); |
|
|
if (sess_id_config.context) { |
if (cfg.context) { |
size_t ctx_len = strlen(sess_id_config.context); |
size_t ctx_len = strlen(cfg.context); |
if (ctx_len > SSL_MAX_SID_CTX_LENGTH) { |
if (ctx_len > SSL_MAX_SID_CTX_LENGTH) { |
BIO_printf(bio_err, "Context too long\n"); |
BIO_printf(bio_err, "Context too long\n"); |
goto end; |
goto end; |
} |
} |
SSL_SESSION_set1_id_context(x, |
SSL_SESSION_set1_id_context(x, |
(unsigned char *)sess_id_config.context, ctx_len); |
(unsigned char *)cfg.context, ctx_len); |
} |
} |
|
|
if (!sess_id_config.noout || sess_id_config.text) { |
if (!cfg.noout || cfg.text) { |
out = BIO_new(BIO_s_file()); |
out = BIO_new(BIO_s_file()); |
if (out == NULL) { |
if (out == NULL) { |
ERR_print_errors(bio_err); |
ERR_print_errors(bio_err); |
goto end; |
goto end; |
} |
} |
if (sess_id_config.outfile == NULL) { |
if (cfg.outfile == NULL) { |
BIO_set_fp(out, stdout, BIO_NOCLOSE); |
BIO_set_fp(out, stdout, BIO_NOCLOSE); |
} else { |
} else { |
if (BIO_write_filename(out, sess_id_config.outfile) |
if (BIO_write_filename(out, cfg.outfile) |
<= 0) { |
<= 0) { |
perror(sess_id_config.outfile); |
perror(cfg.outfile); |
goto end; |
goto end; |
} |
} |
} |
} |
} |
} |
if (sess_id_config.text) { |
if (cfg.text) { |
SSL_SESSION_print(out, x); |
SSL_SESSION_print(out, x); |
|
|
if (sess_id_config.cert) { |
if (cfg.cert) { |
if (peer == NULL) |
if (peer == NULL) |
BIO_puts(out, "No certificate present\n"); |
BIO_puts(out, "No certificate present\n"); |
else |
else |
X509_print(out, peer); |
X509_print(out, peer); |
} |
} |
} |
} |
if (!sess_id_config.noout && !sess_id_config.cert) { |
if (!cfg.noout && !cfg.cert) { |
if (sess_id_config.outformat == FORMAT_ASN1) |
if (cfg.outformat == FORMAT_ASN1) |
i = i2d_SSL_SESSION_bio(out, x); |
i = i2d_SSL_SESSION_bio(out, x); |
else if (sess_id_config.outformat == FORMAT_PEM) |
else if (cfg.outformat == FORMAT_PEM) |
i = PEM_write_bio_SSL_SESSION(out, x); |
i = PEM_write_bio_SSL_SESSION(out, x); |
else { |
else { |
BIO_printf(bio_err, |
BIO_printf(bio_err, |
|
|
BIO_printf(bio_err, "unable to write SSL_SESSION\n"); |
BIO_printf(bio_err, "unable to write SSL_SESSION\n"); |
goto end; |
goto end; |
} |
} |
} else if (!sess_id_config.noout && (peer != NULL)) { |
} else if (!cfg.noout && (peer != NULL)) { |
/* just print the certificate */ |
/* just print the certificate */ |
if (sess_id_config.outformat == FORMAT_ASN1) |
if (cfg.outformat == FORMAT_ASN1) |
i = (int) i2d_X509_bio(out, peer); |
i = (int) i2d_X509_bio(out, peer); |
else if (sess_id_config.outformat == FORMAT_PEM) |
else if (cfg.outformat == FORMAT_PEM) |
i = PEM_write_bio_X509(out, peer); |
i = PEM_write_bio_X509(out, peer); |
else { |
else { |
BIO_printf(bio_err, |
BIO_printf(bio_err, |