Skip to content
GitLab
Explore
Projects
Groups
Topics
Snippets
Projects
Groups
Topics
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
fusiondirectory
WebAuthn
Commits
eab183a7
Commit
eab183a7
authored
3 years ago
by
Lukas Buchs
Browse files
Options
Download
Patches
Plain Diff
PHP 8.1 fixes
parent
8da1c566
master
v2.0.0-beta
v1.1.3
v1.1.2
v1.1.1
v1.1.0
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
_test/server.php
+20
-20
_test/server.php
src/Binary/ByteBuffer.php
+17
-17
src/Binary/ByteBuffer.php
with
37 additions
and
37 deletions
+37
-37
_test/server.php
+
20
−
20
View file @
eab183a7
...
@@ -40,7 +40,7 @@ try {
...
@@ -40,7 +40,7 @@ try {
// read get argument and post body
// read get argument and post body
$fn
=
filter_input
(
INPUT_GET
,
'fn'
);
$fn
=
filter_input
(
INPUT_GET
,
'fn'
);
$requireResidentKey
=
!!
$
_GET
[
'requireResidentKey'
]
;
$requireResidentKey
=
!!
filter_input
(
INPUT
_GET
,
'requireResidentKey'
)
;
$userVerification
=
filter_input
(
INPUT_GET
,
'userVerification'
,
FILTER_SANITIZE_SPECIAL_CHARS
);
$userVerification
=
filter_input
(
INPUT_GET
,
'userVerification'
,
FILTER_SANITIZE_SPECIAL_CHARS
);
$userId
=
filter_input
(
INPUT_GET
,
'userId'
,
FILTER_SANITIZE_SPECIAL_CHARS
);
$userId
=
filter_input
(
INPUT_GET
,
'userId'
,
FILTER_SANITIZE_SPECIAL_CHARS
);
...
@@ -60,30 +60,30 @@ try {
...
@@ -60,30 +60,30 @@ try {
// Formats
// Formats
$formats
=
array
();
$formats
=
array
();
if
(
$
_GET
[
'fmt_android-key'
]
)
{
if
(
filter_input
(
INPUT
_GET
,
'fmt_android-key'
)
)
{
$formats
[]
=
'android-key'
;
$formats
[]
=
'android-key'
;
}
}
if
(
$
_GET
[
'fmt_android-safetynet'
]
)
{
if
(
filter_input
(
INPUT
_GET
,
'fmt_android-safetynet'
)
)
{
$formats
[]
=
'android-safetynet'
;
$formats
[]
=
'android-safetynet'
;
}
}
if
(
$
_GET
[
'fmt_apple'
]
)
{
if
(
filter_input
(
INPUT
_GET
,
'fmt_apple'
)
)
{
$formats
[]
=
'apple'
;
$formats
[]
=
'apple'
;
}
}
if
(
$
_GET
[
'fmt_fido-u2f'
]
)
{
if
(
filter_input
(
INPUT
_GET
,
'fmt_fido-u2f'
)
)
{
$formats
[]
=
'fido-u2f'
;
$formats
[]
=
'fido-u2f'
;
}
}
if
(
$
_GET
[
'fmt_none'
]
)
{
if
(
filter_input
(
INPUT
_GET
,
'fmt_none'
)
)
{
$formats
[]
=
'none'
;
$formats
[]
=
'none'
;
}
}
if
(
$
_GET
[
'fmt_packed'
]
)
{
if
(
filter_input
(
INPUT
_GET
,
'fmt_packed'
)
)
{
$formats
[]
=
'packed'
;
$formats
[]
=
'packed'
;
}
}
if
(
$
_GET
[
'fmt_tpm'
]
)
{
if
(
filter_input
(
INPUT
_GET
,
'fmt_tpm'
)
)
{
$formats
[]
=
'tpm'
;
$formats
[]
=
'tpm'
;
}
}
$rpId
=
'localhost'
;
$rpId
=
'localhost'
;
if
(
$
_GET
[
'rpId'
]
)
{
if
(
filter_input
(
INPUT
_GET
,
'rpId'
)
)
{
$rpId
=
filter_input
(
INPUT_GET
,
'rpId'
,
FILTER_VALIDATE_DOMAIN
);
$rpId
=
filter_input
(
INPUT_GET
,
'rpId'
,
FILTER_VALIDATE_DOMAIN
);
if
(
$rpId
===
false
)
{
if
(
$rpId
===
false
)
{
throw
new
Exception
(
'invalid relying party ID'
);
throw
new
Exception
(
'invalid relying party ID'
);
...
@@ -91,10 +91,10 @@ try {
...
@@ -91,10 +91,10 @@ try {
}
}
// types selected on front end
// types selected on front end
$typeUsb
=
!!
$
_GET
[
'type_usb'
]
;
$typeUsb
=
!!
filter_input
(
INPUT
_GET
,
'type_usb'
)
;
$typeNfc
=
!!
$
_GET
[
'type_nfc'
]
;
$typeNfc
=
!!
filter_input
(
INPUT
_GET
,
'type_nfc'
)
;
$typeBle
=
!!
$
_GET
[
'type_ble'
]
;
$typeBle
=
!!
filter_input
(
INPUT
_GET
,
'type_ble'
)
;
$typeInt
=
!!
$
_GET
[
'type_int'
]
;
$typeInt
=
!!
filter_input
(
INPUT
_GET
,
'type_int'
)
;
// cross-platform: true, if type internal is not allowed
// cross-platform: true, if type internal is not allowed
// false, if only internal is allowed
// false, if only internal is allowed
...
@@ -113,26 +113,26 @@ try {
...
@@ -113,26 +113,26 @@ try {
$WebAuthn
=
new
lbuchs\WebAuthn\WebAuthn
(
'WebAuthn Library'
,
$rpId
,
$formats
);
$WebAuthn
=
new
lbuchs\WebAuthn\WebAuthn
(
'WebAuthn Library'
,
$rpId
,
$formats
);
// add root certificates to validate new registrations
// add root certificates to validate new registrations
if
(
$
_GET
[
'solo'
]
)
{
if
(
filter_input
(
INPUT
_GET
,
'solo'
)
)
{
$WebAuthn
->
addRootCertificates
(
'rootCertificates/solo.pem'
);
$WebAuthn
->
addRootCertificates
(
'rootCertificates/solo.pem'
);
}
}
if
(
$
_GET
[
'apple'
]
)
{
if
(
filter_input
(
INPUT
_GET
,
'apple'
)
)
{
$WebAuthn
->
addRootCertificates
(
'rootCertificates/apple.pem'
);
$WebAuthn
->
addRootCertificates
(
'rootCertificates/apple.pem'
);
}
}
if
(
$
_GET
[
'yubico'
]
)
{
if
(
filter_input
(
INPUT
_GET
,
'yubico'
)
)
{
$WebAuthn
->
addRootCertificates
(
'rootCertificates/yubico.pem'
);
$WebAuthn
->
addRootCertificates
(
'rootCertificates/yubico.pem'
);
}
}
if
(
$
_GET
[
'hypersecu'
]
)
{
if
(
filter_input
(
INPUT
_GET
,
'hypersecu'
)
)
{
$WebAuthn
->
addRootCertificates
(
'rootCertificates/hypersecu.pem'
);
$WebAuthn
->
addRootCertificates
(
'rootCertificates/hypersecu.pem'
);
}
}
if
(
$
_GET
[
'google'
]
)
{
if
(
filter_input
(
INPUT
_GET
,
'google'
)
)
{
$WebAuthn
->
addRootCertificates
(
'rootCertificates/globalSign.pem'
);
$WebAuthn
->
addRootCertificates
(
'rootCertificates/globalSign.pem'
);
$WebAuthn
->
addRootCertificates
(
'rootCertificates/googleHardware.pem'
);
$WebAuthn
->
addRootCertificates
(
'rootCertificates/googleHardware.pem'
);
}
}
if
(
$
_GET
[
'microsoft'
]
)
{
if
(
filter_input
(
INPUT
_GET
,
'microsoft'
)
)
{
$WebAuthn
->
addRootCertificates
(
'rootCertificates/microsoftTpmCollection.pem'
);
$WebAuthn
->
addRootCertificates
(
'rootCertificates/microsoftTpmCollection.pem'
);
}
}
if
(
$
_GET
[
'mds'
]
)
{
if
(
filter_input
(
INPUT
_GET
,
'mds'
)
)
{
$WebAuthn
->
addRootCertificates
(
'rootCertificates/mds'
);
$WebAuthn
->
addRootCertificates
(
'rootCertificates/mds'
);
}
}
...
...
This diff is collapsed.
Click to expand it.
src/Binary/ByteBuffer.php
+
17
−
17
View file @
eab183a7
...
@@ -27,7 +27,7 @@ class ByteBuffer implements \JsonSerializable, \Serializable {
...
@@ -27,7 +27,7 @@ class ByteBuffer implements \JsonSerializable, \Serializable {
private
$_length
;
private
$_length
;
public
function
__construct
(
$binaryData
)
{
public
function
__construct
(
$binaryData
)
{
$this
->
_data
=
$binaryData
;
$this
->
_data
=
(
string
)
$binaryData
;
$this
->
_length
=
\
strlen
(
$binaryData
);
$this
->
_length
=
\
strlen
(
$binaryData
);
}
}
...
@@ -41,7 +41,7 @@ class ByteBuffer implements \JsonSerializable, \Serializable {
...
@@ -41,7 +41,7 @@ class ByteBuffer implements \JsonSerializable, \Serializable {
* @param string $base64url
* @param string $base64url
* @return ByteBuffer
* @return ByteBuffer
*/
*/
public
static
function
fromBase64Url
(
$base64url
)
{
public
static
function
fromBase64Url
(
$base64url
)
:
ByteBuffer
{
$bin
=
self
::
_base64url_decode
(
$base64url
);
$bin
=
self
::
_base64url_decode
(
$base64url
);
if
(
$bin
===
false
)
{
if
(
$bin
===
false
)
{
throw
new
WebAuthnException
(
'ByteBuffer: Invalid base64 url string'
,
WebAuthnException
::
BYTEBUFFER
);
throw
new
WebAuthnException
(
'ByteBuffer: Invalid base64 url string'
,
WebAuthnException
::
BYTEBUFFER
);
...
@@ -54,7 +54,7 @@ class ByteBuffer implements \JsonSerializable, \Serializable {
...
@@ -54,7 +54,7 @@ class ByteBuffer implements \JsonSerializable, \Serializable {
* @param string $hex
* @param string $hex
* @return ByteBuffer
* @return ByteBuffer
*/
*/
public
static
function
fromHex
(
$hex
)
{
public
static
function
fromHex
(
$hex
)
:
ByteBuffer
{
$bin
=
\
hex2bin
(
$hex
);
$bin
=
\
hex2bin
(
$hex
);
if
(
$bin
===
false
)
{
if
(
$bin
===
false
)
{
throw
new
WebAuthnException
(
'ByteBuffer: Invalid hex string'
,
WebAuthnException
::
BYTEBUFFER
);
throw
new
WebAuthnException
(
'ByteBuffer: Invalid hex string'
,
WebAuthnException
::
BYTEBUFFER
);
...
@@ -67,7 +67,7 @@ class ByteBuffer implements \JsonSerializable, \Serializable {
...
@@ -67,7 +67,7 @@ class ByteBuffer implements \JsonSerializable, \Serializable {
* @param string $length
* @param string $length
* @return ByteBuffer
* @return ByteBuffer
*/
*/
public
static
function
randomBuffer
(
$length
)
{
public
static
function
randomBuffer
(
$length
)
:
ByteBuffer
{
if
(
\
function_exists
(
'random_bytes'
))
{
// >PHP 7.0
if
(
\
function_exists
(
'random_bytes'
))
{
// >PHP 7.0
return
new
ByteBuffer
(
\
random_bytes
(
$length
));
return
new
ByteBuffer
(
\
random_bytes
(
$length
));
...
@@ -83,14 +83,14 @@ class ByteBuffer implements \JsonSerializable, \Serializable {
...
@@ -83,14 +83,14 @@ class ByteBuffer implements \JsonSerializable, \Serializable {
// PUBLIC
// PUBLIC
// -----------------------
// -----------------------
public
function
getBytes
(
$offset
,
$length
)
{
public
function
getBytes
(
$offset
,
$length
)
:
string
{
if
(
$offset
<
0
||
$length
<
0
||
(
$offset
+
$length
>
$this
->
_length
))
{
if
(
$offset
<
0
||
$length
<
0
||
(
$offset
+
$length
>
$this
->
_length
))
{
throw
new
WebAuthnException
(
'ByteBuffer: Invalid offset or length'
,
WebAuthnException
::
BYTEBUFFER
);
throw
new
WebAuthnException
(
'ByteBuffer: Invalid offset or length'
,
WebAuthnException
::
BYTEBUFFER
);
}
}
return
\
substr
(
$this
->
_data
,
$offset
,
$length
);
return
\
substr
(
$this
->
_data
,
$offset
,
$length
);
}
}
public
function
getByteVal
(
$offset
)
{
public
function
getByteVal
(
$offset
)
:
int
{
if
(
$offset
<
0
||
$offset
>=
$this
->
_length
)
{
if
(
$offset
<
0
||
$offset
>=
$this
->
_length
)
{
throw
new
WebAuthnException
(
'ByteBuffer: Invalid offset'
,
WebAuthnException
::
BYTEBUFFER
);
throw
new
WebAuthnException
(
'ByteBuffer: Invalid offset'
,
WebAuthnException
::
BYTEBUFFER
);
}
}
...
@@ -105,7 +105,7 @@ class ByteBuffer implements \JsonSerializable, \Serializable {
...
@@ -105,7 +105,7 @@ class ByteBuffer implements \JsonSerializable, \Serializable {
return
$data
;
return
$data
;
}
}
public
function
getLength
()
{
public
function
getLength
()
:
int
{
return
$this
->
_length
;
return
$this
->
_length
;
}
}
...
@@ -181,7 +181,7 @@ class ByteBuffer implements \JsonSerializable, \Serializable {
...
@@ -181,7 +181,7 @@ class ByteBuffer implements \JsonSerializable, \Serializable {
/**
/**
* @return string
* @return string
*/
*/
public
function
getBinaryString
()
{
public
function
getBinaryString
()
:
string
{
return
$this
->
_data
;
return
$this
->
_data
;
}
}
...
@@ -189,21 +189,21 @@ class ByteBuffer implements \JsonSerializable, \Serializable {
...
@@ -189,21 +189,21 @@ class ByteBuffer implements \JsonSerializable, \Serializable {
* @param string $buffer
* @param string $buffer
* @return bool
* @return bool
*/
*/
public
function
equals
(
$buffer
)
{
public
function
equals
(
$buffer
)
:
bool
{
return
is_string
(
$this
->
_data
)
&&
$this
->
_data
===
$buffer
->
data
;
return
is_string
(
$this
->
_data
)
&&
$this
->
_data
===
$buffer
->
data
;
}
}
/**
/**
* @return string
* @return string
*/
*/
public
function
getHex
()
{
public
function
getHex
()
:
string
{
return
\
bin2hex
(
$this
->
_data
);
return
\
bin2hex
(
$this
->
_data
);
}
}
/**
/**
* @return bool
* @return bool
*/
*/
public
function
isEmpty
()
{
public
function
isEmpty
()
:
bool
{
return
$this
->
_length
===
0
;
return
$this
->
_length
===
0
;
}
}
...
@@ -213,7 +213,7 @@ class ByteBuffer implements \JsonSerializable, \Serializable {
...
@@ -213,7 +213,7 @@ class ByteBuffer implements \JsonSerializable, \Serializable {
* return binary data in RFC 1342-Like serialized string
* return binary data in RFC 1342-Like serialized string
* @return string
* @return string
*/
*/
public
function
jsonSerialize
()
{
public
function
jsonSerialize
()
:
string
{
if
(
ByteBuffer
::
$useBase64UrlEncoding
)
{
if
(
ByteBuffer
::
$useBase64UrlEncoding
)
{
return
self
::
_base64url_encode
(
$this
->
_data
);
return
self
::
_base64url_encode
(
$this
->
_data
);
...
@@ -226,7 +226,7 @@ class ByteBuffer implements \JsonSerializable, \Serializable {
...
@@ -226,7 +226,7 @@ class ByteBuffer implements \JsonSerializable, \Serializable {
* Serializable-Interface
* Serializable-Interface
* @return string
* @return string
*/
*/
public
function
serialize
()
{
public
function
serialize
()
:
string
{
return
\
serialize
(
$this
->
_data
);
return
\
serialize
(
$this
->
_data
);
}
}
...
@@ -243,7 +243,7 @@ class ByteBuffer implements \JsonSerializable, \Serializable {
...
@@ -243,7 +243,7 @@ class ByteBuffer implements \JsonSerializable, \Serializable {
* (PHP 8 deprecates Serializable-Interface)
* (PHP 8 deprecates Serializable-Interface)
* @return array
* @return array
*/
*/
public
function
__serialize
()
{
public
function
__serialize
()
:
array
{
return
[
return
[
'data'
=>
\
serialize
(
$this
->
_data
)
'data'
=>
\
serialize
(
$this
->
_data
)
];
];
...
@@ -253,7 +253,7 @@ class ByteBuffer implements \JsonSerializable, \Serializable {
...
@@ -253,7 +253,7 @@ class ByteBuffer implements \JsonSerializable, \Serializable {
* object to string
* object to string
* @return string
* @return string
*/
*/
public
function
__toString
()
{
public
function
__toString
()
:
string
{
return
$this
->
getHex
();
return
$this
->
getHex
();
}
}
...
@@ -278,7 +278,7 @@ class ByteBuffer implements \JsonSerializable, \Serializable {
...
@@ -278,7 +278,7 @@ class ByteBuffer implements \JsonSerializable, \Serializable {
* @param string $data
* @param string $data
* @return string
* @return string
*/
*/
protected
static
function
_base64url_decode
(
$data
)
{
protected
static
function
_base64url_decode
(
$data
)
:
string
{
return
\
base64_decode
(
\
strtr
(
$data
,
'-_'
,
'+/'
)
.
\
str_repeat
(
'='
,
3
-
(
3
+
\
strlen
(
$data
))
%
4
));
return
\
base64_decode
(
\
strtr
(
$data
,
'-_'
,
'+/'
)
.
\
str_repeat
(
'='
,
3
-
(
3
+
\
strlen
(
$data
))
%
4
));
}
}
...
@@ -287,7 +287,7 @@ class ByteBuffer implements \JsonSerializable, \Serializable {
...
@@ -287,7 +287,7 @@ class ByteBuffer implements \JsonSerializable, \Serializable {
* @param string $data
* @param string $data
* @return string
* @return string
*/
*/
protected
static
function
_base64url_encode
(
$data
)
{
protected
static
function
_base64url_encode
(
$data
)
:
string
{
return
\
rtrim
(
\
strtr
(
\
base64_encode
(
$data
),
'+/'
,
'-_'
),
'='
);
return
\
rtrim
(
\
strtr
(
\
base64_encode
(
$data
),
'+/'
,
'-_'
),
'='
);
}
}
}
}
This diff is collapsed.
Click to expand it.
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment
Menu
Explore
Projects
Groups
Topics
Snippets