## 1 Introduction  
The proliferation of smart objects and their connectivity have contributed to the realization of Internet of Things (IoT) paradigm; their features and services have revolutionized our daily life. These smart devices are equipped by different means of communication to access the Internet [1], creating what it is called the smart environment. Different technologies such as WiFi, Bluetooth, NFC, and recently WiFi P2P (WiFi-Direct) can be used to enable IoT device-to-device (D2D) communication and providing more functionalities to enhance the user experience [2]. Currently, all data traffic must pass through a fixed infrastructure in the different wireless cellular network generations, regardless of the device's location. However, to avoid overloading the infrastructures, it is better to enable direct inter-device communication when possible. When devices are in proximity of each other, problems of radio access network load and core network load are observed [3]. One of the methods used to overcome these limitations and effectively manage local group communication while offloading data from the cellular network is to establish direct communication between the nearby devices, and this kind of communication is called IoT D2D communication. Unlike the conventional scenario, where cellular operators are the main middleware handling all inter-device communication within their communication range, IoT D2D communication is a new computing paradigm that allows two proximate mobile devices to directly connect and communicate with each other without the presence of any intermediate authority [4]. The IoT D2D concept is directly related to the used wireless technologies. D2D can be implemented with technologies such as Bluetooth, WiFi-Direct, and LTE Direct, to name a few. Each of them is characterized by its maximum transmission distance, maximum data rate, and the devices' discovery mode, as summarized in Table 1.  
In this work we consider the use of WiFi P2P technology known as WiFi Direct due to its high bandwidth value with 250 Mbps surpassing the LTE Direct and Bluetooth [5], also for its agreeable range which can expand to 200 m, and finally, for the easiest way to discover neighbors for D2D users using the ID Broadcast -the MAC address of mobile devices in most of cases. Since IoT D2D communications are over wireless channels, which are broadcast in nature, many existing attacks can affect them and exploit their vulnerability. Hence, security solutions ensuring efficient authentication and confidentiality are a must [6; 7]. To perform an efficient authentication between users, establishing a shared secret key is an important step. The common solution is the use of the traditional Diffie-Hellman key agreement; however, it suffers from its vulnerability to the man in the middle (MITM) Attack. On the other hand, relying on a hash value of the shared secret key can provide secrecy to the communication protocol, but the size of the information to be compared by IoT D2D users poses a problem. In previous works, the shared secret key must be compared visually or verbally by D2D users. We propose a solution to avoid this human mediation. In this paper, we propose the Secure Key Exchange with QR Code (SeKeQ) protocol. Our proposal serves as a key establishment protocol between IoT D2D users using Diffie-Hellman for key exchange and SHA256 hash function for digital signature of the shared secret key. Furthermore, our proposal is fully autonomous and does not require human mediation. Finally, we use the generated secret key to ensure data confidentiality by encrypting the communication traffic over wireless channel. The performance evaluation comparing SeKeQ to other existing solutions shows that it can ensure a secure communication with fast key generation and less resource consumption. The remainder of this paper is organized in the following fashion: Section 2 presents an overview about WiFi-Direct and some cyber-attacks that may affect D2D communication. Afterwards, we discuss the related works in Section 3.