Until recently, the National Security Agency treated the existence of its phone records program, which sweeps up the calling records of tens of millions of innocent Americans, as a closely held secret. But Edward Snowden's disclosure of a court order authorizing the program forced the government's hand. The government declassified some basic facts about the program last month, and in a Thursday court filing first reported by Wired, the government makes the case for the legality of its once-secret spying program.

To justify the program, the government needs to surmount two legal hurdles. First, it has to convince courts that the program is authorized by Section 215 of the Patriot Act, which allows the government to obtain records that are relevant to a terrorism investigation. Second, it must convince the courts that the program is consistent with the Fourth Amendment, which protects Americans against unreasonable searches.

It might seem like the Patriot Act's relevance requirement bars the government from seeking the phone records from millions of Americans who have no connection to terrorism. But the Obama administration argues otherwise.

"To identify potential terrorist communications ... requires collecting and storing a large volume and high percentage of information about unrelated communications," the government contends. In the government's view, collecting every American's calling record is the only way to "ensure that the much smaller subset of terrorist-related telephony metadata records are contained within the dataset."

The Obama administration argues that if it didn't collect every American's calling records, the records might be deleted by private telephone companies before the government realizes they're needed for counter-terrorism purposes.

"Because the telephony metadata must be available in bulk to allow the Government to identify the records of terrorist communications, there are 'reasonable grounds to believe' that the data are relevant to authorized investigations to protect against international terrorism, as Section 215 requires, even though most of the records in the database are not associated with terrorist activity," the Obama administration concludes.

On the constitutional question, the government points to Smith v. Maryland, the 1979 Supreme Court ruling that phone calling records are not protected by the Fourth Amendment. That was based on the "third party doctrine," the idea that you waive your privacy rights when you transmit the phone numbers you dial to the phone company.

Both of these arguments are controversial. The author of the Patriot Act has accused the government of misinterpreting Section 215 of the Patriot Act. And at least one Supreme Court justice, Sonia Sotomayor, has suggested that the high court should reconsider the third party doctrine.

But at least these questions are now being debated openly. The legal and constitutional issues raised by the surveillance program will be debated in open court, giving the public the opportunity to learn what legal arguments the government is using to justify its surveillance activities.