Answers.Body: <p>Silly mistake. I forgot to update AppBehaviors.php to the newest release after moving the attributes logic to db.php:</p>
  
  <pre><code>$dbConnection = new DbConnection();
  
  $dbConnection-&gt;connectionString = $this-&gt;_processConnectionString();
  $dbConnection-&gt;emulatePrepare   = true;
  $dbConnection-&gt;username         = craft()-&gt;config-&gt;get('user', ConfigFile::Db);
  $dbConnection-&gt;password         = craft()-&gt;config-&gt;get('password', ConfigFile::Db);
  $dbConnection-&gt;charset          = craft()-&gt;config-&gt;get('charset', ConfigFile::Db);
  $dbConnection-&gt;tablePrefix      = $dbConnection-&gt;getNormalizedTablePrefix();
  $dbConnection-&gt;driverMap        = array('mysql' =&gt; 'Craft\MysqlSchema');
  
  // Support for Yii's $initSQLs
  if ($initSQLs = craft()-&gt;config-&gt;get('initSQLs', ConfigFile::Db))
  {
      $dbConnection-&gt;initSQLs = $initSQLs;
  }
  // See if we have any extra PDO attributes passed in.
  if ($attributes = craft()-&gt;config-&gt;get('attributes', ConfigFile::Db))
  {
      $dbConnection-&gt;attributes = $attributes;
  }
  
  $dbConnection-&gt;init();
  </code></pre>
  
  <p>After adding the new lines of code, I was able to connect :)</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-10-26T14:51:13.627Z
Answers.LastActivityDate: 2016-10-26T14:51:13.627Z
Answers.UserDisplayName: Leah Scott
Body: <p>I used to connect to my database over SSL by directly modifying the createDbConnection method in Craft's AppBehavior.php:</p>
  
  <pre><code>$dbConnection = new DbConnection();
  
  $dbConnection-&gt;connectionString = $this-&gt;_processConnectionString();
  $dbConnection-&gt;emulatePrepare   = true;
  $dbConnection-&gt;username         = craft()-&gt;config-&gt;get('user', ConfigFile::Db);
  $dbConnection-&gt;password         = craft()-&gt;config-&gt;get('password', ConfigFile::Db);
  $dbConnection-&gt;charset          = craft()-&gt;config-&gt;get('charset', ConfigFile::Db);
  $dbConnection-&gt;tablePrefix      = $dbConnection-&gt;getNormalizedTablePrefix();
  $dbConnection-&gt;driverMap        = array('mysql' =&gt; 'Craft\MysqlSchema');
  
  // additional attributes to connect over SSL
  if (getenv('DB_SSL_ENABLED') == 'true') 
  {
      $dbConnection-&gt;attributes   = array(
          PDO::MYSQL_ATTR_SSL_CIPHER =&gt; 'DHE-RSA-AES256-SHA:AES128-SHA',
          PDO::MYSQL_ATTR_SSL_CA     =&gt; CRAFT_CONFIG_PATH . 'rds-combined-ca-bundle.pem',
      );
  }
  
  $dbConnection-&gt;init();
  </code></pre>
  
  <p>But as of a new Craft <a href="https://craftcms.com/changelog#build2945" rel="nofollow">release</a> there is a native Craft way to do this by setting a new "attributes" key in the database config file. Unfortunately, Craft won't make a connection when I connect using this new method. I get the dreaded <em>Craft can’t connect to the database with the credentials in craft/config/db.php</em> error. My revised db.php looks like this:</p>
  
  <pre><code>$url = parse_url(getenv("DATABASE_URL"));
  
  define(SERVER, $url["host"]);
  define(USER, $url["user"]);
  define(PASSWORD, $url["pass"]);
  define(DATABASE, substr($url["path"], 1));
  
  return array(
      'server' =&gt; SERVER,
      'user' =&gt; USER,
      'password' =&gt; PASSWORD,
      'database' =&gt; DATABASE,
      'tablePrefix' =&gt; 'craft',
      'attributes' =&gt; array(
          PDO::MYSQL_ATTR_SSL_CIPHER =&gt; 'DHE-RSA-AES256-SHA:AES128-SHA',
          PDO::MYSQL_ATTR_SSL_CA     =&gt; CRAFT_CONFIG_PATH . 'rds-combined-ca-bundle.pem',
       )
  );
  </code></pre>
  
  <p>Not sure what could be going wrong here. Are there additional attributes that need to be set when doing this the Yii way?</p>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-10-25T18:40:51.143Z
Comments.Text: You're saying your first examples works when modifying AppBehavior directly? Craft is passing the attributes config setting directly into `$dbConnection->attributes` just like you're doing: https://github.com/pixelandtonic/Craft-Release/blob/master/app/etc/behaviors/AppBehavior.php#L830-L834
Comments.UserDisplayName: Brad Bell
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-10-25T18:42:07.740Z
Comments.Text: Any chance you need to set PDO::MYSQL_ATTR_SSL_KEY and PDO::MYSQL_ATTR_SSL_CERT, too? https://dev.mysql.com/doc/refman/5.5/en/using-secure-connections.html
Comments.UserDisplayName: Brad Bell
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-10-25T20:19:57.817Z
Comments.Text: When connecting to RDS it is recommended to use only use the ca cert. And I can confirm the connection works without the other keys since the first code block in AppBehavior can connect.
Comments.UserDisplayName: Leah Scott
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-10-25T20:20:55.350Z
Comments.Text: I'm trying to think of other things that could be going wrong. Does PDO need to be escaped from the Craft namespace? I'm grasping at straws here.
Comments.UserDisplayName: Leah Scott
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-10-25T20:35:14.573Z
Comments.Text: Good question... does `\PDO::` work?
Comments.UserDisplayName: Brad Bell
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-10-25T20:53:22.400Z
Comments.Text: Ahhh Brad I forgot to update AppBehaviors from the latest release after moving the logic to db.php. So sorry. It's always the simplest mistakes that are the most baffling. Well, works fine now. Thanks for the assist.
Comments.UserDisplayName: Leah Scott
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-10-25T21:55:35.923Z
Comments.Text: Ahh, nice.  Can you add that as an official answer in case someone else does the same? :)
Comments.UserDisplayName: Brad Bell
Tags: <database><security><ssl>
Title: Problems Securing Database Connection Over SSL
ThreadText: # Problems Securing Database Connection Over SSL
  
  (Asked by: username_0 on 2016-10-25)
  
  I used to connect to my database over SSL by directly modifying the createDbConnection method in Craft's AppBehavior.php:
  
  ```
  $dbConnection = new DbConnection();
  
  $dbConnection->connectionString = $this->_processConnectionString();
  $dbConnection->emulatePrepare   = true;
  $dbConnection->username         = craft()->config->get('user', ConfigFile::Db);
  $dbConnection->password         = craft()->config->get('password', ConfigFile::Db);
  $dbConnection->charset          = craft()->config->get('charset', ConfigFile::Db);
  $dbConnection->tablePrefix      = $dbConnection->getNormalizedTablePrefix();
  $dbConnection->driverMap        = array('mysql' => 'Craft\MysqlSchema');
  
  // additional attributes to connect over SSL
  if (getenv('DB_SSL_ENABLED') == 'true') 
  {
      $dbConnection->attributes   = array(
          PDO::MYSQL_ATTR_SSL_CIPHER => 'DHE-RSA-AES256-SHA:AES128-SHA',
          PDO::MYSQL_ATTR_SSL_CA     => CRAFT_CONFIG_PATH . 'rds-combined-ca-bundle.pem',
      );
  }
  
  $dbConnection->init();
  
  ```
  
  But as of a new Craft [release](https://craftcms.com/changelog#build2945) there is a native Craft way to do this by setting a new "attributes" key in the database config file. Unfortunately, Craft won't make a connection when I connect using this new method. I get the dreaded *Craft can’t connect to the database with the credentials in craft/config/db.php* error. My revised db.php looks like this:
  
  ```
  $url = parse_url(getenv("DATABASE_URL"));
  
  define(SERVER, $url["host"]);
  define(USER, $url["user"]);
  define(PASSWORD, $url["pass"]);
  define(DATABASE, substr($url["path"], 1));
  
  return array(
      'server' => SERVER,
      'user' => USER,
      'password' => PASSWORD,
      'database' => DATABASE,
      'tablePrefix' => 'craft',
      'attributes' => array(
          PDO::MYSQL_ATTR_SSL_CIPHER => 'DHE-RSA-AES256-SHA:AES128-SHA',
          PDO::MYSQL_ATTR_SSL_CA     => CRAFT_CONFIG_PATH . 'rds-combined-ca-bundle.pem',
       )
  );
  
  ```
  
  Not sure what could be going wrong here. Are there additional attributes that need to be set when doing this the Yii way?
  
  **Tags:** database, security, ssl
  
  > **Comments:**
  > **username_1**: You're saying your first examples works when modifying AppBehavior directly? Craft is passing the attributes config setting directly into `$dbConnection->attributes` just like you're doing: https://github.com/pixelandtonic/Craft-Release/blob/master/app/etc/behaviors/AppBehavior.php#L830-L834  
  > **username_1**: Any chance you need to set PDO::MYSQL_ATTR_SSL_KEY and PDO::MYSQL_ATTR_SSL_CERT, too? https://dev.mysql.com/doc/refman/5.5/en/using-secure-connections.html  
  > **username_0**: When connecting to RDS it is recommended to use only use the ca cert. And I can confirm the connection works without the other keys since the first code block in AppBehavior can connect.  
  > **username_0**: I'm trying to think of other things that could be going wrong. Does PDO need to be escaped from the Craft namespace? I'm grasping at straws here.  
  > **username_1**: Good question... does `\PDO::` work?  
  > **username_0**: Ahhh username_1 I forgot to update AppBehaviors from the latest release after moving the logic to db.php. So sorry. It's always the simplest mistakes that are the most baffling. Well, works fine now. Thanks for the assist.  
  > **username_1**: Ahh, nice.  Can you add that as an official answer in case someone else does the same? :)  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_0 on 2016-10-26. Score: 0 | Accepted answer
  
  Silly mistake. I forgot to update AppBehaviors.php to the newest release after moving the attributes logic to db.php:
  
  ```
  $dbConnection = new DbConnection();
  
  $dbConnection->connectionString = $this->_processConnectionString();
  $dbConnection->emulatePrepare   = true;
  $dbConnection->username         = craft()->config->get('user', ConfigFile::Db);
  $dbConnection->password         = craft()->config->get('password', ConfigFile::Db);
  $dbConnection->charset          = craft()->config->get('charset', ConfigFile::Db);
  $dbConnection->tablePrefix      = $dbConnection->getNormalizedTablePrefix();
  $dbConnection->driverMap        = array('mysql' => 'Craft\MysqlSchema');
  
  // Support for Yii's $initSQLs
  if ($initSQLs = craft()->config->get('initSQLs', ConfigFile::Db))
  {
      $dbConnection->initSQLs = $initSQLs;
  }
  // See if we have any extra PDO attributes passed in.
  if ($attributes = craft()->config->get('attributes', ConfigFile::Db))
  {
      $dbConnection->attributes = $attributes;
  }
  
  $dbConnection->init();
  
  ```
  
  After adding the new lines of code, I was able to connect :)
  
  
  ---
  
  