summaryrefslogtreecommitdiffstats
path: root/apps/apps.c
diff options
context:
space:
mode:
authorBen Laurie <ben@openssl.org>2011-11-13 21:55:42 +0000
committerBen Laurie <ben@openssl.org>2011-11-13 21:55:42 +0000
commit68b33cc5c7aa1bb98e95bfb4b61c34192a7a50e3 (patch)
tree8c4298a1cc0487b3223a06764fe5f338f9691ad8 /apps/apps.c
parent4c02cf8ecc4b4cedeb6b6c11185f5d3e49c3cd4a (diff)
Add Next Protocol Negotiation.
Diffstat (limited to 'apps/apps.c')
-rw-r--r--apps/apps.c44
1 files changed, 44 insertions, 0 deletions
diff --git a/apps/apps.c b/apps/apps.c
index feb7ed46e6..b346558d2c 100644
--- a/apps/apps.c
+++ b/apps/apps.c
@@ -2693,6 +2693,50 @@ void jpake_server_auth(BIO *out, BIO *conn, const char *secret)
#endif
+#if !defined(OPENSSL_NO_TLSEXT) && !defined(OPENSSL_NO_NEXTPROTONEG)
+/* next_protos_parse parses a comma separated list of strings into a string
+ * in a format suitable for passing to SSL_CTX_set_next_protos_advertised.
+ * outlen: (output) set to the length of the resulting buffer on success.
+ * err: (maybe NULL) on failure, an error message line is written to this BIO.
+ * in: a NUL termianted string like "abc,def,ghi"
+ *
+ * returns: a malloced buffer or NULL on failure.
+ */
+unsigned char *next_protos_parse(unsigned short *outlen, const char *in)
+ {
+ size_t len;
+ unsigned char *out;
+ size_t i, start = 0;
+
+ len = strlen(in);
+ if (len >= 65535)
+ return NULL;
+
+ out = OPENSSL_malloc(strlen(in) + 1);
+ if (!out)
+ return NULL;
+
+ for (i = 0; i <= len; ++i)
+ {
+ if (i == len || in[i] == ',')
+ {
+ if (i - start > 255)
+ {
+ OPENSSL_free(out);
+ return NULL;
+ }
+ out[start] = i - start;
+ start = i + 1;
+ }
+ else
+ out[i+1] = in[i];
+ }
+
+ *outlen = len + 1;
+ return out;
+ }
+#endif /* !OPENSSL_NO_TLSEXT && !OPENSSL_NO_NEXTPROTONEG */
+
/*
* Platform-specific sections
*/