The country is perfecting a vast network of digital espionage as a means of social control—with implications for democracies worldwide.