Example #1
0
def print_code(totp: pyotp.TOTP, time_delta: int = 0):
    dt = datetime.now()

    if time_delta != 0:
        dt = dt + timedelta(seconds=time_delta)

    print("At %s, the check code is: %s" %
          (dt.strftime("%H:%M:%S"), totp.at(dt)))
Example #2
0
def token_print(secret, n):
    preferred_offset = 0 if time_left > 7 else 1
    for i in range(n):
        totp = TOTP(secret)
        token = totp.at(cur_time, i)
        token_formatted = token[:3] + '-' + token[3:]
        if (i == preferred_offset):
            token_formatted = colored(token_formatted, "green")
            try: 
                copy(token)
            except Exception as e:
                pass
        print(token_formatted)
Example #3
0
def generate_otp(signature,
                 interval=OTP_INTERVAL.OTP_LIVE_TIME,
                 for_time=None):
    """
  :param signature:
  :param interval:
  :param for_time:
  :return: str
  """
    key = generate_secret_key(signature)
    totp = TOTP(key, interval=interval)
    if for_time is None:
        for_time = datetime.datetime.now().replace(microsecond=0)
    # TODO: Logger for generated OTP code
    return totp.at(for_time)
Example #4
0
def test_token():
	totp = TOTP(SECRET, digits=8)
	assert totp.at(1347279358) == "93461643"
	assert totp.at(1347279359) == "93461643"
	assert totp.at(1347279360) == "86031001"
Example #5
0
    def enable_root_mfa_device(self,
                               SerialNumber,
                               Base32StringSeed=None,
                               AuthenticationCode1=None,
                               AuthenticationCode2=None):
        """
        Enables the specified MFA device and associates it with the account root
        user. When enabled, the MFA device is required for every subsequent
        login by the account root user.

        Specify either the ``Base32StringSeed``, or both ``AuthenticationCode1``
        and ``AuthenticationCode2``.

        Request Syntax:
            .. code-block:: python

                response = client.enable_root_mfa_device(
                    SerialNumber=str,
                    Base32StringSeed=str,
                )

            or

            .. code-block:: python

                response = client.enable_root_mfa_device(
                    SerialNumber=str,
                    AuthenticationCode1=str,
                    AuthenticationCode2=str,
                )

        Args:
            SerialNumber (str): The serial number that uniquely identifies the
                MFA device. For virtual MFA devices, the serial number is the
                device ARN.
            Base32StringSeed (str): The Base32 seed defined as specified in
                RFC3548. The Base32StringSeed is Base64-encoded. If set, the
                the current values for the ``AuthenticationCode1`` and
                ``AuthenticationCode2`` arguments will be calculated.
            AuthenticationCode1 (str): An authentication code emitted by the
                device. The format for this parameter is a string of 6 digits.
                If ``Base32StringSeed`` is set, it wil override this argument.
            AuthenticationCode2 (str): An authentication code emitted by the
                device. The format for this parameter is a string of 6 digits.
                If ``Base32StringSeed`` is set, it wil override this argument.

        """
        if Base32StringSeed:
            current = datetime.now()
            previous = current - timedelta(seconds=30)
            totp = TOTP(Base32StringSeed)
            AuthenticationCode1 = totp.at(previous)
            AuthenticationCode2 = totp.at(current)

        r = self._post(
            'api/mfa/enableMfaDevice', {
                'userName': '',
                'serialNumber': SerialNumber,
                'authenticationCode1': AuthenticationCode1,
                'authenticationCode2': AuthenticationCode2
            })
        return r