Skip to content
This repository has been archived by the owner on Apr 29, 2019. It is now read-only.

Commit

Permalink
Use TLS secured connection when registered.
Browse files Browse the repository at this point in the history
  • Loading branch information
Al S-M committed Oct 16, 2014
1 parent 6c435b6 commit e668a44
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 2 deletions.
23 changes: 23 additions & 0 deletions samples/nodejs/IoTFoundation-CA.pem
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
-----BEGIN CERTIFICATE-----
MIIDrzCCApegAwIBAgIQCDvgVpBCRrGhdWrJWZHHSjANBgkqhkiG9w0BAQUFADBh
MQswCQYDVQQGEwJVUzEVMBMGA1UEChMMRGlnaUNlcnQgSW5jMRkwFwYDVQQLExB3
d3cuZGlnaWNlcnQuY29tMSAwHgYDVQQDExdEaWdpQ2VydCBHbG9iYWwgUm9vdCBD
QTAeFw0wNjExMTAwMDAwMDBaFw0zMTExMTAwMDAwMDBaMGExCzAJBgNVBAYTAlVT
MRUwEwYDVQQKEwxEaWdpQ2VydCBJbmMxGTAXBgNVBAsTEHd3dy5kaWdpY2VydC5j
b20xIDAeBgNVBAMTF0RpZ2lDZXJ0IEdsb2JhbCBSb290IENBMIIBIjANBgkqhkiG
9w0BAQEFAAOCAQ8AMIIBCgKCAQEA4jvhEXLeqKTTo1eqUKKPC3eQyaKl7hLOllsB
CSDMAZOnTjC3U/dDxGkAV53ijSLdhwZAAIEJzs4bg7/fzTtxRuLWZscFs3YnFo97
nh6Vfe63SKMI2tavegw5BmV/Sl0fvBf4q77uKNd0f3p4mVmFaG5cIzJLv07A6Fpt
43C/dxC//AH2hdmoRBBYMql1GNXRor5H4idq9Joz+EkIYIvUX7Q6hL+hqkpMfT7P
T19sdl6gSzeRntwi5m3OFBqOasv+zbMUZBfHWymeMr/y7vrTC0LUq7dBMtoM1O/4
gdW7jVg/tRvoSSiicNoxBN33shbyTApOB6jtSj1etX+jkMOvJwIDAQABo2MwYTAO
BgNVHQ8BAf8EBAMCAYYwDwYDVR0TAQH/BAUwAwEB/zAdBgNVHQ4EFgQUA95QNVbR
TLtm8KPiGxvDl7I90VUwHwYDVR0jBBgwFoAUA95QNVbRTLtm8KPiGxvDl7I90VUw
DQYJKoZIhvcNAQEFBQADggEBAMucN6pIExIK+t1EnE9SsPTfrgT1eXkIoyQY/Esr
hMAtudXH/vTBH1jLuG2cenTnmCmrEbXjcKChzUyImZOMkXDiqw8cvpOp/2PV5Adg
06O/nVsJ8dWO41P0jmP6P6fbtGbfYmbW0W5BjfIttep3Sp+dWOIrWcBAI+0tKIJF
PnlUkiaY4IBIqDfv8NZ5YBberOgOzW6sRBc4L0na4UU+Krk2U886UAb3LujEV0ls
YSEY1QSteDwsOoBrp+uvFRTp2InBuThs4pFsiv9kuXclVzDAGySj4dzp30d8tbQk
CAUw7C29C79Fv1C5qfPrmAESrciIxpg0X40KPMbp1ZWVbd4=
-----END CERTIFICATE-----

34 changes: 34 additions & 0 deletions samples/nodejs/IoTFoundation.pem
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
-----BEGIN CERTIFICATE-----
MIIFqzCCBJOgAwIBAgIQCxjQE+z7NGL2+H7H3H33EDANBgkqhkiG9w0BAQsFADBN
MQswCQYDVQQGEwJVUzEVMBMGA1UEChMMRGlnaUNlcnQgSW5jMScwJQYDVQQDEx5E
aWdpQ2VydCBTSEEyIFNlY3VyZSBTZXJ2ZXIgQ0EwHhcNMTQwOTIyMDAwMDAwWhcN
MTcxMTI5MTIwMDAwWjCBwjELMAkGA1UEBhMCR0IxEjAQBgNVBAgTCUhhbXBzaGly
ZTETMBEGA1UEBxMKV2luY2hlc3RlcjEuMCwGA1UEChMlSW50ZXJuYXRpb25hbCBC
dXNpbmVzcyBNYWNoaW5lcyBDb3JwLjEmMCQGA1UECxMdSW50ZXJuZXQgb2YgVGhp
bmdzIEZvdW5kYXRpb24xMjAwBgNVBAMMKSoubWVzc2FnaW5nLmludGVybmV0b2Z0
aGluZ3MuaWJtY2xvdWQuY29tMIIBIjANBgkqhki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VNlcnZlckNBLmNydDAMBgNVHRMBAf8EAjAAMA0GCSqGSIb3DQEBCwUAA4IBAQBE
sTL/E2gWP8nWd5wor5sJpVD4nAnTluR2fSqoBnTi4DlxY+5ujpHYSQIo8f8rp1Fr
ADzy63x3woCNZXtWf5fs1uAJUHi53HK5Y9UH6nFBv4qwnSUiH+8JE+xBWVGT6bl0
uM8miFZVo7r4Jpuc1I13B9oHqxtP2ayQDyMvtcENOv9JvqZk9TEvp7IJgdtmYE4d
BsbKsHRC0m3S1tfXac9cuKA1rND21buWis9nV0cEabwT5XM4YpSITVeIdII6kvZ8
SREOxEG3urjy2xU8RxDDiMTcAYjNwSNshfZPyY7TijFDl4ZXpioHuQ+N3NxtZKzg
51QXrsnRosOX+sa4iSXx
-----END CERTIFICATE-----

13 changes: 11 additions & 2 deletions samples/nodejs/ibm-iot-quickstart.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@
var mqtt = require('mqtt');
var fs = require('fs');
var configFile = "./device.cfg";
var caCerts = ["./IoTFoundation.pem", "IoTFoundation-CA.pem"];


var qs_mode = true;
var port = 1883;
var s_port = 8883;
var broker = "quickstart.messaging.internetofthings.ibmcloud.com";
var topic;
var client;
Expand Down Expand Up @@ -69,13 +71,20 @@ require('getmac').getMac(function(err, macAddress) {
macAddress = config.id;

broker = organization + ".messaging.internetofthings.ibmcloud.com";
qs_mode = false;
}
else {
console.log("No configuration file found, connecting to the quickstart servcice.");
}

options.clientId = "d:" + organization + ":" + deviceType + ":" + macAddress;
client = mqtt.createClient(port, broker, options);
if (qs_mode) {
client = mqtt.createClient(port, broker, options);
} else {
options.ca = caCerts;
options.rejectUnauthorized = true;
client = mqtt.createSecureClient(s_port, broker, options);
}
topic = "iot-2/evt/status/fmt/json";

var interval = setInterval(sendMessage,1000);
Expand Down

0 comments on commit e668a44

Please sign in to comment.