Part-DB.Part-DB-server/src/Entity/UserSystem/U2FKey.php

206 lines
4.7 KiB
PHP
Raw Normal View History

<?php
2020-02-22 18:14:36 +01:00
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
* Copyright (C) 2019 - 2020 Jan Böhmer (https://github.com/jbtronics)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
2020-01-05 15:46:58 +01:00
declare(strict_types=1);
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
* Copyright (C) 2019 Jan Böhmer (https://github.com/jbtronics)
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
namespace App\Entity\UserSystem;
use App\Entity\Base\TimestampTrait;
use Doctrine\ORM\Mapping as ORM;
use R\U2FTwoFactorBundle\Model\U2F\TwoFactorKeyInterface;
use u2flib_server\Registration;
/**
* @ORM\Entity
* @ORM\Table(name="u2f_keys",
* uniqueConstraints={@ORM\UniqueConstraint(name="user_unique",columns={"user_id",
* "key_handle"})})
* @ORM\HasLifecycleCallbacks()
*/
class U2FKey implements TwoFactorKeyInterface
{
use TimestampTrait;
/**
* @ORM\Column(type="string", length=64)
2020-01-04 20:24:09 +01:00
*
* @var string
**/
2019-12-29 13:35:30 +01:00
public $keyHandle;
/**
* @ORM\Column(type="string")
2020-01-04 20:24:09 +01:00
*
* @var string
**/
2019-12-29 13:35:30 +01:00
public $publicKey;
/**
* @ORM\Column(type="text")
2020-01-04 20:24:09 +01:00
*
* @var string
**/
2019-12-29 13:35:30 +01:00
public $certificate;
/**
* @ORM\Column(type="string")
2020-01-04 20:24:09 +01:00
*
* @var int
**/
2019-12-29 13:35:30 +01:00
public $counter;
2020-01-05 15:46:58 +01:00
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
2020-01-05 22:49:00 +01:00
* @ORM\Column(type="string")
2020-01-04 20:24:09 +01:00
*
2020-01-05 22:49:00 +01:00
* @var string
**/
2020-01-05 22:49:00 +01:00
protected $name;
/**
2020-01-05 22:49:00 +01:00
* @ORM\ManyToOne(targetEntity="App\Entity\UserSystem\User", inversedBy="u2fKeys")
2020-01-04 20:24:09 +01:00
*
2020-01-05 22:49:00 +01:00
* @var User
**/
2020-01-05 22:49:00 +01:00
protected $user;
public function fromRegistrationData(Registration $data): void
{
$this->keyHandle = $data->keyHandle;
$this->publicKey = $data->publicKey;
$this->certificate = $data->certificate;
$this->counter = $data->counter;
}
public function getKeyHandle()
{
return $this->keyHandle;
}
2020-02-01 19:42:28 +01:00
public function setKeyHandle($keyHandle): self
{
$this->keyHandle = $keyHandle;
2020-02-01 19:42:28 +01:00
return $this;
}
public function getPublicKey()
{
return $this->publicKey;
}
2020-02-01 19:42:28 +01:00
public function setPublicKey($publicKey): self
{
$this->publicKey = $publicKey;
2020-02-01 19:42:28 +01:00
return $this;
}
public function getCertificate()
{
return $this->certificate;
}
2020-02-01 19:42:28 +01:00
public function setCertificate($certificate): self
{
$this->certificate = $certificate;
2020-02-01 19:42:28 +01:00
return $this;
}
public function getCounter()
{
return $this->counter;
}
2020-02-01 19:42:28 +01:00
public function setCounter($counter): self
{
$this->counter = $counter;
2020-02-01 19:42:28 +01:00
return $this;
}
public function getName()
{
return $this->name;
}
2020-02-01 19:42:28 +01:00
public function setName($name): self
{
$this->name = $name;
2020-02-01 19:42:28 +01:00
return $this;
}
2019-12-29 13:35:30 +01:00
/**
* Gets the user, this U2F key belongs to.
2020-01-04 20:24:09 +01:00
*
2019-12-29 13:35:30 +01:00
* @return User
*/
2020-01-04 20:24:09 +01:00
public function getUser(): User
2019-12-29 13:35:30 +01:00
{
return $this->user;
}
/**
2020-01-04 20:24:09 +01:00
* The primary key ID of this key.
*
* @return int
*/
2020-01-04 20:24:09 +01:00
public function getID(): int
{
return $this->id;
}
2019-12-29 13:35:30 +01:00
/**
* Sets the user this U2F key belongs to.
2020-01-04 20:24:09 +01:00
*
2020-02-02 14:05:36 +01:00
* @param User $new_user
2019-12-29 13:35:30 +01:00
* @return $this
*/
2020-02-01 19:42:28 +01:00
public function setUser(User $new_user): self
2019-12-29 13:35:30 +01:00
{
$this->user = $new_user;
2020-01-04 20:24:09 +01:00
2019-12-29 13:35:30 +01:00
return $this;
}
2020-01-04 20:24:09 +01:00
}