Exemple #1
0
    def to_string(self):
        """
        Return the current configuration as a string (always 64 bytes).
        """
        #define UID_SIZE		6	/* Size of secret ID field */
        #define FIXED_SIZE              16      /* Max size of fixed field */
        #define KEY_SIZE                16      /* Size of AES key */
        #define KEY_SIZE_OATH           20      /* Size of OATH-HOTP key (key field + first 4 of UID field) */
        #define ACC_CODE_SIZE           6       /* Size of access code to re-program device */
        #
        #struct config_st {
        #    unsigned char fixed[FIXED_SIZE];/* Fixed data in binary format */
        #    unsigned char uid[UID_SIZE];    /* Fixed UID part of ticket */
        #    unsigned char key[KEY_SIZE];    /* AES key */
        #    unsigned char accCode[ACC_CODE_SIZE]; /* Access code to re-program device */
        #    unsigned char fixedSize;        /* Number of bytes in fixed field (0 if not used) */
        #    unsigned char extFlags;         /* Extended flags */
        #    unsigned char tktFlags;         /* Ticket configuration flags */
        #    unsigned char cfgFlags;         /* General configuration flags */
        #    unsigned char rfu[2];           /* Reserved for future use */
        #    unsigned short crc;             /* CRC16 value of all fields */
        #};
        t_rfu = 0

        first = struct.pack('<16s6s16s6sBBBBH', self.fixed, self.uid, self.key,
                            self.access_code, len(self.fixed),
                            self.extended_flags.to_integer(),
                            self.ticket_flags.to_integer(),
                            self.config_flags.to_integer(), t_rfu)

        crc = 0xffff - yubico_util.crc16(first)

        second = first + struct.pack('<H', crc) + self.unlock_code
        return second
 def __init__(self, command, payload=''):
     if payload is '':
         payload = '\x00' * 64
     if len(payload) != 64:
         raise yubico_exception.InputError('payload must be empty or 64 bytes')
     self.payload = payload
     self.command = command
     self.crc = yubico_util.crc16(payload)
Exemple #3
0
 def __init__(self, command, payload=''):
     if payload is '':
         payload = '\x00' * 64
     if len(payload) != 64:
         raise yubico_exception.InputError('payload must be empty or 64 bytes')
     self.payload = payload
     self.command = command
     self.crc = yubico_util.crc16(payload)
    def to_string(self):
        """
        Return the current configuration as a string (always 64 bytes).
        """
        # define UID_SIZE		6	/* Size of secret ID field */
        # define FIXED_SIZE              16      /* Max size of fixed field */
        # define KEY_SIZE                16      /* Size of AES key */
        # define KEY_SIZE_OATH           20      /* Size of OATH-HOTP key (key field + first 4 of UID field) */
        # define ACC_CODE_SIZE           6       /* Size of access code to re-program device */
        #
        # struct config_st {
        #    unsigned char fixed[FIXED_SIZE];/* Fixed data in binary format */
        #    unsigned char uid[UID_SIZE];    /* Fixed UID part of ticket */
        #    unsigned char key[KEY_SIZE];    /* AES key */
        #    unsigned char accCode[ACC_CODE_SIZE]; /* Access code to re-program device */
        #    unsigned char fixedSize;        /* Number of bytes in fixed field (0 if not used) */
        #    unsigned char extFlags;         /* Extended flags */
        #    unsigned char tktFlags;         /* Ticket configuration flags */
        #    unsigned char cfgFlags;         /* General configuration flags */
        #    unsigned char rfu[2];           /* Reserved for future use */
        #    unsigned short crc;             /* CRC16 value of all fields */
        # };
        t_rfu = 0

        first = struct.pack(
            "<16s6s16s6sBBBBH",
            self.fixed,
            self.uid,
            self.key,
            self.access_code,
            len(self.fixed),
            self.extended_flags.to_integer(),
            self.ticket_flags.to_integer(),
            self.config_flags.to_integer(),
            t_rfu,
        )

        crc = 0xFFFF - yubico_util.crc16(first)

        second = first + struct.pack("<H", crc) + self.unlock_code
        return second