Not sure what you mean by illegal.
India, Israel, Pakistan and South Sudan are all non-parties to the non-proliferation treaty. Iran is a party.
North Korea was a party, gave notice to withdraw, said they were still in then said they were out. The way that Iran is acting parallels the behavior of North Korea.