Legal where? It's legal in the US for the CIA to hack Russia, and the reverse is also true. International law doesn't really forbid anything (and even when it does it is mostly a joke).
The US was also posturing about actual cyberwarfare during the Gulf war. Not the brightest move since it probably helped focus foreign interest in a field where one can never buy total superiority.