Corruption was on Thursday singled out as the biggest obstacle in the fight against terrorism and insecurity.
Retired Chief of Defence Forces Julius Karangi said crooked government officials had aided the entry of more than 100,000 foreigners into the country, some of them criminals.
He said registration officers, police and administrators were issuing Kenyan identity cards, passports and work permits in exchange for bribes.
General Karangi said between May 2014, when the Kenya Defence Forces was first allowed to man roadblocks, and July, more than 100,000 foreigners were arrested, some with explosive-making materials.
He told how KDF intercepted two foreigners who had travelled to Mombasa to clear highly explosive bomb-making material after passing through several police roadblocks.
The retired general spoke at the annual Law Society of Kenya conference at Leisure Lodge in Diani, Kwale and said intelligence was the most important weapon in the war against terrorism.
He supported the idea of securing the borders, not necessarily by building a concrete wall but by creating designated entry and exit points.
“The idea of building a Berlin-style wall is crazy. What we need is border infrastructure and official barriers. This has worked in the US, Italy and Israel. Tunisia and Egypt are doing the same,” he said.
“In past terrorist attacks such as the Norfolk Hotel, US Embassy, Westgate and Garissa University, the NIS said it had prior knowledge that, however, was not acted upon by its colleagues,” he said.
The former top soldier said poverty was not the cause of insecurity although poor youth from slums are easy prey for recruitment.
He said key causes of terrorism and insecurity include political, socio-economic and self motivation factors.
He said Kenya had a major challenge in striking a balance between the war on terrorism and observing human rights.
He said in dictatorships, terrorism was not prominent “because the issue of human rights does not exist”.
In his address, read on his behalf by Solicitor-General Njee Muturi, President Uhuru Kenyatta said corruption fuels insecurity.
“Insecurity, especially terrorism and the spectre of militant violence, cattle rustling and banditry, cyber crime and complex transnational criminal syndicates have all conspired to undermine the gains we made,” said Mr Kenyatta.
The President also accused police and immigration officers of subverting justice by taking bribes to free suspects.