Do key validation only when key is provided

key_id is optional, the previous code didn't handle the case of key_id
not specified
Merge pull request #4553 from mmoya/features

Do key validation only when key is provided