WASHINGTON (Reuters) - U.S. government lawyers on Wednesday defended the legality of a warrantless surveillance program challenged as unconstitutional in an Oregon court by a Somali-born American citizen convicted of attempting to detonate a bomb at a Christmas tree-lighting ceremony.

The logo of the U.S. National Security Agency is seen in Fort Meade, Maryland, January 25, 2006.

A three-judge panel of the 9th U.S. Circuit Court of Appeals in Portland heard arguments in the case brought by Mohamed Mohamud, convicted in 2013 of plotting to use a weapon of mass destruction in the 2010 incident and sentenced to 30 years in prison.

The case is the first of its kind to consider whether a criminal defendant’s constitutional rights are violated under a National Security Agency program that allows spying on Americans’ international phone calls and internet communications.

Mohamud contends the program violates the Constitution’s Fourth Amendment prohibition on unreasonable searches and seizures.

Kelly Zusman, a lawyer with the U.S. Attorney’s Office in Portland, told the court that because surveillance data on foreigners is legally collected under the program, no warrant is required when searching that information even if it is conducted to find communications involving an American.

Stephen Sady, a federal public defender representing Mohamud, said the government’s argument represented an “incredible diminution of the privacy rights of all Americans.”

“That is a step that should never be taken,” Sady added.

Mohamud, a naturalized U.S. citizen who was 19 when he was arrested, attempted to remotely detonate what he thought was a car bomb near a square in downtown Portland crowded with thousands of people attending a Christmas tree-lighting ceremony the day after the Thanksgiving holiday.

The bomb was actually a fake. Mohamud’s lawyers said he was entrapped by U.S. law enforcement officers posing as al Qaeda militants.

Mohamud is challenging the admissibility of evidence used against him at trial that was obtained under a foreign intelligence statute. His lawyers argue that the law does not allow the government to retain and access content of communications belonging to Americans and that the statute is unconstitutional.

The law, enacted in 2008 by Congress as an amendment to the Foreign Intelligence Surveillance Act and known as Section 702, involves internet surveillance programs known as Prism and Upstream that were first disclosed publicly in a series of leaks three years ago by former NSA contractor Edward Snowden.

Prism gathers messaging data from Alphabet Inc’s Google, Facebook Inc, Microsoft Corp, Apple Inc and other major tech companies that is sent to and from a foreign target under surveillance. Upstream allows the NSA to copy web traffic flowing along the internet backbone located inside the United States and search that data for certain terms associated with a target.

U.S. officials have conceded that data about Americans is sometimes “incidentally” collected under these programs and later used for domestic criminal investigations. Critics see this as unlawful back-door surveillance of Americans without a warrant.

During the arguments, Judge Carlos Bea, an appointee of former Republican President George W. Bush, challenged claims by Mohamud’s lawyers that data on U.S. citizens and lawful residents caught up in a legal foreign surveillance program was off limits.

“Tell me why, once it is legally procured, it becomes illegal to look at it?” Bea asked.

Zusman acknowledged some of the criticisms of Section 702 may be valid but that changes to its implementation should be decided by policymakers, not the courts.

The government has not disclosed which program was used with Mohamud, and it alerted him and his lawyers about how evidence against him was collected only after his conviction.

The case may have political implications, as Congress must reauthorize Section 702 by Dec. 31, 2017, or let it expire.