Want the best of VICE News straight to your inbox? Sign up here.

The Saudi military pilot who shot and killed three people on a Florida Navy base Friday exploited a once-obscure loophole in federal law to buy his 9mm Glock model 45 pistol.

The 21-year-old gunman, Mohammed Alshamrani, was a second lieutenant from the Royal Saudi Air Force, in the country for an international training program offered to U.S. allies at the Pensacola Naval Air Station.

He acquired his gun and multiple magazines legally — and then used them to unleash a hail of bullets through a classroom door on the Navy base, injuring 11 people altogether. He died exchanging gunfire with law enforcement, and the incident is now being investigated as an act of terrorism.

Under federal law, “nonimmigrant aliens” —people on student visas, short-term business visas, or tourist visas — can’t buy a gun, borrow a gun, or even use a gun at a shooting range. But, a few exceptions are enshrined in the law, most notably, for anyone with a hunting license, or a sports shooting license.

“I didn’t even know this particular provision was there until this all happened,” said Adam Winkler, professor at UCLA School of Law and author of “Gunfight: The Battle Over the Right to Bear Arms in America.”

Obtaining a hunting license isn’t difficult. In Florida, all someone needs is a valid Florida driver’s license or an ID-card showing a Florida address that’s been verified by the Department of Highway Safety and Motor Vehicles. Most states offer driver’s licenses to foreigners but may have slight variations on requirements to obtain a hunting permit.

Other exceptions to the law allow foreign law enforcement officers of an “allied foreign government,” who are in the U.S on official law enforcement business to possess a gun. The same goes for the slightly murkier category of “distinguished foreign visitors” or individuals considered official representatives of a foreign government.

Finally, there’s an option to petition the Justice Department and receive explicit permission to carry a gun in the U.S. from the Attorney General.

On Tuesday, the FBI’s office in Jacksonville, Florida, confirmed that the shooter had qualified for a valid Florida hunting license, but added that he “may have qualified under other exceptions as well.”

The shooter started the 15-week process of buying his gun back in April, the Daily Beast reported on Monday. That was around the same time that he filed a complaint against his instructor, who had referred to him as “Porn Stash” in front of the class.

“That’s a federal loophole that he took advantage of,” Florida Gov. Ron DeSantis said at a news conference Sunday evening. “I’m a big supporter of the Second Amendment, but the Second Amendment applies so that we, the American people, can keep and bear arms. It does not apply to Saudi Arabians.”

A universal background check, which the House passed earlier this year before the bill stalled in the GOP-controlled Senate — would close these loopholes, including the “background check loophole” that allows individuals to buy guns through private vendors even after they’ve failed a background check.

“For years, gun safety advocates have argued that there are too many loopholes and that terrorists would take advantage of them,” Winkler said. “Indeed, here we are. Terrorists are taking advantage of our lax laws, for terrorist purposes.”

The FBI is still combing through his electronics and personal possessions, and conducting interviews, to try and establish a motive. SITE Intelligence Agency, which monitors online extremism, surfaced a Twitter account apparently linked to the shooter, which criticized U.S. foreign policy and its treatment of Muslims and quoted Osama Bin Laden.

Editor's note 12/10: This story has been updated to reflect confirmation from the FBI which path the gunman pursued to qualify for the loophole that allowed him to purchase his gun.