Regarding http.ListenAndServerTLS...

xuanbao · · 672 次点击    
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
<p>Hi everybody!</p> <p>I&#39;m working on setting up a system that will generate a cert/key.pem pair for users upon registering with the system. I have a http.Server running with the &#34;ListenAndServeTLS()&#34; function, to handle these requests.</p> <p>My confusion comes from the fact that &#39;ListenAndServeTLS()&#39; requires 2 arguments: a certificate file, and a key file. So, this being said... how do I append certificates to the running server as they are generated? The goDocs page for this function states that the cert/key file arguments &#39;must&#39; be included - so I get the impression that I cannot retroactively add certificates to it?</p> <p>Any advice/suggestions or any other form of input is appreciated. Thank you :)</p> <hr/>**评论:**<br/><br/>mwholt: <pre><p>You need to use the <a href="https://golang.org/pkg/crypto/tls/#Config" rel="nofollow">GetCertificate callback</a> of a tls.Config and manage your own certificate cache.</p></pre>vietnq: <pre><p>You can just add cert to tls.Config and call ListenAndServeTLS with empty strings (<a href="https://golang.org/src/net/http/server.go?s=85702:85770#L2855" rel="nofollow">https://golang.org/src/net/http/server.go?s=85702:85770#L2855</a>). If server is already running, you need to implement GetCertificate like <a href="https://godoc.org/golang.org/x/crypto/acme/autocert#Manager.GetCertificate" rel="nofollow">https://godoc.org/golang.org/x/crypto/acme/autocert#Manager.GetCertificate</a></p></pre>ArturusPendragon: <pre><p>Perfect! Thank you :)</p></pre>DemandsBattletoads: <pre><p>You may need to write the keys to disk and restart the server. I&#39;m not aware of any server out there that can do this live as it could cause all kinds of cryptographic race conditions.</p></pre>jerf: <pre><p>The more I read your post, the less I understand what it is you are trying to do. What do the newly generated certificates have to do with your HTTPS server? You shouldn&#39;t be trying to change the certificate of the server after it is generated.</p></pre>

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

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