Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ALPN values are not limited to ASCII #91763

Open
msoxzw opened this issue Apr 20, 2022 · 1 comment
Open

ALPN values are not limited to ASCII #91763

msoxzw opened this issue Apr 20, 2022 · 1 comment
Labels
expert-SSL type-bug An unexpected behavior, bug, or error

Comments

@msoxzw
Copy link
Contributor

msoxzw commented Apr 20, 2022

According to ALPN Identification Sequence, Python should accordingly not confine ALPN values to ASCII strings in

cpython/Lib/ssl.py

Lines 565 to 575 in 1c8b3b5

def set_alpn_protocols(self, alpn_protocols):
protos = bytearray()
for protocol in alpn_protocols:
b = bytes(protocol, 'ascii')
if len(b) == 0 or len(b) > 255:
raise SSLError('ALPN protocols must be 1 to 255 in length')
protos.append(len(b))
protos.extend(b)
self._set_alpn_protocols(protos)
and

cpython/Modules/_ssl.c

Lines 2064 to 2081 in 1c8b3b5

/*[clinic input]
_ssl._SSLSocket.selected_alpn_protocol
[clinic start generated code]*/
static PyObject *
_ssl__SSLSocket_selected_alpn_protocol_impl(PySSLSocket *self)
/*[clinic end generated code: output=ec33688b303d250f input=442de30e35bc2913]*/
{
const unsigned char *out;
unsigned int outlen;
SSL_get0_alpn_selected(self->ssl, &out, &outlen);
if (out == NULL)
Py_RETURN_NONE;
return PyUnicode_FromStringAndSize((char *)out, outlen);
}

The OpenJDK proposed to use "latin-1" encoding instead of ASCII. However, @jlaine views this workaround as a hack and suggests a more agreeable and maintainable solution aiortc/aioquic#275 (comment) .

Therefore, which is the more ideal solution, or another better fix?

@msoxzw msoxzw added the type-bug An unexpected behavior, bug, or error label Apr 20, 2022
@ronaldoussoren
Copy link
Contributor

ronaldoussoren commented May 3, 2022

According to RFC7301 the alpn identifier is a sequence of octets without a specified encoding. Most registrations are currently ASCII strings, except for some GREASE values.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
expert-SSL type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

2 participants