## 1 Introduction  
Recent advances in wireless communication technologies and applications have enabled the large-scale deployment of wireless sensor networks (WSNs). These networks have applications in many important and critical areas, such as military, critical infrastructure monitoring, traffic control, healthcare, environment monitoring and manufacturing [1]. Security and privacy are critical issues for most of these sensor network applications. However, providing security and privacy to WSNs is very challenging due to the heterogeneity of sensor nodes and their limited capabilities in terms of energy, processing power and memory. Thus, generic security solutions do not fit well with the special requirements of WSNs. This problem can be tackled from two different points of view. On the one hand, there is currently an important effort being made to develop specific algorithms for WSNs in the fields of trust, security and privacy [1], such as new algorithms for authentication [2], positioning [3], network intrusion detection [4], efficient key management for dynamic WSNs [5], _etc._ Since these algorithms need to run in a myriad of sensors with different low-level programming abstractions, limited capabilities, different routing protocols, _etc._, new algorithms are continuously appearing that improve upon previous ones. This means that sensor network applications are currently in need of being self-adapting to these changes with the lowest impact for users and without stopping the devices. Additionally, these applications need to react to changes in the environment by changing the security policies that are currently deployed in the running applications. Ideally, such applications should be capable of self-protection in the sense that they could dynamically self-adapt the algorithms used to provide security. On the other hand, we need to consider the security of WSNs also from a software engineering point of view. Software development processes should provide security solutions that take into account the high heterogeneity and variability of sensors devices and applications and also the high variability of both security requirements and solutions. The use of advanced software engineering technologies could hide the complexity of WSNs from software developers and could also deal with the automatic adaptation of the applications when the security and privacy requirements change. Dynamic software product lines (DSPLs) [6,7] allow managing both variability and dynamic software adaptation, so they can be considered a key technology in successfully developing self-protected WSNs' applications. In this paper, we propose a self-protection solution for WSNs based on the use of DSPLs. Basically, DSPLs produce software products capable of adapting to requirements that may change at runtime, by modeling the elements that could be adapted dynamically as dynamic variation points. The runtime adaptation of security policies for heterogeneous systems implies both the modeling and the dynamic negotiation of security policies. According to the literature on security solutions for pervasive applications, there is a lack of powerful techniques to address the problem of security policy negotiation, interoperability and dynamic enforcement. In this paper, we address all these issues by combining the INTER-TRUST (INTERoperable TRUST Assurance Infrastructure)security framework [8] and the FamiWare middleware [9]. INTER-TRUST is a dynamic and scalable framework to support trustworthy services and applications for heterogeneous networks and devices. It is mainly based on the dynamic enforcement of interoperable and changing security policies [8] by modeling secure interoperability policies with different constraints. As faras we know, INTER-TRUST is the only existing framework for the dynamic negotiation of security policies in heterogeneous environments.