[ Index ] |
PHP Cross Reference of Joomla 4.2.2 documentation |
[Summary view] [Print] [Text view]
1 <?php 2 3 declare(strict_types=1); 4 5 /* 6 * The MIT License (MIT) 7 * 8 * Copyright (c) 2014-2019 Spomky-Labs 9 * 10 * This software may be modified and distributed under the terms 11 * of the MIT license. See the LICENSE file for details. 12 */ 13 14 namespace Webauthn; 15 16 use Assert\Assertion; 17 use Base64Url\Base64Url; 18 use InvalidArgumentException; 19 use JsonSerializable; 20 use Ramsey\Uuid\Uuid; 21 use Ramsey\Uuid\UuidInterface; 22 use Throwable; 23 use Webauthn\TrustPath\TrustPath; 24 use Webauthn\TrustPath\TrustPathLoader; 25 26 /** 27 * @see https://www.w3.org/TR/webauthn/#iface-pkcredential 28 */ 29 class PublicKeyCredentialSource implements JsonSerializable 30 { 31 /** 32 * @var string 33 */ 34 protected $publicKeyCredentialId; 35 36 /** 37 * @var string 38 */ 39 protected $type; 40 41 /** 42 * @var string[] 43 */ 44 protected $transports; 45 46 /** 47 * @var string 48 */ 49 protected $attestationType; 50 51 /** 52 * @var TrustPath 53 */ 54 protected $trustPath; 55 56 /** 57 * @var UuidInterface 58 */ 59 protected $aaguid; 60 61 /** 62 * @var string 63 */ 64 protected $credentialPublicKey; 65 66 /** 67 * @var string 68 */ 69 protected $userHandle; 70 71 /** 72 * @var int 73 */ 74 protected $counter; 75 76 public function __construct(string $publicKeyCredentialId, string $type, array $transports, string $attestationType, TrustPath $trustPath, UuidInterface $aaguid, string $credentialPublicKey, string $userHandle, int $counter) 77 { 78 $this->publicKeyCredentialId = $publicKeyCredentialId; 79 $this->type = $type; 80 $this->transports = $transports; 81 $this->aaguid = $aaguid; 82 $this->credentialPublicKey = $credentialPublicKey; 83 $this->userHandle = $userHandle; 84 $this->counter = $counter; 85 $this->attestationType = $attestationType; 86 $this->trustPath = $trustPath; 87 } 88 89 /** 90 * @deprecated Deprecated since v2.1. Will be removed in v3.0. Please use response from the credential source returned by the AuthenticatorAttestationResponseValidator after "check" method 91 */ 92 public static function createFromPublicKeyCredential(PublicKeyCredential $publicKeyCredential, string $userHandle): self 93 { 94 $response = $publicKeyCredential->getResponse(); 95 Assertion::isInstanceOf($response, AuthenticatorAttestationResponse::class, 'This method is only available with public key credential containing an authenticator attestation response.'); 96 $publicKeyCredentialDescriptor = $publicKeyCredential->getPublicKeyCredentialDescriptor(); 97 $attestationStatement = $response->getAttestationObject()->getAttStmt(); 98 $authenticatorData = $response->getAttestationObject()->getAuthData(); 99 $attestedCredentialData = $authenticatorData->getAttestedCredentialData(); 100 Assertion::notNull($attestedCredentialData, 'No attested credential data available'); 101 102 return new self( 103 $publicKeyCredentialDescriptor->getId(), 104 $publicKeyCredentialDescriptor->getType(), 105 $publicKeyCredentialDescriptor->getTransports(), 106 $attestationStatement->getType(), 107 $attestationStatement->getTrustPath(), 108 $attestedCredentialData->getAaguid(), 109 $attestedCredentialData->getCredentialPublicKey(), 110 $userHandle, 111 $authenticatorData->getSignCount() 112 ); 113 } 114 115 public function getPublicKeyCredentialId(): string 116 { 117 return $this->publicKeyCredentialId; 118 } 119 120 public function getPublicKeyCredentialDescriptor(): PublicKeyCredentialDescriptor 121 { 122 return new PublicKeyCredentialDescriptor( 123 $this->type, 124 $this->publicKeyCredentialId, 125 $this->transports 126 ); 127 } 128 129 public function getAttestationType(): string 130 { 131 return $this->attestationType; 132 } 133 134 public function getTrustPath(): TrustPath 135 { 136 return $this->trustPath; 137 } 138 139 public function getAttestedCredentialData(): AttestedCredentialData 140 { 141 return new AttestedCredentialData( 142 $this->aaguid, 143 $this->publicKeyCredentialId, 144 $this->credentialPublicKey 145 ); 146 } 147 148 public function getType(): string 149 { 150 return $this->type; 151 } 152 153 /** 154 * @return string[] 155 */ 156 public function getTransports(): array 157 { 158 return $this->transports; 159 } 160 161 public function getAaguid(): UuidInterface 162 { 163 return $this->aaguid; 164 } 165 166 public function getCredentialPublicKey(): string 167 { 168 return $this->credentialPublicKey; 169 } 170 171 public function getUserHandle(): string 172 { 173 return $this->userHandle; 174 } 175 176 public function getCounter(): int 177 { 178 return $this->counter; 179 } 180 181 public function setCounter(int $counter): void 182 { 183 $this->counter = $counter; 184 } 185 186 public static function createFromArray(array $data): self 187 { 188 $keys = array_keys(get_class_vars(self::class)); 189 foreach ($keys as $key) { 190 Assertion::keyExists($data, $key, sprintf('The parameter "%s" is missing', $key)); 191 } 192 switch (true) { 193 case 36 === mb_strlen($data['aaguid'], '8bit'): 194 $uuid = Uuid::fromString($data['aaguid']); 195 break; 196 default: // Kept for compatibility with old format 197 $decoded = base64_decode($data['aaguid'], true); 198 Assertion::string($decoded, 'Invalid AAGUID'); 199 $uuid = Uuid::fromBytes($decoded); 200 } 201 202 try { 203 return new self( 204 Base64Url::decode($data['publicKeyCredentialId']), 205 $data['type'], 206 $data['transports'], 207 $data['attestationType'], 208 TrustPathLoader::loadTrustPath($data['trustPath']), 209 $uuid, 210 Base64Url::decode($data['credentialPublicKey']), 211 Base64Url::decode($data['userHandle']), 212 $data['counter'] 213 ); 214 } catch (Throwable $throwable) { 215 throw new InvalidArgumentException('Unable to load the data', $throwable->getCode(), $throwable); 216 } 217 } 218 219 public function jsonSerialize(): array 220 { 221 return [ 222 'publicKeyCredentialId' => Base64Url::encode($this->publicKeyCredentialId), 223 'type' => $this->type, 224 'transports' => $this->transports, 225 'attestationType' => $this->attestationType, 226 'trustPath' => $this->trustPath, 227 'aaguid' => $this->aaguid->toString(), 228 'credentialPublicKey' => Base64Url::encode($this->credentialPublicKey), 229 'userHandle' => Base64Url::encode($this->userHandle), 230 'counter' => $this->counter, 231 ]; 232 } 233 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Wed Sep 7 05:41:13 2022 | Chilli.vc Blog - For Webmaster,Blog-Writer,System Admin and Domainer |