Working with encrypted values in SugarCRM 6.5

SugarCRM comes with a variety of modules that store values in the database.  Some of those values are encrypted.  For example, mailbox passwords for inbound and outbound email configurations.

When you create this configurations through the web interface or the API, you don’t need to worry about encryption, as SugarCRM handles that all by itself.  But sometimes, you need to access those values from third-party code.  The easiest way would be of course to use the same API functionality, but this is not always possible (different machines, different technology stack, etc).

It is still possible decrypt the values in the database, if you know where to look.

First of all, here is a little side note for InboundEmail and OutboundEmail modules.  InboundEmail is a full-featured module, which you can find in modules/InboundEmail folder.  OutboundEmail is however not – it lives in include/OutboundEmail .  This might seem surprising, but the reason for this (probably, as I don’t know for sure) is that outbound email configuration is much simpler.  Inbound emails are linked with folders, which are then used to subscribe users, etc.  Outbound emails are just SMTP configurations to use, directly linked to users.

Anyways.  Let’s get back on track.

Most of the encryption and decryption magic happens in include/utils/encryption_utils.php.  If you look through the code, you’ll notice that it deals with mostly two things:

  1. Generating or reading an existing encryption key.
  2. Encrypting or decrypting text with Blowfish, using the encryptionkey.

Encryption keys are stored in custom/blowfish/ folder.  The files that you’ll find there have weird names and a .php extension.  The name of the file comes from the module, for which the key will be used.  ROT13 algorithm is used to convert the name of the module into the file name.  (Note, that for outbound email, the name of the module is OutBoundEmail, not OutboundEmail).

If the encryption key file does not exist, a new one will be generated.  The file will contain a PHP snippet like this:

<?php // created: 2016-04-18 10:00:00 
  $key = array ( 0 => 'a0a0a0a0-b1b1-c3c3-d4d4-e5e5e5e5e5e5',
);

If you accidentally remove the file, then you won’t be able to decrypt any of the values, encrypted with this key, so make sure you backup this up.  Especially considering that this folder might be in your .gitignore, as a sub-folder of custom/ which stored lots of auto-generated stuff.

Note that the file actually defines a $key variable, which, if you will include it in your code, can overwrite your $key variable. So, be warned.

Now, the encryption and decryption is handled with the Crypt_Blowfish library from Pear.  You can find it in include/Pear/Crypt_Blowfish folder.

A little note for the above as well.  The Blowfish.php file which contains the Crypt_Blowfish class, requires the Blowfish/DefaultKey.php file (from the setKey() method).  That requirement uses relative path, but not based on the current file.  Yeah, I know.  So, if you just copy over the library somewhere else, you might need to adjust either path variables, or the setKey() method.

Armed with this knowledge, you can now work with encrypted values stored by the SugarCRM in the database.  Good luck!

35 new ways to do your work right inside of HipChat

HipChat keeps extending the amazing list of integrations with other tools and services.  This blog post – 35 new ways to do your work right inside of HipChat – lists some of the recently added.  Included, among others, is even a multiplayer snake game.

HipSnake

 

Rocket.Chat – the ultimate self-hosted open source chat platform

Chat is becoming more and more important for team communication and collaboration (what is ChatOps?).  Old school applications like Skype are being replaced with modern, web-based chat platforms, that provide group/room and one-on-one chats, file uploads, screen sharing, voice and video communications, API integration and more.  There are plenty of solutions to choose from too.

Traditionally, self-hosted solutions were difficult to setup and maintain, and were lacking in integration options.  So many teams choose to go for the third-party hosted approach.  This is not very exciting for companies that deal with sensitive data though.

As mentioned before, at work, we are using HipChat.  It’s nice, it’s free, and it integrates nicely.  Lately, there has been a lot of hype about Slack, which I tried, but didn’t particularly like.

rocket.chat

Today, however, I came across a very nice option, which seems to be a breeze to self-host and maintain – Rocket.Chat.  It’s modern – written in JavaScript, it has a long list of features, and there is a vibrant community around it.

You can try the live demo, or deploy it to your infrastructure via a gadzillion different methods, or read the beautiful documentation.  And there’s a rumor of HipChat and Slack import tool, so you won’t have to start from scratch…

Let me know what you think.

WordPress 4.5 “Coleman”

WordPress 4.5 “Coleman” – the newest WordPress version has been released (I’ve just upgraded).  Some of the changes included in this release are:

  • New and improved user interface for editing links in posts and pages.
  • More Markdown-like shortcuts for formatting text (now with code and horizontal lines).
  • Logo support in themes
  • Much improved image optimizations (initially expected in WordPress 4.4)
  • Better embed templates
  • Update for underlying libraries, such as jQuery, Backbone, and Underscore.

If you already manage a WordPress website, you’ll find the notification of the update in your admin area.  If not, then go and download it.