{"comment":{"url":"https://api.github.com/repos/kazu-yamamoto/hs-tls/comments/31233593","html_url":"https://github.com/kazu-yamamoto/hs-tls/commit/d06ddf9977fee3680a85e3a87e7bd9b20acb1f07#commitcomment-31233593","id":31233593,"node_id":"MDEzOkNvbW1pdENvbW1lbnQzMTIzMzU5Mw==","user":{"login":"kazu-yamamoto","id":165387,"node_id":"MDQ6VXNlcjE2NTM4Nw==","avatar_url":"https://avatars3.githubusercontent.com/u/165387?v=4","gravatar_id":"","url":"https://api.github.com/users/kazu-yamamoto","html_url":"https://github.com/kazu-yamamoto","followers_url":"https://api.github.com/users/kazu-yamamoto/followers","following_url":"https://api.github.com/users/kazu-yamamoto/following{/other_user}","gists_url":"https://api.github.com/users/kazu-yamamoto/gists{/gist_id}","starred_url":"https://api.github.com/users/kazu-yamamoto/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kazu-yamamoto/subscriptions","organizations_url":"https://api.github.com/users/kazu-yamamoto/orgs","repos_url":"https://api.github.com/users/kazu-yamamoto/repos","events_url":"https://api.github.com/users/kazu-yamamoto/events{/privacy}","received_events_url":"https://api.github.com/users/kazu-yamamoto/received_events","type":"User","site_admin":false},"position":4,"line":224,"path":"core/Network/TLS/Extension.hs","commit_id":"d06ddf9977fee3680a85e3a87e7bd9b20acb1f07","created_at":"2018-11-09T05:10:30Z","updated_at":"2018-11-09T05:10:30Z","author_association":"OWNER","body":"[TLS 1.2](https://tools.ietf.org/html/rfc5246) does not define contexted-based extensions. `extensionDecode` did not need to take the `Bool` argument.\r\n\r\n[Renegotiation Indication Extension](https://tools.ietf.org/html/rfc5746) introduced context:\r\n\r\n> - For ClientHellos that are renegotiating, this field contains the\r\n      \"client_verify_data\" specified in Section 3.1.\r\n> - For ServerHellos that are renegotiating, this field contains the\r\n      concatenation of client_verify_data and server_verify_data.  For\r\n      current versions of TLS, this will be a 24-byte value (for SSLv3,\r\n      it will be a 72-byte value).\r\n\r\nThis is why the `Bool` argument is added to `extensionDecode`:\r\n\r\n```haskell\r\nclass Extension a where\r\n    extensionDecode :: Bool -> ByteString -> Maybe a\r\n\r\ninstance Extension SecureRenegotiation where\r\n    extensionDecode isServerHello = runGetMaybe $ do\r\n        opaque <- getOpaque8\r\n        if isServerHello\r\n           then let (cvd, svd) = B.splitAt (B.length opaque `div` 2) opaque\r\n                 in return $ SecureRenegotiation cvd (Just svd)\r\n           else return $ SecureRenegotiation opaque Nothing\r\n```\r\n\r\nHaskellers are prone to choose `Bool` unwisely to express two values. Honestly, I cannot tell what `False` refers to.\r\n\r\n[TLS 1.3](https://tools.ietf.org/html/rfc8446) started to use `case` syntax to express the context.\r\n\r\n```\r\n      struct {\r\n          select (Handshake.msg_type) {\r\n              case client_hello:\r\n                   ProtocolVersion versions<2..254>;\r\n\r\n              case server_hello: /* and HelloRetryRequest */\r\n                   ProtocolVersion selected_version;\r\n          };\r\n      } SupportedVersions;\r\n```\r\n\r\nTo express these context, I replaced `Bool` with `MessageType`.\r\n\r\nUnfortunately, the final specification introduced an exception which does not use `case`s:\r\n\r\n```\r\n      struct {\r\n          KeyShareEntry client_shares<0..2^16-1>;\r\n      } KeyShareClientHello;\r\n\r\n      struct {\r\n          NamedGroup selected_group;\r\n      } KeyShareHelloRetryRequest;\r\n\r\n      struct {\r\n          KeyShareEntry server_share;\r\n      } KeyShareServerHello;\r\n```\r\n\r\nIn old specifications, hello retry request is an independent handshake message. So, `case`s were used to define these three variants. The final specification decided to reuse the server hello to express hello retry request.\r\n\r\nWe should clarify what `MessageType` is and how to use it.\r\n"}}
{"actor":{"display_login":"kazu-yamamoto"}}