'Makes sure this client has a private key set.
It first tries to load an RSA key from the certificate.
If no certificate is found, or it is invalid, we make a new random RSA key,
and store it as our certificate.
Returns:
An RSA key - either from the certificate or a new random key.'

def InitPrivateKey(self):

    if self.private_key:
        try:
            self.common_name = rdf_client.ClientURN.FromPrivateKey(self.private_key)
            logging.info('Starting    client    %s', self.common_name)
            return self.private_key
        except type_info.TypeValueError:
            pass
    key = rdf_crypto.RSAPrivateKey.GenerateKey(bits=config.CONFIG['Client.rsa_key_length'])
    self.common_name = rdf_client.ClientURN.FromPrivateKey(key)
    logging.info('Client    pending    enrolment    %s', self.common_name)
    self.SavePrivateKey(key)
    return key
