예제 #1
0
파일: auth.py 프로젝트: ngoniboi/pyHANA
    def perform_handshake(self):
        request = RequestMessage.new(
            self.connection,
            RequestSegment(
                message_types.AUTHENTICATE,
                Authentication(self.user, {self.method: self.client_key})))
        response = self.connection.send_request(request, no_reconnect=True)

        auth_part = response.segments[0].parts[0]
        if self.method not in auth_part.methods:
            raise Exception(
                "Only unknown authentication methods available: %s" %
                b",".join(auth_part.methods.keys()))

        salt, server_key = Fields.unpack_data(
            BytesIO(auth_part.methods[self.method]))

        self.client_proof = self.calculate_client_proof([salt], server_key)
        return Authentication(self.user, {'SCRAMSHA256': self.client_proof})
예제 #2
0
def test_pack_data():
    part = Authentication(
        "TestUser", {
            "SCRAMSHA256":
            b"\xed\xbd\x7c\xc8\xb2\xf2\x64\x89\xd6\x5a\x7c"
            b"\xd5\x1e\x27\xf2\xe7\x3f\xca\x22\x7d\x1a\xb6"
            b"\xaa\xfc\xac\x0f\x42\x8c\xa4\xd8\xe1\x0c\x19"
            b"\xe3\xe3\x8f\x3a\xac\x51\x07\x5e\x67\xbb\xe5"
            b"\x2f\xdb\x61\x03\xa7\xc3\x4c\x8a\x70\x90\x8e"
            b"\xd5\xbe\x0b\x35\x42\x70\x5f\x73\x8c"
        })

    arguments, payload = part.pack_data(constants.MAX_SEGMENT_SIZE)
    assert payload == \
        b"\x03\x00\x08\x54\x65\x73\x74\x55\x73\x65\x72\x0b\x53\x43\x52\x41" \
        b"\x4d\x53\x48\x41\x32\x35\x36\x40\xed\xbd\x7c\xc8\xb2\xf2\x64\x89" \
        b"\xd6\x5a\x7c\xd5\x1e\x27\xf2\xe7\x3f\xca\x22\x7d\x1a\xb6\xaa\xfc" \
        b"\xac\x0f\x42\x8c\xa4\xd8\xe1\x0c\x19\xe3\xe3\x8f\x3a\xac\x51\x07" \
        b"\x5e\x67\xbb\xe5\x2f\xdb\x61\x03\xa7\xc3\x4c\x8a\x70\x90\x8e\xd5" \
        b"\xbe\x0b\x35\x42\x70\x5f\x73\x8c"