{"action":"created","issue":{"url":"https://api.github.com/repos/bcgit/bc-java/issues/133","labels_url":"https://api.github.com/repos/bcgit/bc-java/issues/133/labels{/name}","comments_url":"https://api.github.com/repos/bcgit/bc-java/issues/133/comments","events_url":"https://api.github.com/repos/bcgit/bc-java/issues/133/events","html_url":"https://github.com/bcgit/bc-java/issues/133","id":125146745,"number":133,"title":"Non-blocking TlsProtocol accepts non-TLS data","user":{"login":"martin-robo","id":1705517,"avatar_url":"https://avatars.githubusercontent.com/u/1705517?v=3","gravatar_id":"","url":"https://api.github.com/users/martin-robo","html_url":"https://github.com/martin-robo","followers_url":"https://api.github.com/users/martin-robo/followers","following_url":"https://api.github.com/users/martin-robo/following{/other_user}","gists_url":"https://api.github.com/users/martin-robo/gists{/gist_id}","starred_url":"https://api.github.com/users/martin-robo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/martin-robo/subscriptions","organizations_url":"https://api.github.com/users/martin-robo/orgs","repos_url":"https://api.github.com/users/martin-robo/repos","events_url":"https://api.github.com/users/martin-robo/events{/privacy}","received_events_url":"https://api.github.com/users/martin-robo/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":{"login":"peterdettman","id":3423981,"avatar_url":"https://avatars.githubusercontent.com/u/3423981?v=3","gravatar_id":"","url":"https://api.github.com/users/peterdettman","html_url":"https://github.com/peterdettman","followers_url":"https://api.github.com/users/peterdettman/followers","following_url":"https://api.github.com/users/peterdettman/following{/other_user}","gists_url":"https://api.github.com/users/peterdettman/gists{/gist_id}","starred_url":"https://api.github.com/users/peterdettman/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/peterdettman/subscriptions","organizations_url":"https://api.github.com/users/peterdettman/orgs","repos_url":"https://api.github.com/users/peterdettman/repos","events_url":"https://api.github.com/users/peterdettman/events{/privacy}","received_events_url":"https://api.github.com/users/peterdettman/received_events","type":"User","site_admin":false},"milestone":null,"comments":1,"created_at":"2016-01-06T10:10:25Z","updated_at":"2016-01-06T17:02:16Z","closed_at":null,"body":"With 1.54 I wrote a TLS server that offers received data directly to BC TLS protocol via `TlsProtocol.offerInput(byte[])`. I connected via Telnet and hit random keys on my keyboard. The connection was not terminated, though. It seems BC TLS protocol simply accepted all my non-TLS data.\r\n\r\nI had a look at the code of BC TLS protocol. I guess the bytes I sent resulted in a negative number with `TlsUtils.readUint16(byte[], int)`. Neither TlsUtils, nor TlsProtocol check the calculated record length to be reasonable.\r\n\r\nI suggest there should be some kind of check the received input data matches the TLS standard."},"comment":{"url":"https://api.github.com/repos/bcgit/bc-java/issues/comments/169388636","html_url":"https://github.com/bcgit/bc-java/issues/133#issuecomment-169388636","issue_url":"https://api.github.com/repos/bcgit/bc-java/issues/133","id":169388636,"user":{"login":"peterdettman","id":3423981,"avatar_url":"https://avatars.githubusercontent.com/u/3423981?v=3","gravatar_id":"","url":"https://api.github.com/users/peterdettman","html_url":"https://github.com/peterdettman","followers_url":"https://api.github.com/users/peterdettman/followers","following_url":"https://api.github.com/users/peterdettman/following{/other_user}","gists_url":"https://api.github.com/users/peterdettman/gists{/gist_id}","starred_url":"https://api.github.com/users/peterdettman/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/peterdettman/subscriptions","organizations_url":"https://api.github.com/users/peterdettman/orgs","repos_url":"https://api.github.com/users/peterdettman/repos","events_url":"https://api.github.com/users/peterdettman/events{/privacy}","received_events_url":"https://api.github.com/users/peterdettman/received_events","type":"User","site_admin":false},"created_at":"2016-01-06T17:02:16Z","updated_at":"2016-01-06T17:02:16Z","body":"I don't believe TlsUtils,readUint16 can return a negative value, the problem must be elsewhere. There are quite a few checks on the record sanity in RecordStream.readRecord, let me know if you think some check is missing there. I have to guess perhaps you are using offerInput by passing a fixed buffer to each call (see javadoc for why that would be a problem).\r\n\r\nWe're keen to fix this if there's an error, but I think we'll need a small test case that shows the problem."}}