Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error when connecting to PKI enabled server #169

Open
hamiltoncj opened this issue Oct 21, 2020 · 5 comments
Open

Error when connecting to PKI enabled server #169

hamiltoncj opened this issue Oct 21, 2020 · 5 comments

Comments

@hamiltoncj
Copy link

When I attempt to add a repository to a server that uses PKI authentication. I click on the "Add..." button and give it a name and url, then next to Authentication I click on Add to select my certificate token then click on "OK", I get this error message:

type object 'QgsAuthManager' has no attribute 'instance'

@hamiltoncj
Copy link
Author

hamiltoncj commented Oct 21, 2020

This error occurs in network_manager.py and probably at line 56 with these lines of code:

            QgsAuthManager.instance().updateNetworkRequest(
                request, self._auth_cfg
            )

I have been using QgsNetworkContentFetcher for these calls and it works beautifully because auth_cfg is integrated into it. The only problem is that it requires QGIS 3.10 and above. QgsBlockingNetworkRequest also works well and works with QGIS 3.6 and above. I made some attempt to fix the problem, but am not sure how to do it with a QNetworkRequest.

zacharlie added a commit to zacharlie/QGIS-ResourceSharing that referenced this issue Oct 22, 2020
The API for QgsAuthManager.instance() has changed QgsApplication.authManager() to address QGIS-Contribution#169
@zacharlie
Copy link

I also got the type object 'QgsAuthManager' has no attribute 'instance' error when trying to use the authentication manager.

@ricardogsilva pointed out to me that QgsApplication.authManager() is the correct way to instantiate the authentication manager.

I had a look and it seems the API changed. I have a draft pull request #170 which seemed to fix this for me but I think needs further testing.

@hamiltoncj
Copy link
Author

I have already tried this as a fix, but it is not sufficient. PKI authentication is quite complex and I tried at one time to implement it with QNetworkRequest, but there is much more to it then this. I never really got it working. The QGIS team put a lot of work into QgsNetworkContentFetcher and QgsBlockingNetworkRequest and made sure they work with PKI. I don't recommend that you use QNetworkRequest because it is going to continually cause problems. I recommend that you switch to one of these QGIS integrated calls.

@hamiltoncj
Copy link
Author

I have one other comment which is that QgsApplication.authManager() fixed the error I first reported, but it does not fix the PKI authentication. What fails now is the SSL handshake.

@hamiltoncj
Copy link
Author

hamiltoncj commented Nov 3, 2020

@zacharlie
I have been doing some more testing, using

QgsApplication.authManager().updateNetworkRequest(
request, self._auth_cfg
)

fixes this main problem and allows the directory of resources to be read; however, it appears that that the auth_cfg id is not being used when the actual resource is requested which results in an SSL error to download the resource.

You can see this as follows:

In the file basy.py around line 128 in fetch_metadata, NetworkManager is called

network_manager = NetworkManager(self.metadata_url, self.auth_cfg)

but when the resource is requested it is without auth_cfg (remote_zip_handler.py line 49)

network_manager = NetworkManager(self.file_url(collection_path)) # No auth_cfg

Also in repository_manager.py line 92

downloader = NetworkManager(self.Directory_URL) # No auth_cfg

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants