diff options
Diffstat (limited to 'src/usr.bin')
| -rw-r--r-- | src/usr.bin/openssl/asn1pars.c | 26 | ||||
| -rw-r--r-- | src/usr.bin/openssl/openssl.1 | 5 | ||||
| -rw-r--r-- | src/usr.bin/openssl/s_client.c | 61 |
3 files changed, 75 insertions, 17 deletions
diff --git a/src/usr.bin/openssl/asn1pars.c b/src/usr.bin/openssl/asn1pars.c index 52991c392e..7ce5ca34f2 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.18 2025/11/27 08:22:32 tb Exp $ */ | 1 | /* $OpenBSD: asn1pars.c,v 1.20 2026/01/31 09:01:09 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 | * |
| @@ -237,12 +237,10 @@ int | |||
| 237 | asn1parse_main(int argc, char **argv) | 237 | asn1parse_main(int argc, char **argv) |
| 238 | { | 238 | { |
| 239 | int i, j, ret = 1; | 239 | int i, j, ret = 1; |
| 240 | long num, tmplen; | 240 | long num; |
| 241 | BIO *in = NULL, *out = NULL, *b64 = NULL, *derout = NULL; | 241 | BIO *in = NULL, *out = NULL, *b64 = NULL, *derout = NULL; |
| 242 | char *str = NULL; | ||
| 243 | const char *errstr = NULL; | 242 | const char *errstr = NULL; |
| 244 | const unsigned char *tmpbuf; | 243 | const unsigned char *str; |
| 245 | const unsigned char *ctmpbuf; | ||
| 246 | BUF_MEM *buf = NULL; | 244 | BUF_MEM *buf = NULL; |
| 247 | ASN1_TYPE *at = NULL; | 245 | ASN1_TYPE *at = NULL; |
| 248 | 246 | ||
| @@ -330,13 +328,15 @@ asn1parse_main(int argc, char **argv) | |||
| 330 | num += i; | 328 | num += i; |
| 331 | } | 329 | } |
| 332 | } | 330 | } |
| 333 | str = buf->data; | 331 | str = (const unsigned char *)buf->data; |
| 334 | 332 | ||
| 335 | /* If any structs to parse go through in sequence */ | 333 | /* If any structs to parse go through in sequence */ |
| 336 | 334 | ||
| 337 | if (sk_OPENSSL_STRING_num(cfg.osk) > 0) { | 335 | if (sk_OPENSSL_STRING_num(cfg.osk) > 0) { |
| 338 | tmpbuf = (unsigned char *) str; | 336 | const unsigned char *p; |
| 339 | tmplen = num; | 337 | const unsigned char *tmpbuf = str; |
| 338 | long tmplen = num; | ||
| 339 | |||
| 340 | for (i = 0; i < sk_OPENSSL_STRING_num(cfg.osk); i++) { | 340 | for (i = 0; i < sk_OPENSSL_STRING_num(cfg.osk); i++) { |
| 341 | ASN1_TYPE *atmp; | 341 | ASN1_TYPE *atmp; |
| 342 | int typ; | 342 | int typ; |
| @@ -351,8 +351,8 @@ asn1parse_main(int argc, char **argv) | |||
| 351 | tmpbuf += j; | 351 | tmpbuf += j; |
| 352 | tmplen -= j; | 352 | tmplen -= j; |
| 353 | atmp = at; | 353 | atmp = at; |
| 354 | ctmpbuf = tmpbuf; | 354 | p = tmpbuf; |
| 355 | at = d2i_ASN1_TYPE(NULL, &ctmpbuf, tmplen); | 355 | at = d2i_ASN1_TYPE(NULL, &p, tmplen); |
| 356 | ASN1_TYPE_free(atmp); | 356 | ASN1_TYPE_free(atmp); |
| 357 | if (!at) { | 357 | if (!at) { |
| 358 | BIO_printf(bio_err, "Error parsing structure\n"); | 358 | BIO_printf(bio_err, "Error parsing structure\n"); |
| @@ -371,7 +371,7 @@ asn1parse_main(int argc, char **argv) | |||
| 371 | tmpbuf = ASN1_STRING_get0_data(at->value.asn1_string); | 371 | tmpbuf = ASN1_STRING_get0_data(at->value.asn1_string); |
| 372 | tmplen = ASN1_STRING_length(at->value.asn1_string); | 372 | tmplen = ASN1_STRING_length(at->value.asn1_string); |
| 373 | } | 373 | } |
| 374 | str = (char *) tmpbuf; | 374 | str = tmpbuf; |
| 375 | num = tmplen; | 375 | num = tmplen; |
| 376 | } | 376 | } |
| 377 | if (cfg.offset >= num) { | 377 | if (cfg.offset >= num) { |
| @@ -390,8 +390,8 @@ asn1parse_main(int argc, char **argv) | |||
| 390 | goto end; | 390 | goto end; |
| 391 | } | 391 | } |
| 392 | } | 392 | } |
| 393 | if (!cfg.noout && !ASN1_parse_dump(out, | 393 | if (!cfg.noout && !ASN1_parse_dump(out, &str[cfg.offset], cfg.length, |
| 394 | (unsigned char *)&str[cfg.offset], cfg.length, cfg.indent, cfg.dump)) { | 394 | cfg.indent, cfg.dump)) { |
| 395 | ERR_print_errors(bio_err); | 395 | ERR_print_errors(bio_err); |
| 396 | goto end; | 396 | goto end; |
| 397 | } | 397 | } |
diff --git a/src/usr.bin/openssl/openssl.1 b/src/usr.bin/openssl/openssl.1 index f3e0be15ed..b9eba1a1de 100644 --- a/src/usr.bin/openssl/openssl.1 +++ b/src/usr.bin/openssl/openssl.1 | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | .\" $OpenBSD: openssl.1,v 1.168 2025/12/20 07:02:37 tb Exp $ | 1 | .\" $OpenBSD: openssl.1,v 1.169 2026/02/01 08:45:31 martijn Exp $ |
| 2 | .\" ==================================================================== | 2 | .\" ==================================================================== |
| 3 | .\" Copyright (c) 1998-2002 The OpenSSL Project. All rights reserved. | 3 | .\" Copyright (c) 1998-2002 The OpenSSL Project. All rights reserved. |
| 4 | .\" | 4 | .\" |
| @@ -110,7 +110,7 @@ | |||
| 110 | .\" copied and put under another distribution licence | 110 | .\" copied and put under another distribution licence |
| 111 | .\" [including the GNU Public Licence.] | 111 | .\" [including the GNU Public Licence.] |
| 112 | .\" | 112 | .\" |
| 113 | .Dd $Mdocdate: December 20 2025 $ | 113 | .Dd $Mdocdate: February 1 2026 $ |
| 114 | .Dt OPENSSL 1 | 114 | .Dt OPENSSL 1 |
| 115 | .Os | 115 | .Os |
| 116 | .Sh NAME | 116 | .Sh NAME |
| @@ -4416,6 +4416,7 @@ is a keyword for the intended protocol. | |||
| 4416 | Currently, the supported keywords are | 4416 | Currently, the supported keywords are |
| 4417 | .Qq ftp , | 4417 | .Qq ftp , |
| 4418 | .Qq imap , | 4418 | .Qq imap , |
| 4419 | .Qq sieve , | ||
| 4419 | .Qq smtp , | 4420 | .Qq smtp , |
| 4420 | .Qq pop3 , | 4421 | .Qq pop3 , |
| 4421 | and | 4422 | and |
diff --git a/src/usr.bin/openssl/s_client.c b/src/usr.bin/openssl/s_client.c index 84718c19fd..2b05facc17 100644 --- a/src/usr.bin/openssl/s_client.c +++ b/src/usr.bin/openssl/s_client.c | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | /* $OpenBSD: s_client.c,v 1.67 2025/01/02 16:07:41 tb Exp $ */ | 1 | /* $OpenBSD: s_client.c,v 1.68 2026/02/01 08:45:31 martijn 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 | * |
| @@ -174,6 +174,7 @@ enum { | |||
| 174 | PROTO_LMTP, | 174 | PROTO_LMTP, |
| 175 | PROTO_POP3, | 175 | PROTO_POP3, |
| 176 | PROTO_IMAP, | 176 | PROTO_IMAP, |
| 177 | PROTO_SIEVE, | ||
| 177 | PROTO_FTP, | 178 | PROTO_FTP, |
| 178 | PROTO_XMPP, | 179 | PROTO_XMPP, |
| 179 | }; | 180 | }; |
| @@ -335,6 +336,8 @@ s_client_opt_starttls(char *arg) | |||
| 335 | cfg.starttls_proto = PROTO_POP3; | 336 | cfg.starttls_proto = PROTO_POP3; |
| 336 | else if (strcmp(arg, "imap") == 0) | 337 | else if (strcmp(arg, "imap") == 0) |
| 337 | cfg.starttls_proto = PROTO_IMAP; | 338 | cfg.starttls_proto = PROTO_IMAP; |
| 339 | else if (strcmp(arg, "sieve") == 0) | ||
| 340 | cfg.starttls_proto = PROTO_SIEVE; | ||
| 338 | else if (strcmp(arg, "ftp") == 0) | 341 | else if (strcmp(arg, "ftp") == 0) |
| 339 | cfg.starttls_proto = PROTO_FTP; | 342 | cfg.starttls_proto = PROTO_FTP; |
| 340 | else if (strcmp(arg, "xmpp") == 0) | 343 | else if (strcmp(arg, "xmpp") == 0) |
| @@ -729,7 +732,8 @@ static const struct option s_client_options[] = { | |||
| 729 | .name = "starttls", | 732 | .name = "starttls", |
| 730 | .argname = "protocol", | 733 | .argname = "protocol", |
| 731 | .desc = "Use the STARTTLS command before starting TLS,\n" | 734 | .desc = "Use the STARTTLS command before starting TLS,\n" |
| 732 | "smtp, lmtp, pop3, imap, ftp and xmpp are supported.", | 735 | "smtp, lmtp, pop3, imap, sieve, ftp and xmpp " |
| 736 | "are supported.", | ||
| 733 | .type = OPTION_ARG_FUNC, | 737 | .type = OPTION_ARG_FUNC, |
| 734 | .opt.argfunc = s_client_opt_starttls, | 738 | .opt.argfunc = s_client_opt_starttls, |
| 735 | }, | 739 | }, |
| @@ -834,6 +838,28 @@ sc_usage(void) | |||
| 834 | fprintf(stderr, "\n"); | 838 | fprintf(stderr, "\n"); |
| 835 | } | 839 | } |
| 836 | 840 | ||
| 841 | static int | ||
| 842 | s_client_sieve_response_ok(const char *resp, int resplen) | ||
| 843 | { | ||
| 844 | /* All lines need to be CRLF terminated */ | ||
| 845 | if (resplen <= 2) { | ||
| 846 | BIO_printf(bio_err, "Failed to get full server line\n"); | ||
| 847 | return 0; | ||
| 848 | } | ||
| 849 | if (resplen >= 4 && strncasecmp(resp, "OK", 2) == 0 && | ||
| 850 | (resp[2] == ' ' || resp[2] == '\r')) | ||
| 851 | return 1; | ||
| 852 | if (resplen >= 4 && strncasecmp(resp, "NO", 2) == 0 && | ||
| 853 | (resp[2] == ' ' || resp[2] == '\r')) | ||
| 854 | BIO_printf(bio_err, "Server rejected our connection\n"); | ||
| 855 | else if (resplen >= 5 && strncasecmp(resp, "BYE", 3) == 0 && | ||
| 856 | (resp[3] == ' ' || resp[3] == '\r')) | ||
| 857 | BIO_printf(bio_err, "Server disconnected our connection\n"); | ||
| 858 | else | ||
| 859 | BIO_printf(bio_err, "Server sent invalid response\n"); | ||
| 860 | return 0; | ||
| 861 | } | ||
| 862 | |||
| 837 | int | 863 | int |
| 838 | s_client_main(int argc, char **argv) | 864 | s_client_main(int argc, char **argv) |
| 839 | { | 865 | { |
| @@ -1220,6 +1246,37 @@ s_client_main(int argc, char **argv) | |||
| 1220 | " try anyway...\n"); | 1246 | " try anyway...\n"); |
| 1221 | BIO_printf(sbio, ". STARTTLS\r\n"); | 1247 | BIO_printf(sbio, ". STARTTLS\r\n"); |
| 1222 | BIO_read(sbio, sbuf, BUFSIZZ); | 1248 | BIO_read(sbio, sbuf, BUFSIZZ); |
| 1249 | } else if (cfg.starttls_proto == PROTO_SIEVE) { | ||
| 1250 | int foundit = 0; | ||
| 1251 | BIO *fbio; | ||
| 1252 | |||
| 1253 | if ((fbio = BIO_new(BIO_f_buffer()))== NULL) { | ||
| 1254 | BIO_printf(bio_err, "Failed to create BIO\n"); | ||
| 1255 | goto end; | ||
| 1256 | } | ||
| 1257 | BIO_push(fbio, sbio); | ||
| 1258 | /* wait for multi-line CAPABILITY response */ | ||
| 1259 | while (1) { | ||
| 1260 | mbuf_len = BIO_gets(fbio, mbuf, BUFSIZZ); | ||
| 1261 | if (mbuf_len > 2 && mbuf[0] == '"') { | ||
| 1262 | if (strcasecmp(mbuf, "\"STARTTLS\"\r\n") == 0) | ||
| 1263 | foundit = 1; | ||
| 1264 | } else if (s_client_sieve_response_ok(mbuf, mbuf_len)) | ||
| 1265 | break; | ||
| 1266 | else | ||
| 1267 | goto end; | ||
| 1268 | } | ||
| 1269 | if (!foundit) | ||
| 1270 | BIO_printf(bio_err, | ||
| 1271 | "didn't find STARTTLS in server response," | ||
| 1272 | " try anyway...\n"); | ||
| 1273 | BIO_printf(sbio, "STARTTLS\r\n"); | ||
| 1274 | mbuf_len = BIO_gets(fbio, mbuf, BUFSIZZ); | ||
| 1275 | (void) BIO_flush(fbio); | ||
| 1276 | BIO_pop(fbio); | ||
| 1277 | BIO_free(fbio); | ||
| 1278 | if (!s_client_sieve_response_ok(mbuf, mbuf_len)) | ||
| 1279 | goto end; | ||
| 1223 | } else if (cfg.starttls_proto == PROTO_FTP) { | 1280 | } else if (cfg.starttls_proto == PROTO_FTP) { |
| 1224 | BIO *fbio = BIO_new(BIO_f_buffer()); | 1281 | BIO *fbio = BIO_new(BIO_f_buffer()); |
| 1225 | BIO_push(fbio, sbio); | 1282 | BIO_push(fbio, sbio); |
