Jack Goldsmith, a former assistant attorney general in the Bush administration, is a professor at Harvard Law School and a member of the Hoover Institution task force on national security and law. He is the author of “Power and Constraint: The Accountable Presidency after 9/11.”

As the general-election campaign comes into focus, conventional wisdom holds that President Obama is untouchable on national security. But the presidential politics of counterterrorism are less clear than they may seem. Mitt Romney has advantages; the risk is that he will overplay them.

The nation has suffered no major terror attack during Obama’s presidency. Through bold use of intelligence, drones and special forces, Obama’s team has killed Osama bin Laden and dozens of other senior terrorists. Almost as important, Obama’s rhetorical focus on war against al-Qaeda rather than war against Islamists has damaged al-Qaeda’s brand and has drawn complaints from terrorists (including bin Laden, according to documents found after his death). The original al-Qaeda organization seems in disarray. Unsurprisingly, Obama receives high marks from the American people on national security.

These successes have not translated into political capital on counterterrorism issues at home. Obama failed in his signature pledge to close the Guantanamo Bay detention center. His administration had to back down from its attempt to prosecute in civilian court senior terrorist leaders held at Guantanamo. In both contexts, large majorities in Congress, with broad popular support, opposed the president’s policies and enacted laws that forbid closing Guantanamo or trying terrorists held there in civilian court.

Congress pushed back against Obama partly for political reasons and partly because lawmakers did not fully trust his judgment in those contexts. Problems began with some clumsy public errors in the administration’s first year, including the ill-advised attempt to release some detainees into the United States, a waffling reaction to the failed Christmas Day attack by “underwear bomber” Umar Farouk Abdulmutallab and the poorly vetted decision to prosecute 9/11 mastermind Khalid Sheik Mohammed in civilian court. These and related controversies spurred Republicans and many Democrats to hurl charges of insufficient seriousness on counterterrorism — and led to the unprecedented congressional restrictions under which Obama labors.

Obama never really tried to leverage his reputation for killing terrorists abroad into success on Guantanamo-related issues at home. The Bush administration used every tool of the presidency — the bully pulpit, political trench warfare in Congress and threats to disregard congressional restrictions — to further its counterterrorism priorities. The Obama administration has been internally divided on terrorist detention and trial issues and preoccupied with higher-priority matters; it has rarely spent political capital on the Guantanamo detainees.

Although he has not exerted himself, Obama insists he wants to implement his unpopular positions on Guantanamo and civilian trials for accused terrorists. This provides an opening for Romney, who could acknowledge Obama’s successes with targeted killings and at the same time lambaste the president for being too solicitous toward Guantanamo detainees.

Romney could also attack Obama for lacking an effective policy for detaining current terrorist threats, as the administration is ending its detention operations in Afghanistan and refuses to send newly captured suspects to Guantanamo. Romney could press the president for cutting back too much, and more than the law requires, on terrorist interrogation.

Although there is legitimate room for Romney to attack Obama’s counterterrorism ­stances, he runs the danger of going too far. Romney has gone beyond defending Guantanamo and military commissions to suggest that detainees at Gitmo should not have any constitutional rights — a suggestion that flies in the face of a 2008 Supreme Court ruling ( Boumediene v. Bush ) that Guantanamo detainees have at least the constitutional right to habeas corpus, and maybe more.

Romney and his aides also refuse to rule out the possibility that as president he would deploy waterboarding as an interrogation technique, a position hard to square with two congressional laws and a 2006 Supreme Court ruling ( Hamdan v. Rumsfeld ) that together effectively ban the practice.

The perception that the president is constrained by law is vital to the success of counterterrorism policies in courts and cooperation on counterterrorism issues with allies. The opposite perception harmed President George W. Bush in both contexts. Obama has had more success in these contexts despite continuing most of the late Bush-era policies. Obama succeeded in part because he won office having campaigned on restraint in counterterrorism policy and in part because, once in office, his administration acknowledged the limits of presidential authority and the importance of adhering to law in executive orders, litigation positions, speeches and other acts.

Romney must bear these lessons in mind. He will have many chances to attack Obama’s counterterrorism positions on the campaign trail. But in pressing his advantage, Romney should respect established legal limits and convey a responsible conception of the presidency. The reputation that Romney develops on these matters the next six months will inform how his policies fare should he become president.