Programming, Sitecore

Encrypt And Decrypt A Sitecore ConnectionStrings.Config File

Encrypting .Net application web.config files are easy enough. However Sitecore is NOT a fan of you messing with the web.config. This is even part of the reason the connection strings are stored out into a separate file in Sitecore. I’ll go through a quick method of taking care of doing it on the separate Sitecore file.

  • Ensure you have .Net framework installed where you are going to perform the encryption (my examples are 4.0, you can use 2.0 if need be)
  • !!!IMPORTANT!!! Make a backup of your Sitecore ConnectionStrings.config file
  • Create a folder on C: to hold your encrypt/decrypt batch files (example will be C:\decrypter) where the .Net framework exists
  • Open notepad and create a batch file (encrypt.bat), put the following in for your encryption statement and then save it to your folder you just created
echo Encrypting app_config/connectionstrings.config
 C:\Windows\Microsoft.NET\Framework64\v4.0.30319\aspnet_regiis.exe -pef "connectionStrings" "C:\decrypter"
 Pause
  • Repeat this step for the decryption statement (decrypt.bat)
echo Encrypting app_config/connectionstrings.config
 C:\Windows\Microsoft.NET\Framework64\v4.0.30319\aspnet_regiis.exe -pdf "connectionStrings" "C:\decrypter"
 Pause
  • Create a blank web.config (THIS IS YOUR WEB.CONFIG YOU MADE AND NOT THE SITECORE WEB.CONFIG!!!), put and wrap your Sitecore connection strings (from ConnectionStrings.config) inside and save it to the folder you created. it should look something like:
<?xml version="1.0" encoding="utf-8"?>
 <configuration>
 <connectionStrings>
 <add name="core" connectionString="user id=sitecoreuser;password=sitecorepw;Data Source=servernameorip;Database=Sitecore_Core" />
 <add name="master" connectionString="user id=sitecoreuser;password=sitecorepw;Data Source=servernameorip;Database=Sitecore_Master" />
 <add name="web" connectionString="user id=sitecoresql;password=sitecorepw;Data Source=servernameorip;Database=Sitecore_Web" />
 <add name="reporting" connectionString="user id=sitecoresql;password=sitecorepw;Data Source=servernameorip;Database=Sitecore_Analytics" />
 </connectionStrings>
 </configuration>
  •  Once you have both batch files and the web.config then run the encrypt batch file as an administrator. It will look something like this:

encrypt

  • You’ll then have a web.config in your folder now similar to this:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<connectionStrings configProtectionProvider="RsaProtectedConfigurationProvider">
<EncryptedData Type="http://www.w3.org/2001/04/xmlenc#Element"
xmlns="http://www.w3.org/2001/04/xmlenc#">
<EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#tripledes-cbc" />
<KeyInfo xmlns="http://www.w3.org/2000/09/xmldsig#">
<EncryptedKey xmlns="http://www.w3.org/2001/04/xmlenc#">
<EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#rsa-1_5" />
<KeyInfo xmlns="http://www.w3.org/2000/09/xmldsig#">
<KeyName>Rsa Key</KeyName>
</KeyInfo>
<CipherData>
<CipherValue>(you'll have a long cipher here)</CipherValue>
</CipherData>
</EncryptedKey>
</KeyInfo>
<CipherData>
<CipherValue>(you'll have a long cipher here)</CipherValue>
</CipherData>
</EncryptedData>
</connectionStrings>
</configuration>
  • Once completed take the connectionStrings section of the web.config and replace your ConnectionStrings.config file with the encrypted connectionStrings section (run notepad in admin mode if your sitecore is in the web root).
  • Recycle the app pool to refresh. You should now be encrypted!
  • If this fails for you at some point then replace your Sitecore connectionStrings.config file with the backup you took at the start.
  • And yes, to decrypt (to update your strings) put your encrypted connectionstrings section in your web.config (THIS IS YOUR WEB.CONFIG YOU MADE AND NOT THE SITECORE WEB.CONFIG!!!) in the windows folder you made and run the decrypt.bat as an admin. You should get:

decrypt

Again, I hope this helps someone. Questions and comments are always welcome! And for the sake of hoping I catch the skimmers here, DO NOT MODIFY THE SITECORE WEB.CONFIG. DO THIS ON THE CONNECTIONSTRINGS.CONFIG! You have been warned…

MongoDB, Sitecore

Connect Sitecore xDB To A MongoDB On Rackspace’s ObjectRocket Platform With SSL

This was a fun experience. Anyway, let’s go. Got a 5GB $149/mo Medium pricing package from Object Rocket (Note: Small does not have SSL in its package).

ORPricing

So after you get someone to kindly pay for your package then you will get a login to Object Rocket and (more importantly) the ability to create a mongodb instance:

instance

Then once you have your instance you can create your user to add to the instance:

adduser

Once you have an instance and a user added to it then grab your SSL address:

address

So now you have instance databases, a database user, and a SSL address to connect to. From here we move to Sitecore. For the sake of keeping this short we are going to assume you have Sitecore Analytics enabled in your instance.

Once you have worked your magic then navigate to your ConnectionStrings.config (located in your web root/Website/App_Config and add the connection strings for the four pieces (analytics, tracking.live, tracking.history, and tracking.contact):

<add name="analytics" connectionString="mongodb://easyaspieuser:easyaspiepassword@iad-mongos2.objectrocket.com:25123/EASYASPIE_analytics?ssl=true;sslverifycertificate=false" />
<add name="tracking.live" connectionString="mongodb://easyaspieuser:easyaspiepassword@iad-mongos2.objectrocket.com:25123/EASYASPIE_live?ssl=true;sslverifycertificate=false" />
<add name="tracking.history" connectionString="mongodb://easyaspieuser:easyaspiepassword@iad-mongos2.objectrocket.com:25123/EASYASPIE_tracking_history?ssl=true;sslverifycertificate=false" />
<add name="tracking.contact" connectionString="mongodb://easyaspieuser:easyaspiepassword@iad-mongos2.objectrocket.com:25123/EASYASPIE_tracking_contact?ssl=true;sslverifycertificate=false" />

A couple things of note:

  • ssl=true indicates to sitecore and mongo that you are going to connect with SSL.
  • You can test your connection with a tool like Robomongo or Mongovue.
  • If you have an instance that has a network appliance in front of it (like in my case) then you will need to add sslverifycertificate=false to keep the SSL connection from trying to read a .pem file from you.
  • Parameters you pass need to be separated by a semi-colon. Yes, I thought ampersand as well (and even see it documented as such here). ObjectRocket was kind enough to help me figure that out.
  • If you are in a DMZ that is heavily firewalled then you will need the port number firewall exception put in for you (for my example it would be TCP 25123)
  • Troubleshoot by reading the Sitecore logs (usually located in your website instance/data/logs/)

Getting a successful connection will bring up data:

analytics

I hope this helps, questions are welcome!

Sitecore, Web

Sluggish Sitecore Development Environment? Here’s An Easy Method To Disable Sitecore Analytics

When you install a new 8.0 instance of Sitecore you will find the site can be laggy and sluggish to load. To speed up your dev environment I would recommend this easy fix.

First create a folder called z in your app config sitecore path: C:\inetpub\wwwroot\yoursitecore\Website\App_Config\z

Then, create a file called zwoa.config and paste the following in:

<configuration xmlns:patch="<a href="http://www.sitecore.net/xmlconfig/">http://www.sitecore.net/xmlconfig/</a>">
 <sitecore>
 <pipelines>
 <initialize>
 <processor type="Sitecore.Pipelines.Initialize.PrecompileSpeakViews, Sitecore.Speak.Clientpro" >
 <patch:delete />
 </processor>
 <processor type="Sitecore.ContentTesting.Pipelines.Initialize.RegisterContentTestingCommandRoute, Sitecore.ContentTesting" >
 <patch:delete />
 </processor>
 <processor type="Sitecore.Pipelines.Initialize.PrecompileSpeakViews, Sitecore.Speak.Client" use="ContentTesting" >
 <patch:delete />
 </processor>
 </initialize>
 <mvc.renderPageExtenders>
 <processor patch:after="processor[@type='Sitecore.Mvc.ExperienceEditor.Pipelines.RenderPageExtenders.RenderExtendersContainer, Sitecore.Mvc.ExperienceEditor']" type="Sitecore.Mvc.ExperienceEditor.Pipelines.RenderPageExtenders.RenderPageEditorExtender, Sitecore.Mvc.ExperienceEditor"></processor>
 <processor patch:after="processor[@type='Sitecore.Mvc.ExperienceEditor.Pipelines.RenderPageExtenders.RenderExtendersContainer, Sitecore.Mvc.ExperienceEditor']" type="Sitecore.Mvc.ExperienceEditor.Pipelines.RenderPageExtenders.RenderPreviewExtender, Sitecore.Mvc.ExperienceEditor"></processor>
 <processor patch:after="processor[@type='Sitecore.Mvc.ExperienceEditor.Pipelines.RenderPageExtenders.RenderExtendersContainer, Sitecore.Mvc.ExperienceEditor']" type="Sitecore.Mvc.ExperienceEditor.Pipelines.RenderPageExtenders.RenderDebugExtender, Sitecore.Mvc.ExperienceEditor"></processor>
 <processor type=""Sitecore.Mvc.ExperienceEditor.Pipelines.RenderPageExtenders.SpeakRibbon.RenderPageEditorSpeakExtender, Sitecore.Mvc.ExperienceEditor" >
 <patch:delete />
 </processor>
 </mvc.renderPageExtenders>
 </pipelines>
 <settings>
 <setting name="Analytics.Enabled" > <patch:attribute name="value" value="false" />
 </setting>
 </settings>
 </sitecore>
 </configuration>

Refresh your Sitecore in a web browser and watch it go!