Add missing code to generate "key of last resort"
Add unit test to check for key of last resort generation