A federal district court judge in New York today called into question several of the federal government’s arguments in its push to make Apple unlock San Bernardino shooter Syed Rizwan Farook’s iPhone.

U.S. Magistrate Judge James Orenstein, of the U.S. District Court for the Eastern District of New York, focused much of his vigorous attack on the use of the All Writs Act in the case. Orenstein has spent the past several months handling a separate case — it involves Jun Feng, a resident of Queens, New York, who was indicted on charges of meth trafficking and whose iPhone 5s was taken by U.S. Drug Enforcement Administration (DEA) agents — but one in which Apple feared that the All Writs Act would be invoked.

“This matter [involving the San Bernardino shooter] is therefore one of a dozen pending cases in which the government and Apple disagree as to the court’s authority to command Apple to assist the government in defeating the passcode security of devices Apple has manufactured,” Judge Orenstein wrote. He went on to dismantle the specific citation of the All Writs Act in several ways.

The opinion is fascinating because it shows a federal judge is going against what attorneys from the U.S. Department of Justice (DOJ) have pushed for — and instead aligning with Apple.

Judge Orenstein echoed some of the points that Apple chief executive Tim Cook has made.

For instance, in the end, the judge suggested that the debate about this topic ought to be held in Congress, not behind closed doors in courts:

[It] must take place among legislators who are equipped to consider the technological and cultural realities of a world their predecessors could not begin to conceive. It would betray our constitutional heritage and our people’s claim to democratic governance for a judge to pretend that our Founders already had that debate, and ended it, in 1789.

And the judge recognizes the slippery slope that could result from a ruling in the government’s favor. In a footnote Judge Orenstein goes beyond discussion of Apple’s iPhones and addresses the general category of Internet-connected devices, an area that hasn’t gotten a whole lot of attention in discussions about this case:

In a world in which so many devices, not just smartphones, will be connected to the Internet of Things, the government’s theory that a licensing agreement allows it to compel the manufacturers of such products to help it surveil the products’ users will result in a virtually limitless expansion of the government’s legal authority to surreptitiously intrude on personal privacy.

The judge also doesn’t assign much fault to the way that Apple has not overtly done things to get in the way of the advancement of the investigation.

“Apple has not conspired with Feng to make the data on his device inaccessible,” Judge Orenstein wrote. “More importantly, perhaps, it has not even done what the telephone company did in N.Y. Telephone Co. — namely, it has not barred the door to its property to prevent law enforcement agents from entering and performing actions they were otherwise competent to undertake in executing the warrant for themselves.”

And that point by extension means that the federal government can’t necessarily compare Apple with the New York Telephone Co. while resting its defense on the All Writs Act. For Judge Orenstein, that part of the argument just doesn’t hold up.

The New York Telephone Co. was classified as a regulated public utility in the 1977 Supreme Court case that the U.S. brought against it. But here again Judge Orenstein does not see how Apple is like the New York Telephone Co.

“It has a duty is to serve its shareholders rather than the public,” Judge Orenstein wrote.

Arguably the most significant attack that the judge leveled at the government today is its wavering in whether it has suitable technology to be able to unlock an iPhone. This might seem tactical, but its importance is really legal in nature. The government sought help through the courts here on the basis that it didn’t have the capability to unlock the phone, but as Judge Orenstein pointed out, that might not actually be the case.

“Two months earlier, however, in opposing a suppression motion in an unrelated criminal case in this district, the government said something quite different,” the judge wrote. He went on to quote from a letter the government submitted in the case United States v. Adamou Djibo:

T]he lack of a passcode is not fatal to the government’s ability to obtain the records. That is because [the Department of Homeland Security (“DHS”), Homeland Security Investigations (“HSI”)] is in possession of technology that would allow its forensic technicians to override the passcode security feature on the Subject iPhone and obtain the data contained therein. In other words, even if HSI agents did not have the defendant’s passcode, they would nevertheless have been able to obtain the records stored in the Subject iPhone using specialized software. The software works to bypass the passcode entry requirement and “unlock” the cellular telephone without having to enter the code. Once the device is “unlocked” all records in it can be accessed and copied.

The technology in question here is the “IP-BOX,” which runs brute force attacks on iOS devices in order to unlock them. And the iPhone in the Djibo case is an iPhone 5 running iOS 8.1.2. When Judge Orenstein asked the government about the gap between what the government said then and what it said now, the government came back with a very confusing and obfuscating answer. Orenstein provides it here:

The government has consulted with the testifying agent in Djibo, who noted that the government’s ability to bypass the passcode on an iPhone is highly device-specific, and depends in part on the specific hardware and software in place. The investigators in this case have examined the possibility of using various third-party technologies, including the hacking tool referenced in Djibo, and determined that, in this case, using such technology on the Target Phone [i.e., Feng’s iPhone] presents a non-trivial risk of data destruction. Specifically, the tool, which serially tests various passcodes until detecting the correct one, could activate the “erase data” feature of the iPhone and render the data in the Target Phone permanently inaccessible. By contrast, in this case, Apple has the unique ability to safely perform a passcode bypass on the Target Phone without risking such data destruction.

Judge Orenstein does not come away very convinced that the government’s argument is sound.

“What it does establish is simply that the government has made so many conflicting statements in the two cases as to render any single one of them unreliable,” the judge wrote. “Because it is the government’s burden, as the movant seeking relief, to demonstrate a basis for granting its request, I necessarily conclude that it has failed to establish that the help it seeks from Apple is necessary for purposes of the test under N.Y. Telephone Co.”

For a full overview of the Apple-FBI case, check out our ongoing timeline.