<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def _authenticate_x509(credentials, sock_info):
 """Authenticate using MONGODB-X509. """

    query = SON([('authenticate', 1),
                 ('mechanism', 'MONGODB-X509')])
    if credentials.username is not None:
        query['user'] = credentials.username
    elif sock_info.max_wire_version < 5:
        raise ConfigurationError(
            "A username is required for MONGODB-X509 authentication "
            "when connected to MongoDB versions older than 3.4.")
    sock_info.command('$external', query)