Windows Mobile Support

  • Subscribe to our RSS feed.
  • Twitter
  • StumbleUpon
  • Reddit
  • Facebook
  • Digg

Monday, 18 June 2012

How to secure connection string of a SQL server in a Winwdows Azure application

Posted on 04:41 by Unknown

As in any application, when developing applications for Windows Azure that use SQL Azure, the security of connection string appear (especially database user password) when the application begin to be deployed on the testing or production environment. In this post I will try to offer a solution about how we can secure the connection string.
Usually when we get to the end of a project and our application begin to be deployed on the production environment also, we need to separate each database (development, testing and production). For safety reason we need to use different connection string for each environment that we used. In this moment we don’t want to allow development team to access the production or testing environment. Because of this we need to secure the connection string.
Why is this so important? For example what happen if we are in maintenance with our application and the developer have access to sensitive information? We don’t want this to happen, especially when we store on the database passwords, salaries and so on.
Normally between our company and our client we have a SLA. Also another SLA exists between our company and each developer, but this is not enough. If we can we need to secure access because we need to reduce the risk of someone accessing our client data. If you think that you will increase the database security by encrypting the database password from connection string, you need to know that this is not truth. When someone will be able to access the machine where the application is hosted that we can decrypt the connection string, is only a matter of time.
We want to encrypt the connection string of production environment only for our team (development or testing team). Maybe we have a source control where we store the configuration file and we don’t want to have this information stored in clear text. The solution that I will explain in the next lines can be used only with the condition that out team doesn’t have access to the production servers. In some conditions, the only think that we want to let them to have access is to make a “fast” deploy of the application but without any remote access rights on the Windows Azure machines.
I propose a solution that is based on certificates. Because a certificate can have a public or a private key, we can share this information in such way that the team can only create and prepare our application package, but without any rights to decrypt or use the connection string of the production environment.
Our team (development for example) will have only the public key. Based on this key they will be able to generate the application package that will be used for deployment. Our SQL engineer for example will have access to the public key of the certificate. Based on the public key, the connection string will be encrypted. Any person that will have the public key will not be able to decrypt the connection string.
On our production environment we need to install the private key. Only the person/environment that has the private key of the certificate can decrypt the connection string.
In the next part of the post I will try to explain each step that need to be done to encrypt the connection string and how to generate the certificate.
The first step is to create a signed certificate. This certificate can be created in different methods. One method is to use the “makecert” command from Visual Studio. A password will be required to enter when you will run this command. This password will be used to secure the generated key that is created when the certificate is generated.
akecert -r -pe -n "CN=mysecureconfig" -sky exchange "mysecureconfig.cer" -sv "mysecureconfig.pvk"
pvk2pfx -pvk "mysecureconfig.pvk" -spc "mysecureconfig.cer" -pfx "mysecureconfig.pfx" -pi mysecretpassword
 "mysecureconfig.cer" represents our certificate that will be created (the public key). This file will be used by our SQL administrator to encrypt the connection string.
"mysecureconfig.pvk" represent our private key that need to be installed only on the production environment. Try not to store this file in the same location where you have the source of our application, because in this case the developers will have access to this key and they will be able to decrypt the connection string.
The next step is to generate a certificate of type .pfx. This will be used to import our certificate and the private key on Windows Azure. Now we have the .pfx file and we can import the certificate to cloud. To do this, we need to access the “Certificate” tab from Windows Azure. On this page we can upload our certificate. At this step, we will need to introduce the certificate password that we entered when we created the certificate.
The output of this import will be a thumbprint. This thumbprint need to be added to our application configuration file. Based on this thumbprint, our application will have access to our private key and will be able to decrypt the connection string.
At this step I want to remind you that the SQL administrator will need only the public key. The private key doesn’t need to be shared with anyone. Also, the database user from the connection string needs to have only the right that is needed by our application.
The third step is the most interesting one. In our configuration file of our application we need to add our connection string with user and password. Besides this information we will need to add a new provider that will be used to protect our data (in our case the connection string).
<configProtectedData>

    <providers>

      <add name="PKCS12ProtectedConfigurationProvider" 
           thumbprint="myThumbprintFromWindowsAzurePortal"
           type="Pkcs12PrLinkotectedConfigurationProvider.
                      Pkcs12ProtectedConfigurationProvider, 
           PKCS12ProtectedConfigurationProvider, 
           Version=1.0.0.0, Culture=neutral, 
           PublicKeyToken=34da007ac91f901d"/>

    </providers>

  </configProtectedData>
If you don’t have this provider (PKCS12ProtectedConfigurationProvider) installed on your system, you can download it from the following address: http://archive.msdn.microsoft.com/pkcs12protectedconfg.
Before the last step, I want to make a recap of what we need to have on the machine that wills encrypted the connection string:
  1. The certificate that we created installed (only the public key)
  2. The PKCS12ProtectedConfigurationProvider provider installed
  3. The provider that is used to encrypt the data added to the configuration file
  4. The connection string added to our configuration file (with user and password in clear – for now only)
Now, we can do the last step – to run from Visual Studio command prompt the following command:
aspnet_regiis -pef "connectionStrings" "." -prov 
"PKCS12ProtectedConfigurationProvider"
What does this command do? This command will encrypt the connection string based on our certificate. The only location from where this connection string can be decrypted is the machine that has the private key installed.
After this command is run, in the configuration file we will have the connection string encrypted. Don’t forget to add the following assembly to your solution: “PKCS12ProtectedConfigurationProvider.dll”, because the web role or the worker role will not have provider preinstalled.
Using this method, we can hide the database credentials from the production or testing environment from the development team. Even if they will see the connection string, they will see encrypted data and without the private key they cannot see the user and password.
What do you think about this solution? What other solution did you used for this case?
I decided to translate one of my blog posts in English: http://vunvulearadu.blogspot.ro/2012/06/how-to-secure-connection-string-of-sql.html
Email ThisBlogThis!Share to XShare to FacebookShare to Pinterest
Posted in Azure, connection string, sql, Sql Azure, Windows Azure | No comments
Newer Post Older Post Home

0 comments:

Post a Comment

Subscribe to: Post Comments (Atom)

Popular Posts

  • Service Bus Topic - Automatic forward messages from a subscription to a topic
    Windows Azure Service Bus Topic is a service that enables us to distribute the same messages to different consumers without having to know e...
  • CDN is not the only solution to improve the page speed - Reverse Caching Proxy
    I heard more and more often think like this: “If your website is to slow, you should use a CDN.” Great, CDN is THE solution for any kind of ...
  • Content Types - Level 6: Rich Media
    Level 6: Rich Media NOTE: This is part 7 of 7 and the conclusion of this continuing series; please see earlier posts for more background inf...
  • Publishing our CellCast Widget for iPad
    The rush has been on this week as our development team worked to design a new version of our CellCast Widget specifically for Apple's up...
  • Patterns in Windows Azure Service Bus - Message Splitter Pattern
    In one of my post about Service Bus Topics from Windows Azure I told you that I will write about a post that describe how we can design an a...
  • E-Learning Vendors Attempt to Morph Mobile
    The sign should read: " Don't touch! Wet Paint !" I had a good chuckle today after receiving my latest emailed copy of the eLe...
  • SQL - UNION and UNION ALL
    I think that all of us used until now UNION in a SQLstatement. Using this operator we can combine the result of 2 queries. For example we wa...
  • Cum sa salvezi un stream direct intr-un fisier
    Cred ca este a 2-a oara când întâlnesc aceasta cerința in decurs de câteva săptămâni. Se da un stream și o locație unde trebuie salvat, se c...
  • Task.Yield(...), Task.Delay(...)
    I think that a lot of person already heard about these new methods. In this post I want to clarify some things about these new methods that ...
  • Content Types - Level 4: Reference
    Level 4: Reference Materials & Static Content NOTE: This is part 5 of 7 in a continuing series; please see earlier posts for more backgr...

Categories

  • .NET
  • .NET nice to have
  • #if DEBUG
  • 15 iunie 2011
  • 15 octombrie 2011
  • 2011
  • abstracta
  • action
  • adaugare
  • ajax
  • Amsterdam
  • Android
  • aplicatii
  • App Fabric
  • Apple iSlate
  • array
  • as
  • ASP.NET
  • AsReadOnly
  • Assembly comun
  • async
  • Asynchronous programming
  • asyncron
  • Autofac
  • AutoMapper
  • az
  • Azure
  • Azure AppFabric Cache
  • Azure backup solution
  • Azure Storage Explorer
  • azure. cloud
  • backup
  • BCP utility
  • bing maps v7
  • BitArray
  • BlackBerry
  • blob
  • BlobContainerPublicAccessType
  • breakpoint
  • bucuresti
  • C#
  • cache
  • CallerMemberName
  • CellCast
  • Certificate
  • CES
  • change
  • ChannelFactory
  • clasa
  • classinitialize
  • clean code
  • click event
  • close
  • Cloud
  • Cluj
  • cluj-napoca
  • Code contracts
  • code retrat
  • codecamp
  • CollectionAssert
  • Compact Edition
  • compara
  • Comparer T .Default
  • CompareTo
  • comparison
  • comunitate
  • concurs
  • Conditional attribute
  • configurare
  • connection string
  • container
  • content type
  • control
  • Convert
  • convertAll
  • convertor
  • cross platform
  • CRUD
  • css
  • custom properties
  • custom request
  • DACPAC
  • Daniel Andres
  • data sync service
  • database
  • date time
  • datetime
  • debug
  • default
  • delegate
  • dependency injection
  • deploy
  • DeploymentItem
  • design patterns
  • Dev de Amsterdam
  • development stoage
  • dictionary
  • diferente
  • digging
  • director
  • Directory.Exist
  • disable
  • dispatcher
  • dispose
  • dropdown
  • dynamic
  • EF
  • email
  • encoding
  • entity framework
  • enum
  • enumerable
  • Environment.NewLine
  • error
  • error 404
  • error handling
  • eveniment
  • event
  • ews
  • excel
  • exception
  • exchange
  • exita
  • explicit
  • export
  • extension
  • field
  • File.Exist
  • finalize
  • fire and forget
  • Fluent interface pattern
  • format
  • func
  • GC.SuppressFinalize
  • generic
  • getdirectoryname
  • globalization
  • gmail
  • hackathon
  • Hadoop
  • handle
  • HTML
  • html 5
  • Html.ActionLink
  • http://www.blogger.com/img/blank.gif
  • HttpModule
  • IComparable
  • IE
  • ienumerable
  • IIS
  • image
  • implicit
  • import
  • int
  • internationalization
  • Internet Explorer
  • interop
  • Ioc
  • IP Filter
  • iPhone
  • iQuest
  • IStructuralEquatable
  • ITCamp
  • itspark
  • java script
  • javascript
  • July 2012
  • KeyedByTypeCollection
  • KeyNotFoundException
  • Kinect SDK
  • lambda expression
  • LightSwitch Microsoft Silverlight
  • linq
  • list
  • lista
  • lista servicii
  • liste
  • Live Connect
  • Live ID
  • load
  • localization
  • lock
  • m-learning
  • MAC
  • Mango
  • map
  • mapare
  • mapare propietati
  • messagequeue
  • meta properties
  • method
  • MethodImpl
  • Metro App
  • Microsoft
  • Microsoft Sync Framework
  • mlearning
  • mlearning devices
  • Mobile Apps
  • mobile in the cloud
  • mobile learning
  • mobile services
  • Mobile Web
  • mongoDb
  • monitorizare
  • msmq
  • multitasking
  • MVC
  • MVC 3
  • MVVM
  • namespace
  • nextpartitionkey
  • nextrowkey
  • Ninject
  • nivel acces
  • no result
  • normalize
  • nosql
  • null expcetion
  • null object pattern
  • NullReferenceException
  • OAuth API
  • office
  • offline
  • Open ID
  • openhackeu2011
  • operations
  • operator
  • optimization
  • option
  • outputcache
  • OutputCacheProvider
  • override
  • paginare
  • pagination
  • path
  • persistare
  • Portable Library tool
  • Post event – CodeCamp Cluj-Napoca
  • predicate
  • predictions
  • prezentare
  • process
  • proiect
  • property
  • propietati
  • query
  • ReadOnlyCollection
  • ReadOnlyDictionary
  • referinta
  • reflection
  • remote
  • reply command
  • request
  • request response
  • resouce
  • REST
  • REST Client
  • RESTSharp
  • ronua
  • rss
  • rulare
  • salvare in fisier
  • sc
  • schimbare timp
  • select
  • select nodes
  • send
  • serializare
  • serialization
  • Server.Transfer. Resposen.Redirect
  • service bus
  • ServiceBase
  • servicecontroller
  • sesiune
  • session
  • Session_End
  • Session_Start
  • setup
  • Sibiu
  • signalR
  • Silverlight
  • sincronizare
  • Single Responsibility Principle
  • SkyDrive
  • skype
  • smartphones
  • smtp
  • Snapguide
  • sniffer
  • socket
  • solid
  • spec#
  • sql
  • Sql Azure
  • SQL CE
  • sql server 2008 RC
  • SRP
  • startuptype
  • stateful
  • stateless
  • static
  • stergere
  • store
  • store procedure
  • stream
  • string
  • string.join
  • struct
  • StructuralEqualityComparer
  • submit
  • switch
  • Symbian
  • Synchronized
  • system
  • tabele
  • table
  • techEd 2012
  • tempdata
  • test
  • testcleanup
  • testinitialize
  • testmethod
  • thread
  • timer
  • ToLower
  • tool
  • tostring
  • Total Cost Calculator
  • trace ASP.NET
  • transcoding
  • tuplu
  • tutorial
  • TWmLearning
  • type
  • unit test
  • unittest
  • UrlParameter.Optional
  • Validate
  • validation
  • verificare
  • video
  • view
  • ViewBag
  • virtual
  • visual studio
  • VM role
  • Vunvulea Radu
  • wallpaper
  • WCF
  • WebBrower
  • WebRequest
  • where clause
  • Windows
  • windows 8
  • Windows Azure
  • Windows Azure Service Management CmdLets
  • windows live messenger
  • Windows Mobile
  • Windows Phone
  • windows service
  • windows store application
  • Windows Task
  • WinRT
  • word
  • workaround
  • XBox
  • xml
  • xmlns
  • XNA
  • xpath
  • YMesseger
  • Yonder
  • Zip

Blog Archive

  • ►  2013 (139)
    • ►  November (17)
    • ►  October (12)
    • ►  September (10)
    • ►  August (7)
    • ►  July (8)
    • ►  June (15)
    • ►  May (12)
    • ►  April (17)
    • ►  March (16)
    • ►  February (9)
    • ►  January (16)
  • ▼  2012 (251)
    • ►  December (9)
    • ►  November (19)
    • ►  October (26)
    • ►  September (13)
    • ►  August (35)
    • ►  July (28)
    • ▼  June (27)
      • Day 4 of TechEd 2012 - Amsterdam
      • Day 3 of TechEd 2012 - Amsterdam
      • Memento Pattern - the key to unde/redo functionality
      • Day 2 of TechEd 2012 - Amsterdam
      • Serie de turoriale despre debug in Visual Studio
      • Day 1 of TechEd 2012 - Amsterdam
      • How should we treat virtual methods exposed in API...
      • How should we treat virtual methods exposed in APIs
      • XXX takes a dependency on Microsoft.VCLibs.110 fra...
      • How to validate a Windows 8 application
      • Why I cannot use Live account on some Microsoft Se...
      • Applications bugs that can be caused by 'ref' keyword
      • Visual Studio debugging tips and tricks
      • New debugging functionalities in Visual Studio 2012
      • How to secure connection string of a SQL server in...
      • WTF - Package Load Failure - Microsoft.VisualStudi...
      • Some cool stuff debugging with Debugger Canvas
      • Debugging multithreaded applications in Visual Studio
      • Could this be a good case when to use 'params'
      • The provided URI scheme 'file' is invalid; expecte...
      • Base Visual Studio debugging functionalities
      • How to manual create and restore a database from S...
      • Fundamental books for a software engineer (developer)
      • Windows 2008 Server + Office 2007 = InteropService...
      • How to secure connection string of a SQL server in...
      • How to create a setup package for a Metro Applicat...
      • How to backup SQL Azure database using blobs or Da...
    • ►  May (24)
    • ►  April (18)
    • ►  March (17)
    • ►  February (20)
    • ►  January (15)
  • ►  2011 (127)
    • ►  December (11)
    • ►  November (20)
    • ►  October (8)
    • ►  September (8)
    • ►  August (8)
    • ►  July (10)
    • ►  June (5)
    • ►  May (8)
    • ►  April (9)
    • ►  March (14)
    • ►  February (20)
    • ►  January (6)
  • ►  2010 (26)
    • ►  December (1)
    • ►  November (1)
    • ►  October (1)
    • ►  June (2)
    • ►  May (1)
    • ►  April (4)
    • ►  March (1)
    • ►  February (1)
    • ►  January (14)
Powered by Blogger.

About Me

Unknown
View my complete profile