Skip to content

Commit

Permalink
Atualização
Browse files Browse the repository at this point in the history
  • Loading branch information
Ronierys2 committed Oct 9, 2024
1 parent 025a655 commit 3467850
Show file tree
Hide file tree
Showing 43 changed files with 51,485 additions and 1,446 deletions.
Binary file added CORE/Extras/AndroidSSL.rar
Binary file not shown.
3 changes: 3 additions & 0 deletions CORE/Extras/AndroidSSL.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Extrair os arquivos compactados na sua pasta do Delphi

EX : C:\Program Files (x86)\Embarcadero\Studio\23.0\lib\android64\release
Binary file added CORE/Extras/Indy.rar
Binary file not shown.
Binary file removed CORE/Extras/Indy.zip
Binary file not shown.
Binary file added CORE/Extras/openssl-1.1.1w.zip
Binary file not shown.
40 changes: 38 additions & 2 deletions CORE/Packages/Lazarus/RESTDataWareComponents.lpk
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<PathDelim Value="\"/>
<SearchPaths>
<IncludeFiles Value="..\..\Source;..\..\Source\Basic\Crypto;..\..\Source\Includes;..\..\Source\Plugins\DMDados;..\..\Source\Plugins\JSONViewer;..\..\Source\Plugins\SQLEditor;..\..\Source\Wizards\lazarus"/>
<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"/>
<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"/>
<UnitOutputDirectory Value="..\..\compiledlaz"/>
</SearchPaths>
<CodeGeneration>
Expand All @@ -32,7 +32,7 @@
<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."/>
<License Value="GPL- 3.0"/>
<Version Major="2" Minor="1"/>
<Files Count="82">
<Files Count="91">
<Item1>
<Filename Value="RESTDataWareComponents.lrs"/>
<Type Value="LRS"/>
Expand Down Expand Up @@ -362,6 +362,42 @@
<Filename Value="..\..\Source\Basic\uRESTDWStorageBin.pas"/>
<UnitName Value="uRESTDWStorageBin"/>
</Item82>
<Item83>
<Filename Value="..\..\Source\utils\SSL\OpenSSL.Api_11.pas"/>
<UnitName Value="OpenSSL.Api_11"/>
</Item83>
<Item84>
<Filename Value="..\..\Source\utils\SSL\uRESTDW.BinaryCoding.pas"/>
<UnitName Value="uRESTDW.BinaryCoding"/>
</Item84>
<Item85>
<Filename Value="..\..\Source\utils\SSL\uRESTDW.Bson.IO.pas"/>
<UnitName Value="uRESTDW.Bson.IO"/>
</Item85>
<Item86>
<Filename Value="..\..\Source\utils\SSL\uRESTDW.Bson.pas"/>
<UnitName Value="uRESTDW.Bson"/>
</Item86>
<Item87>
<Filename Value="..\..\Source\utils\SSL\uRESTDW.DateUtils.pas"/>
<UnitName Value="uRESTDW.DateUtils"/>
</Item87>
<Item88>
<Filename Value="..\..\Source\utils\SSL\uRESTDW.OAuth2.pas"/>
<UnitName Value="uRESTDW.OAuth2"/>
</Item88>
<Item89>
<Filename Value="..\..\Source\utils\SSL\uRESTDW.OpenSsl_11.pas"/>
<UnitName Value="uRESTDW.OpenSsl_11"/>
</Item89>
<Item90>
<Filename Value="..\..\Source\utils\SSL\uRESTDW.System.pas"/>
<UnitName Value="uRESTDW.System"/>
</Item90>
<Item91>
<Filename Value="..\..\Source\utils\SSL\uRESTDW.SysUtils.pas"/>
<UnitName Value="uRESTDW.SysUtils"/>
</Item91>
</Files>
<CompatibilityMode Value="True"/>
<RequiredPkgs Count="3">
Expand Down
4 changes: 3 additions & 1 deletion CORE/Packages/Lazarus/RESTDataWareComponents.pas
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ interface
uRESTDWJSONInterface, uRESTDWSerialize, uRESTDWMimeTypes, uRESTDWAbout,
uRESTDWZlib, uRESTDWMemoryDataset, uRESTDWDesignReg, uRESTDWProtoTypes,
uRESTDWSelfSigned, uRESTDWExprParser, uRESTDWAuthenticators,
uRESTDWStorageBin, LazarusPackageIntf;
uRESTDWStorageBin, OpenSSL.Api_11, uRESTDW.BinaryCoding, uRESTDW.Bson.IO,
uRESTDW.Bson, uRESTDW.DateUtils, uRESTDW.OAuth2, uRESTDW.OpenSsl_11,
uRESTDW.System, uRESTDW.SysUtils, LazarusPackageIntf;

implementation

Expand Down
27 changes: 13 additions & 14 deletions CORE/Source/Basic/Crypto/DWDCPcrypt2.pas
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ interface

{ ****************************************************************** }
{ The base class from which all hash algorithms are to be derived }

type
EDWDCP_hash = class(Exception);

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

type
TDWDCP_ciphermode = (cmCBC, cmCFB8bit, cmCFBblock, cmOFB, cmCTR);
EDWDCP_cipher = class(Exception);

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

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

Expand Down Expand Up @@ -268,7 +267,7 @@ TDWDCP_blockcipher = class(TDWDCP_cipher)

published
property BlockSize: integer read _GetBlockSize write DeadInt;
property CipherMode: TDWDCP_ciphermode read fCipherMode write fCipherMode default cmCBC;
property CipherMode: TDWDCP_ciphermode read fCipherMode write fCipherMode default TDWDCP_ciphermode.cmCBC;
end;

TDWDCP_blockcipherclass = class of TDWDCP_blockcipher;
Expand Down Expand Up @@ -703,15 +702,15 @@ procedure TDWDCP_blockcipher.GetIV(var Value);
procedure TDWDCP_blockcipher.Encrypt(const Indata; var Outdata; Size: longword);
begin
case fCipherMode of
cmCBC:
TDWDCP_ciphermode.cmCBC:
EncryptCBC(Indata, Outdata, Size);
cmCFB8bit:
TDWDCP_ciphermode.cmCFB8bit:
EncryptCFB8bit(Indata, Outdata, Size);
cmCFBblock:
TDWDCP_ciphermode.cmCFBblock:
EncryptCFBblock(Indata, Outdata, Size);
cmOFB:
TDWDCP_ciphermode.cmOFB:
EncryptOFB(Indata, Outdata, Size);
cmCTR:
TDWDCP_ciphermode.cmCTR:
EncryptCTR(Indata, Outdata, Size);
end;
end;
Expand Down Expand Up @@ -750,15 +749,15 @@ function TDWDCP_blockcipher.EncryptString(const Str: DWDCPUnicodeString): DWDCPU
procedure TDWDCP_blockcipher.Decrypt(const Indata; var Outdata; Size: longword);
begin
case fCipherMode of
cmCBC:
TDWDCP_ciphermode.cmCBC:
DecryptCBC(Indata, Outdata, Size);
cmCFB8bit:
TDWDCP_ciphermode.cmCFB8bit:
DecryptCFB8bit(Indata, Outdata, Size);
cmCFBblock:
TDWDCP_ciphermode.cmCFBblock:
DecryptCFBblock(Indata, Outdata, Size);
cmOFB:
TDWDCP_ciphermode.cmOFB:
DecryptOFB(Indata, Outdata, Size);
cmCTR:
TDWDCP_ciphermode.cmCTR:
DecryptCTR(Indata, Outdata, Size);
end;
end;
Expand Down Expand Up @@ -814,7 +813,7 @@ procedure TDWDCP_blockcipher.DecryptCTR(const Indata; var Outdata; Size: longwor
constructor TDWDCP_blockcipher.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
fCipherMode := cmCBC;
fCipherMode := TDWDCP_ciphermode.cmCBC;
end;

// Version 2.1 : Partial Stream Read capability.
Expand Down
1 change: 1 addition & 0 deletions CORE/Source/Basic/Crypto/DWDCPrijndael.pas
Original file line number Diff line number Diff line change
Expand Up @@ -367,3 +367,4 @@ procedure TRESTDWDCP_rijndael.DecryptECB(const InData; var OutData);


end.

160 changes: 111 additions & 49 deletions CORE/Source/Basic/Mechanics/uRESTDWAuthenticators.pas
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
unit uRESTDWAuthenticators;
unit uRESTDWAuthenticators;

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

Expand Down Expand Up @@ -32,8 +32,20 @@ interface

uses
Classes, SysUtils, DateUtils,
uRESTDWConsts, uRESTDWAbout, uRESTDWDataUtils, uRESTDWJSONInterface,
uRESTDWTools, uRESTDWParams;
uRESTDWConsts, uRESTDWAbout, uRESTDWDataUtils, uRESTDWJSONInterface,
uRESTDWTools, uRESTDWParams, uRESTDWProtoTypes, uRESTDW.OpenSsl_11;

Type
TRESTDWCertOptions = Record
Country,
State,
Locality,
Organization,
OrgUnit,
CommonName,
ServerName : String;
ExpiresDays : Integer;
End;

Type
TRESTDWAuthenticatorBase = class(TRESTDWComponent)
Expand Down Expand Up @@ -138,36 +150,63 @@ TRESTDWAuthToken = class(TRESTDWServerAuthBase)
property AutoRenewToken: Boolean read FAutoRenewToken write FAutoRenewToken;
end;

TRESTDWAuthOAuth = class(TRESTDWServerAuthBase)
TRESTDWAuthOAuth = Class(TRESTDWServerAuthBase)
private
FTokenType: TRESTDWAuthOptionTypes;
FAutoBuildHex: Boolean;
FToken: String;
FGrantCodeEvent: String;
FGrantType: String;
FGetTokenEvent: String;
FClientID: String;
FClientSecret: String;
FRedirectURI: String;
FExpiresIn: TDateTime;
FTokenType : TRESTDWAuthOptionTypes;
FBeginTime,
FEndTime : TDateTime;
FRSASHA256_Validation,
FServerValidationCert,
FAutoBuildHex : Boolean;
FLifeCycle : Integer;
FToken,
FGrantCodeEvent,
FGrantType,
FGetTokenEvent,
FHeader,
FPayLoad,
FSignature,
FPublicKey,
FPrivateKey,
FRedirectURI : String;
public
constructor Create(aOwner: TComponent); override;
function AuthValidate(ADataModuleRESTDW: TObject;
AUrlToExec, AWelcomeMessage, AAccessTag, AAuthUsername, AAuthPassword: String;
ARawHeaders: TStrings; ARequestType: TRequestType; var ADWParams: TRESTDWParams;
var AGetToken: Boolean; var ATokenValidate: Boolean; var AToken: String;
var AErrorCode: Integer; var AErrorMessage: String; var AAcceptAuth: Boolean): Boolean; override;
Constructor Create (aOwner : TComponent); Override;
Function CreateSelfSignedCert_X509(CertOptions : TRESTDWCertOptions;
Var Certificate,
PrivateKey : TRESTDWBytes) : Boolean;
Function AuthValidate (ADataModuleRESTDW : TObject;
AUrlToExec,
AWelcomeMessage,
AAccessTag,
AAuthUsername,
AAuthPassword : String;
ARawHeaders : TStrings;
ARequestType : TRequestType;
Var ADWParams : TRESTDWParams;
Var AGetToken : Boolean;
Var ATokenValidate : Boolean;
Var AToken : String;
Var AErrorCode : Integer;
Var AErrorMessage : String;
Var AAcceptAuth : Boolean) : Boolean; Override;
published
property TokenType: TRESTDWAuthOptionTypes read FTokenType write FTokenType;
property AutoBuildHex: Boolean read FAutoBuildHex write FAutoBuildHex;
property Token: String read FToken write FToken;
property GrantCodeEvent: String read FGrantCodeEvent write FGrantCodeEvent;
property GrantType: String read FGrantType write FGrantType;
property GetTokenEvent: String read FGetTokenEvent write FGetTokenEvent;
property ClientID: String read FClientID write FClientID;
property ClientSecret: String read FClientSecret write FClientSecret;
property RedirectURI: String read FRedirectURI write FRedirectURI;
property ExpiresIn: TDateTime read FExpiresIn;
Property TokenType : TRESTDWAuthOptionTypes Read FTokenType Write FTokenType;
Property AutoBuildHex : Boolean Read FAutoBuildHex Write FAutoBuildHex;
Property RSASHA256_Validation : Boolean Read FRSASHA256_Validation Write FRSASHA256_Validation;
Property LifeCycle : Integer Read FLifeCycle Write FLifeCycle;
Property BeginTime : TDateTime Read FBeginTime Write FBeginTime; //iat
Property EndTime : TDateTime Read FEndTime Write FEndTime;//exp
Property ServerValidationCert : Boolean Read FServerValidationCert Write FServerValidationCert;
Property Token : String Read FToken Write FToken;
Property GrantCodeEvent : String Read FGrantCodeEvent Write FGrantCodeEvent;
Property GrantType : String Read FGrantType Write FGrantType;
Property GetTokenEvent : String Read FGetTokenEvent Write FGetTokenEvent;
Property Header : String Read FHeader;
Property PayLoad : String Read FPayLoad Write FPayLoad;
Property Signature : String Read FSignature Write FSignature;
Property PublicKey : String Read FPublicKey Write FPublicKey;
Property PrivateKey : String Read FPrivateKey Write FPrivateKey;
Property RedirectURI : String Read FRedirectURI Write FRedirectURI;
end;

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

TOnGetToken = Procedure(Welcomemsg,
AccessTag : String;
Params : TRESTDWParams;
AuthOptions : TRESTDWAuthToken;
Var ErrorCode : Integer;
Var ErrorMessage : String;
Var TokenID : String;
Var Accept : Boolean) Of Object;
TOnGetToken = Procedure(Welcomemsg,
AccessTag : String;
Params : TRESTDWParams;
AuthOptions : TRESTDWAuthToken;
Var ErrorCode : Integer;
Var ErrorMessage : String;
Var TokenID : String;
Var Accept : Boolean) Of Object;

TOnUserTokenAuth = Procedure(Welcomemsg,
AccessTag : String;
Expand Down Expand Up @@ -926,7 +965,22 @@ procedure TRESTDWAuthToken.SetToken(AValue: String);

{ TRESTDWAuthOAuth }

Function TRESTDWAuthOAuth.AuthValidate(ADataModuleRESTDW : TObject;
Function TRESTDWAuthOAuth.CreateSelfSignedCert_X509(CertOptions : TRESTDWCertOptions;
Var Certificate,
PrivateKey : TRESTDWBytes) : Boolean;
begin
Result := TRESTDWOpenSSLHelper.CreateSelfSignedCert_X509(CertOptions.Country,
CertOptions.State,
CertOptions.Locality,
CertOptions.Organization,
CertOptions.OrgUnit,
CertOptions.CommonName,
CertOptions.ServerName,
CertOptions.ExpiresDays,
Certificate, PrivateKey);
End;

Function TRESTDWAuthOAuth.AuthValidate(ADataModuleRESTDW : TObject;
AUrlToExec,
AWelcomeMessage,
AAccessTag,
Expand All @@ -950,16 +1004,24 @@ procedure TRESTDWAuthToken.SetToken(AValue: String);
Constructor TRESTDWAuthOAuth.Create(aOwner: TComponent);
Begin
Inherited;
FClientID := '';
FClientSecret := '';
FToken := '';
FRedirectURI := '';
FGrantType := 'client_credentials';
FGetTokenEvent := 'access-token';
FGrantCodeEvent := 'authorize';
FAutoBuildHex := False;
FExpiresIn := 0;
FTokenType := rdwOATBasic;
FRSASHA256_Validation := True;
FServerValidationCert := True;
FToken := '';
FRedirectURI := '';
FGrantType := 'client_credentials';
FGetTokenEvent := 'access-token';
FGrantCodeEvent := 'authorize';
FHeader := '{"alg": "RS256", "typ": "JWT"}';
FLifeCycle := 1800; // 30 Minutos
FPayLoad := '';
FSignature := '';
FPublicKey := '';
FPrivateKey := '';
FRedirectURI := '';
FBeginTime := 0;
FEndTime := 0;
FAutoBuildHex := False;
FTokenType := rdwOATBasic;
End;

{ TRESTDWAuthenticatorBase }
Expand Down
Loading

0 comments on commit 3467850

Please sign in to comment.