Journalist Barton Gellman met with a Google security engineer for a beer one Sunday in late autumn of 2013. Gellman had a 23-page top-secret National Security Agency document on his laptop that NSA leaker Edward Snowden had shared with him. It discussed ways the agency had devised for defeating Google’s security. Gellman flipped open his computer, scrolled down to page 14, and the engineer started reading. After several moments, he leaned toward the machine and read the page a second time, his eyebrows rising in disbelief. “Mo-ther-f------,” he muttered.

The document showed a hand-drawn cartoon of two fluffy clouds side by side, one labeled “Public Internet” and the other “Google Cloud.” An arrow pointed to where the two bubbles met, “the digital borderland,” as Gellman put it in his book “Dark Mirror,” “between Google’s inside networks and the outside world.” The cartoon appeared to show that the NSA found a way around Google’s encryption technology that protects information on the Internet. Studying the document, the Google engineer realized that the NSA had understood Google’s internal network architecture and spotted an opening that could be targeted on cables outside the United States. Gellman asked how Google protected itself from such an attack. “I’m not going to tell you,” the engineer replied.

“Not well enough,” Gellman said.

“I’ll tell you one thing — that’s going to change,” the engineer promised.

Nearly seven years have passed since that meeting. Now it’s time to reassess Snowden by moving beyond the hackneyed question of whether he is a hero or a traitor. Yes, he caused significant harm to U.S. intelligence collection — and, yes, he spurred significant improvements to Internet security. His activities weakened national security, but strengthened American democracy. Gellman’s illuminating book, in effect, turns a faux contradiction into a real question: Was it necessary to harm U.S. national security in the short term to secure the Internet in the long run? It’s hard to admit that the answer may be yes, especially for the many intelligence officers and diplomats and civil servants who were so offended by the biggest intelligence leak in U.S. history. President Trump inadvertently is helping to put Snowden into a more nuanced perspective.

Several firsthand accounts have appeared since 2013: most notably, Glenn Greenwald’s 2014 memoir, “No Place to Hide”; Laura Poitras’s 2014 documentary, “Citizenfour”; and Snowden’s 2019 memoir, “Permanent Record.”

“Dark Mirror” stands out from all the other accounts. Gellman, a Pulitzer Prize-winning former Washington Post investigative reporter and author of “Angler,” an influential 2008 biography of Dick Cheney, didn’t just use the Snowden files as sources; he used them as starting points for deep, labor-intensive reporting. He hired Ashkan Soltani, a highly respected technical research assistant, met with technology companies, worked his contacts in and around Washington. And he understood that labeling a document “secret” doesn’t necessarily mean it’s accurate and that “top secret” doesn’t necessarily mean more accurate.

“Dark Mirror” adds newsworthy detail about the NSA’s controversial collection of data on the phone calls of Americans. The metadata program, now abandoned, ingested U.S. call records on a massive scale. It took off soon after the attacks of Sept. 11, 2001, when the NSA confronted the challenge of gathering very large amounts of communications data in the interests of protecting against another attack.

The agency needed tools not just to store the data but to crunch the information in a way that would make queries by intelligence analysts quicker and more precise. One tool that emerged was called MAINWAY, which was designed to handle and process the data of hundreds of billions of phone calls.

An internal NSA dictionary described MAINWAY as a “precomputed contact chaining service,” comparable perhaps to the way Google is precomputing websites so that searches can unlock a query instantly and precisely. MAINWAY churned through about 1 billion call records a day and then had to purge about that amount every day to comply with court orders.

Spying on innocent Americans is a cultural and legal taboo for U.S. intelligence agencies. But here NSA was collecting reams of call records of ordinary citizens. More than that: By building dedicated machines to sift the data, the eavesdropping agency apparently created what amounts to a dossier on every American citizen with a phone, unseen by human eyes, of course (the sifting was automated), but a form of dossier full of intimately private information nevertheless. Gellman recalls how the realization finally sank in, as he was parsing documents and interviewing sources, that the NSA had effectively built a social network of most if not all Americans, not unlike a Facebook listing of friends, and friends of friends, and friends of friends of friends, a live, ever-updating “mass social graph” of the United States, as Gellman put it. This vast, hidden diagram of who communicates with whom also pointed to potential terrorism dangers.

Even if no human analyst looked at the data, the machines could still spot suspicious behavior. For example: Criminals and militants often used “burner phones” — mobile phones, purchased with cash, that they would use only to call a small number of trusted co-conspirators, in the belief that this was good security practice. But viewed through the vast telephony graph, the burner phones would stand out as a “closed loop,” as intelligence analysts call it, because they connected only to one another and not to the wider jumble of phone conversations. It appears that MAINWAY was used for such automated spying; one NSA document stressed, Gellman reveals, that the system was able to move “from the more traditional analysis of what is collected to the analysis of what to collect.”

Gellman holds senior intelligence officials accountable for deceiving the public about the NSA’s data-collection activities. After revealing the language in classified documents, Gellman gives us the officials’ public statements, including that of ex-NSA director Keith Alexander in 2012 (“We don’t hold data on U.S. citizens”) and Director of National Intelligence James R. Clapper Jr. (“No, sir,” in response to Sen. Ron Wyden (D-Ore.) asking whether the NSA collected any type of data on Americans). When Gellman mentioned to Dennis Blair, a former director of national intelligence, at an event in Aspen, that the NSA was collecting U.S. telephone records in bulk, the admiral responded, testily: “I think you’re misusing the word ‘collect.’ I think the word, the proper word here, is ‘store.’ ”

In hindsight, the reputation and credibility of these officials was not diminished by Snowden or the leaked files, but by themselves, by their own inept reactions and denials. Trust in senior national security officials has only eroded further in the past three years as intelligence assessments and criticism, especially related to Russia, have become fiercely politicized.

But another trend is quieter and more insidious. Three years into the Trump administration, careful observers measure trust in national security institutions by the amount of open friction between their leadership and the White House. Yet perceived dissent can result in stiff action such as the president’s firing of Michael Atkinson, the intelligence community inspector general responsible for notifying Congress of a whistleblower complaint. Trump installed loyal supporters in several usually nonpartisan positions, including attorney general and acting director of national intelligence. This bringing into line of a once more independent security establishment would no doubt continue in a second Trump term. At the same time the president regularly calls journalists and domestic opponents “enemies of the people,” thus normalizing language that makes confrontations less civil, and the peace more brittle. Early on, Snowden called the United States’ secret surveillance capabilities “turnkey tyranny.” I cringed when I heard that haughty phrase in mid-2013; by mid-2020, I no longer do. The nation’s open flirtation with authoritarian rule has bent the arc of history in Snowden’s favor.

Dark Mirror

Edward Snowden and the American Surveillance State

By Barton Gellman

Penguin Press. 426 pp. $30