{"action":"created","issue":{"url":"https://api.github.com/repos/balderdashy/sails-mysql/issues/227","labels_url":"https://api.github.com/repos/balderdashy/sails-mysql/issues/227/labels{/name}","comments_url":"https://api.github.com/repos/balderdashy/sails-mysql/issues/227/comments","events_url":"https://api.github.com/repos/balderdashy/sails-mysql/issues/227/events","html_url":"https://github.com/balderdashy/sails-mysql/issues/227","id":87412601,"number":227,"title":"Unable to connect to CloudSQL on SSL.","user":{"login":"zaheershaik","id":4075084,"avatar_url":"https://avatars.githubusercontent.com/u/4075084?v=3","gravatar_id":"","url":"https://api.github.com/users/zaheershaik","html_url":"https://github.com/zaheershaik","followers_url":"https://api.github.com/users/zaheershaik/followers","following_url":"https://api.github.com/users/zaheershaik/following{/other_user}","gists_url":"https://api.github.com/users/zaheershaik/gists{/gist_id}","starred_url":"https://api.github.com/users/zaheershaik/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zaheershaik/subscriptions","organizations_url":"https://api.github.com/users/zaheershaik/orgs","repos_url":"https://api.github.com/users/zaheershaik/repos","events_url":"https://api.github.com/users/zaheershaik/events{/privacy}","received_events_url":"https://api.github.com/users/zaheershaik/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":5,"created_at":"2015-06-11T16:52:57Z","updated_at":"2015-07-01T16:55:04Z","closed_at":null,"body":"Hello,\r\n\r\nI'm trying to connect to Google CloudSQL MySQL DB using sails-mysql adapter on SSL and I get the following issue. I downloaded the client certs by generating from the GC console. I'm able to connect from command line using the same certs, but not from sails. Could you please help?\r\n\r\nNote that I've no issues connecting using the adapter without SSL.\r\n\r\n```\r\nmysql --ssl-ca=server-ca.pem --ssl-cert=client-cert.pem --ssl-key=client-key.pem -h HOST -u\"USER\" -p'PASSWORD' DB\r\n```\r\n\r\n```\r\nmysqlServer: {\r\n\tmodule: 'sails-mysql',\r\n\thost: 'HOST',\r\n\tport: 3306,\r\n\tuser: 'USER',\r\n\tpassword: 'PASS',\r\n\tdatabase: 'DB',\r\n\tssl  : {\r\n\t  key: fs.readFileSync(__dirname + '/ssl/cloudsql/client-key.pem'),\r\n\t  cert: fs.readFileSync(__dirname + '/ssl/cloudsql/client-cert.pem'),\r\n\t  ca : fs.readFileSync(__dirname + '/ssl/cloudsql/server-ca.pem')\r\n\t}\r\n}\r\n```\r\n\r\n```\r\nSending 500 (\"Server Error\") response: \r\n Error (E_UNKNOWN) :: Encountered an unexpected error\r\n: Could not connect to MySQL:\r\nError: unable to verify the first certificate\r\n    at afterwards (/test/node_modules/sails-mysql/lib/connections/spawn.js:72:13)\r\n    at /test/node_modules/sails-mysql/lib/connections/spawn.js:40:7\r\n    at Handshake.onConnect (/test/node_modules/sails-mysql/node_modules/mysql/lib/Pool.js:54:9)\r\n    at Handshake.Sequence.end (/test/node_modules/sails-mysql/node_modules/mysql/lib/protocol/sequences/Sequence.js:96:24)\r\n    at /test/node_modules/sails-mysql/node_modules/mysql/lib/protocol/Protocol.js:169:20\r\n    at TLSSocket.<anonymous> (/test/node_modules/sails-mysql/node_modules/mysql/lib/Connection.js:292:7)\r\n    at TLSSocket.emit (events.js:104:17)\r\n    at TLSSocket._finishInit (_tls_wrap.js:460:8)\r\n```"},"comment":{"url":"https://api.github.com/repos/balderdashy/sails-mysql/issues/comments/117749268","html_url":"https://github.com/balderdashy/sails-mysql/issues/227#issuecomment-117749268","issue_url":"https://api.github.com/repos/balderdashy/sails-mysql/issues/227","id":117749268,"user":{"login":"cludden","id":4565917,"avatar_url":"https://avatars.githubusercontent.com/u/4565917?v=3","gravatar_id":"","url":"https://api.github.com/users/cludden","html_url":"https://github.com/cludden","followers_url":"https://api.github.com/users/cludden/followers","following_url":"https://api.github.com/users/cludden/following{/other_user}","gists_url":"https://api.github.com/users/cludden/gists{/gist_id}","starred_url":"https://api.github.com/users/cludden/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cludden/subscriptions","organizations_url":"https://api.github.com/users/cludden/orgs","repos_url":"https://api.github.com/users/cludden/repos","events_url":"https://api.github.com/users/cludden/events{/privacy}","received_events_url":"https://api.github.com/users/cludden/received_events","type":"User","site_admin":false},"created_at":"2015-07-01T16:55:04Z","updated_at":"2015-07-01T16:55:04Z","body":"I think the problem may have something to do with the fact that at some point the file buffers are getting converted into objects:\r\n\r\nthis works and comes from a console.log of the original config options:\r\n```\r\n{ host: ****,\r\n  user: ****,\r\n  password: *****,\r\n  database: *****,\r\n  ssl: \r\n   { ca: <Buffer bunch of stuff here... >,\r\n     cert: <Buffer bunch of stuff here ... >,\r\n     key: <Buffer bunch of stuff here... > } \r\n}\r\n```\r\n\r\nhowever, when I log the config options from inside node-mysql's Pool.getConnection method, the ssl certifications have been transformed into:\r\n```\r\n{ host: *******,\r\n  port: 3306,\r\n  localAddress: undefined,\r\n  socketPath: undefined,\r\n  user: *****,\r\n  password: undefined,\r\n  database: *****,\r\n// some other stuff here\r\n  ssl: \r\n   { key: \r\n      { '0': 45,\r\n        '1': 45,\r\n        '2': 45,\r\n        '3': 45,\r\n        '4': 45,\r\n        '5': 66,\r\n        '6': 69,\r\n        '7': 71,\r\n        '8': 73,\r\n        '9': 78,\r\n        '10': 32,\r\n//etc\r\n        length: 1674,\r\n        parent: [Object] },\r\n     cert: \r\n      { '0': 45,\r\n        '1': 45,\r\n        '2': 45,\r\n        '3': 45,\r\n        '4': 45,\r\n        '5': 66,\r\n        '6': 69,\r\n        '7': 71,\r\n        '8': 73,\r\n        '9': 78,\r\n        '10': 32,\r\n//etc\r\n        length: 1146,\r\n        parent: [Object] },\r\n     ca: \r\n      { '0': 45,\r\n        '1': 45,\r\n        '2': 45,\r\n        '3': 45,\r\n        '4': 45,\r\n        '5': 66,\r\n        '6': 69,\r\n        '7': 71,\r\n        '8': 73,\r\n        '9': 78,\r\n        '10': 32,\r\n//etc\r\n        length: 1146,\r\n        parent: [Object] },\r\n     rejectUnauthorized: true },\r\n  multipleStatements: false,\r\n  typeCast: true,\r\n  maxPacketSize: 0,\r\n  charsetNumber: 33,\r\n  clientFlags: 455631 }\r\n```"}}