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

Add client-cert-fail #164

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 20 additions & 3 deletions openconnect_sso/authenticator.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ async def authenticate(self, display_mode):
self._detect_authentication_target_url()

response = self._start_authentication()

if isinstance(response, CertRequestResponse):
response = self._start_authentication(no_cert=True)

if not isinstance(response, AuthRequestResponse):
logger.error(
"Could not start authentication. Invalid response type in current state",
Expand Down Expand Up @@ -60,8 +64,8 @@ def _detect_authentication_target_url(self):
self.host.address = response.url
logger.debug("Auth target url", url=self.host.vpn_url)

def _start_authentication(self):
request = _create_auth_init_request(self.host, self.host.vpn_url, self.version)
def _start_authentication(self, no_cert=False):
request = _create_auth_init_request(self.host, self.host.vpn_url, self.version, no_cert)
logger.debug("Sending auth init request", content=request)
response = self.session.post(self.host.vpn_url, request)
logger.debug("Auth init response received", content=response.content)
Expand Down Expand Up @@ -111,14 +115,15 @@ def create_http_session(proxy, version):
E = objectify.ElementMaker(annotate=False)


def _create_auth_init_request(host, url, version):
def _create_auth_init_request(host, url, version, no_cert=False):
ConfigAuth = getattr(E, "config-auth")
Version = E.version
DeviceId = getattr(E, "device-id")
GroupSelect = getattr(E, "group-select")
GroupAccess = getattr(E, "group-access")
Capabilities = E.capabilities
AuthMethod = getattr(E, "auth-method")
ClientCertFail = getattr(E, "client-cert-fail")

root = ConfigAuth(
{"client": "vpn", "type": "init", "aggregate-auth-version": "2"},
Expand All @@ -128,6 +133,9 @@ def _create_auth_init_request(host, url, version):
GroupAccess(url),
Capabilities(AuthMethod("single-sign-on-v2")),
)
if no_cert:
root.append(ClientCertFail())

return etree.tostring(
root, pretty_print=True, xml_declaration=True, encoding="UTF-8"
)
Expand All @@ -144,6 +152,10 @@ def parse_response(resp):


def parse_auth_request_response(xml):
if hasattr(xml, 'client-cert-request'):
logger.info("client-cert-request received")
return CertRequestResponse()

assert xml.auth.get("id") == "main"

try:
Expand Down Expand Up @@ -181,6 +193,11 @@ class AuthRequestResponse:
opaque = attr.ib()


@attr.s
class CertRequestResponse:
pass


def parse_auth_complete_response(xml):
assert xml.auth.get("id") == "success"
resp = AuthCompleteResponse(
Expand Down