简体   繁体   English

如何使用 ssl 选项确保 npgsql 连接的安全

[英]How secure npgsql connection with ssl option

i use npgsql version 2270 and i would to secure my connection passing db password NOT in cleartext and with capability to use SSL connection on a preconfigured postgresql server.我使用 npgsql 2270 版,我希望通过非明文形式的 db 密码来保护我的连接,并且能够在预配置的 postgresql 服务器上使用 SSL 连接。 My doubt is about how set the connection string with npgsql.我的疑问是如何使用 npgsql 设置连接字符串。

I tryed adding ssl=true sslmode=prefer to conn string but i have not idea about how to verify if it work.我尝试添加 ssl=true sslmode=prefer 到 conn 字符串,但我不知道如何验证它是否有效。
Is sufficient for secure data transit?足以保证安全的数据传输吗? is string correct?字符串正确吗?
Is needed to activate ssl also on server is right?是否也需要在服务器上激活 ssl 对吗?
How can i verify if data transit on ssl mode ?如何验证数据是否在 ssl 模式下传输? Thanks all.谢谢大家。

First, SSL isn't really about encrypting your password - it's about encrypting the entire stream.首先,SSL 并不是真正要加密您的密码——而是要加密整个流。 If you use PostgreSQL's md5 authentication method (see your pg_hba.conf), then passwords are never transferred in cleartext regardless of whether you're using SSL or not.如果您使用 PostgreSQL 的md5身份验证方法(请参阅您的 pg_hba.conf),那么无论您是否使用 SSL,密码都不会以明文形式传输。

To use SSL, it's better to set SSL Mode to require rather than prefer : the latter will attempt to establish an SSL connection, but will fallback to non-SSL if the server doesn't support it.要使用 SSL,最好将SSL Mode设置为require而不是prefer :后者将尝试建立 SSL 连接,但如果服务器不支持它,则会回退到非 SSL。 require will fail the connection attempt if SSL could not be established.如果无法建立 SSL, require将使连接尝试失败。

Regardless, yes, you need to set up SSL on PostgreSQL, including a certificate and a private key - you can read about this in the documentation .无论如何,是的,您需要在 PostgreSQL 上设置 SSL,包括证书和私钥 - 您可以在文档中阅读相关内容。

If the aim is only to avoid sending passwords in cleartext, using md5 (or sha256 in more recent versions) is the simplest way.如果目的只是为了避免以明文形式发送密码,则使用md5 (或更新版本中的sha256 )是最简单的方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM