如何保护基于客户端-服务器的 Java 桌面应用程序的数据库凭据
好吧,在开始之前,我知道很多人已经问过这个问题了。但我确实没有找到我正在寻找的解决方案。所以我在这里解释我的项目和要求,&问同样的问题。
我正在做一个关于远程电子投票系统的最后一年的项目。 使用 java 开发客户端应用程序,允许公共用户使用 LOGINID 和密码登录到应用程序。登录密码(由选举委员会等给予每个选民)。 然后客户端应用程序显示参加选举的候选人列表,并显示选举结果。有单选按钮可以选择其中之一。选择后,用户可以按下“CAST VOTE”按钮来“投票”。
现在的问题是,要“投票”,我需要将此信息发送到服务器上的数据库。如何从客户端应用程序到数据库建立连接以更新所需的表/详细信息?我将数据库凭据硬编码到源代码中,但最近意识到它非常不安全。
我真的不能使用属性文件或配置文件&使用操作系统功能来保护它,因为最终用户也可以读取这些功能(因为他们是操作系统的管理员/所有者)
哦,是的,我将把客户端应用程序作为 JAR 文件等分发, &因此,无论我将其硬编码到源代码中、对其进行加密还是使用属性文件,所有这些仍然存在风险和风险。反编译以了解数据库详细信息。
有替代方案吗? 有什么解决办法吗? 如果有的话,能否详细说明一下或者如何实现?
谢谢。
Ok, before I start, I know a lot of people have already asked this question. But I really didnt find the solution I was looking for. So here I am, explaining my project & requirements, & asking the same question.
I am doing a final year project on REMOTE ELECTRONIC VOTING SYSTEM.
Developing a client side application, using java, that allows the public users to login to the APPLICATION using a LOGINID & LOGINPASS(Given to each & every voter by the election commission or so).
The client-side application then displays a list of candidates participating in the election, & has radio buttons to choose one of it. After choosing, the user can then press a "CAST VOTE" button in order the "cast the vote".
The problem now is, to "cast the vote", I need to send this information to a database on the server. How can I make a connection from the client-side app to the database in order to update the desired table/details? I was hardcoding the database credentials into the source code, but realized recently that it is very insecure.
I cant really use a PROPERTIES files or a CONFIG file & protect it using OS features, since these can be read by the end-users as well(since they are the admin/owner of the OS)
And oh yeah, I'll be distributing the client-side app as JAR files or so, & hence whether I hardcode it into the source code, encrypt it, or use properties file, all of it are still open for risks & decompiling in order to know the database details.
Is there an alternate for this?
Any workaround?
If there is, can you please provide the details about it or how to implement it?
Thank You.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
使用普通的客户端-服务器应用程序,您不会直接从客户端连接到数据库服务器。相反,客户端连接到服务器(使用 LOGINID 和 LOGINPASS 作为身份验证),然后服务器连接到数据库服务器。
这意味着客户端不存储有关数据库的任何信息,并且服务器协调对数据库的所有访问。
With a normal client-server app, you don't connect directly from the client to the database server. Rather, the client connects to the server (using LOGINID and LOGINPASS as authentication), which then connects to the database server.
That means the client doesn't store any information about the database, and the server mediates all access to it.
我认为这两件事的解决方案是相同的。您已经以某种方式询问服务器选民的用户名和密码是否正确。
将其作为数据库前面的 Web 服务,并且只需进行两个调用(均由 Loginuser 和 LoginPass 进行身份验证)
GET /user/_self
这将返回有关用户的一些信息,以便您可以适当地向他们打招呼,并允许您检查他们知道自己的密码。
您需要确保不允许暴力攻击或拒绝服务。
POST /candiates/candidate
这将为登录用户注册投票。
如果您将其放在 SSL 上,并同时使用客户端和服务器证书验证,那么您很有可能客户端不会被欺骗而向无效客户端发送登录详细信息,并且服务器不会从任何客户端收到无效请求。老客户。
如果您将其设为 Web 启动应用程序(需要签名的 jar 文件)并在客户端上进行一些密钥安装,那么您将拥有一个相当安全的路径。
您可以将数据库放置在防火墙区域中,将 Web 应用程序放置在 DMZ 中。从 Web 应用程序到数据库的访问可以使用正常方法完成,但对于某种程度安全的应用程序,您将尽最大努力确保如果 DMZ 框被破坏,您仍然无法进行有效投票。
请注意:
I think the solution to the two things is the same. You already are asking the server somehow if the username and password is correct for the voter.
Make this a webservice in front of the database, and simply have two calls (both authenticated by loginuser & loginpass)
GET /user/_self
This would return some information about the user, so you can greet them appropriately, and allow you to check that they know their password.
You would need to make sure that you didn't allow brute force attacks, nor denial of service.
POST /candiates/candidate
This would register a vote for from the logged in user.
If you put this over SSL, and use both client and server certificate validation, then you have a good chance that the client isn't spoofed into sending login details to an invalid client, and that the server doesn't get invalid requests from any old client.
If you make this a web start app (which requires signed jar files) and do a bit of key installation on the client, then you will have a reasonably secureish path.
You would place the DB in a firewalled zone, with the web application in a DMZ. Access from the web application to the database could be done using normal methods, but for a somewhat secured application, you would do your best to ensure that if the DMZ box were compromised, you still couldn't cast a valid vote.
Note that:
永远不要让用户直接远程写入数据库!!!!
编写一个服务器应用程序(php、servlet?),用户可以登录,并且该应用程序可以更新数据库。
如果您不知道如何做到这一点,说真的,您不应该编写投票应用程序。
Never let the user write directly to the database remotely!!!!!
Write a server app (php, servlets?), the user can log in to, and this app can update the DB.
If you don't know how to do this, seriously, you shouldn't write a voting app.
请注意,无论您以哪种方式实现该程序,在客户端运行的程序从根本上来说都是不安全的。
我知道这只是一个大学项目工作,永远不会成为一个真正的投票系统,但你必须深信这一事实。
请记住,“您嵌入程序中的任何密钥都可以由具有该程序的完全访问权限的人恢复,您能做的最好的事情就是让这样做变得耗时。”。请参阅 stackexchange 上的此问题,了解原因 https:// security.stackexchange.com/questions/35235/how-to-efficiently-save-database-password-inside-desktop-application。
这就是DRM在整个计算历史上始终被击败的主要原因。
现在,如果您想实现一个更现实的投票系统,您可能会将其实现为一个 Web 应用程序(例如 JavaEE),用户将在其中使用浏览器进行投票。
这会更安全,并且不需要选民在他的计算机上安装任何程序。
还有选民身份和选民胁迫的问题,但我想每个人都清楚这一点。
Please be aware that this program running on the client side whichever way you'll implement it will be fundamentally insecure.
I know that this is just a university project work and will never be a real voting system however you must be deeply convinced about this fact.
Remember indeed that "Any secret key that you embed in a program can be recovered by a person who has full access to that program, the best you can do is make it time consuming to do so.". See this question on stackexchange to know why https://security.stackexchange.com/questions/35235/how-to-effectively-save-database-password-inside-desktop-application.
This is the main reason why DRM has always been defeated in all history of computing.
Now if you wanted to implement a more realistic voting system you would probably implement it as a web application (JavaEE for instance) where the user would use the browser to vote.
This would be both more secure and wouldn't require for the voter to install any program on his computer.
Then there's the problem of the identity of the voter and voter coercion, but that I think is clear to everyone.