Exemplo n.º 1
0
def validate_before(not_before, slack):
    if not_before:
        now = time_util.utc_now()
        nbefore = calendar.timegm(time_util.str_to_time(not_before))
        if nbefore > now + slack:
            raise Exception("Can't use it yet %d <= %d" % (nbefore, now))

    return True
Exemplo n.º 2
0
def validate_before(not_before, slack):
    if not_before:
        now = time_util.utc_now()
        nbefore = calendar.timegm(time_util.str_to_time(not_before))
        if nbefore > now + slack:
            raise Exception("Can't use it yet %d <= %d" % (nbefore, now))

    return True
Exemplo n.º 3
0
def validate_on_or_after(not_on_or_after, slack):
    if not_on_or_after:
        now = time_util.utc_now()
        nooa = calendar.timegm(time_util.str_to_time(not_on_or_after))
        if now > nooa + slack:
            raise Exception("Can't use it, it's too old %d > %d" % (nooa, now))
        return nooa
    else:
        return False
Exemplo n.º 4
0
 def issue_instant_ok(self):
     """ Check that the request was issued at a reasonable time """
     upper = time_util.shift_time(time_util.time_in_a_while(days=1),
                                  self.timeslack).timetuple()
     lower = time_util.shift_time(time_util.time_a_while_ago(days=1),
                                  - self.timeslack).timetuple()
     # print "issue_instant: %s" % self.message.issue_instant
     # print "%s < x < %s" % (lower, upper)
     issued_at = time_util.str_to_time(self.message.issue_instant)
     return issued_at > lower and issued_at < upper
Exemplo n.º 5
0
def validate_on_or_after(not_on_or_after, slack):
    if not_on_or_after:
        now = time_util.utc_now()
        nooa = calendar.timegm(time_util.str_to_time(not_on_or_after))
        if now > nooa + slack:
            raise Exception("Can't use it, it's too old %d > %d" %
                            (nooa, now))
        return nooa
    else:
        return False
Exemplo n.º 6
0
 def authn_statement_ok(self, optional=False):
     try:
         # the assertion MUST contain one AuthNStatement
         assert len(self.assertion.authn_statement) == 1
     except AssertionError:
         if optional:
             return True
         else:
             raise
         
     authn_statement = self.assertion.authn_statement[0]
     if authn_statement.session_not_on_or_after:
         if validate_on_or_after(authn_statement.session_not_on_or_after,
                                 self.timeslack):
             self.session_not_on_or_after = calendar.timegm(
                 time_util.str_to_time(
                     authn_statement.session_not_on_or_after))
         else:
             return False
     return True
Exemplo n.º 7
0
def valid_date_time(item):
    try:
        time_util.str_to_time(item)
    except Exception:
        raise NotValid("dateTime")
    return True
Exemplo n.º 8
0
def valid_date_time(item):
    try:
        time_util.str_to_time(item)
    except Exception:
        raise NotValid("dateTime")
    return True