-
Notifications
You must be signed in to change notification settings - Fork 38
SNI extension #105
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
Merged
Merged
SNI extension #105
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
48ec7fb
Define ServerNameList extension constructs
ashfall 53af807
Implmenet constructs for server_name extension
ashfall 83c26cc
a B for py3
ashfall 07534f8
Remove unused import
ashfall 4e4541c
Extra whitespace
ashfall 3562b89
pep8
ashfall 7f0488c
HostName doesn't need to be a struct
ashfall f836618
Add a failing test for server_name extension's presence in ServerHello
ashfall 4538855
Correctly validate extensions that should go in client hello vs. serv…
ashfall 01b6f2a
Sometimes, I can spell.
ashfall 8ac0124
Add a check for unsupported extensions in ServerHello.as_bytes()
ashfall 5de80f8
Test ClientHello.from_bytes() with an unsupported extension
ashfall 7c77cc8
Reject unsupported extensions in ClientHello.as_bytes()
ashfall File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,3 +7,7 @@ | |
|
|
||
| class UnsupportedCipherException(Exception): | ||
| pass | ||
|
|
||
|
|
||
| class UnsupportedExtensionException(Exception): | ||
| pass | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,6 +12,8 @@ | |
|
|
||
| from tls._common import enums | ||
|
|
||
| from tls.exceptions import UnsupportedExtensionException | ||
|
|
||
|
|
||
| @attr.s | ||
| class ProtocolVersion(object): | ||
|
|
@@ -31,6 +33,15 @@ class Random(object): | |
| random_bytes = attr.ib() | ||
|
|
||
|
|
||
| @attr.s | ||
| class ServerName(object): | ||
| """ | ||
| An object representing a ServerName struct. | ||
| """ | ||
| name_type = attr.ib() | ||
| name = attr.ib() | ||
|
|
||
|
|
||
| @attr.s | ||
| class ClientHello(object): | ||
| """ | ||
|
|
@@ -42,8 +53,20 @@ class ClientHello(object): | |
| cipher_suites = attr.ib() | ||
| compression_methods = attr.ib() | ||
| extensions = attr.ib() | ||
| allowed_extensions = frozenset([ | ||
| enums.ExtensionType.SERVER_NAME, | ||
| enums.ExtensionType.MAX_FRAGMENT_LENGTH, | ||
| enums.ExtensionType.CLIENT_CERTIFICATE_URL, | ||
| enums.ExtensionType.SIGNATURE_ALGORITHMS, | ||
| # XXX Incomplete list, needs to be populated as we implement more | ||
| # extensions. | ||
| ]) | ||
|
|
||
| def as_bytes(self): | ||
| if any(extension.type not in self.allowed_extensions | ||
| for extension in self.extensions): | ||
| raise UnsupportedExtensionException | ||
|
|
||
| return _constructs.ClientHello.build( | ||
| Container( | ||
| version=Container(major=self.client_version.major, | ||
|
|
@@ -72,6 +95,9 @@ def from_bytes(cls, bytes): | |
| :return: ClientHello object. | ||
| """ | ||
| construct = _constructs.ClientHello.parse(bytes) | ||
| if any(extension.type not in cls.allowed_extensions | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This was an excellent catch! Should |
||
| for extension in construct.extensions): | ||
| raise UnsupportedExtensionException | ||
| return ClientHello( | ||
| client_version=ProtocolVersion( | ||
| major=construct.version.major, | ||
|
|
@@ -101,8 +127,13 @@ class ServerHello(object): | |
| cipher_suite = attr.ib() | ||
| compression_method = attr.ib() | ||
| extensions = attr.ib() | ||
| allowed_extensions = frozenset([]) | ||
|
|
||
| def as_bytes(self): | ||
| if any(extension.type not in self.allowed_extensions | ||
| for extension in self.extensions): | ||
| raise UnsupportedExtensionException | ||
|
|
||
| return _constructs.ServerHello.build( | ||
| Container( | ||
| version=Container(major=self.server_version.major, | ||
|
|
@@ -128,6 +159,9 @@ def from_bytes(cls, bytes): | |
| :return: ServerHello object. | ||
| """ | ||
| construct = _constructs.ServerHello.parse(bytes) | ||
| if any(extension.type not in cls.allowed_extensions | ||
| for extension in construct.extensions): | ||
| raise UnsupportedExtensionException | ||
| return ServerHello( | ||
| server_version=ProtocolVersion( | ||
| major=construct.version.major, | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps EnumSwitch would go better here
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed!
EDIT I just realized that comment wasn't clear -- sorry! I meant to say that it's OK to make this use
EnumSwitchin this PR, but I'm happy to see this addressed in a separate PR that closes #106.