Get OTP from YubiKey.
5102
def get_otp(hsm, args):
    
    if args.no_otp:
        return None
    if hsm.version.have_unlock():
        if args.stdin:
            otp = sys.stdin.readline()
            while otp and otp[-1] == '\n':
                otp = otp[:-1]
        else:
            otp = raw_input('Enter admin YubiKey OTP (press enter to skip) : ')
        if len(otp) == 44:
            # YubiHSM admin OTP's always have a public_id length of 6 bytes
            return otp
        if otp:
            sys.stderr.write("ERROR: Invalid YubiKey OTP\n")
    return None
1031125
def __refillOTPKs(self):
        

        remainingOTPKs = len(self.__otpks)

        if remainingOTPKs < self.__min_num_otpks:
            self.__generateOTPKs(self.__max_num_otpks - remainingOTPKs)
1201589
def _read(self):
        
        request_type = _USB_TYPE_CLASS | _USB_RECIP_INTERFACE | _USB_ENDPOINT_IN
        value = _REPORT_TYPE_FEATURE << 8    # apparently required for YubiKey 1.3.2, but not 2.2.x
        recv = self._usb_handle.controlMsg(request_type,
                                          _HID_GET_REPORT,
                                          _FEATURE_RPT_SIZE,
                                          value = value,
                                          timeout = _USB_TIMEOUT_MS)
        if len(recv) != _FEATURE_RPT_SIZE:
            self._debug("Failed reading %i bytes (got %i) from USB HID YubiKey.\n"
                        % (_FEATURE_RPT_SIZE, recv))
            raise YubiKeyUSBHIDError('Failed reading from USB HID YubiKey')
        data = b''.join(yubico_util.chr_byte(c) for c in recv)
        self._debug("READ  : %s" % (yubico_util.hexdump(data, colorize=True)))
        return data
1331355
def parse_args():
    
    global default_device

    parser = argparse.ArgumentParser(description = "Validate YubiKey OTP's using YubiHSM",
                                     add_help=True
                                     )
    parser.add_argument('-D', '--device',
                        dest='device',
                        default=default_device,
                        required=False,
                        help='YubiHSM device (default : %s).' % default_device
                        )
    parser.add_argument('-v', '--verbose',
                        dest='verbose',
                        action='store_true', default=False,
                        help='Enable verbose operation.'
                        )
    parser.add_argument('--debug',
                        dest='debug',
                        action='store_true', default=False,
                        help='Enable debug operation.'
                        )
    group = parser.add_argument_group('Modes', 'What you want to validate')
    mode_group = group.add_mutually_exclusive_group(required = True)
    mode_group.add_argument('--otp',
                            dest='otp',
                            help='The output from your YubiKey.'
                            )
    mode_group.add_argument('--oath',
                            dest='oath',
                            help='The output from your OATH-HOTP token.'
                            )

    args = parser.parse_args()
    return args
276137
@ReadOperation
    public YubiKeyAccount get(@Selector final String username) {
        val result = registry.getAccount(username);
        return result.orElse(null);
    }
624385
def get(method, hmc, uri, uri_parms, logon_required):
        """"""
        cpc_oid = uri_parms[0]
        query_str = uri_parms[1]
        try:
            cpc = hmc.cpcs.lookup_by_oid(cpc_oid)
        except KeyError:
            raise InvalidResourceError(method, uri)
        result_vswitches = []
        if cpc.dpm_enabled:
            filter_args = parse_query_parms(method, uri, query_str)
            for vswitch in cpc.virtual_switches.list(filter_args):
                result_vswitch = {}
                for prop in vswitch.properties:
                    if prop in ('object-uri', 'name', 'type'):
                        result_vswitch[prop] = vswitch.properties[prop]
                result_vswitches.append(result_vswitch)
        return {'virtual-switches': result_vswitches}
1156492
def _get_pkey(self):
        """"""
        keypath = self.config.server["pkey"]
        with open(os.path.expanduser(keypath)) as f:
            pkey = paramiko.RSAKey.from_private_key(f)

        return pkey
1275547
def getkey(ctx, pubkey):
    
    click.echo(ctx.peerplays.wallet.getPrivateKeyForPublicKey(pubkey))
426182
def _waitfor(self, mode, mask, may_block, timeout=2):
        
        finished = False
        sleep = 0.01
        # After six sleeps, we've slept 0.64 seconds.
        wait_num = (timeout * 2) - 1 + 6
        resp_timeout = False    # YubiKey hasn't indicated RESP_TIMEOUT (yet)
        while not finished:
            time.sleep(sleep)
            this = self._read()
            flags = yubico_util.ord_byte(this[7])

            if flags & yubikey_defs.RESP_TIMEOUT_WAIT_FLAG:
                if not resp_timeout:
                    resp_timeout = True
                    seconds_left = flags & yubikey_defs.RESP_TIMEOUT_WAIT_MASK
                    self._debug("Device indicates RESP_TIMEOUT (%i seconds left)\n" \
                                    % (seconds_left))
                    if may_block:
                        # calculate new wait_num - never more than 20 seconds
                        seconds_left = min(20, seconds_left)
                        wait_num = (seconds_left * 2) - 1 + 6

            if mode is 'nand':
                if not flags & mask == mask:
                    finished = True
                else:
                    self._debug("Status %s (0x%x) has not cleared bits %s (0x%x)\n"
                                % (bin(flags), flags, bin(mask), mask))
            elif mode is 'and':
                if flags & mask == mask:
                    finished = True
                else:
                    self._debug("Status %s (0x%x) has not set bits %s (0x%x)\n"
                                % (bin(flags), flags, bin(mask), mask))
            else:
                assert()

            if not finished:
                wait_num -= 1
                if wait_num == 0:
                    if mode is 'nand':
                        reason = 'Timed out waiting for YubiKey to clear status 0x%x' % mask
                    else:
                        reason = 'Timed out waiting for YubiKey to set status 0x%x' % mask
                    raise yubikey_base.YubiKeyTimeout(reason)
                sleep = min(sleep + sleep, 0.5)
            else:
                return this
553979
def get_key(key_name, region=None, key=None, keyid=None, profile=None):
    '''
    
    '''
    conn = _get_conn(region=region, key=key, keyid=keyid, profile=profile)

    try:
        key = conn.get_key_pair(key_name)
        log.debug("the key to return is : %s", key)
        if key is None:
            return False
        return key.name, key.fingerprint
    except boto.exception.BotoServerError as e:
        log.debug(e)
        return False
688977
def _DecodeKey(self, key):
        """"""

        if self.dict.attrindex.HasBackward(key):
            return self.dict.attrindex.GetBackward(key)
        return key
562366
def valid_configs(self):
        
        if self.ykver() < (2,1,0):
            raise YubiKeyUSBHIDError('Valid configs unsupported in firmware %s' % (self.version()))
        res = []
        if self.touch_level & self.CONFIG1_VALID == self.CONFIG1_VALID:
            res.append(1)
        if self.touch_level & self.CONFIG2_VALID == self.CONFIG2_VALID:
            res.append(2)
        return res
1250332
def status(self):
        
        data = self._read()
        self._status = YubiKeyUSBHIDStatus(data)
        return self._status
1296324
def get(self, key):
        """"""
        self._started = self._backend_client.load()
        self._needs_save = True

        return self._backend_client.get(key)
903918
def get_status_key(self, instance):
        """"""
        key_id = "inst_%s" % id(instance) if instance.pk is None else instance.pk
        return "%s.%s-%s-%s" % (instance._meta.app_label,
                                get_model_name(instance),
                                key_id,
                                self.field.name)
170311
def to_frame(self, slot=1):
        
        data = self.to_string()
        payload = data.ljust(64, yubico_util.chr_byte(0x0))
        if slot is 1:
            if self._update_config:
                command = SLOT.UPDATE1
            else:
                command = SLOT.CONFIG
        elif slot is 2:
            if self._update_config:
                command = SLOT.UPDATE2
            else:
                command = SLOT.CONFIG2
        else:
            assert()

        if self._swap_slots:
            command = SLOT.SWAP

        if self._zap:
            payload = b''

        return yubikey_frame.YubiKeyFrame(command=command, payload=payload)
361054
def get_version():
    """"""

    with open('yubico/yubico_version.py', 'r') as f:
        match = VERSION_PATTERN.search(f.read())
        return match.group(1)