예제 #1
0
파일: sspi.py 프로젝트: nickpfeil/Cellar
    def step(self, in_token=None):
        log.debug("SSPI step input: %s",
                  to_text(base64.b64encode(in_token or b"")))

        sec_tokens = []
        if in_token:
            sec_tokens.append(SecBuffer(SecBufferType.token, in_token))

        if self.channel_bindings:
            sec_tokens.append(
                SecBuffer(SecBufferType.channel_bindings,
                          self._get_native_bindings()))

        in_buffer = SecBufferDesc(sec_tokens) if sec_tokens else None
        out_buffer = SecBufferDesc([SecBuffer(SecBufferType.token)])

        if self.usage == 'initiate':
            res = initialize_security_context(self._credential,
                                              self._context,
                                              self.spn,
                                              context_req=self._context_req,
                                              input_buffer=in_buffer,
                                              output_buffer=out_buffer)
        else:
            res = accept_security_context(self._credential,
                                          self._context,
                                          in_buffer,
                                          context_req=self._context_req,
                                          output_buffer=out_buffer)

        self._context_attr = int(self._context.context_attr)

        if res == SecStatus.SEC_E_OK:
            self._complete = True
            self._attr_sizes = query_context_attributes(
                self._context, SecPkgAttr.sizes)

        # TODO: Determine if this returns None or an empty byte string.
        out_token = out_buffer[0].buffer

        log.debug("SSPI step output: %s",
                  to_text(base64.b64encode(out_token or b"")))

        return out_token
예제 #2
0
def test_query_context_attributes_invalid_handle(attribute):
    with pytest.raises(WindowsError, match="The handle specified is invalid"):
        sspi.query_context_attributes(sspi.SecurityContext(), attribute)
예제 #3
0
def test_query_context_attributes_unknown():
    with pytest.raises(
            NotImplementedError,
            match=
            "Only names, package_info, session_key, or sizes is implemented"):
        sspi.query_context_attributes(sspi.SecurityContext(), 1024)
예제 #4
0
파일: sspi.py 프로젝트: nickpfeil/Cellar
 def session_key(self):
     return query_context_attributes(self._context, SecPkgAttr.session_key)
예제 #5
0
파일: sspi.py 프로젝트: nickpfeil/Cellar
 def negotiated_protocol(self):
     # FIXME: Try and replicate GSSAPI. Will return None for acceptor until the first token is returned. Negotiate
     # for both iniator and acceptor until the context is established.
     package_info = query_context_attributes(self._context,
                                             SecPkgAttr.package_info)
     return to_native(package_info.name).lower()
예제 #6
0
파일: sspi.py 프로젝트: nickpfeil/Cellar
 def client_principal(self):
     if self.usage == 'accept':
         return query_context_attributes(self._context, SecPkgAttr.names)