Пример #1
0
 def testConsistency(self):
     """
     Test if when given the same input in different times the user will get
     the same checksum.
     """
     with open("/dev/urandom", "rb") as f:
         data = f.read(50)
     self.assertEquals(misc.checksum(data, 16), misc.checksum(data, 16))
Пример #2
0
 def testConsistency(self):
     """
     Test if when given the same input in different times the user will get
     the same checksum.
     """
     with open("/dev/urandom", "rb") as f:
         data = f.read(50)
     self.assertEqual(misc.checksum(data, 16), misc.checksum(data, 16))
Пример #3
0
 def test_good_checksum(self):
     msg = "x" * sm.MESSAGE_SIZE
     padding = sm.MAILBOX_SIZE - sm.MESSAGE_SIZE - sm.CHECKSUM_BYTES
     data = msg + padding * "\0"
     n = misc.checksum(data, sm.CHECKSUM_BYTES)
     checksum = struct.pack('<l', n)
     mailbox = data + checksum
     self.assertTrue(sm.SPM_MailMonitor.validateMailbox(mailbox, 7))
Пример #4
0
 def _sendMail(self):
     self.log.info("HSM_MailMonitor sending mail to SPM - " +
                   str(self._outCmd))
     chk = misc.checksum(
         self._outgoingMail[0:MAILBOX_SIZE - CHECKSUM_BYTES],
         CHECKSUM_BYTES)
     pChk = struct.pack('<l', chk)  # Assumes CHECKSUM_BYTES equals 4!!!
     self._outgoingMail = \
         self._outgoingMail[0:MAILBOX_SIZE - CHECKSUM_BYTES] + pChk
     _mboxExecCmd(self._outCmd, data=self._outgoingMail)
Пример #5
0
 def _sendMail(self):
     self.log.info("HSM_MailMonitor sending mail to SPM - " +
                   str(self._outCmd))
     chk = misc.checksum(
         self._outgoingMail[0:MAILBOX_SIZE - CHECKSUM_BYTES],
         CHECKSUM_BYTES)
     pChk = struct.pack('<l', chk)  # Assumes CHECKSUM_BYTES equals 4!!!
     self._outgoingMail = \
         self._outgoingMail[0:MAILBOX_SIZE - CHECKSUM_BYTES] + pChk
     _mboxExecCmd(self._outCmd, data=self._outgoingMail)
Пример #6
0
 def _validateMailbox(self, mailbox, mailboxIndex):
     chkStart = MAILBOX_SIZE - CHECKSUM_BYTES
     chk = misc.checksum(mailbox[0:chkStart], CHECKSUM_BYTES)
     pChk = struct.pack('<l', chk)  # Assumes CHECKSUM_BYTES equals 4!!!
     if pChk != mailbox[chkStart:chkStart + CHECKSUM_BYTES]:
         self.log.error(
             "SPM_MailMonitor: mailbox %s checksum failed, not "
             "clearing mailbox, clearing newMail.", str(mailboxIndex))
         return False
     elif pChk == pZeroChecksum:
         return False  # Ignore messages of empty mailbox
     return True
Пример #7
0
 def _validateMailbox(self, mailbox, mailboxIndex):
     chkStart = MAILBOX_SIZE - CHECKSUM_BYTES
     chk = misc.checksum(mailbox[0:chkStart], CHECKSUM_BYTES)
     pChk = struct.pack('<l', chk)  # Assumes CHECKSUM_BYTES equals 4!!!
     if pChk != mailbox[chkStart:chkStart + CHECKSUM_BYTES]:
         self.log.error("SPM_MailMonitor: mailbox %s checksum failed, not "
                        "clearing mailbox, clearing newMail.",
                        str(mailboxIndex))
         return False
     elif pChk == pZeroChecksum:
         return False  # Ignore messages of empty mailbox
     return True
Пример #8
0
 def validateMailbox(self, mailbox, mailboxIndex):
     """
     Return True if mailbox has a valid checksum, and is not an empty
     mailbox, False otherwise.
     """
     assert len(mailbox) == MAILBOX_SIZE
     data = mailbox[:-CHECKSUM_BYTES]
     checksum = mailbox[-CHECKSUM_BYTES:]
     n = misc.checksum(data, CHECKSUM_BYTES)
     expected = struct.pack('<l', n)  # Assumes CHECKSUM_BYTES equals 4!!!
     if checksum != expected:
         self.log.error(
             "mailbox %s checksum failed, not clearing mailbox, clearing "
             "new mail (data=%r, checksum=%r, expected=%r)",
             mailboxIndex, data, checksum, expected)
         return False
     elif expected == pZeroChecksum:
         return False  # Ignore messages of empty mailbox
     return True
Пример #9
0
 def validateMailbox(self, mailbox, mailboxIndex):
     """
     Return True if mailbox has a valid checksum, and is not an empty
     mailbox, False otherwise.
     """
     assert len(mailbox) == MAILBOX_SIZE
     data = mailbox[:-CHECKSUM_BYTES]
     checksum = mailbox[-CHECKSUM_BYTES:]
     n = misc.checksum(data, CHECKSUM_BYTES)
     expected = struct.pack('<l', n)  # Assumes CHECKSUM_BYTES equals 4!!!
     if checksum != expected:
         self.log.error(
             "mailbox %s checksum failed, not clearing mailbox, clearing "
             "new mail (data=%r, checksum=%r, expected=%r)",
             mailboxIndex, data, checksum, expected)
         return False
     elif expected == pZeroChecksum:
         return False  # Ignore messages of empty mailbox
     return True
Пример #10
0
PACKED_UUID_SIZE = 16
VOLUME_MAX_SIZE = 0xFFFFFFFF  # 64 bit unsigned max size
SIZE_CHARS = 16
MESSAGE_VERSION = "1"
MESSAGE_SIZE = 64
CLEAN_MESSAGE = "\1" * MESSAGE_SIZE
EXTEND_CODE = "xtnd"
BLOCK_SIZE = 512
REPLY_OK = 1
EMPTYMAILBOX = MAILBOX_SIZE * "\0"
SLOTS_PER_MAILBOX = int(MAILBOX_SIZE / MESSAGE_SIZE)
# Last message slot is reserved for metadata (checksum, extendable mailbox,
# etc)
MESSAGES_PER_MAILBOX = SLOTS_PER_MAILBOX - 1

_zeroCheck = misc.checksum(EMPTYMAILBOX, CHECKSUM_BYTES)
# Assumes CHECKSUM_BYTES equals 4!!!
pZeroChecksum = struct.pack('<l', _zeroCheck)


def dec2hex(n):
    return "%x" % n


def runTask(args):
    if type(args) == tuple:
        cmd = args[0]
        args = args[1:]
    else:
        cmd = args
        args = None
Пример #11
0
VOLUME_MAX_SIZE = 0xFFFFFFFF  # 64 bit unsigned max size
SIZE_CHARS = 16
MESSAGE_VERSION = "1"
MESSAGE_SIZE = 64
CLEAN_MESSAGE = "\1" * MESSAGE_SIZE
EXTEND_CODE = "xtnd"
BLOCK_SIZE = 512
REPLY_OK = 1
EMPTYMAILBOX = MAILBOX_SIZE * "\0"
BLOCKS_PER_MAILBOX = int(MAILBOX_SIZE / BLOCK_SIZE)
SLOTS_PER_MAILBOX = int(MAILBOX_SIZE / MESSAGE_SIZE)
# Last message slot is reserved for metadata (checksum, extendable mailbox,
# etc)
MESSAGES_PER_MAILBOX = SLOTS_PER_MAILBOX - 1

_zeroCheck = misc.checksum(EMPTYMAILBOX, CHECKSUM_BYTES)
# Assumes CHECKSUM_BYTES equals 4!!!
pZeroChecksum = struct.pack('<l', _zeroCheck)


def dec2hex(n):
    return "%x" % n


def runTask(args):
    if type(args) == tuple:
        cmd = args[0]
        args = args[1:]
    else:
        cmd = args
        args = None