utils.cloud: factorization & better handling of password handshakes

/cc @techhat @regilero