Credit Bryan R. Smith for The New York Times
WASHINGTON â Time and again after the introduction of the iPhone nearly a decade ago, the Justice Department asked Apple for help opening a locked phone. And nearly without fail, the company agreed.
Then last fall, the company changed its mind. In a routine drug case in a Brooklyn federal court, prosecutors sought a court order demanding that Apple unlock a methamphetamine dealerâs iPhone 5s running old, easy-to-unlock software. The company acknowledged that it could open the phone, as it had before. But this time, it pushed back.
âWeâre being forced to become an agent of law enforcement,â the companyâs lawyer, Marc Zwillinger, protested in court.
That stance foreshadowed this weekâs showdown between the Obama administration and Apple over the locked iPhone belonging to one of the suspects in the San Bernardino shooting rampage. By the time of Mr. Zwillingerâs statement, Apple and the government had been at odds for more than a year, since the debut of Appleâs new encrypted operating system, iOS 8, in late 2014.
Is Apple Right in Defying the F.B.I.?
The new technology repeatedly stymied investigators â the New York authorities said on Thursday that they had been locked out of 175 iPhones in cases they were pursuing. But both sides held out hope for a compromise that would avoid the type of confrontation that occurred this week when a federal magistrate judge ordered Apple to comply with the Justice Departmentâs request.
With last Octoberâs court filing, the confrontation became all but inevitable. The company left no doubt that it would fight any effort to crack its new, encrypted phones. The only real question was what crime the government would use to press its case.
Appleâs stance that day in Brooklyn caught the Justice Department off guard. Despite the issue with the iOS 8, the company had continued to cooperate. In the first half of 2015 alone, the company provided data in response to more than 3,000 law enforcement requests, Apple said. And company lawyers gave prosecutors no indication that the drug case against Jun Feng would be any different.
Mr. Feng, 45, claimed to have forgotten his passcode, making his cooperation a moot point even if he were willing to extend it, according to a government filing. Unlike the phone in the San Bernardino case, Mr. Fengâs ran iOS 7, an older version of Appleâs operating system that does not automatically encrypt its data. The Justice Department figured it would have the information from Mr. Fengâs phone within a day.
Mr. Zwillinger said the drug case would be Appleâs line in the sand. âCustomer data is under siege from a variety of different directions,â he said. âNever has the privacy and security of customer data been as important as it is now.â
It was a delicate period for the Obama administration, which was focused on finding a way to break into the new encrypted iPhones. The F.B.I., in particular, was lobbying hard to win support for that idea in the face of skepticism from Silicon Valley, Congress and the public.
Timothy D. Cook, Appleâs chief executive, described data privacy as a human rights issue. Backed by leading technologists, Mr. Cook argued that if the company designed a way to defeat encryption for the United States government, that tool would be exploited by hackers or foreign governments like China.
Under the attorney general Eric H. Holder Jr., the Justice Department was sympathetic to that point of view, even in the face of an aggressive campaign from the F.B.I. director, James B. Comey. Mr. Holder favored meeting with technology executives in the hope of finding common ground, current and former Justice Department officials said.
Others in the department strongly disagreed. National security and criminal prosecutors argued that, with the introduction of the encrypted iOS 8, Apple (along with Google, which had started its own encrypted Android phone software) had made thumbing its nose at the government a business strategy. The only hope, these prosecutors argued, was a court fight or an act of Congress requiring companies to provide the government unencrypted data.
Local law enforcement officials, too, were sounding alarms. âThis has become, ladies and gentlemen, the Wild West in technology,â Cyrus R. Vance Jr., the district attorney in Manhattan, said at a news conference Thursday, echoing complaints he and others have made for many months. âApple and Google are their own sheriffs. There are no rules.â
When the attorney general Loretta E. Lynch and her deputy, Sally Q. Yates, took office last year, the F.B.I. and its law enforcement allies found more receptive ears. Ms. Yates, in particular, took up the issue, giving speeches and testifying before Congress alongside Mr. Comey.
Despite the campaign, the White House showed no appetite for legislation. And Apple showed no signs of budging. In a few instances, the two sides appeared bound for a court fight, only to resolve it at the last moment. Last summer, Apple refused to give the Justice Department real-time access to iMessages â the companyâs proprietary text messages â in a gun case. The matter nearly escalated, but Apple eventually turned over some messages that had been backed up to the companyâs iCloud servers. It was not all that the government wanted, but authorities viewed it as a sign of cooperation.
Such compromises forestalled a major court showdown, but increased the frustration at the Justice Department. Several current and former career prosecutors involved in the issue said they viewed it as hypocritical that Apple encouraged its customers to save its data to iCloud â which it would turn over to the government â but regarded the cellphone as sacrosanct.
Credit Bryan R. Smith for The New York Times
Then came the Feng case. By refusing to help, the Justice Department thought Apple was sending a clear signal. If it would no longer cooperate with requests to help unlock old phones, there was little chance it would give in and build a way to unlock the new encrypted phones running iOS 8.
âForcing Apple to extract data in this case, absent clear legal authority to do so, could threaten the trust between Apple and its customers and substantially tarnish the Apple brand,â Mr. Zwillinger said.
By that time, 90 percent of Apple devices were running iOS 8 or newer versions. The F.B.I. warned that it was only a matter of time before its agents were locked out of a phone in a case with lives at stake.
The San Bernardino, Calif., attacks, which killed 14 people, presented the F.B.I. with a seemingly perfect test case. One of the shooters, Syed Rizwan Farook, was killed by the police and left behind a locked, encrypted iPhone 5S. The F.B.I. has not been able to unlock it.
Mr. Farookâs phone is protected by a password that Apple says it does not keep and Apple says it cannot break the encryption without the password. The F.B.I. wants to write a program to send the phone an unlimited combination of passwords until it finds one that works.
But Apple built its phones to protect against that tactic. Each wrong guess causes a short delay, which would significantly slow the F.B.I.âs effort. After too many incorrect guesses, the phone will automatically erase its memory.
The authorities are still interested in more than just Mr. Farookâs phone. On Thursday, a team of F.B.I. agents raided the Southern California home of his brother, Syed Raheel Farook, and carted off boxes of belongings. The authorities would not say what they were searching for.
But there is no telling what is on Mr. Farookâs phone â maybe clues to accomplices or his inspiration, maybe nothing â but nobody in the government questioned the need for obtaining access to that data. From a public relations standpoint, Apple had been on the side of privacy advocates and civil libertarians. This case put the company on the side of a terrorist.
âThey need to figure that out now before there is that bigger body count. So this is as good a test case as any to have that fight,â said Ron Hosko, who until 2014 led the F.B.I.âs criminal division. âCrack that thing for me now, Tim Cook, because itâs only going to get worse.â
This week, the Justice Department got its wish when Apple was ordered to override its defenses, even if it meant building a tool that did not exist.
Law enforcement officials cheered the ruling, though they acknowledged that the fight was not over. Apple promised to appeal. In New York, William Bratton, the police commissioner, held up a phone that he said was used by an associate of a man who shot and wounded two police officers in the Bronx recently.
âDespite having a court order, we cannot access this iPhone,â Mr. Bratton said. âJust one example, a very significant example in which two of my officers were shot, that impeding that case going forward is our inability to get into this device.â
The case in Brooklyn continues, even though Mr. Feng has already pleaded guilty. While the Justice Department sees the San Bernardino incident as its ideal test case, Apple is hoping for a legal win in Brooklyn.
Judge James Orenstein has given the company reason to be hopeful. In the past, he has been skeptical of the way the government uses an 18th-century law â the All Writs Act â that the Justice Department is now claiming gives it the authority to force Apple to unlock the phones. He once even described the Justice Departmentâs use of it as a âHail Mary play.â
But he has yet to rule.