From 69796297c812640415c6cea074ea61afc899cbaa Mon Sep 17 00:00:00 2001 From: "djm@openbsd.org" Date: Fri, 5 Jun 2020 03:24:36 +0000 Subject: upstream: make sshbuf_dump() args const OpenBSD-Commit-ID: b4a5accae750875d665b862504169769bcf663bd --- sshbuf-misc.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'sshbuf-misc.c') diff --git a/sshbuf-misc.c b/sshbuf-misc.c index 9b5aa208c..86e5fa34f 100644 --- a/sshbuf-misc.c +++ b/sshbuf-misc.c @@ -1,4 +1,4 @@ -/* $OpenBSD: sshbuf-misc.c,v 1.14 2020/02/26 13:40:09 jsg Exp $ */ +/* $OpenBSD: sshbuf-misc.c,v 1.15 2020/06/05 03:24:36 djm Exp $ */ /* * Copyright (c) 2011 Damien Miller * @@ -63,7 +63,7 @@ sshbuf_dump_data(const void *s, size_t len, FILE *f) } void -sshbuf_dump(struct sshbuf *buf, FILE *f) +sshbuf_dump(const struct sshbuf *buf, FILE *f) { fprintf(f, "buffer %p len = %zu\n", buf, sshbuf_len(buf)); sshbuf_dump_data(sshbuf_ptr(buf), sshbuf_len(buf), f); -- cgit v1.2.3 From 12848191f8fe725af4485d3600e0842d92f8637f Mon Sep 17 00:00:00 2001 From: "djm@openbsd.org" Date: Mon, 22 Jun 2020 05:54:10 +0000 Subject: upstream: support for RFC4648 base64url encoding; ok markus OpenBSD-Commit-ID: 0ef22c55e772dda05c112c88412c0797fec66eb4 --- sshbuf-misc.c | 45 ++++++++++++++++++++++++++++++++++++++++++++- sshbuf.h | 4 +++- 2 files changed, 47 insertions(+), 2 deletions(-) (limited to 'sshbuf-misc.c') diff --git a/sshbuf-misc.c b/sshbuf-misc.c index 86e5fa34f..afaab8d61 100644 --- a/sshbuf-misc.c +++ b/sshbuf-misc.c @@ -1,4 +1,4 @@ -/* $OpenBSD: sshbuf-misc.c,v 1.15 2020/06/05 03:24:36 djm Exp $ */ +/* $OpenBSD: sshbuf-misc.c,v 1.16 2020/06/22 05:54:10 djm Exp $ */ /* * Copyright (c) 2011 Damien Miller * @@ -167,6 +167,49 @@ sshbuf_b64tod(struct sshbuf *buf, const char *b64) return 0; } +int +sshbuf_dtourlb64(const struct sshbuf *d, struct sshbuf *b64, int wrap) +{ + int r = SSH_ERR_INTERNAL_ERROR; + u_char *p; + struct sshbuf *b = NULL; + size_t i, l; + + if ((b = sshbuf_new()) == NULL) + return SSH_ERR_ALLOC_FAIL; + /* Encode using regular base64; we'll transform it once done */ + if ((r = sshbuf_dtob64(d, b, wrap)) != 0) + goto out; + /* remove padding from end of encoded string*/ + for (;;) { + l = sshbuf_len(b); + if (l <= 1 || sshbuf_ptr(b) == NULL) { + r = SSH_ERR_INTERNAL_ERROR; + goto out; + } + if (sshbuf_ptr(b)[l - 1] != '=') + break; + if ((r = sshbuf_consume_end(b, 1)) != 0) + goto out; + } + /* Replace characters with rfc4648 equivalents */ + l = sshbuf_len(b); + if ((p = sshbuf_mutable_ptr(b)) == NULL) { + r = SSH_ERR_INTERNAL_ERROR; + goto out; + } + for (i = 0; i < l; i++) { + if (p[i] == '+') + p[i] = '-'; + else if (p[i] == '/') + p[i] = '_'; + } + r = sshbuf_putb(b64, b); + out: + sshbuf_free(b); + return r; +} + char * sshbuf_dup_string(struct sshbuf *buf) { diff --git a/sshbuf.h b/sshbuf.h index ec7514eb3..2ad0e61be 100644 --- a/sshbuf.h +++ b/sshbuf.h @@ -1,4 +1,4 @@ -/* $OpenBSD: sshbuf.h,v 1.22 2020/06/05 03:24:36 djm Exp $ */ +/* $OpenBSD: sshbuf.h,v 1.23 2020/06/22 05:54:10 djm Exp $ */ /* * Copyright (c) 2011 Damien Miller * @@ -253,6 +253,8 @@ char *sshbuf_dtob16(struct sshbuf *buf); /* Encode the contents of the buffer as base64 */ char *sshbuf_dtob64_string(const struct sshbuf *buf, int wrap); int sshbuf_dtob64(const struct sshbuf *d, struct sshbuf *b64, int wrap); +/* RFC4648 "base64url" encoding variant */ +int sshbuf_dtourlb64(const struct sshbuf *d, struct sshbuf *b64, int wrap); /* Decode base64 data and append it to the buffer */ int sshbuf_b64tod(struct sshbuf *buf, const char *b64); -- cgit v1.2.3