Five Arab Muslim men have been held for years under the "security certificate" program, which the Justice Department has said is a key tool in the fight against global terrorism and essential to Canada's security.

The court found that the system violated the Charter of Rights and Freedoms, Canada's bill of rights. However, it suspended its ruling for a year to give Parliament time to rewrite the part of the Immigration and Refugee Protection Act that covers the certificate process.

The security certificates were challenged by three men from Morocco, Syria and Algeria -- all alleged by the Canadian Security Intelligence Service to have ties to terrorist networks.

The men have spent years in jail while fighting deportation orders.

They risk being labeled terrorists and sent back to their native countries, where they say they could face torture.

The court said the treatment of the suspects was a violation of their rights.

"The overarching principle of fundamental justice that applies here is this: Before the state can detain people for significant periods of time, it must accord them a fair judicial process," Chief Justice Beverley McLachlin wrote in a ruling for all nine justices.

"The secrecy required by the scheme denies the person named in a certificate the opportunity to know the case put against him or her, and hence to challenge the government's case," she said.

The challenged law allows sensitive intelligence to be heard behind closed doors by a federal judge, with only sketchy summaries given to defense attorneys.

The court said the men and their lawyers should have a right to respond to the evidence used against them by intelligence agents.

Stockwell Day, the minister of public safety, noted that because the ruling does not take effect for a year, the certificates would remain in place. He said the government would address the court's ruling "in a timely and decisive fashion."

Two of the men are out on bail and remain under house arrest. Three others are being held in a federal facility in Ontario.