<p><a href="https://github.com/aubble/goTunneLS" rel="nofollow">https://github.com/aubble/goTunneLS</a></p>
<p>Hello I posted earlier for code review on my repos except I wasn't very specific, however this time it's just this one little project, a TLS wrapper in go, basically a stunnel clone. It allows you take applications not programmed to use TLS and wrap them in it. It takes a json config file for the various ports you want forwarded over TLS through goTunneLS to another goTunneLS (could be any wrapper that doesn't have its own protocol, just uses standard TLS) instance which then routes them to their final location. I'd really appreciate if someone could look this over and check if I did everything right. If there are any vulnerabilities or nooby mistakes etc, specifically my use of TLS. Thanks in advance!!! </p>
<hr/>**评论:**<br/><br/>joushou: <pre><p>First of all, a disclaimer: You asked for a review, so a review is what you're getting! Don't take anything as insults, or as me looking down on your code; it is merely constructive criticism.</p>
<ol>
<li><p>Write a description in the README. That's very important, so that people seeing the project will know what to do with it. It also helps exposure, as it increases the chance of being found by Google searches.</p></li>
<li><p>Your socket seems to have turned into a class with your application logic, although it seems to also be your configuration object. I would heavily suggest splitting server and client, with your server logic most likely residing directly in main() (It's just a loop calling Accept()), and having your configuration completely separate. In case of multiple servers running, make it a function that takes the required function as arguments (certPool, []tls.Certificates, listening address and connection address). There is nothing here that seems to require any state, so it's free functions all the way.</p></li>
<li><p>getCertArray doesn't do anything specific to the socket, so don't make it take a socket as a receiver. It's just a free function!</p></li>
<li><p>Related to 3, I would suggest parsing the certs before giving them to any handler - that abstracts the format away, leaving the config handler to figure out how to parse things, as long as it spits out a []tls.Certificate.</p></li>
<li><p>Close the net.Conn's when you're done with them. In this case, you can cheat a bit and just not not "go" one of the io.Copy's, and then defer the Close of both the incoming and outgoing net.Conns.</p></li>
<li><p>You just try again in case of errors? That's a good way to burn CPU cycles if the configuration is broken. Print them and exit!</p></li>
<li><p>The names "server" and "client" doesn't seem particularly descriptive when both are actually proxies. One is "unwrapped-to-TLS" and the other is "TLS-to-unwrapped". Those are of course terrible names, but try to think of something more descriptive.
You can submit for another review which focuses more on the application logic itself once some of those have been taken care of.</p></li>
<li><p>Defaulting to "aubble.com" doesn't seem like a particularly sane default!</p></li>
</ol>
<p>Once some of those have been fixed, we can take a look at a re-review at more application-logic specific parts.</p></pre>nhooyr: <pre><p>thank you very much. time to fix it up.</p></pre>
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889
- 请尽量让自己的回复能够对别人有帮助
- 支持 Markdown 格式, **粗体**、~~删除线~~、
`单行代码`
- 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
- 图片支持拖拽、截图粘贴等方式上传