A Security Framework for Wireless Sensor Networks