Skip to content

Commit 0616da6

Browse files
authored
Dev (#394)
2 parents 686f59b + c1582dc commit 0616da6

44 files changed

Lines changed: 51624 additions & 1600 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

CORE/Extras/AndroidSSL.rar

5.38 MB
Binary file not shown.

CORE/Extras/AndroidSSL.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Extrair os arquivos compactados na sua pasta do Delphi
2+
3+
EX : C:\Program Files (x86)\Embarcadero\Studio\23.0\lib\android64\release

CORE/Extras/Indy.rar

8.08 MB
Binary file not shown.

CORE/Extras/Indy.zip

-8.93 MB
Binary file not shown.

CORE/Extras/openssl-1.1.1w.zip

15.2 MB
Binary file not shown.

CORE/Packages/Lazarus/RESTDataWareComponents.lpk

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
<PathDelim Value="\"/>
1111
<SearchPaths>
1212
<IncludeFiles Value="..\..\Source;..\..\Source\Basic\Crypto;..\..\Source\Includes;..\..\Source\Plugins\DMDados;..\..\Source\Plugins\JSONViewer;..\..\Source\Plugins\SQLEditor;..\..\Source\Wizards\lazarus"/>
13-
<OtherUnitFiles Value="..\..\Source;..\..\Source\Basic;..\..\Source\Basic\Crypto;..\..\Source\Basic\Dialogs;..\..\Source\Basic\Mechanics;..\..\Source\Consts;..\..\Source\utils;..\..\Source\utils\JSON;..\..\Source\Plugins\DMDados;..\..\Source\Plugins\JSONViewer;..\..\Source\Plugins\Memdataset;..\..\Source\Plugins\SQLEditor;..\..\Source\Wizards\lazarus;..\..\Source\Database_Drivers;..\..\Source\Plugins\SelfSigned"/>
13+
<OtherUnitFiles Value="..\..\Source;..\..\Source\Basic;..\..\Source\Basic\Crypto;..\..\Source\Basic\Dialogs;..\..\Source\Basic\Mechanics;..\..\Source\Consts;..\..\Source\utils;..\..\Source\utils\JSON;..\..\Source\Plugins\DMDados;..\..\Source\Plugins\JSONViewer;..\..\Source\Plugins\Memdataset;..\..\Source\Plugins\SQLEditor;..\..\Source\Wizards\lazarus;..\..\Source\Database_Drivers;..\..\Source\Plugins\SelfSigned;..\..\Source\utils\SSL"/>
1414
<UnitOutputDirectory Value="..\..\compiledlaz"/>
1515
</SearchPaths>
1616
<CodeGeneration>
@@ -32,7 +32,7 @@
3232
<Description Value="The proposal was fulfilled. REST DW was created to facilitate the creation of CRUDs in the same model that we created applications for Client / Server Database. Today, being able to write data to a bank via WebService is too complex for simple operations, making scheduling of simple screens time-consuming. With REST Dataware, you no longer have to worry about creating SQL Insertion, Deletion, Read, and Execution methods via Webservice; Simply add a RESTDataBase connection component and add a RESTClientSQL component that will already have your SQL solution fully functional as you did back in the day and with all the power of modern REST / JSON technology with data compression and everything the language can offer. Have fun."/>
3333
<License Value="GPL- 3.0"/>
3434
<Version Major="2" Minor="1"/>
35-
<Files Count="82">
35+
<Files Count="91">
3636
<Item1>
3737
<Filename Value="RESTDataWareComponents.lrs"/>
3838
<Type Value="LRS"/>
@@ -362,6 +362,42 @@
362362
<Filename Value="..\..\Source\Basic\uRESTDWStorageBin.pas"/>
363363
<UnitName Value="uRESTDWStorageBin"/>
364364
</Item82>
365+
<Item83>
366+
<Filename Value="..\..\Source\utils\SSL\OpenSSL.Api_11.pas"/>
367+
<UnitName Value="OpenSSL.Api_11"/>
368+
</Item83>
369+
<Item84>
370+
<Filename Value="..\..\Source\utils\SSL\uRESTDW.BinaryCoding.pas"/>
371+
<UnitName Value="uRESTDW.BinaryCoding"/>
372+
</Item84>
373+
<Item85>
374+
<Filename Value="..\..\Source\utils\SSL\uRESTDW.Bson.IO.pas"/>
375+
<UnitName Value="uRESTDW.Bson.IO"/>
376+
</Item85>
377+
<Item86>
378+
<Filename Value="..\..\Source\utils\SSL\uRESTDW.Bson.pas"/>
379+
<UnitName Value="uRESTDW.Bson"/>
380+
</Item86>
381+
<Item87>
382+
<Filename Value="..\..\Source\utils\SSL\uRESTDW.DateUtils.pas"/>
383+
<UnitName Value="uRESTDW.DateUtils"/>
384+
</Item87>
385+
<Item88>
386+
<Filename Value="..\..\Source\utils\SSL\uRESTDW.OAuth2.pas"/>
387+
<UnitName Value="uRESTDW.OAuth2"/>
388+
</Item88>
389+
<Item89>
390+
<Filename Value="..\..\Source\utils\SSL\uRESTDW.OpenSsl_11.pas"/>
391+
<UnitName Value="uRESTDW.OpenSsl_11"/>
392+
</Item89>
393+
<Item90>
394+
<Filename Value="..\..\Source\utils\SSL\uRESTDW.System.pas"/>
395+
<UnitName Value="uRESTDW.System"/>
396+
</Item90>
397+
<Item91>
398+
<Filename Value="..\..\Source\utils\SSL\uRESTDW.SysUtils.pas"/>
399+
<UnitName Value="uRESTDW.SysUtils"/>
400+
</Item91>
365401
</Files>
366402
<CompatibilityMode Value="True"/>
367403
<RequiredPkgs Count="3">

CORE/Packages/Lazarus/RESTDataWareComponents.pas

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@ interface
2828
uRESTDWJSONInterface, uRESTDWSerialize, uRESTDWMimeTypes, uRESTDWAbout,
2929
uRESTDWZlib, uRESTDWMemoryDataset, uRESTDWDesignReg, uRESTDWProtoTypes,
3030
uRESTDWSelfSigned, uRESTDWExprParser, uRESTDWAuthenticators,
31-
uRESTDWStorageBin, LazarusPackageIntf;
31+
uRESTDWStorageBin, OpenSSL.Api_11, uRESTDW.BinaryCoding, uRESTDW.Bson.IO,
32+
uRESTDW.Bson, uRESTDW.DateUtils, uRESTDW.OAuth2, uRESTDW.OpenSsl_11,
33+
uRESTDW.System, uRESTDW.SysUtils, LazarusPackageIntf;
3234

3335
implementation
3436

CORE/Source/Basic/Crypto/DWDCPcrypt2.pas

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ interface
3636

3737
{ ****************************************************************** }
3838
{ The base class from which all hash algorithms are to be derived }
39-
4039
type
4140
EDWDCP_hash = class(Exception);
4241

@@ -106,6 +105,7 @@ TDWDCP_hashclass = class of TDWDCP_hash;
106105
{ Block ciphers will have a further foundation class TDWDCP_blockcipher. }
107106

108107
type
108+
TDWDCP_ciphermode = (cmCBC, cmCFB8bit, cmCFBblock, cmOFB, cmCTR);
109109
EDWDCP_cipher = class(Exception);
110110

111111
TDWDCP_cipher = class(TComponent)
@@ -200,7 +200,6 @@ TDWDCP_cipherclass = class of TDWDCP_cipher;
200200
{ extra class takes care of the different block encryption modes. }
201201

202202
type
203-
TDWDCP_ciphermode = (cmCBC, cmCFB8bit, cmCFBblock, cmOFB, cmCTR);
204203
// cmCFB8bit is equal to DWDCPcrypt v1.xx's CFB mode
205204
EDWDCP_blockcipher = class(EDWDCP_cipher);
206205

@@ -268,7 +267,7 @@ TDWDCP_blockcipher = class(TDWDCP_cipher)
268267

269268
published
270269
property BlockSize: integer read _GetBlockSize write DeadInt;
271-
property CipherMode: TDWDCP_ciphermode read fCipherMode write fCipherMode default cmCBC;
270+
property CipherMode: TDWDCP_ciphermode read fCipherMode write fCipherMode default TDWDCP_ciphermode.cmCBC;
272271
end;
273272

274273
TDWDCP_blockcipherclass = class of TDWDCP_blockcipher;
@@ -703,15 +702,15 @@ procedure TDWDCP_blockcipher.GetIV(var Value);
703702
procedure TDWDCP_blockcipher.Encrypt(const Indata; var Outdata; Size: longword);
704703
begin
705704
case fCipherMode of
706-
cmCBC:
705+
TDWDCP_ciphermode.cmCBC:
707706
EncryptCBC(Indata, Outdata, Size);
708-
cmCFB8bit:
707+
TDWDCP_ciphermode.cmCFB8bit:
709708
EncryptCFB8bit(Indata, Outdata, Size);
710-
cmCFBblock:
709+
TDWDCP_ciphermode.cmCFBblock:
711710
EncryptCFBblock(Indata, Outdata, Size);
712-
cmOFB:
711+
TDWDCP_ciphermode.cmOFB:
713712
EncryptOFB(Indata, Outdata, Size);
714-
cmCTR:
713+
TDWDCP_ciphermode.cmCTR:
715714
EncryptCTR(Indata, Outdata, Size);
716715
end;
717716
end;
@@ -750,15 +749,15 @@ function TDWDCP_blockcipher.EncryptString(const Str: DWDCPUnicodeString): DWDCPU
750749
procedure TDWDCP_blockcipher.Decrypt(const Indata; var Outdata; Size: longword);
751750
begin
752751
case fCipherMode of
753-
cmCBC:
752+
TDWDCP_ciphermode.cmCBC:
754753
DecryptCBC(Indata, Outdata, Size);
755-
cmCFB8bit:
754+
TDWDCP_ciphermode.cmCFB8bit:
756755
DecryptCFB8bit(Indata, Outdata, Size);
757-
cmCFBblock:
756+
TDWDCP_ciphermode.cmCFBblock:
758757
DecryptCFBblock(Indata, Outdata, Size);
759-
cmOFB:
758+
TDWDCP_ciphermode.cmOFB:
760759
DecryptOFB(Indata, Outdata, Size);
761-
cmCTR:
760+
TDWDCP_ciphermode.cmCTR:
762761
DecryptCTR(Indata, Outdata, Size);
763762
end;
764763
end;
@@ -814,7 +813,7 @@ procedure TDWDCP_blockcipher.DecryptCTR(const Indata; var Outdata; Size: longwor
814813
constructor TDWDCP_blockcipher.Create(AOwner: TComponent);
815814
begin
816815
inherited Create(AOwner);
817-
fCipherMode := cmCBC;
816+
fCipherMode := TDWDCP_ciphermode.cmCBC;
818817
end;
819818

820819
// Version 2.1 : Partial Stream Read capability.

CORE/Source/Basic/Crypto/DWDCPrijndael.pas

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -367,3 +367,4 @@ procedure TRESTDWDCP_rijndael.DecryptECB(const InData; var OutData);
367367

368368

369369
end.
370+

CORE/Source/Basic/Mechanics/uRESTDWAuthenticators.pas

Lines changed: 111 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
unit uRESTDWAuthenticators;
1+
unit uRESTDWAuthenticators;
22

33
{$I ..\..\Includes\uRESTDW.inc}
44

@@ -32,8 +32,20 @@ interface
3232

3333
uses
3434
Classes, SysUtils, DateUtils,
35-
uRESTDWConsts, uRESTDWAbout, uRESTDWDataUtils, uRESTDWJSONInterface,
36-
uRESTDWTools, uRESTDWParams;
35+
uRESTDWConsts, uRESTDWAbout, uRESTDWDataUtils, uRESTDWJSONInterface,
36+
uRESTDWTools, uRESTDWParams, uRESTDWProtoTypes, uRESTDW.OpenSsl_11;
37+
38+
Type
39+
TRESTDWCertOptions = Record
40+
Country,
41+
State,
42+
Locality,
43+
Organization,
44+
OrgUnit,
45+
CommonName,
46+
ServerName : String;
47+
ExpiresDays : Integer;
48+
End;
3749

3850
Type
3951
TRESTDWAuthenticatorBase = class(TRESTDWComponent)
@@ -138,36 +150,63 @@ TRESTDWAuthToken = class(TRESTDWServerAuthBase)
138150
property AutoRenewToken: Boolean read FAutoRenewToken write FAutoRenewToken;
139151
end;
140152

141-
TRESTDWAuthOAuth = class(TRESTDWServerAuthBase)
153+
TRESTDWAuthOAuth = Class(TRESTDWServerAuthBase)
142154
private
143-
FTokenType: TRESTDWAuthOptionTypes;
144-
FAutoBuildHex: Boolean;
145-
FToken: String;
146-
FGrantCodeEvent: String;
147-
FGrantType: String;
148-
FGetTokenEvent: String;
149-
FClientID: String;
150-
FClientSecret: String;
151-
FRedirectURI: String;
152-
FExpiresIn: TDateTime;
155+
FTokenType : TRESTDWAuthOptionTypes;
156+
FBeginTime,
157+
FEndTime : TDateTime;
158+
FRSASHA256_Validation,
159+
FServerValidationCert,
160+
FAutoBuildHex : Boolean;
161+
FLifeCycle : Integer;
162+
FToken,
163+
FGrantCodeEvent,
164+
FGrantType,
165+
FGetTokenEvent,
166+
FHeader,
167+
FPayLoad,
168+
FSignature,
169+
FPublicKey,
170+
FPrivateKey,
171+
FRedirectURI : String;
153172
public
154-
constructor Create(aOwner: TComponent); override;
155-
function AuthValidate(ADataModuleRESTDW: TObject;
156-
AUrlToExec, AWelcomeMessage, AAccessTag, AAuthUsername, AAuthPassword: String;
157-
ARawHeaders: TStrings; ARequestType: TRequestType; var ADWParams: TRESTDWParams;
158-
var AGetToken: Boolean; var ATokenValidate: Boolean; var AToken: String;
159-
var AErrorCode: Integer; var AErrorMessage: String; var AAcceptAuth: Boolean): Boolean; override;
173+
Constructor Create (aOwner : TComponent); Override;
174+
Function CreateSelfSignedCert_X509(CertOptions : TRESTDWCertOptions;
175+
Var Certificate,
176+
PrivateKey : TRESTDWBytes) : Boolean;
177+
Function AuthValidate (ADataModuleRESTDW : TObject;
178+
AUrlToExec,
179+
AWelcomeMessage,
180+
AAccessTag,
181+
AAuthUsername,
182+
AAuthPassword : String;
183+
ARawHeaders : TStrings;
184+
ARequestType : TRequestType;
185+
Var ADWParams : TRESTDWParams;
186+
Var AGetToken : Boolean;
187+
Var ATokenValidate : Boolean;
188+
Var AToken : String;
189+
Var AErrorCode : Integer;
190+
Var AErrorMessage : String;
191+
Var AAcceptAuth : Boolean) : Boolean; Override;
160192
published
161-
property TokenType: TRESTDWAuthOptionTypes read FTokenType write FTokenType;
162-
property AutoBuildHex: Boolean read FAutoBuildHex write FAutoBuildHex;
163-
property Token: String read FToken write FToken;
164-
property GrantCodeEvent: String read FGrantCodeEvent write FGrantCodeEvent;
165-
property GrantType: String read FGrantType write FGrantType;
166-
property GetTokenEvent: String read FGetTokenEvent write FGetTokenEvent;
167-
property ClientID: String read FClientID write FClientID;
168-
property ClientSecret: String read FClientSecret write FClientSecret;
169-
property RedirectURI: String read FRedirectURI write FRedirectURI;
170-
property ExpiresIn: TDateTime read FExpiresIn;
193+
Property TokenType : TRESTDWAuthOptionTypes Read FTokenType Write FTokenType;
194+
Property AutoBuildHex : Boolean Read FAutoBuildHex Write FAutoBuildHex;
195+
Property RSASHA256_Validation : Boolean Read FRSASHA256_Validation Write FRSASHA256_Validation;
196+
Property LifeCycle : Integer Read FLifeCycle Write FLifeCycle;
197+
Property BeginTime : TDateTime Read FBeginTime Write FBeginTime; //iat
198+
Property EndTime : TDateTime Read FEndTime Write FEndTime;//exp
199+
Property ServerValidationCert : Boolean Read FServerValidationCert Write FServerValidationCert;
200+
Property Token : String Read FToken Write FToken;
201+
Property GrantCodeEvent : String Read FGrantCodeEvent Write FGrantCodeEvent;
202+
Property GrantType : String Read FGrantType Write FGrantType;
203+
Property GetTokenEvent : String Read FGetTokenEvent Write FGetTokenEvent;
204+
Property Header : String Read FHeader;
205+
Property PayLoad : String Read FPayLoad Write FPayLoad;
206+
Property Signature : String Read FSignature Write FSignature;
207+
Property PublicKey : String Read FPublicKey Write FPublicKey;
208+
Property PrivateKey : String Read FPrivateKey Write FPrivateKey;
209+
Property RedirectURI : String Read FRedirectURI Write FRedirectURI;
171210
end;
172211

173212
TOnUserBasicAuth = Procedure(Welcomemsg, AccessTag,
@@ -177,14 +216,14 @@ TRESTDWAuthOAuth = class(TRESTDWServerAuthBase)
177216
Var ErrorMessage : String;
178217
Var Accept : Boolean) Of Object;
179218

180-
TOnGetToken = Procedure(Welcomemsg,
181-
AccessTag : String;
182-
Params : TRESTDWParams;
183-
AuthOptions : TRESTDWAuthToken;
184-
Var ErrorCode : Integer;
185-
Var ErrorMessage : String;
186-
Var TokenID : String;
187-
Var Accept : Boolean) Of Object;
219+
TOnGetToken = Procedure(Welcomemsg,
220+
AccessTag : String;
221+
Params : TRESTDWParams;
222+
AuthOptions : TRESTDWAuthToken;
223+
Var ErrorCode : Integer;
224+
Var ErrorMessage : String;
225+
Var TokenID : String;
226+
Var Accept : Boolean) Of Object;
188227

189228
TOnUserTokenAuth = Procedure(Welcomemsg,
190229
AccessTag : String;
@@ -926,7 +965,22 @@ procedure TRESTDWAuthToken.SetToken(AValue: String);
926965

927966
{ TRESTDWAuthOAuth }
928967

929-
Function TRESTDWAuthOAuth.AuthValidate(ADataModuleRESTDW : TObject;
968+
Function TRESTDWAuthOAuth.CreateSelfSignedCert_X509(CertOptions : TRESTDWCertOptions;
969+
Var Certificate,
970+
PrivateKey : TRESTDWBytes) : Boolean;
971+
begin
972+
Result := TRESTDWOpenSSLHelper.CreateSelfSignedCert_X509(CertOptions.Country,
973+
CertOptions.State,
974+
CertOptions.Locality,
975+
CertOptions.Organization,
976+
CertOptions.OrgUnit,
977+
CertOptions.CommonName,
978+
CertOptions.ServerName,
979+
CertOptions.ExpiresDays,
980+
Certificate, PrivateKey);
981+
End;
982+
983+
Function TRESTDWAuthOAuth.AuthValidate(ADataModuleRESTDW : TObject;
930984
AUrlToExec,
931985
AWelcomeMessage,
932986
AAccessTag,
@@ -950,16 +1004,24 @@ procedure TRESTDWAuthToken.SetToken(AValue: String);
9501004
Constructor TRESTDWAuthOAuth.Create(aOwner: TComponent);
9511005
Begin
9521006
Inherited;
953-
FClientID := '';
954-
FClientSecret := '';
955-
FToken := '';
956-
FRedirectURI := '';
957-
FGrantType := 'client_credentials';
958-
FGetTokenEvent := 'access-token';
959-
FGrantCodeEvent := 'authorize';
960-
FAutoBuildHex := False;
961-
FExpiresIn := 0;
962-
FTokenType := rdwOATBasic;
1007+
FRSASHA256_Validation := True;
1008+
FServerValidationCert := True;
1009+
FToken := '';
1010+
FRedirectURI := '';
1011+
FGrantType := 'client_credentials';
1012+
FGetTokenEvent := 'access-token';
1013+
FGrantCodeEvent := 'authorize';
1014+
FHeader := '{"alg": "RS256", "typ": "JWT"}';
1015+
FLifeCycle := 1800; // 30 Minutos
1016+
FPayLoad := '';
1017+
FSignature := '';
1018+
FPublicKey := '';
1019+
FPrivateKey := '';
1020+
FRedirectURI := '';
1021+
FBeginTime := 0;
1022+
FEndTime := 0;
1023+
FAutoBuildHex := False;
1024+
FTokenType := rdwOATBasic;
9631025
End;
9641026

9651027
{ TRESTDWAuthenticatorBase }

0 commit comments

Comments
 (0)