From b22273e9e9cab7055b55ee06bc6d818b24c18e10 Mon Sep 17 00:00:00 2001 From: ZiHang Gao Date: Thu, 11 Apr 2019 10:51:56 +0800 Subject: [PATCH 1/9] =?UTF-8?q?=F0=9F=90=9B=20FIX:=20requires=20OpenSSL=20?= =?UTF-8?q?>=3D=201.1.0j?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .vscode/ipch/c87120f649063e47/mmap_address.bin | Bin 0 -> 8 bytes README.md | 2 +- config.m4 | 2 +- 3 files changed, 2 insertions(+), 2 deletions(-) create mode 100644 .vscode/ipch/c87120f649063e47/mmap_address.bin diff --git a/.vscode/ipch/c87120f649063e47/mmap_address.bin b/.vscode/ipch/c87120f649063e47/mmap_address.bin new file mode 100644 index 0000000000000000000000000000000000000000..71307aba69936426bbbcb4dbf2d50dfa1afc5d76 GIT binary patch literal 8 PcmZQzU|?osU|;|M02=@W literal 0 HcmV?d00001 diff --git a/README.md b/README.md index 79bc397..6135079 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ - PHP 7 + - PHP json extension, need to json extension before loading JWT extension. -- OpenSSL (Version >= 1.0.1f) Might work with older version as well, but I did not check that. +- OpenSSL (Version >= 1.1.0j) Might work with older version as well, but I did not check that. ## Install diff --git a/config.m4 b/config.m4 index e2cd84b..8dc23bd 100644 --- a/config.m4 +++ b/config.m4 @@ -5,7 +5,7 @@ PHP_ARG_ENABLE(jwt, whether to enable jwt support, [ --enable-jwt Enable jwt support]) PHP_ARG_WITH(openssl, whether to use OpenSSL library, - [ --with-openssl[=DIR] Ignore presence of OpenSSL library (requires OpenSSL >= 0.9.8)]) + [ --with-openssl[=DIR] Ignore presence of OpenSSL library (requires OpenSSL >= 1.1.0j)]) if test "$PHP_JWT" != "no"; then From 3f2b4c7def56ec49dda34c5759d67cfa172b6144 Mon Sep 17 00:00:00 2001 From: ZiHang Gao Date: Thu, 11 Apr 2019 10:54:38 +0800 Subject: [PATCH 2/9] =?UTF-8?q?=F0=9F=91=8C=20IMPROVE:=20delete=20vscode?= =?UTF-8?q?=20file?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .vscode/ipch/c87120f649063e47/mmap_address.bin | Bin 8 -> 0 bytes 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 .vscode/ipch/c87120f649063e47/mmap_address.bin diff --git a/.vscode/ipch/c87120f649063e47/mmap_address.bin b/.vscode/ipch/c87120f649063e47/mmap_address.bin deleted file mode 100644 index 71307aba69936426bbbcb4dbf2d50dfa1afc5d76..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 8 PcmZQzU|?osU|;|M02=@W From 0c31cd0582fb28328774968e2475714e89fceba1 Mon Sep 17 00:00:00 2001 From: sergiy-petrov Date: Sun, 17 May 2020 18:29:05 +0300 Subject: [PATCH 3/9] test against php 7.3 and 7.4 --- .travis.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index b76e7b0..6e99d61 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,6 +4,8 @@ php: - 7.0 - 7.1 - 7.2 + - 7.3 + - 7.4 notifications: email: false @@ -17,4 +19,4 @@ before_script: # Run PHPs run-tests.php script: - - ./travis/run-test.sh \ No newline at end of file + - ./travis/run-test.sh From 02cef28b372e4465d7b7103bb4eab6575024e404 Mon Sep 17 00:00:00 2001 From: Dreamszhu Date: Tue, 13 Oct 2020 11:19:17 +0800 Subject: [PATCH 4/9] Update jwt.c --- jwt.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/jwt.c b/jwt.c index 2050769..ade8d0f 100644 --- a/jwt.c +++ b/jwt.c @@ -487,7 +487,8 @@ static void php_jwt_encode(INTERNAL_FUNCTION_PARAMETERS) { smart_str_free(&json_header); smart_str_free(&json_payload); - buf = (char *)emalloc(strlen(header_b64) + strlen(payload_b64) + 1); + int buflen = strlen(header_b64) + strlen(payload_b64) + 2; + buf = (char *)ecalloc(buflen, 1); strcpy(buf, header_b64); strcat(buf, "."); strcat(buf, payload_b64); @@ -497,9 +498,11 @@ static void php_jwt_encode(INTERNAL_FUNCTION_PARAMETERS) { /* sign */ if (jwt->alg == JWT_ALG_NONE) { + buflen+=1; /* alg none */ - buf = (char *)erealloc(buf, strlen(buf) + 1); + buf = (char *)erealloc(buf, buflen); strcat(buf, "."); + buf[buflen]='\0'; } else { /* set jwt struct */ jwt->key = key; @@ -516,7 +519,8 @@ static void php_jwt_encode(INTERNAL_FUNCTION_PARAMETERS) { zend_string *sig_str = zend_string_init(sig, sig_len, 0); char *sig_b64 = jwt_b64_url_encode(sig_str); - char *tmp = (char *)emalloc(strlen(sig_b64) + strlen(buf) + 1); + buflen = strlen(sig_b64) + strlen(buf) + 2; + char *tmp = (char *)ecalloc(buflen, 1); sprintf(tmp, "%s.%s", buf, sig_b64); efree(buf); @@ -534,11 +538,8 @@ static void php_jwt_encode(INTERNAL_FUNCTION_PARAMETERS) { jwt_free(jwt); - char *ret = alloca(strlen(buf)); - strcpy(ret, buf); + RETVAL_STRINGL(buf, strlen(buf)); efree(buf); - - RETURN_STRING(ret); } /* Jwt decode */ From 1f7cb7f061251dcc4884795ab5d093e849450e20 Mon Sep 17 00:00:00 2001 From: Dreamszhu Date: Tue, 13 Oct 2020 11:20:08 +0800 Subject: [PATCH 5/9] Update jwt.c --- jwt.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jwt.c b/jwt.c index ade8d0f..159d7c1 100644 --- a/jwt.c +++ b/jwt.c @@ -487,7 +487,7 @@ static void php_jwt_encode(INTERNAL_FUNCTION_PARAMETERS) { smart_str_free(&json_header); smart_str_free(&json_payload); - int buflen = strlen(header_b64) + strlen(payload_b64) + 2; + int buflen = strlen(header_b64) + strlen(payload_b64) + 2; buf = (char *)ecalloc(buflen, 1); strcpy(buf, header_b64); strcat(buf, "."); From d19cf430d881b228576aa9aae6621a95d7de46c7 Mon Sep 17 00:00:00 2001 From: ZiHang Gao Date: Tue, 13 Oct 2020 16:41:40 +0800 Subject: [PATCH 6/9] =?UTF-8?q?=F0=9F=8F=B7=20Format?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- jwt.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/jwt.c b/jwt.c index 159d7c1..3c98668 100644 --- a/jwt.c +++ b/jwt.c @@ -498,11 +498,11 @@ static void php_jwt_encode(INTERNAL_FUNCTION_PARAMETERS) { /* sign */ if (jwt->alg == JWT_ALG_NONE) { - buflen+=1; + buflen += 1; /* alg none */ buf = (char *)erealloc(buf, buflen); strcat(buf, "."); - buf[buflen]='\0'; + buf[buflen] = '\0'; } else { /* set jwt struct */ jwt->key = key; @@ -519,7 +519,7 @@ static void php_jwt_encode(INTERNAL_FUNCTION_PARAMETERS) { zend_string *sig_str = zend_string_init(sig, sig_len, 0); char *sig_b64 = jwt_b64_url_encode(sig_str); - buflen = strlen(sig_b64) + strlen(buf) + 2; + buflen = strlen(sig_b64) + strlen(buf) + 2; char *tmp = (char *)ecalloc(buflen, 1); sprintf(tmp, "%s.%s", buf, sig_b64); @@ -538,7 +538,7 @@ static void php_jwt_encode(INTERNAL_FUNCTION_PARAMETERS) { jwt_free(jwt); - RETVAL_STRINGL(buf, strlen(buf)); + RETVAL_STRINGL(buf, strlen(buf)); efree(buf); } From 75cc5bd371e1b39e035111442d7a936a999e17bc Mon Sep 17 00:00:00 2001 From: Martin Krisell Date: Sun, 1 Nov 2020 09:53:06 +0100 Subject: [PATCH 7/9] Consistently use short array syntax in readme --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 6135079..3869738 100644 --- a/README.md +++ b/README.md @@ -25,14 +25,14 @@ $ make && make install ```php $key = "example-hmac-key"; -$payload = array( +$payload = [ "data" => [ "name" => "ZiHang Gao", "admin" => true ], "iss" => "http://example.org", "sub" => "1234567890", -); +]; // default HS256 algorithm $token = jwt_encode($payload, $key); @@ -350,4 +350,4 @@ ECDSA|ES256|ES384|ES512 PHP License 3.01. See the [LICENSE](LICENSE) file. [travis-url]: https://travis-ci.org/cdoco/php-jwt -[travis-image]: https://travis-ci.org/cdoco/php-jwt.svg \ No newline at end of file +[travis-image]: https://travis-ci.org/cdoco/php-jwt.svg From d0632d200f782fc700bb894b2493e6ba2531e5fb Mon Sep 17 00:00:00 2001 From: Muhammad Hussein Fattahizadeh Date: Sun, 14 Feb 2021 21:45:05 +0330 Subject: [PATCH 8/9] Add IDE Helper --- README.md | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/README.md b/README.md index 3869738..c14bfd9 100644 --- a/README.md +++ b/README.md @@ -330,6 +330,36 @@ string jwt_encode(array $payload, string $key [, string $algorithm = 'HS256']) array jwt_decode(string $token, string $key [, array $options = ['algorithm' => 'HS256']]) ``` +## IDE Helper + +```php + Date: Sun, 14 Feb 2021 23:00:06 +0330 Subject: [PATCH 9/9] Update README.md --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index c14bfd9..3227742 100644 --- a/README.md +++ b/README.md @@ -343,6 +343,7 @@ namespace { { return ''; } + function jwt_decode(string $token, string $key, string $algorithm = 'HS256'): array { return []; @@ -355,6 +356,7 @@ namespace Cdoco { // @codingStandardsIgnoreEnd { abstract public static function encode(array $payload, string $key, string $algorithm = 'HS256'): string; + abstract public static function decode(string $token, string $key, string $algorithm = 'HS256'): array; } }