GithubHelp home page GithubHelp logo

yubikey's Introduction

Yubikey PHP Library

Travis-CI Build Status Codacy Badge Code Climate Total Downloads

This library lets you easily interface with the Yubico REST API for validating the codes created by the Yubikey.

Requirements:

  • An API as requested from the Yubico site
  • A client ID requested from Yubico
  • A Yubikey to test out the implementation

Installation

Use the followng command to install the library via Composer:

composer require enygma/yubikey

Usage:

Look at the test.php example script to see how to use it. This can be executed like:

php test.php [generated key]

Example code:

<?php
$apiKey = 'dGVzdGluZzEyMzQ1Njc4OTA=';
$clientId = '12345';

$v = new \Yubikey\Validate($apiKey, $clientId);
$response = $v->check($inputtedKey);

echo ($response->success() === true) ? 'success!' : 'you failed. aw.';
?>

HTTP vs HTTPS

By default the library will try to use a HTTPS request to the host given. If you need to disable this for some reason (like no SSL support), you can use the setUseSecure method and set it to false:

$v = new \Yubikey\Validate($apiKey, $clientId);
$v->setUseSecure(false);

Overriding hosts

The library comes with a set of hostnames for the Yubico external API servers (api.yubico.com through api5.yubico.com). If you ever have a need to override these, you can use setHosts:

$v = new \Yubikey\Validate($apiKey, $clientId);
$v->setHosts(array(
    'api.myhost1.com',
    'api1.myhost.com'
));

Remember, this will overwrite the current hosts in the class, so be sure you don't still need those. If you just want to add another host, look at the addHost method.

Multi-Server Requests:

Additonally, the library also supports simultaneous connections to multiple servers. By default it will only make the request to the first server in the hosts list. You can enable the multi-server checking with a second parameter on the check() method:

<?php
$v = new \Yubikey\Validate($apiKey, $clientId);
$response = $v->check($inputtedKey, true);

echo ($response->success() === true) ? 'success!' : 'you failed. aw.';
?>

This will make multiple requests and return the pass/fail status of the aggregate responses from each. So, if you have all but one server pass, the overall response will be a fail. If all return OK though, you're in the clear.

"First in" result

Additionally, you can also switch on and off this aggregation of the results and go with only the "first in" response. You do this with a flag on the success checking method:

<?php
$v = new \Yubikey\Validate($apiKey, $clientId);
$response = $v->check($inputtedKey, true);

echo ($response->success(true) === true) ? 'success!' : 'you failed. aw.';
?>

NOTE: This will still work without multi-server checking. The "first in" will just always be the single response.

@author Chris Cornutt [email protected]

yubikey's People

Contributors

enygma avatar matason avatar mbolli avatar potherca avatar sarciszewski avatar tylermenezes avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

yubikey's Issues

a + in the signature is encoded twice

You have added the signature to the params array in your commit
f12e259. Now a + in the signature is
encoded twice because in generateSignature() you replace + already with
%2B and http_build_query($params) encodes it too.

Deprecated Warning When Validating YubiKey OTP Despite Using the Latest Version

When validating a YubiKey OTP using the latest version of the software, I encountered an error. When providing an incorrect OTP value, I receive the following deprecated warning:

Deprecated: Creation of dynamic property Yubikey\Validate::$clientId is deprecated in /Users/Shared/www/inc/vendor/enygma/yubikey/src/Yubikey/Validate.php on line 145.

This error occurs even though I previously passed the correct Secret Code and API Code that I obtained beforehand.

Steps to Reproduce:

  1. Use the latest version of the software.
    
  2. Generate an invalid YubiKey OTP.
    
  3. Pass the OTP value to the validation process.
    
  4. Observe the deprecated warning that occurs.
    

Expected Behavior:
The software should correctly identify the error and provide a meaningful error message instead of generating a deprecated warning.

Additional Information:

  • Operating System: MAC OS - Ventura 13.4
    
  • Software Version: 13.4
    

Failing build

A different PHPUnit version is needed for PHP 7.1 and also requires a different usage.

clarify LICENSE

It seems (according to composer.json) that this library is released under MIT license, would it be possible to make this more explicit in the README, as well as adding a LICENSE file and/or specify in the headers of the PHP files?

Current composer release doesn't work

The current release on packagist (3.1) has an intermittent error with signatures failing, which was fixed shortly after the release was made. The current version of master works fine.

Please create a release

Hello,

I like the library a lot, for production use we need to fix the dependency to a release version in composer. Could you please create a release tag we can fix it on?

Thank you!

Incompatable with Windows

Experienced this odd quirk toady and was able to confirm it with WSL.
Inside WSL the code works as expected but, let me give a brief introduction.

Environment details:
Windows:

C:\Users\elyci\PhpstormProjects\disblog>php -v
PHP 7.2.2 (cli) (built: Jan 31 2018 19:31:15) ( NTS MSVC15 (Visual C++ 2017) x64 )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies

WSL:

elycin@DESKTOP-67FBEPH:/mnt/c/Users/elyci/PhpstormProjects/disblog$ php -v
PHP 7.2.3-1+ubuntu16.04.1+deb.sury.org+1 (cli) (built: Mar  6 2018 11:18:25) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
    with Zend OPcache v7.2.3-1+ubuntu16.04.1+deb.sury.org+1, Copyright (c) 1999-2018, by Zend Technologies

I have a windows development machine that has an instance of php 7.2.2 installed via chocolatey with a modified php.ini to support curl and pdo_mysql extensions, upon testing some of the example code inside a laravel project I've determined in a windows environment that using the dd debugger with the validator's ->success() function, that I get different results.

Windows 10 (Native Environment)

C:\Users\elyci\PhpstormProjects\disblog>php artisan add:yubikey ccccccfrkvvreeivddjvfgrgftttlutbuvftgefnence
false

Windows 10 Subsystem for Linux (with different freshly generated OTP token)

elycin@DESKTOP-67FBEPH:/mnt/c/Users/elyci/PhpstormProjects/disblog$ php artisan add:yubikey ccccccfrkvvreulghldgtcfbhfunvccrnnhifnbhhkut
true

I wish I could provide more details since this seems to be a platform specific bug, maybe even a extension problem but I hope this helps find a possible solution for others.

manual installation

is there some way to install this software without some obnoxious alpha software like composer?

Support parallel server-requests?

Do you plan on adding support for multi-servers? That is, talking to all servers at the same time and using the first answer?

I'm going through our existing "php-yubico" client and updating it, and started "yubico-php-client" for that, but it was pointed out that your project existed. Generally, do you plan on maintaining and working on this going forward? I'd like to see a "good" PHP library for talking to the YubiCloud, and that it is properly packaged.

Check response signature

The request generates a signature with the api key, but the response class does not validate the server signature.

Check at least one server response

If the connection to the server fails the responses array in the
ResponseCollection class is empty and the success function returns true.
Perhaps the default value of $success should be false and set to true if
at least one response was successful.

    public function success($first = false)
    {
        $success = false;
        if ($first === true) {
            // Sort them by timestamp, pop the first one and return pass/fail
            usort($this->responses, function($r1, $r2) {
                return $r1->getMt() > $r2->getMt();
            });
            $response = $this->responses[0];
            return $response->success();
        } else {
            foreach ($this->responses as $response) {
                if ($response->success() === false) {
                    return false;
                } else {
                    $success = true;
                }
            }
        }
        return $success;
    }

Add a function to get the public key

Currently missing inside of this implementation of the Yubikey, is a function that parses out the public key. Commonly used within "two factor authentication".

The first 12 characters of the string according to the Yubico documentation and also known as "prefix" within the data array of Yubico's own php implementation.

With that, dont forget the password. So parsing out the first 12 characters, wont work in every situation.

Deprecated warning utf8_encode

Using this code

            $otp = $_GET['otp'];

            $validator = new Validate(
                $secret,
                $id
            );

            try {
                $response = $validator->check($otp);
            }
            catch (\Exception) {
                die('Access denied!');
            }

            if ($response->success()) {
                die('Access granted!');
            }
            else {
                die('Access denied!');
            }

yields the following response

Deprecated: Function utf8_encode() is deprecated in /var/www/html/vendor/enygma/yubikey/src/Yubikey/Validate.php on line 257

Deprecated: Function utf8_encode() is deprecated in /var/www/html/vendor/enygma/yubikey/src/Yubikey/Validate.php on line 257
Access granted!

I am using PHP 8.2 and enygma/yubikey 3.6

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.