| 
														
															@@ -1,6 +1,7 @@ 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 package main 
														 | 
														
														 | 
														
															 package main 
														 | 
													
												
											
												
													
														| 
														 | 
														
															  
														 | 
														
														 | 
														
															  
														 | 
													
												
											
												
													
														| 
														 | 
														
															 import ( 
														 | 
														
														 | 
														
															 import ( 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+	"crypto/tls" 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 	"encoding/hex" 
														 | 
														
														 | 
														
															 	"encoding/hex" 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 	"encoding/json" 
														 | 
														
														 | 
														
															 	"encoding/json" 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 	"fmt" 
														 | 
														
														 | 
														
															 	"fmt" 
														 | 
													
												
											
										
											
												
													
														 | 
														
															@@ -12,7 +13,6 @@ import ( 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 	"sparrow/pkg/coap" 
														 | 
														
														 | 
														
															 	"sparrow/pkg/coap" 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 	"sparrow/pkg/klink" 
														 | 
														
														 | 
														
															 	"sparrow/pkg/klink" 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 	"sparrow/pkg/protocol" 
														 | 
														
														 | 
														
															 	"sparrow/pkg/protocol" 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-	"sparrow/pkg/server" 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 	"sparrow/pkg/tlv" 
														 | 
														
														 | 
														
															 	"sparrow/pkg/tlv" 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 	"time" 
														 | 
														
														 | 
														
															 	"time" 
														 | 
													
												
											
												
													
														| 
														 | 
														
															  
														 | 
														
														 | 
														
															  
														 | 
													
												
											
										
											
												
													
														 | 
														
															@@ -402,20 +402,26 @@ func (d *Device) doMQTTAccess() error { 
														 | 
													
												
											
												
													
														| 
														 | 
														
															  
														 | 
														
														 | 
														
															  
														 | 
													
												
											
												
													
														| 
														 | 
														
															 	//create a ClientOptions struct setting the broker address, clientid, turn 
														 | 
														
														 | 
														
															 	//create a ClientOptions struct setting the broker address, clientid, turn 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 	//off trace output and set the default message handler 
														 | 
														
														 | 
														
															 	//off trace output and set the default message handler 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-	opts := MQTT.NewClientOptions().AddBroker("tcp://" + d.access) 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+	opts := MQTT.NewClientOptions().AddBroker("ssl://" + d.access) 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 	clientid := fmt.Sprintf("%x", d.id) 
														 | 
														
														 | 
														
															 	clientid := fmt.Sprintf("%x", d.id) 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 	opts.SetClientID(clientid) 
														 | 
														
														 | 
														
															 	opts.SetClientID(clientid) 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 	opts.SetUsername(clientid) // clientid as username 
														 | 
														
														 | 
														
															 	opts.SetUsername(clientid) // clientid as username 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 	opts.SetPassword(hex.EncodeToString(d.token)) 
														 | 
														
														 | 
														
															 	opts.SetPassword(hex.EncodeToString(d.token)) 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 	opts.SetKeepAlive(30 * time.Second) 
														 | 
														
														 | 
														
															 	opts.SetKeepAlive(30 * time.Second) 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+	// process key files 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+	cert, err := tls.LoadX509KeyPair(*confCAFile, *confKeyFile) 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+	if err != nil { 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+		panic(err) 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+	} 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+ 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 	opts.SetDefaultPublishHandler(d.messageHandler) 
														 | 
														
														 | 
														
															 	opts.SetDefaultPublishHandler(d.messageHandler) 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-	//opts.SetTLSConfig(&tls.Config{Certificates: nil, InsecureSkipVerify: true}) 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+	opts.SetTLSConfig(&tls.Config{Certificates: []tls.Certificate{cert}, InsecureSkipVerify: true}) 
														 | 
													
												
											
												
													
														| 
														 | 
														
															  
														 | 
														
														 | 
														
															  
														 | 
													
												
											
												
													
														| 
														 | 
														
															 	//create and start a client using the above ClientOptions 
														 | 
														
														 | 
														
															 	//create and start a client using the above ClientOptions 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 	c := MQTT.NewClient(opts) 
														 | 
														
														 | 
														
															 	c := MQTT.NewClient(opts) 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 	go func() { 
														 | 
														
														 | 
														
															 	go func() { 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 		if token := c.Connect(); token.Wait() && token.Error() != nil { 
														 | 
														
														 | 
														
															 		if token := c.Connect(); token.Wait() && token.Error() != nil { 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-			server.Log.Error(token.Error()) 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+			fmt.Println(err.Error()) 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 			return 
														 | 
														
														 | 
														
															 			return 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 		} 
														 | 
														
														 | 
														
															 		} 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 	}() 
														 | 
														
														 | 
														
															 	}() 
														 |