A c # client-Java Web server interaction experience (for help)

Source: Internet
Author: User
Tags db2 driver

The company is about to build a client system, C # development. There are many places on the client that involve money, so you have to interact with the database.

This is why I am asking for help from my. Net blog.

If the company uses a client system internally, the common method is to directly connect to the internal database server through the client for data interaction. Because it is used internally, you do not need to consider data security issues. But we need to develop a set of software for n-bit customers, so that we cannot guarantee the user level. If a slight error occurs in a certain aspect, our database may be downloaded directly. After all, the account and password used to connect to the database may be stored in the client program, and all the connection information can be directly viewed through decompilation. Even if encrypted, it may be decrypted.

I first thought of a set of modes, that is, a slightly more complex client to operate on Web Service data, which can avoid the client to operate on the database directly, and the database changes will not affect the client in the future, it is advantageous in all aspects. Before implementation, the team conducted a series of discussions and research on the solution, and finally it was temporarily rejected. When the data volume is large, it is enough to interact with the Web server to obtain the result. xml must be parsed, which is not easy. In this way, I started to seek help online, and finally did not get a good conclusion.

The Short Message-related service started after the development of data interaction was abandoned. A new task was launched and sent via the MAS System of Huawei. API is provided by Huawei. It should be c-developed API, which is not very difficult. The security problem arises again, and the API usage requirements are relatively Bt. the DB2 driver must be installed. This is because you need to reference the DLL provided by Huawei and connect to our enterprise account and hardware devices during use. Such sensitive connection information is exposed to the source code of the program. After decompiling the source code, it will still allow others to send text messages for free. You have to encapsulate text message-related services into Web Services. The company's Web Server is a configured Java environment, and there is no need to configure. net. Therefore, I chose the xfire framework in Java for Web service development. Don't talk about unnecessary things first. Let's talk about my specific operation process and help me to see what problems may exist. After all, I am not very technical. Thank you first.

Directly making the client interact with the Web service on the server is certainly not a good way. If the user captures the Web service connection address, it will make people play for free. In the preliminary design, I thought that each time the client calls the server, it uses an account and password for verification and encrypts it. It says, and the problem is found again. The final principle of connecting the client to the Web service must be an HTTP request, so that if the user intercepts all requests from the local machine, it will immediately expose our service address and parameters, then directly write a program to simulate the request, so that no matter how advanced encryption is performed on the client, it will still be directly bypassed for verification. It evolved my idea that a random value was sent to the Web service each time, and then the Web service was verified. The first thought was to pass the time and encrypt a value for verification, because the time is unique and can ensure the consistency between the client and the server. Haha, after a while, I still pass my idea, because in case the client and server time are not consistent, this function will be discarded directly, because the time is not synchronized and the encrypted value is different, when network latency is added, this authentication method will definitely fail.

Therefore, the idea has evolved further. Generate a NNID from the initialization method of Web Service (guid in C #, Java is called NNID). This ID is recorded and automatically destroyed n minutes later (after destruction, the client will instantiate the class again, generate a new NNID), and then generate a random number of less than 1-10 from the server (what will be said later ). Then obtain this value from the client and provide a login method for the Web service. Each login passes in a value encrypted from the client. The client-side encryption value is encrypted by the NNID generated by the server. The number of encryption times is determined by the random number mentioned above. If the random number is 3, it is encrypted three times. What we just mentioned is to encrypt a unique value generated from the server from the client, so we need to encrypt the same algorithm and the same number of times from the server, finally, compare the server-side encryption results with the client-side results. If the results are the same, the verification is successful! Maybe I am stupid in this method, so I need more comments. Let me explain why I want to do this. I have considered the following points.

  1. For example, if the user obtains my web service address and interacts with each other according to the preceding method, You have to verify the address. You may think that I will capture all your request parameters directly, is it okay to simulate this request? As mentioned earlier, the NNID will be recorded somewhere and will be automatically destroyed in n minutes.
  2. Assume that the user has caught this address, and the user cannot directly use my web service from my client. Because my NNID is encrypted, he knows that this address is not enough, in addition, the number of times that the NNID is encrypted is still random, and he needs to know the number of encrypted times in real time before successful verification.
  3. Maybe the user will decompile my program and then see how I encrypt it. Then I can implement my encryption algorithm through C ++, generate a DLL file, and shell the DLL file to prevent decompilation, this ensures that my encryption algorithm is not leaked.
  4. Even if the user can use it out of my program, the user can only use it for n minutes, because the ID will be destroyed in n minutes, and the user authentication will fail. Because NNID is globally unique, the chance of repetition is very low. In addition, I keep a record for each verification on the server. If an error occurs during user verification, it indicates that there is definitely a problem. In this case, the user can be directly blocked and cannot be used.

This is the method I have come up with. The expected effect is the same as I have imagined. It may waste some memory when managing NNID, but I think it will be possible to optimize it in the future, for example, if many users can be stored in databases, This Is My naive idea. I am not technically competent. I sincerely hope that the bloggers in the blog Park can give me some advice, I may not have considered many details. Thank you!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.