Question: TLS on client

agolangf · · 379 次点击    
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
<p>Hey,</p> <p>I have a server running on HTTPS with let&#39;s encrypt.</p> <p>I am now writing a client and I would like to login a user to the server in a secure way, meaning I do not want to send their password without TLS.</p> <p>Is something like this enough to send their password encrypted?</p> <pre><code>serverURL := &#34;https://server.com/login&#34; tr := &amp;http.Transport{ TLSClientConfig: &amp;tls.Config{}, } client := &amp;http.Client{Transport: tr} resp, err := client.Post(serverURL) // ... </code></pre> <p>Do I need anything extra in <code>&amp;tls.Config{}</code>? Do I need to create a self signed certificate for my client in order to use TLS or is the server running on HTTPS enough?</p> <p>Thanks</p> <hr/>**评论:**<br/><br/>mwholt: <pre><p>You can just do:</p> <p><code> resp, err := http.Post(serverURL, &#34;content type&#34;, body) </code></p> <p>As long as the server&#39;s URL begins with &#34;https://&#34; your client will use TLS with sane defaults.</p></pre>nesigma: <pre><p>Oh wow that&#39;s amazing!! Thanks!</p></pre>tialaramex: <pre><p>Client certificates prove the client&#39;s identity to the server (exactly as sever certificates prove the server&#39;s identity to the client) they&#39;re not necessary if either you trust any client (e.g. google.com searches don&#39;t care who you are) or when doing some other form of authentication, as you are with passwords. So, don&#39;t bother with client certs in this scenario.</p></pre>SilentWeaponQuietWar: <pre><pre><code>tr := &amp;http.Transport{ TLSClientConfig: &amp;tls.Config{}, } </code></pre> <p>FYI this might not be immediately obvious, but if you are going to use your own Transport settings, might want to be sure and set MaxIdleConns, otherwise it will be set to 0, which means unlimited.</p> <p>From the docs:</p> <blockquote> <p>// MaxIdleConns controls the maximum number of idle (keep-alive) // connections across all hosts. <strong>Zero means no limit.</strong></p> </blockquote></pre>

入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889

379 次点击  
加入收藏 微博
0 回复
暂无回复
添加一条新回复 (您需要 登录 后才能回复 没有账号 ?)
  • 请尽量让自己的回复能够对别人有帮助
  • 支持 Markdown 格式, **粗体**、~~删除线~~、`单行代码`
  • 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
  • 图片支持拖拽、截图粘贴等方式上传