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

idna is dissatisfied with underscores #17

Closed
bpicolo opened this issue Aug 3, 2015 · 4 comments
Closed

idna is dissatisfied with underscores #17

bpicolo opened this issue Aug 3, 2015 · 4 comments

Comments

@bpicolo
Copy link

bpicolo commented Aug 3, 2015

import idna
 idna.encode('ex_ample.example.org')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/nail/home/benp/pg/utils/bravado-promised/virtualenv_run/local/lib/python2.7/site-packages/idna/core.py", line 354, in encode
    result.append(alabel(label))
  File "/nail/home/benp/pg/utils/bravado-promised/virtualenv_run/local/lib/python2.7/site-packages/idna/core.py", line 275, in alabel
    check_label(label)
  File "/nail/home/benp/pg/utils/bravado-promised/virtualenv_run/local/lib/python2.7/site-packages/idna/core.py", line 252, in check_label
    raise InvalidCodepoint('Codepoint {0} at position {1} of {2} not allowed'.format(_unot(cp_value), pos+1, repr(label)))
idna.core.InvalidCodepoint: Codepoint U+005F at position 3 of u'ex_ample' not allowed

Seems like underscores in hostname should be perfectly allowed? Can't find any RFC that suggests otherwise (and browsers seem happy with URLs in hostname).

Perhaps this is more of a twisted bug where it shouldn't pass this sort of url to idna ever, not sure. This is just an issue I hit as an end user

@bpicolo bpicolo changed the title idna is dissatisfied with underscores? idna is dissatisfied with underscores Aug 3, 2015
@kjd
Copy link
Owner

kjd commented Aug 3, 2015

Underscores are not legal in IDNs (or, for that matter, ASCII domain names that follow hostname rules which most domain registries apply). There are certain circumstances where they are legal but not as it pertains to IDNs.

Specifically, see http://www.iana.org/assignments/idna-tables-6.3.0/idna-tables-6.3.0.xhtml under "IDNA Derived Properties", U+003A-U+0060 are DISALLOWED. See also https://tools.ietf.org/html/rfc5890#section-2.3.1 for further discussion.

There may be an idea to add a "less strict" flag (i.e. non-STD 3 rules) to the idna library such that if it received a string that is pure ASCII, it doesn't throw an exception if it is not LDH.

@bpicolo
Copy link
Author

bpicolo commented Aug 3, 2015

@kjd Maybe you could help enlighten me a bit? It seems the point I'm dying at is ssl verification through twisted.
http://twistedmatrix.com/trac/browser/tags/releases/twisted-15.2.1/twisted/internet/_sslverify.py#L67

Should a hostname like foo_bar.baz.com never be a valid hostname? Or should it just never be passed to idna encoding since underscore is a valid ascii character?

That is, underscores appear to be valid in ascii hostnames, but that conflicts with IDNs in some way?

@jribbens
Copy link
Collaborator

jribbens commented Aug 4, 2015

Underscores are not valid in ASCII hostnames, and never were. That fact has nothing to do with IDNA. Only letters, digits and hyphen are valid. See RFC 952 for details.

@bpicolo
Copy link
Author

bpicolo commented Aug 4, 2015

@jribbens Awesome, I see now, thanks!

"While a hostname may not contain other characters, such as the underscore character (_), other DNS names may contain the underscore" looks like that's more or less where my confusion lies. I'll close this ticket. Thanks for the weigh in guys! This wasn't my area of expertise. : )

@bpicolo bpicolo closed this as completed Aug 4, 2015
aequitas pushed a commit to aequitas/home-assistant that referenced this issue Nov 19, 2016
aequitas pushed a commit to aequitas/home-assistant that referenced this issue Dec 1, 2016
balloob pushed a commit to home-assistant/core that referenced this issue Dec 2, 2016
* Add MAC vendor lookup for device_tracker.

* Test vendor mac lookup and fix device attribute.

* Generate requirements.

* Style.

* Use hyphen instead of underscore to satisfy 'idna'.

kjd/idna#17

* Resort imports.

* Refactor macvendor to use macvendors.com API instead of netaddr library.

* Test vendor lookup using macvendors.com api.

* Remove debugging.

* Correct description.

* No longer needed.

* Device tracker is now an async component. Fix ddwrt tests.

* Fix linting.

* Add test case for error conditions.

* There is no reason to retry failes vendor loopups as they won't be saved to the file anyways at that point.

* Sorry, bad assumption, this only made things worse.

* Wait for async parts during setup component to complete before asserting results.

* Fix linting.

* Is generated when running 'coverage html'.

* Undo isort.

* Make aioclient_mock exception more generic.

* Only lookup mac vendor string with adding new device to known_devices.yaml.

* Undo isort.

* Revert unneeded change.

* Adjust to use new websession pattern.

* Always make sure to cleanup response.

* Use correct function to release response.

* Fix tests.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants