Open Source Cloud Authors: Liz McMillan, Yeshim Deniz, Elizabeth White, Pat Romanski, Greg Schulz

Related Topics: Microsoft Cloud, Containers Expo Blog

Microsoft Cloud: Article

Securing Enterprise Data Transfer with SQL Server CE

Securing Enterprise Data Transfer with SQL Server CE

In the first article in this series, "Accessing Enterprise Data from SQL Server CE" [.NETDJ, Vol. 1, issue 6], we constructed a solution that allowed us to provide enterprise data access to mobile devices while in a disconnected environment using Visual Studio .NET 2003, the .NET Compact Framework, and SQL Server CE 2.0. Providing mobile users offline access to their enterprise data, along with the ability to propagate changes back to the server, is a powerful addition to any mobile architecture. But this additional functionality comes with the responsibility of securing your data while "out in the wild."

Whenever you create architectural scenarios in which your data is accessible outside of your infrastructure, you need to make data security a top-priority feature. Mobile data access is no exception. Consider the ramifications of hackers abusing your application's SSCE virtual directory to either deny access to legitimate users or steal critical enterprise data. While the functionality of mobile enterprise data access is a powerful addition to your architecture, it comes with great responsibility. Combining solid code and great features with sound security practices provides your users with a compelling application from both a functional and nonfunctional point of view.

In this article, we'll take the functionality we developed in the first installment and harden the solution to be both functional and secure. We'll secure access to the data on the back-end server by leveraging security features built into Windows Server 2003, SQL Server 2000, and IIS 6.0. We'll secure the transmission of data between device and server to ensure that data is hidden from prying eyes while en route. Finally, we'll modify our code to allow authenticated and secure transfer of data between server and device.

For this article, you'll need to start with the solution offered in our earlier article. (The source code is available at www.sys-con.com/dotnet/sourcec.cfm.) For this solution, we'll use Visual Studio .NET 2003 and the .NET Compact Framework to develop the solution, and SQL Server 2000, IIS 6.0, and Windows 2003 for the server infrastructure. Some of the steps will be slightly different on Windows Server 2000, so check the documentation if you are using that version of the server.

Secure Infrastructure Topology
Our previous solution used some less-than-secure coding and infrastructure practices to get the functional side of things up and running. We leveraged Anonymous authentication when connecting to the SSCE virtual directory via HTTP and we left the data transfer open to prying eyes by sending the data over the wire unencrypted. We used sa/password as our account for accessing the data and passed that account information over the wire as plain text. All of this should leave a modern developer queasy when imagining such practices in production. Let's take a look at a functional and secure way of delivering this functionality.

As we learned in the first article, using SSCE gives you the advantage of using existing infrastructure to create the solution, most notably using IIS 6.0 and Web infrastructure as the means of communication between the device and server, as well as leveraging SQL Server functionality such as replication. It should come as no surprise that we'll be securing our mobile data solution using security concepts that are well known to .NET developers, including IIS authentication/authorization, as well as SQL Server replication security features.

Figure 1 illustrates the topology of our secure solution. We'll authenticate users using IIS and Basic authentication. Once authenticated, we'll use NTFS security to provide authorization to resources such as the virtual directory and the server agent ISAPI DLL. Note: Since we're using Basic authentication with IIS, we'll need to configure our server to use HTTPS/SSL for communications to protect the account information as it moves over the wire. (Basic authentication works for the Internet, but sends authentication information over the wire as clear text.) HTTPS/SSL will also protect the data as it moves between the device and the server. The UI will be modified to prompt for account information and will use that account information for all communications with IIS 6.0, as well as SQL Server.


Securing Your SQL Server Database
We'll start by securing access to our database by allowing only specific users access to the database. Using SQL Server Enterprise Manager and the SimpleSSCEExample database we created last time, create two accounts on your server machine for testing, UserCanAccess and UserCannotAccess. Give each user a strong password. Add both accounts to SQL Server as logins and add the UserCanAccess account to the SimpleSSCEExample as a User with the proper permissions for accessing the database, including inserts, updates, and deletes. At this point, we have one user who can access the database via RDA, and one who cannot. Remember that RDA just passes SQL statements to SQL Server, and does not have any explicit security features itself. If the user is authenticated and has rights to the database he or she can pull and push data between device and server.

On the other hand, replication lets you differentiate users who can access the database and users who can access the publication. We'll restrict access to the Publication and the Publication Articles, so that only specifically authenticated users can transfer data via merge replication. Select the SimpleSSCEExamplePub and open the Properties dialog. Click on the Publication Access List tab, click Add, and select <MyMachineName> \UserCanAccess and click OK. Now only UserCanAccess can access the publication. Next, we'll use the Check Permissions option on the publication articles themselves to further refine who can or cannot merge data with the publication database. Click the Articles tab and click the ellipses button next to each article. While in the Article dialog, click the Merging Changes tab and select INSERT, UPDATE and DELETE. This change forces a check on whether the authenticated user has rights to change data via Insert, Update, and Delete statements. Use this feature to refine which modifications are allowed on each article via replication. This is a great way to differentiate between users who can pull down data for viewing and those who can modify data via replication (and to what level). Click Apply.

Using IIS 6.0 Basic Authentication and SSL
Now that we have the database configured for access to authorized users, we need to configure the virtual directory for authentication. We'll do this without the wizards so we can discuss each step of the process and how it impacts our infrastructure.

Start by opening the SQL Server CE Connectivity MMC and deleting the current SimpleSSCEExampleSynch entry. Also delete the virtual directory folder.

Next, open IIS Manager and create a new virtual directory named SimpleSSCEExampleSynch and map it to a directory on your machine with the same name, such as c:\SimpleSSCEExampleSynch. Copy the SSCE Server Agent DLL, sscesa20.dll, to this location (it can be found on a machine with SSCE server components installed under C:\Program Files\Microsoft SQL Server CE 2.0\Server) and give the virtual directory Execute permissions.

With the virtual directory in place, configure IIS 6.0 so that we can identify who is requesting access to the server agent and then limit execution rights to users of the system. We'll do this using Basic authentication. In IIS Manager, select the SimpleSSCEExampleSynch virtual directory and open the Properties page. Select the Directory Security tab in the Properties dialog and click the Edit button under Authentication and Access Control group. Make sure that only Basic authentication is selected and note the warning about sending authentication information over the wire as clear text. In order to use Basic authentication in a secure manner, we'll need to configure SSL as well to protect the transmission. Utilizing SSL in this manner will also protect the transmission of data between the device and the server agent endpoint.

In order to do this, you'll need to install a server certificate on your server. See the IIS documentation on how to set up SSL with server certificates. Once you have a certificate installed, click Edit under Secure Communications in order to configure SSL. Select Require Secure Channel and Require 128-bit encryption. Click OK until the Properties dialog is dismissed.

Now that we've set up the authentication of our users, we need to enable execution of the sscesa20.dll and enable the proper NTFS permissions for exchanging data. Browse to the directory that is mapped to the SimpleSSCEExampleSych virtual directory in Windows Explorer and right-click on folder to access the Properties dialog. Grant read and write NTFS permissions to the UserCanAccess account for this folder so that intermediate files can be placed in this folder by sscesa20.dll. Open the folder and grant read and execute NTFS permissions to the sscesa20.dll for the same account so this DLL can execute under the authenticated identity of our UserCanAccess account. You'll need to do this for each user, or preferably create a role for the users and add users to that role.

In this example I'm running Windows Server 2003, so I'll need to add sscesa20.dll as a Web extension in IIS 6.0. IIS 6.0 by default will not allow dynamic content, including ISAPI DLLs, to be served until you enable it. Open IIS 6.0, select the Web Service Extensions folder, and click the link for Add a new Web Service Extension. Give the new extension the name SecureSSCESynch and browse to the sscesa20.dll in our virtual directory to designate which DLL is allowed as the Web extension. Also set the Set Extension status to Allowed so the DLL will be allowed to execute out of the gate.

Now that we have the virtual directory covered, we'll further lock down our infrastructure by configuring a specific snapshot folder for intermediate files during replication and restrict access to that folder. Since the sscesa20.dll will run under the account that has been authenticated by IIS, we'll need to provide read access to the snapshot folder for each account that will perform replication. Create a shared folder called SimpleSSCEExample_Snap shot. Give UserCanAccess read access to the folder. Also give full control to the account that the SQL Server Service and SQL Server Agent will run under.

Finally, point the SecureSSCEPub publication to use the SimpleSSCEExample_Snapshot folder. Open Enterprise Manager, open the Properties dialog, uncheck Generate snapshots in the normal snapshot location, check Generate snapshots in the following location, designate \\<MyServerName>\ C$\Sim pleSSCEExample_Snapshot as the new location, and click Apply.

Checking your work at this point is a good idea. Open IE on your development machine and on your device and browse to https://<MyServerName>/SSCEExampleSynch/sscesa20.dll. You should be prompted to enter your account info. Enter the UserCanAccess account and then the UserCannotAccess account to make sure that authorized users have access to the SSCE Server Agent virtual directory. You know you've got the configuration right when UserCanAccess gets the message "SQL Server CE Server Agent" when browsing to the virtual directory directly.

Securing the SSCE Application Code
In this step we'll take a look at the code that's needed to access the secure connection to the server. First, we'll modify the UI to request user name and password. Open the SSCEExample.sln you created in VS.NET 2003 from our previous article and drop the controls described in Table 1 onto the form.


Now let's modify the code step by step, making our mobile application more secure while fixing security faux pas that we made while getting things up and running. First, let's correct the connection string we used as the olddbConnectionString parameter when using RDA to execute SQL statements on our remote server. Compare the connection strings shown in Listing 1.

The commented-out version is abysmal. It uses SQL Authentication and sa/password (the insecure developer's "dirty little secret" to get things running). The new version is much more secure. It uses the setting "Integrate Security = SSPI", which uses the current authenticated user (running sscesa20.dll in IIS) as the identity to pass to SQL Server. It also uses the setting "Persist Security Info=False", which prevents the account information from being returned in the result of the connection being made. So already we've avoided a password in our code and we're using the authenticated user's account to flow authorization. That's a good start.

Next, we need to change our code to use SSL and provide the account information that we'll use to authenticate our user with IIS and SQL Server 2000. Take a look at the code in Listing 2 to see the changes to our RDA code.

This is straightforward; we just need to point our instance of the SqlCeRemoteDataAccess class to the new URL that is protected via SSL encryption and the account information via the InternetLogin and InternetPassword properties of that class. That's it for RDA. You can run the solution and click on the RDA button to check your work.

To finish up replication, we need to make a few more changes to the code behind the corresponding button and our usage of the SqlCeReplication class. Take a look at the code in Listing 3.

Again, these simple code changes correspond to our infrastructure changes, including the usage of SSL reflected in the InternetURL property and the inclusion of account information in the InternetLogin and InternetPassword properties. Note: We're getting rid of another security "worst practice" by changing the PublisherSecurityMode setting to SecurityType.NTAuthentication in order to flow the NT account information provided earlier and to avoid the propagation of sa/password usage.

That's the final code change. Run the solution using the UserCanAccess account we've set up and test the exchange of data between the device and server. Also check to make sure that unauthorized accounts cannot access the server data and add some useful exception handling for the exceptions that are raised. If you have issues, take a look at SQL Server CE 2.0 Books Online (Click Here!) for troubleshooting information and recheck your infrastructure settings. Often a single check box setting can make all the difference with security-based code if things don't work out on the first try.

Now we have a solution that is both functional and secure, which is what we set out to do. We've restricted access to our server by requiring that users authenticate when using either RDA or replication. We used encryption via SSL to ensure that both account information and our data is protected as it moves across the wire. We also managed permissions on server resources to grant the least-required permissions to get the solution up and running. From there it was just a matter of some simple code changes.

Now we have the best of both worlds, mobile device access to our enterprise data, as well as the confidence that our data and server can be accessed only by legitimate users. Take this code and integrate it into your infrastructure to add to your solutions the "wow factor" that only mobile development can add.

Please note that the ideas, opinions, and information contained in this article are those of the writers, not of Microsoft Corporation.

More Stories By Chris Mayo

Chris Mayo is a .NET developer evangelist based in the Midwest. Chris has over 10 years experience developing enterprise software as a developer and an architect. His experience dates back to the days of VB 2.0 and includes development on the COM(+), .NET, and J2EE platforms. As the local .NET developer evangelist, Chris speaks at INETA, VS, and .NET user group meetings; the MSDN series; and conferences such as VSLive! and DevDays.

Comments (0)

Share your thoughts on this story.

Add your comment
You must be signed in to add a comment. Sign-in | Register

In accordance with our Comment Policy, we encourage comments that are on topic, relevant and to-the-point. We will remove comments that include profanity, personal attacks, racial slurs, threats of violence, or other inappropriate material that violates our Terms and Conditions, and will block users who make repeated violations. We ask all readers to expect diversity of opinion and to treat one another with dignity and respect.

@ThingsExpo Stories
Artificial intelligence, machine learning, neural networks. We’re in the midst of a wave of excitement around AI such as hasn’t been seen for a few decades. But those previous periods of inflated expectations led to troughs of disappointment. Will this time be different? Most likely. Applications of AI such as predictive analytics are already decreasing costs and improving reliability of industrial machinery. Furthermore, the funding and research going into AI now comes from a wide range of com...
"When we talk about cloud without compromise what we're talking about is that when people think about 'I need the flexibility of the cloud' - it's the ability to create applications and run them in a cloud environment that's far more flexible,” explained Matthew Finnie, CTO of Interoute, in this SYS-CON.tv interview at 20th Cloud Expo, held June 6-8, 2017, at the Javits Center in New York City, NY.
The current age of digital transformation means that IT organizations must adapt their toolset to cover all digital experiences, beyond just the end users’. Today’s businesses can no longer focus solely on the digital interactions they manage with employees or customers; they must now contend with non-traditional factors. Whether it's the power of brand to make or break a company, the need to monitor across all locations 24/7, or the ability to proactively resolve issues, companies must adapt to...
Internet of @ThingsExpo, taking place October 31 - November 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA, is co-located with 21st Cloud Expo and will feature technical sessions from a rock star conference faculty and the leading industry players in the world. The Internet of Things (IoT) is the most profound change in personal and enterprise IT since the creation of the Worldwide Web more than 20 years ago. All major researchers estimate there will be tens of billions devic...
SYS-CON Events announced today that MobiDev, a client-oriented software development company, will exhibit at SYS-CON's 21st International Cloud Expo®, which will take place October 31-November 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. MobiDev is a software company that develops and delivers turn-key mobile apps, websites, web services, and complex software systems for startups and enterprises. Since 2009 it has grown from a small group of passionate engineers and business...
SYS-CON Events announced today that GrapeUp, the leading provider of rapid product development at the speed of business, will exhibit at SYS-CON's 21st International Cloud Expo®, which will take place October 31-November 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. Grape Up is a software company, specialized in cloud native application development and professional services related to Cloud Foundry PaaS. With five expert teams that operate in various sectors of the market acr...
SYS-CON Events announced today that Ayehu will exhibit at SYS-CON's 21st International Cloud Expo®, which will take place on October 31 - November 2, 2017 at the Santa Clara Convention Center in Santa Clara California. Ayehu provides IT Process Automation & Orchestration solutions for IT and Security professionals to identify and resolve critical incidents and enable rapid containment, eradication, and recovery from cyber security breaches. Ayehu provides customers greater control over IT infras...
In this presentation, Striim CTO and founder Steve Wilkes will discuss practical strategies for counteracting fraud and cyberattacks by leveraging real-time streaming analytics. In his session at @ThingsExpo, Steve Wilkes, Founder and Chief Technology Officer at Striim, will provide a detailed look into leveraging streaming data management to correlate events in real time, and identify potential breaches across IoT and non-IoT systems throughout the enterprise. Strategies for processing massive ...
SYS-CON Events announced today that Cloud Academy named "Bronze Sponsor" of 21st International Cloud Expo which will take place October 31 - November 2, 2017 at the Santa Clara Convention Center in Santa Clara, CA. Cloud Academy is the industry’s most innovative, vendor-neutral cloud technology training platform. Cloud Academy provides continuous learning solutions for individuals and enterprise teams for Amazon Web Services, Microsoft Azure, Google Cloud Platform, and the most popular cloud com...
In his session at Cloud Expo, Alan Winters, an entertainment executive/TV producer turned serial entrepreneur, presented a success story of an entrepreneur who has both suffered through and benefited from offshore development across multiple businesses: The smart choice, or how to select the right offshore development partner Warning signs, or how to minimize chances of making the wrong choice Collaboration, or how to establish the most effective work processes Budget control, or how to ma...
SYS-CON Events announced today that Enzu will exhibit at SYS-CON's 21st Int\ernational Cloud Expo®, which will take place October 31-November 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. Enzu’s mission is to be the leading provider of enterprise cloud solutions worldwide. Enzu enables online businesses to use its IT infrastructure to their competitive advantage. By offering a suite of proven hosting and management services, Enzu wants companies to focus on the core of their ...
We build IoT infrastructure products - when you have to integrate different devices, different systems and cloud you have to build an application to do that but we eliminate the need to build an application. Our products can integrate any device, any system, any cloud regardless of protocol," explained Peter Jung, Chief Product Officer at Pulzze Systems, in this SYS-CON.tv interview at @ThingsExpo, held November 1-3, 2016, at the Santa Clara Convention Center in Santa Clara, CA
With major technology companies and startups seriously embracing Cloud strategies, now is the perfect time to attend 21st Cloud Expo October 31 - November 2, 2017, at the Santa Clara Convention Center, CA, and June 12-14, 2018, at the Javits Center in New York City, NY, and learn what is going on, contribute to the discussions, and ensure that your enterprise is on the right path to Digital Transformation.
SYS-CON Events announced today that IBM has been named “Diamond Sponsor” of SYS-CON's 21st Cloud Expo, which will take place on October 31 through November 2nd 2017 at the Santa Clara Convention Center in Santa Clara, California.
SYS-CON Events announced today that CA Technologies has been named "Platinum Sponsor" of SYS-CON's 21st International Cloud Expo®, which will take place October 31-November 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. CA Technologies helps customers succeed in a future where every business - from apparel to energy - is being rewritten by software. From planning to development to management to security, CA creates software that fuels transformation for companies in the applic...
Amazon started as an online bookseller 20 years ago. Since then, it has evolved into a technology juggernaut that has disrupted multiple markets and industries and touches many aspects of our lives. It is a relentless technology and business model innovator driving disruption throughout numerous ecosystems. Amazon’s AWS revenues alone are approaching $16B a year making it one of the largest IT companies in the world. With dominant offerings in Cloud, IoT, eCommerce, Big Data, AI, Digital Assista...
Multiple data types are pouring into IoT deployments. Data is coming in small packages as well as enormous files and data streams of many sizes. Widespread use of mobile devices adds to the total. In this power panel at @ThingsExpo, moderated by Conference Chair Roger Strukhoff, panelists looked at the tools and environments that are being put to use in IoT deployments, as well as the team skills a modern enterprise IT shop needs to keep things running, get a handle on all this data, and deliver...
In his session at @ThingsExpo, Eric Lachapelle, CEO of the Professional Evaluation and Certification Board (PECB), provided an overview of various initiatives to certify the security of connected devices and future trends in ensuring public trust of IoT. Eric Lachapelle is the Chief Executive Officer of the Professional Evaluation and Certification Board (PECB), an international certification body. His role is to help companies and individuals to achieve professional, accredited and worldwide re...
With the introduction of IoT and Smart Living in every aspect of our lives, one question has become relevant: What are the security implications? To answer this, first we have to look and explore the security models of the technologies that IoT is founded upon. In his session at @ThingsExpo, Nevi Kaja, a Research Engineer at Ford Motor Company, discussed some of the security challenges of the IoT infrastructure and related how these aspects impact Smart Living. The material was delivered interac...
IoT solutions exploit operational data generated by Internet-connected smart “things” for the purpose of gaining operational insight and producing “better outcomes” (for example, create new business models, eliminate unscheduled maintenance, etc.). The explosive proliferation of IoT solutions will result in an exponential growth in the volume of IoT data, precipitating significant Information Governance issues: who owns the IoT data, what are the rights/duties of IoT solutions adopters towards t...