FBI Director James Comey said his agency’s ongoing dispute with Apple raises “the hardest question I’ve seen in government.” Comey was testifying before the House Intelligence Committee on Thursday about the government’s attempt to force Apple to write software than undoes its own security protocols.

But Comey has faced considerably tougher questions in his career. Before becoming FBI director, he was the deputy assistant attorney general in George W. Bush’s Justice Department, where he pushed back on certain elements of the Bush-Cheney torture and surveillance programs — but ended up signing off on both.

In April 2004, several months after Comey arrived at DOJ, news broke that U.S. soldiers had tortured prisoners at the Abu Ghraib detention facility in Iraq. Two months later, reporters discovered a memo written in August 2002 by then-Assistant Attorney General Jay Bybee, which outlined a particularly aberrant legal theory for circumventing the U.S.’ anti-torture laws.

The Justice Department, with Comey’s support, retracted that memo soon after it became public. But it did not retract a second memo — which didn’t become public until 2009 — that grotesquely outlined a list of very specific authorized torture tactics, including stress positions, hypothermia, sleep deprivation, and waterboarding.

Because the second memo relied on the first, it had to be rewritten — and the new memo was addressed to “James B. Comey, Deputy Attorney General.” The new memo upheld the conclusions of the former, and did not amend the list of torture techniques.

In 2005, the Bush administration demanded two more memos — another one that spelled out a list of authorized torture techniques, and a second that argued that techniques could be used in combination. In an email, Comey said that he “concurred” with the first memo, but he disagreed with the second.

Comey had twice signed off on waterboarding, but drew the line at combining it with other methods of torture.

Comey would later become a minor celebrity when he testified to Congress in 2007 about a March 2004 confrontation with the Bush White House. While Attorney General John Ashcroft was hospitalized with acute pancreatitis, Comey refused to reauthorize Bush’s mass surveillance program. The White House famously dispatched then-White House Counsel Alberto R. Gonzales and then-White House Chief of Staff Andrew H. Card Jr. to the hospital to persuade Ashcroft to reauthorize it, but Comey beat them to the hospital room, and Ashcroft refused to sign.

The White House eventually capitulated to Comey’s only demand — that the NSA stop collecting email metadata in bulk. Comey then signed off on everything else — including the hugely controversial collection of hundreds of millions of domestic phone records and transnational communications by the NSA.

Despite his involvement with Bush-era torture and mass surveillance, Comey’s public confrontation with the Bush administration endeared him to Democrats, and he was confirmed as FBI director by a 93-1 vote.