Fix logic to validate keyfile