crits / crits_services

CRITs Services Collection
182 stars 129 forks source link

taxii_services: Send to TAXII Server fails with "local variable 'proxy' referenced before assignment" #249

Closed packet-rat closed 8 years ago

packet-rat commented 8 years ago

Send to TAXII Server fails with "local variable 'proxy' referenced before assignment" In the configuration scenario below (No Proxy, https):

2016-07-25_19-12-52

Example:

2016-07-25_16-08-57

2016-07-25_16-09-15

2016-07-25_16-09-30

Adding a check for HTTP_PROXY before attempting client.setProxy(proxy) solved the problem for me.

@ ~ line 1300

Was

# Setup client authentication and proxy communication
        if https:
            client.setUseHttps(True)
        client.setProxy(proxy)
        if akey and lcert and user:
            client.setAuthType(tc.HttpClient.AUTH_CERT_BASIC)
            client.setAuthCredentials({'key_file': akey, 'cert_file': lcert,
                                       'username': user, 'password': pword})

Is

@ ~ line 1300

# Setup client authentication and proxy communication
        if https:
            client.setUseHttps(True)
        if settings.HTTP_PROXY:
            client.setProxy(proxy)
        if akey and lcert and user:
            client.setAuthType(tc.HttpClient.AUTH_CERT_BASIC)
            client.setAuthCredentials({'key_file': akey, 'cert_file': lcert,
                                       'username': user, 'password': pword})

Didn't know if there was a specific reason to not issue client.setProxy after line ~1258 (similar to the identical code block at line 265):


# Get Proxy settings
    if settings.HTTP_PROXY:
        proxy = settings.HTTP_PROXY
        if not proxy.startswith('http://'):
            proxy = 'http://' + proxy

# Get Proxy settings
    if settings.HTTP_PROXY:
        proxy = settings.HTTP_PROXY
        if not proxy.startswith('http://'):
            proxy = 'http://' + proxy
        client.setProxy(proxy)
brlogan commented 8 years ago

Oops, good catch, @packet-rat! This is fixed with PR #250.