From 7a42c608a6a9f2dcf8ca5bdad0f2bf52c1f03651 Mon Sep 17 00:00:00 2001 From: Vinicius Sanchez Date: Tue, 8 Feb 2022 14:17:51 -0300 Subject: [PATCH] Bug fix jwt lazarus --- boss-lock.json | 29 +++++++++++++++-------------- boss.json | 10 +++++----- horse_jwt.dproj | 2 +- samples/delphi/auth/samples.dpr | 2 +- samples/delphi/auth/samples.dproj | 2 +- samples/delphi/client/samples.dproj | 2 +- samples/lazarus/client/Console.lpi | 17 ++++++++++++----- src/Horse.JWT.pas | 4 ++-- 8 files changed, 38 insertions(+), 30 deletions(-) diff --git a/boss-lock.json b/boss-lock.json index f856789..e08030c 100644 --- a/boss-lock.json +++ b/boss-lock.json @@ -1,29 +1,30 @@ { - "hash": "445774d05b3e1b873cfcdb89032b3e1f", - "updated": "2019-10-29T12:23:27.0587203-03:00", + "hash": "d41d8cd98f00b204e9800998ecf8427e", + "updated": "2022-02-08T14:16:13.4097104-03:00", "installedModules": { - "github.com/hashload/horse": { - "name": "horse", - "version": "2.0.13", - "hash": "32daa5a81f115ecc285cbbbbdbcddcea", + "github.com/andre-djsystem/hashlib4pascal": { + "name": "hashlib4pascal", + "version": "1.0.0", + "hash": "8528036224699ab509c7d8f31d691ffb", "artifacts": {}, "failed": false, "changed": false }, - "github.com/paolo-rossi/delphi-jose-jwt": { - "name": "delphi-jose-jwt", - "version": "v3.0.0", - "hash": "e07d23afdc06adef34b7fbbabd97ce83", + "github.com/hashload/horse": { + "name": "horse", + "version": "v2.0.14", + "hash": "38c6bebdc7b9712d6e5856d299289a26", "artifacts": {}, "failed": false, "changed": false }, - "github.com/andre-djsystem/HashLib4Pascal": { - "name": "HashLib4Pascal", - "version": "v1.0.0", + "github.com/paolo-rossi/delphi-jose-jwt": { + "name": "delphi-jose-jwt", + "version": "v3.0.3", + "hash": "d8b6ff80aff10e83d87219f45fa43ffb", "artifacts": {}, "failed": false, "changed": false - } + } } } \ No newline at end of file diff --git a/boss.json b/boss.json index 0f805d3..92739f3 100644 --- a/boss.json +++ b/boss.json @@ -1,13 +1,13 @@ { "name": "horse-jwt", "description": "", - "version": "2.0.0", + "version": "1.0.0", "homepage": "", - "mainsrc": "src/", + "mainsrc": "./src", "projects": [], "dependencies": { - "github.com/hashload/horse": "^2.0.8", - "github.com/paolo-rossi/delphi-jose-jwt": "^v3.0.0" - "github.com/andre-djsystem/HashLib4Pascal": "^v1.0.0" + "github.com/andre-djsystem/hashlib4pascal": "^1.0.0", + "github.com/hashload/horse": "^v2.0.14", + "github.com/paolo-rossi/delphi-jose-jwt": "^v3.0.3" } } \ No newline at end of file diff --git a/horse_jwt.dproj b/horse_jwt.dproj index a9ec375..23a4606 100644 --- a/horse_jwt.dproj +++ b/horse_jwt.dproj @@ -58,7 +58,7 @@ All true horse_jwt - C:\Users\hunsc\projects\hashload\horse-jwt\modules\horse\src\;C:\Users\hunsc\projects\hashload\horse-jwt\modules\delphi-jwt\Samples\Basic\;C:\Users\hunsc\projects\hashload\horse-jwt\modules\delphi-jwt\Samples\Console\;C:\Users\hunsc\projects\hashload\horse-jwt\modules\delphi-jwt\Samples\CustomClaims\;C:\Users\hunsc\projects\hashload\horse-jwt\modules\delphi-jwt\Source\Common\;C:\Users\hunsc\projects\hashload\horse-jwt\modules\delphi-jwt\Source\JOSE\;$(DCC_UnitSearchPath);modules\.dcp;modules\.dcu;modules;modules\delphi-jose-jwt\Samples\Basic;modules\delphi-jose-jwt\Samples\Console;modules\delphi-jose-jwt\Samples\CryptoTest;modules\delphi-jose-jwt\Samples\CustomClaims;modules\delphi-jose-jwt\Source\Common;modules\delphi-jose-jwt\Source\JOSE;modules\delphi-jose-jwt\Tests\Source;modules\horse\src + C:\Users\hunsc\projects\hashload\horse-jwt\modules\horse\src\;C:\Users\hunsc\projects\hashload\horse-jwt\modules\delphi-jwt\Samples\Basic\;C:\Users\hunsc\projects\hashload\horse-jwt\modules\delphi-jwt\Samples\Console\;C:\Users\hunsc\projects\hashload\horse-jwt\modules\delphi-jwt\Samples\CustomClaims\;C:\Users\hunsc\projects\hashload\horse-jwt\modules\delphi-jwt\Source\Common\;C:\Users\hunsc\projects\hashload\horse-jwt\modules\delphi-jwt\Source\JOSE\;$(DCC_UnitSearchPath);modules\.dcp;modules\.dcu;modules;modules\delphi-jose-jwt\Source\Common;modules\delphi-jose-jwt\Source\JOSE;modules\hashlib4pascal\HashLib\src\Base;modules\hashlib4pascal\HashLib\src\Checksum;modules\hashlib4pascal\HashLib\src\Crypto\Blake2BParams;modules\hashlib4pascal\HashLib\src\Crypto\Blake2SParams;modules\hashlib4pascal\HashLib\src\Crypto;modules\hashlib4pascal\HashLib\src\Hash128;modules\hashlib4pascal\HashLib\src\Hash32;modules\hashlib4pascal\HashLib\src\Hash64;modules\hashlib4pascal\HashLib\src\Include;modules\hashlib4pascal\HashLib\src\Interfaces;modules\hashlib4pascal\HashLib\src\Interfaces\IBlake2BParams;modules\hashlib4pascal\HashLib\src\Interfaces\IBlake2SParams;modules\hashlib4pascal\HashLib\src\KDF;modules\hashlib4pascal\HashLib\src\NullDigest;modules\hashlib4pascal\HashLib\src\Nullable;modules\hashlib4pascal\HashLib\src\Packages\FPC;modules\hashlib4pascal\HashLib\src\Utils;modules\hashlib4pascal\HashLib.Benchmark\src\Core;modules\hashlib4pascal\HashLib.Benchmark\src\Forms\FMX;modules\hashlib4pascal\HashLib.Tests\src;modules\horse\src None diff --git a/samples/delphi/auth/samples.dpr b/samples/delphi/auth/samples.dpr index 35a16e5..c65c332 100644 --- a/samples/delphi/auth/samples.dpr +++ b/samples/delphi/auth/samples.dpr @@ -31,5 +31,5 @@ begin end; end); - THorse.Listen(9000); + THorse.Listen(3000); end. diff --git a/samples/delphi/auth/samples.dproj b/samples/delphi/auth/samples.dproj index e7e6795..694c083 100644 --- a/samples/delphi/auth/samples.dproj +++ b/samples/delphi/auth/samples.dproj @@ -76,7 +76,7 @@ true $(BDS)\bin\delphi_PROJECTICON.ico $(BDS)\bin\delphi_PROJECTICNS.icns - $(Horse);$(DCC_UnitSearchPath);modules\.dcp;modules\.dcu;modules;modules\delphi-jose-jwt\Source\Common;modules\delphi-jose-jwt\Source\JOSE;modules\horse\src;modules\jhonson\src + $(Horse);modules\.dcp;modules\.dcu;modules;modules\delphi-jose-jwt\Source\Common;modules\delphi-jose-jwt\Source\JOSE;modules\horse\src;modules\jhonson\src;$(DCC_UnitSearchPath) VCL;$(DCC_Framework) samples diff --git a/samples/delphi/client/samples.dproj b/samples/delphi/client/samples.dproj index add789d..90edb9c 100644 --- a/samples/delphi/client/samples.dproj +++ b/samples/delphi/client/samples.dproj @@ -71,7 +71,7 @@ true $(BDS)\bin\delphi_PROJECTICON.ico $(BDS)\bin\delphi_PROJECTICNS.icns - $(Horse);modules\.dcp;modules\.dcu;modules;modules\delphi-jose-jwt\Source\Common;modules\delphi-jose-jwt\Source\JOSE;modules\horse\src;$(DCC_UnitSearchPath) + $(Horse);$(DCC_UnitSearchPath);modules\.dcp;modules\.dcu;modules;modules\delphi-jose-jwt\Source\Common;modules\delphi-jose-jwt\Source\JOSE;modules\horse\src VCL;$(DCC_Framework) samples diff --git a/samples/lazarus/client/Console.lpi b/samples/lazarus/client/Console.lpi index 03d57a3..d123a39 100644 --- a/samples/lazarus/client/Console.lpi +++ b/samples/lazarus/client/Console.lpi @@ -1,16 +1,16 @@ - + + - <UseAppBundle Value="False"/> <ResourceType Value="res"/> @@ -24,7 +24,6 @@ </PublishOptions> <RunParams> <FormatVersion Value="2"/> - <Modes Count="0"/> </RunParams> <Units Count="1"> <Unit0> @@ -41,15 +40,20 @@ </Target> <SearchPaths> <IncludeFiles Value="$(ProjOutDir)"/> - <OtherUnitFiles Value="..\..\..\src;modules\.dcp;modules\.dcu;modules;modules\horse\src;modules\hashlib4pascal\HashLib\src\Base;modules\hashlib4pascal\HashLib\src\Crypto\Blake2BParams;modules\hashlib4pascal\HashLib\src\Crypto\Blake2SParams;modules\hashlib4pascal\HashLib\src\Interfaces\IBlake2BParams;modules\hashlib4pascal\HashLib\src\Interfaces\IBlake2SParams;modules\hashlib4pascal\HashLib\src\Checksum;modules\hashlib4pascal\HashLib\src\Crypto;modules\hashlib4pascal\HashLib\src\Hash32;modules\hashlib4pascal\HashLib\src\Hash64;modules\hashlib4pascal\HashLib\src\Hash128;modules\hashlib4pascal\HashLib\src\Include;modules\hashlib4pascal\HashLib\src\Interfaces;modules\hashlib4pascal\HashLib\src\KDF;modules\hashlib4pascal\HashLib\src\Nullable;modules\hashlib4pascal\HashLib\src\NullDigest;modules\hashlib4pascal\HashLib\src\Utils"/> + <OtherUnitFiles Value="..\..\..\src;modules\.dcp;modules\.dcu;modules;modules\hashlib4pascal\HashLib\src\Base;modules\hashlib4pascal\HashLib\src\Checksum;modules\hashlib4pascal\HashLib\src\Crypto\Blake2BParams;modules\hashlib4pascal\HashLib\src\Crypto\Blake2SParams;modules\hashlib4pascal\HashLib\src\Crypto;modules\hashlib4pascal\HashLib\src\Hash128;modules\hashlib4pascal\HashLib\src\Hash32;modules\hashlib4pascal\HashLib\src\Hash64;modules\hashlib4pascal\HashLib\src\Include;modules\hashlib4pascal\HashLib\src\Interfaces;modules\hashlib4pascal\HashLib\src\Interfaces\IBlake2BParams;modules\hashlib4pascal\HashLib\src\Interfaces\IBlake2SParams;modules\hashlib4pascal\HashLib\src\KDF;modules\hashlib4pascal\HashLib\src\NullDigest;modules\hashlib4pascal\HashLib\src\Nullable;modules\hashlib4pascal\HashLib\src\Packages\FPC;modules\hashlib4pascal\HashLib\src\Utils;modules\hashlib4pascal\HashLib.Benchmark\src\Core;modules\hashlib4pascal\HashLib.Benchmark\src\Forms\FMX;modules\hashlib4pascal\HashLib.Tests\src;modules\horse\src"/> <UnitOutputDirectory Value="lib\$(TargetCPU)-$(TargetOS)"/> </SearchPaths> + <Linking> + <Debugging> + <DebugInfoType Value="dsDwarf2Set"/> + </Debugging> + </Linking> <Other> <CustomOptions Value="-dUseCThreads"/> </Other> </CompilerOptions> <Debugging> - <Exceptions Count="3"> + <Exceptions Count="4"> <Item1> <Name Value="EAbort"/> </Item1> @@ -59,6 +63,9 @@ <Item3> <Name Value="EFOpenError"/> </Item3> + <Item4> + <Name Value="EResNotFound"/> + </Item4> </Exceptions> </Debugging> </CONFIG> diff --git a/src/Horse.JWT.pas b/src/Horse.JWT.pas index c01e4d2..605c07e 100644 --- a/src/Horse.JWT.pas +++ b/src/Horse.JWT.pas @@ -8,7 +8,7 @@ interface uses {$IF DEFINED(FPC)} - Generics.Collections, Classes, fpjson, SysUtils, HTTPDefs, fpjwt, Base64, DateUtils, + Generics.Collections, Classes, fpjson, SysUtils, HTTPDefs, fpjwt, Base64, DateUtils, jsonparser, HlpIHashInfo, HlpConverters, HlpHashFactory, {$ELSE} System.Generics.Collections, System.Classes, System.JSON, System.SysUtils, Web.HTTPApp, REST.JSON, JOSE.Core.JWT, @@ -211,7 +211,7 @@ procedure Middleware(AHorseRequest: THorseRequest; if (Trim(LJWT.Signature) = EmptyStr) or (not ValidateSignature) then raise Exception.Create('Invalid signature'); - if (LJWT.Claims.exp <> 0) and (LJWT.Claims.exp > DateTimeToUnix(Now)) then + if (LJWT.Claims.exp <> 0) and (LJWT.Claims.exp < DateTimeToUnix(Now)) then raise Exception.Create(Format( 'The JWT is no longer valid - the evaluation time [%s] is on or after the Expiration Time [exp=%s]', [DateToISO8601(Now, False), DateToISO8601(LJWT.Claims.exp, False)]));