Ejemplo n.º 1
0
use SURFnet\VPN\Common\Logger;
use SURFnet\VPN\Server\OtpLog;
use SURFnet\VPN\Server\Exception\TwoFactorException;
$logger = new Logger(basename($argv[0]));
$envData = [];
try {
    $envKeys = ['INSTANCE_ID', 'POOL_ID', 'common_name', 'username', 'password'];
    // read environment variables
    foreach ($envKeys as $envKey) {
        $envValue = getenv($envKey);
        if (empty($envValue)) {
            throw new RuntimeException(sprintf('environment variable "%s" is not set', $envKey));
        }
        $envData[$envKey] = $envValue;
    }
    $otpLog = new OtpLog(new PDO(sprintf('sqlite://%s/openvpn-data/%s/otp.sqlite', dirname(__DIR__), $envData['INSTANCE_ID'])));
    $connection = new TwoFactor(dirname(__DIR__), $otpLog);
    $connection->twoFactor($envData);
    $envData['ok'] = true;
    $envData['password'] = '******';
    $logger->info(json_encode($envData));
} catch (TwoFactorException $e) {
    $envData['ok'] = false;
    $envData['password'] = '******';
    $envData['error_msg'] = $e->getMessage();
    $logger->error(json_encode($envData));
    exit(1);
} catch (Exception $e) {
    $logger->error($e->getMessage());
    exit(1);
}
Ejemplo n.º 2
0
 /**
  * @expectedException \SURFnet\VPN\Server\Exception\TwoFactorException
  * @expectedExceptionMessage no OTP secret registered
  */
 public function testTwoFactorNotEnrolled()
 {
     $c = new TwoFactor(__DIR__, $this->otpLog);
     $c->twoFactor(['INSTANCE_ID' => 'vpn.example', 'POOL_ID' => 'internet', 'common_name' => 'bar_xyz', 'username' => 'totp', 'password' => '999999']);
 }