示例#1
0
def cvctest():
    cvc = CVC(TEST_CVC)
    cvc_desc = eac.d2i_CVC_CERTIFICATE_DESCRIPTION(TEST_DESCRIPTION)
    print cvc.chat
    #eac.cvc_chat_print(cvc.chat, 4)

    asn1_chat = "\x7F\x4C\x12\x06\x09\x04\x00\x7F\x00\x07\x03\x01\x02\x02\x53\x05\x00\x01\x01\x98\x04"

    chat = CHAT(asn1_chat)
    print(chat)
    print(chat.get_role())
    print(chat.get_terminal_type())
    print(chat.get_relative_authorizations())

    eac.CVC_CERTIFICATE_DESCRIPTION_free(cvc_desc)

    terminal_cert = CVC(CHAIN_CVC)
    print terminal_cert
    dvca_cert = CVC(DVCA)
    print dvca_cert
    cvca_cert = CVC(CVCA)
    print("Certificate chain:")
    print(cvca_cert.get_chr() + " -> " + dvca_cert.get_chr() + " -> " +
          terminal_cert.get_chr())
    print(terminal_cert.get_chr() + " -> " + terminal_cert.get_car() + " -> " +
          dvca_cert.get_car())
    print("Terminal certificate validity period:")
    print(terminal_cert.get_effective_date())
    print(terminal_cert.get_expiration_date())
    print("Terminal certificate profile identifier")
    print(terminal_cert.get_profile_identifier())
示例#2
0
def cvctest():
    cvc = CVC(TEST_CVC)
    cvc_desc = eac.d2i_CVC_CERTIFICATE_DESCRIPTION(TEST_DESCRIPTION)
    print cvc.chat
    #eac.cvc_chat_print(cvc.chat, 4)

    asn1_chat="\x7F\x4C\x12\x06\x09\x04\x00\x7F\x00\x07\x03\x01\x02\x02\x53\x05\x00\x01\x01\x98\x04"

    chat = CHAT(asn1_chat)
    print(chat)
    print(chat.get_role())
    print(chat.get_terminal_type())
    print(chat.get_relative_authorizations())

    eac.CVC_CERTIFICATE_DESCRIPTION_free(cvc_desc)

    terminal_cert = CVC(CHAIN_CVC)
    print terminal_cert
    dvca_cert = CVC(DVCA)
    print dvca_cert
    cvca_cert = CVC(CVCA)
    print("Certificate chain:")
    print(cvca_cert.get_chr() + " -> " + dvca_cert.get_chr() + " -> " + terminal_cert.get_chr())
    print(terminal_cert.get_chr() + " -> " + terminal_cert.get_car() + " -> " + dvca_cert.get_car())
    print("Terminal certificate validity period:")
    print(terminal_cert.get_effective_date())
    print(terminal_cert.get_expiration_date())
    print("Terminal certificate profile identifier")
    print(terminal_cert.get_profile_identifier())
示例#3
0
    def Process_Chat(self):

        chat = CHAT()

        if chat.Is_Valid():

            self.Add_Chat(chat)

            self.Pickle()

        return chat
示例#4
0
class CLIENT:
    def __init__(self):
        self.connection = CONNECT(HOST, PORT)
        self.chat = CHAT()

    def start_connection(self):
        #open connection with the server
        message_type = ''
        self.connection.connect_to_server()
        while message_type != START_MESSAGE:
            self.chat.login()
            start_message = self.chat.create_start_message()
            self.connection.send_message(start_message)
            data = self.connection.get_message()
            message_type, message = self.chat.split_data(data)
            if message_type != START_MESSAGE:
                print('user name is already exist')
        self.chat.start_chat(self.create_room, self.join_room)

    def create_room(self):
        #create a new room, in the server side too
        self.connection.send_message(CREATE_SIGN)
        answer = self.connection.get_message()
        if answer == FAILED_MESSAGE:
            print('create room faild')
        else:
            self.chat.room_id = answer
            print('your room id is', answer)
            self.chat_mode()

    def join_room(self):
        #join to chat room, in the server side too
        answer = ''
        while answer != SUCCESS_MESSAGE:
            room_id = input('Enter room id: ')
            self.chat.room_id = room_id
            self.connection.send_message(JOIN_SIGN + SPLIT_CHAR + room_id)
            answer = self.connection.get_message()
            if answer == FAILED_MESSAGE:
                print('wrong room id')
        self.chat_mode()

    def chat_mode(self):
        # enter the user to chat mode, send message to the chat room and printing chat room messages.
        print('chat mode')
        new_message = ''
        start_new_thread(self.printing_chat_message, ())
        while new_message != EXIT_SIGN:
            new_message = input()
            self.connection.send_message(
                self.chat.create_chat_message(new_message))

    def printing_chat_message(self):
        # its thread in chat mode, printing all server message (chat room message).
        while True:
            message = self.connection.get_message()
            print(message)
示例#5
0
    def parse_SE_config(self, config):
        r = 0x9000
        try:
            ControlReferenceTemplate.parse_SE_config(self, config)
        except SwError as e:
            structure = unpack(config)
            for tlv in structure:
                tag, length, value = tlv
                if tag == 0x7f4c:
                    self.chat = CHAT(bertlv_pack([[tag, length, value]]))
                    print(self.chat)
                elif tag == 0x67:
                    self.auxiliary_data = bertlv_pack([[tag, length, value]])
                elif tag == 0x80 or tag == 0x84 or tag == 0x83 or tag == 0x91:
                    # handled by ControlReferenceTemplate.parse_SE_config
                    pass
                else:
                    raise SwError(SW["ERR_REFNOTUSABLE"])

        return r, ""
示例#6
0
    def parse_SE_config(self, config):
        r = 0x9000
        try:
            ControlReferenceTemplate.parse_SE_config(self, config)
        except SwError as e:
            structure = unpack(config)
            for tlv in structure:
                tag, length, value = tlv
                if tag == 0x7f4c:
                    self.chat = CHAT(bertlv_pack([[tag, length, value]]))
                elif tag == 0x67:
                    self.auxiliary_data = bertlv_pack([[tag, length, value]])
                    # extract reference values for verifying
                    # DateOfBirth, DateOfExpiry and CommunityID
                    for ddo in decodeDiscretionaryDataObjects(value):
                        try:
                            oidvalue = ddo[0][2]
                            reference = ddo[1][2]
                            mapped_algo = ALGO_MAPPING[oidvalue]
                            if mapped_algo == "DateOfBirth":
                                self.DateOfBirth = int(reference)
                                logging.info("Found reference DateOfBirth: " +
                                             str(self.DateOfBirth))
                            elif mapped_algo == "DateOfExpiry":
                                self.DateOfExpiry = int(reference)
                                logging.info("Found reference DateOfExpiry: " +
                                             str(self.DateOfExpiry))
                            elif mapped_algo == "CommunityID":
                                self.CommunityID = binascii.hexlify(reference)
                                logging.info("Found reference CommunityID: " +
                                             str(self.CommunityID))
                        except:
                            pass
                elif tag == 0x80 or tag == 0x84 or tag == 0x83 or tag == 0x91:
                    # handled by ControlReferenceTemplate.parse_SE_config
                    pass
                else:
                    raise SwError(SW["ERR_REFNOTUSABLE"])

        return r, b""
示例#7
0
 def __init__(self):
     self.connection = CONNECT(HOST, PORT)
     self.chat = CHAT()
    else:
        userName = arguments[0]
        chatString = arguments[1]

        return userName, chatString


def Quit_If_Requested(chatString):

    if chatString == 'q':

        exit()


# ----------------------------- Main function ------------------------

db = DATABASE()

userName, chatString = Get_UserName_And_ChatString()

while True:

    Quit_If_Requested(chatString)

    chat = CHAT(db, userName, chatString)

    chat.Process()

    chatString = input(userName + ': ')