mirror of
https://github.com/unidoc/unipdf.git
synced 2025-04-30 13:48:51 +08:00
129 lines
24 KiB
Go
129 lines
24 KiB
Go
//
|
|
// Copyright 2020 FoxyUtils ehf. All rights reserved.
|
|
//
|
|
// This is a commercial product and requires a license to operate.
|
|
// A trial license can be obtained at https://unidoc.io
|
|
//
|
|
// DO NOT EDIT: generated by unitwist Go source code obfuscator.
|
|
//
|
|
// Use of this source code is governed by the UniDoc End User License Agreement
|
|
// terms that can be accessed at https://unidoc.io/eula/
|
|
|
|
package security ;import (_a "bytes";_ff "crypto/aes";_c "crypto/cipher";_bg "crypto/md5";_ga "crypto/rand";_g "crypto/rc4";_bb "crypto/sha256";_ef "crypto/sha512";_bf "encoding/binary";_d "errors";_db "fmt";_bfe "github.com/unidoc/unipdf/v3/common";_e "hash";
|
|
_b "io";_bbb "math";);
|
|
|
|
// GenerateParams generates and sets O and U parameters for the encryption dictionary.
|
|
// It expects R, P and EncryptMetadata fields to be set.
|
|
func (_fgb stdHandlerR4 )GenerateParams (d *StdEncryptDict ,opass ,upass []byte )([]byte ,error ){O ,_gca :=_fgb .alg3 (d .R ,upass ,opass );if _gca !=nil {_bfe .Log .Debug ("\u0045R\u0052\u004fR\u003a\u0020\u0045r\u0072\u006f\u0072\u0020\u0067\u0065\u006ee\u0072\u0061\u0074\u0069\u006e\u0067 \u004f\u0020\u0066\u006f\u0072\u0020\u0065\u006e\u0063\u0072\u0079p\u0074\u0069\u006f\u006e\u0020\u0028\u0025\u0073\u0029",_gca );
|
|
return nil ,_gca ;};d .O =O ;_bfe .Log .Trace ("\u0067\u0065\u006e\u0020\u004f\u003a\u0020\u0025\u0020\u0078",O );_daa :=_fgb .alg2 (d ,upass );U ,_gca :=_fgb .alg5 (_daa ,upass );if _gca !=nil {_bfe .Log .Debug ("\u0045R\u0052\u004fR\u003a\u0020\u0045r\u0072\u006f\u0072\u0020\u0067\u0065\u006ee\u0072\u0061\u0074\u0069\u006e\u0067 \u004f\u0020\u0066\u006f\u0072\u0020\u0065\u006e\u0063\u0072\u0079p\u0074\u0069\u006f\u006e\u0020\u0028\u0025\u0073\u0029",_gca );
|
|
return nil ,_gca ;};d .U =U ;_bfe .Log .Trace ("\u0067\u0065\u006e\u0020\u0055\u003a\u0020\u0025\u0020\u0078",U );return _daa ,nil ;};
|
|
|
|
// StdHandler is an interface for standard security handlers.
|
|
type StdHandler interface{
|
|
|
|
// GenerateParams uses owner and user passwords to set encryption parameters and generate an encryption key.
|
|
// It assumes that R, P and EncryptMetadata are already set.
|
|
GenerateParams (_dg *StdEncryptDict ,_ge ,_dc []byte )([]byte ,error );
|
|
|
|
// Authenticate uses encryption dictionary parameters and the password to calculate
|
|
// the document encryption key. It also returns permissions that should be granted to a user.
|
|
// In case of failed authentication, it returns empty key and zero permissions with no error.
|
|
Authenticate (_dgc *StdEncryptDict ,_bgg []byte )([]byte ,Permissions ,error );};func (_fef stdHandlerR6 )alg8 (_egb *StdEncryptDict ,_bee []byte ,_abb []byte )error {if _fdg :=_ecb ("\u0061\u006c\u0067\u0038","\u004b\u0065\u0079",32,_bee );_fdg !=nil {return _fdg ;
|
|
};var _bdc [16]byte ;if _ ,_dbe :=_b .ReadFull (_ga .Reader ,_bdc [:]);_dbe !=nil {return _dbe ;};_bfb :=_bdc [0:8];_cbdf :=_bdc [8:16];_ged :=make ([]byte ,len (_abb )+len (_bfb ));_dddf :=copy (_ged ,_abb );copy (_ged [_dddf :],_bfb );_ccb ,_fcg :=_fef .alg2b (_egb .R ,_ged ,_abb ,nil );
|
|
if _fcg !=nil {return _fcg ;};U :=make ([]byte ,len (_ccb )+len (_bfb )+len (_cbdf ));_dddf =copy (U ,_ccb [:32]);_dddf +=copy (U [_dddf :],_bfb );copy (U [_dddf :],_cbdf );_egb .U =U ;_dddf =len (_abb );copy (_ged [_dddf :],_cbdf );_ccb ,_fcg =_fef .alg2b (_egb .R ,_ged ,_abb ,nil );
|
|
if _fcg !=nil {return _fcg ;};_ddg ,_fcg :=_cbd (_ccb [:32]);if _fcg !=nil {return _fcg ;};_bag :=make ([]byte ,_ff .BlockSize );_bde :=_c .NewCBCEncrypter (_ddg ,_bag );UE :=make ([]byte ,32);_bde .CryptBlocks (UE ,_bee [:32]);_egb .UE =UE ;return nil ;
|
|
};func (_gd stdHandlerR4 )alg6 (_aa *StdEncryptDict ,_ffd []byte )([]byte ,error ){var (_dfe []byte ;_af error ;);_ac :=_gd .alg2 (_aa ,_ffd );if _aa .R ==2{_dfe ,_af =_gd .alg4 (_ac ,_ffd );}else if _aa .R >=3{_dfe ,_af =_gd .alg5 (_ac ,_ffd );}else {return nil ,_d .New ("\u0069n\u0076\u0061\u006c\u0069\u0064\u0020R");
|
|
};if _af !=nil {return nil ,_af ;};_bfe .Log .Trace ("\u0063\u0068\u0065\u0063k:\u0020\u0025\u0020\u0078\u0020\u003d\u003d\u0020\u0025\u0020\u0078\u0020\u003f",string (_dfe ),string (_aa .U ));_gdf :=_dfe ;_ace :=_aa .U ;if _aa .R >=3{if len (_gdf )> 16{_gdf =_gdf [0:16];
|
|
};if len (_ace )> 16{_ace =_ace [0:16];};};if !_a .Equal (_gdf ,_ace ){return nil ,nil ;};return _ac ,nil ;};type stdHandlerR4 struct{Length int ;ID0 string ;};type stdHandlerR6 struct{};
|
|
|
|
// Allowed checks if a set of permissions can be granted.
|
|
func (_cb Permissions )Allowed (p2 Permissions )bool {return _cb &p2 ==p2 };func _gaf (_bd _c .Block )*ecb {return &ecb {_fg :_bd ,_ea :_bd .BlockSize ()}};func _cbd (_gcf []byte )(_c .Block ,error ){_gcgf ,_ddb :=_ff .NewCipher (_gcf );if _ddb !=nil {_bfe .Log .Error ("\u0045\u0052\u0052\u004f\u0052\u003a\u0020\u0063\u006f\u0075\u006c\u0064\u0020\u006e\u006f\u0074\u0020\u0063\u0072\u0065\u0061\u0074\u0065\u0020A\u0045\u0053\u0020\u0063\u0069p\u0068\u0065r\u003a\u0020\u0025\u0076",_ddb );
|
|
return nil ,_ddb ;};return _gcgf ,nil ;};func (_ad *ecbDecrypter )BlockSize ()int {return _ad ._ea };
|
|
|
|
// NewHandlerR4 creates a new standard security handler for R<=4.
|
|
func NewHandlerR4 (id0 string ,length int )StdHandler {return stdHandlerR4 {ID0 :id0 ,Length :length }};func (_adc stdHandlerR6 )alg9 (_eadf *StdEncryptDict ,_eefg []byte ,_dfb []byte )error {if _bcge :=_ecb ("\u0061\u006c\u0067\u0039","\u004b\u0065\u0079",32,_eefg );
|
|
_bcge !=nil {return _bcge ;};if _bga :=_ecb ("\u0061\u006c\u0067\u0039","\u0055",48,_eadf .U );_bga !=nil {return _bga ;};var _gbc [16]byte ;if _ ,_ffec :=_b .ReadFull (_ga .Reader ,_gbc [:]);_ffec !=nil {return _ffec ;};_afe :=_gbc [0:8];_gbda :=_gbc [8:16];
|
|
_gcab :=_eadf .U [:48];_cdf :=make ([]byte ,len (_dfb )+len (_afe )+len (_gcab ));_fca :=copy (_cdf ,_dfb );_fca +=copy (_cdf [_fca :],_afe );_fca +=copy (_cdf [_fca :],_gcab );_cbe ,_bea :=_adc .alg2b (_eadf .R ,_cdf ,_dfb ,_gcab );if _bea !=nil {return _bea ;
|
|
};O :=make ([]byte ,len (_cbe )+len (_afe )+len (_gbda ));_fca =copy (O ,_cbe [:32]);_fca +=copy (O [_fca :],_afe );_fca +=copy (O [_fca :],_gbda );_eadf .O =O ;_fca =len (_dfb );_fca +=copy (_cdf [_fca :],_gbda );_cbe ,_bea =_adc .alg2b (_eadf .R ,_cdf ,_dfb ,_gcab );
|
|
if _bea !=nil {return _bea ;};_gfb ,_bea :=_cbd (_cbe [:32]);if _bea !=nil {return _bea ;};_dag :=make ([]byte ,_ff .BlockSize );_daac :=_c .NewCBCEncrypter (_gfb ,_dag );OE :=make ([]byte ,32);_daac .CryptBlocks (OE ,_eefg [:32]);_eadf .OE =OE ;return nil ;
|
|
};const _da ="\x28\277\116\136\x4e\x75\x8a\x41\x64\000\x4e\x56\377"+"\xfa\001\010\056\x2e\x00\xb6\xd0\x68\076\x80\x2f\014"+"\251\xfe\x64\x53\x69\172";
|
|
|
|
// StdEncryptDict is a set of additional fields used in standard encryption dictionary.
|
|
type StdEncryptDict struct{R int ;P Permissions ;EncryptMetadata bool ;O ,U []byte ;OE ,UE []byte ;Perms []byte ;};var _ StdHandler =stdHandlerR6 {};var _ StdHandler =stdHandlerR4 {};func _ded (_fa []byte )([]byte ,error ){_abf :=_bb .New ();_abf .Write (_fa );
|
|
return _abf .Sum (nil ),nil };func (_df stdHandlerR4 )alg5 (_cgbc []byte ,_gf []byte )([]byte ,error ){_agd :=_bg .New ();_agd .Write ([]byte (_da ));_agd .Write ([]byte (_df .ID0 ));_gfd :=_agd .Sum (nil );_bfe .Log .Trace ("\u0061\u006c\u0067\u0035");
|
|
_bfe .Log .Trace ("\u0065k\u0065\u0079\u003a\u0020\u0025\u0020x",_cgbc );_bfe .Log .Trace ("\u0049D\u003a\u0020\u0025\u0020\u0078",_df .ID0 );if len (_gfd )!=16{return nil ,_d .New ("\u0068a\u0073\u0068\u0020\u006c\u0065\u006e\u0067\u0074\u0068\u0020\u006eo\u0074\u0020\u0031\u0036\u0020\u0062\u0079\u0074\u0065\u0073");
|
|
};_gg ,_agfc :=_g .NewCipher (_cgbc );if _agfc !=nil {return nil ,_d .New ("\u0066a\u0069l\u0065\u0064\u0020\u0072\u0063\u0034\u0020\u0063\u0069\u0070\u0068");};_bda :=make ([]byte ,16);_gg .XORKeyStream (_bda ,_gfd );_cgg :=make ([]byte ,len (_cgbc ));
|
|
for _eegd :=0;_eegd < 19;_eegd ++{for _gbb :=0;_gbb < len (_cgbc );_gbb ++{_cgg [_gbb ]=_cgbc [_gbb ]^byte (_eegd +1);};_gg ,_agfc =_g .NewCipher (_cgg );if _agfc !=nil {return nil ,_d .New ("\u0066a\u0069l\u0065\u0064\u0020\u0072\u0063\u0034\u0020\u0063\u0069\u0070\u0068");
|
|
};_gg .XORKeyStream (_bda ,_bda );_bfe .Log .Trace ("\u0069\u0020\u003d\u0020\u0025\u0064\u002c\u0020\u0065\u006b\u0065\u0079:\u0020\u0025\u0020\u0078",_eegd ,_cgg );_bfe .Log .Trace ("\u0069\u0020\u003d\u0020\u0025\u0064\u0020\u002d\u003e\u0020\u0025\u0020\u0078",_eegd ,_bda );
|
|
};_bfef :=make ([]byte ,32);for _gef :=0;_gef < 16;_gef ++{_bfef [_gef ]=_bda [_gef ];};_ ,_agfc =_ga .Read (_bfef [16:32]);if _agfc !=nil {return nil ,_d .New ("\u0066a\u0069\u006c\u0065\u0064 \u0074\u006f\u0020\u0067\u0065n\u0020r\u0061n\u0064\u0020\u006e\u0075\u006d\u0062\u0065r");
|
|
};return _bfef ,nil ;};func (_ab stdHandlerR4 )alg3Key (R int ,_cg []byte )[]byte {_efd :=_bg .New ();_cad :=_ab .paddedPass (_cg );_efd .Write (_cad );if R >=3{for _agf :=0;_agf < 50;_agf ++{_bbd :=_efd .Sum (nil );_efd =_bg .New ();_efd .Write (_bbd );
|
|
};};_dde :=_efd .Sum (nil );if R ==2{_dde =_dde [0:5];}else {_dde =_dde [0:_ab .Length /8];};return _dde ;};func (stdHandlerR4 )paddedPass (_eeg []byte )[]byte {_fd :=make ([]byte ,32);_caa :=copy (_fd ,_eeg );for ;_caa < 32;_caa ++{_fd [_caa ]=_da [_caa -len (_eeg )];
|
|
};return _fd ;};
|
|
|
|
// AuthEvent is an event type that triggers authentication.
|
|
type AuthEvent string ;
|
|
|
|
// Authenticate implements StdHandler interface.
|
|
func (_cdfd stdHandlerR6 )Authenticate (d *StdEncryptDict ,pass []byte )([]byte ,Permissions ,error ){return _cdfd .alg2a (d ,pass );};const (EventDocOpen =AuthEvent ("\u0044o\u0063\u004f\u0070\u0065\u006e");EventEFOpen =AuthEvent ("\u0045\u0046\u004f\u0070\u0065\u006e");
|
|
);
|
|
|
|
// Permissions is a bitmask of access permissions for a PDF file.
|
|
type Permissions uint32 ;type ecbEncrypter ecb ;type errInvalidField struct{Func string ;Field string ;Exp int ;Got int ;};func (_dcf stdHandlerR6 )alg2a (_ega *StdEncryptDict ,_eec []byte )([]byte ,Permissions ,error ){if _gfa :=_ecb ("\u0061\u006c\u00672\u0061","\u004f",48,_ega .O );
|
|
_gfa !=nil {return nil ,0,_gfa ;};if _fde :=_ecb ("\u0061\u006c\u00672\u0061","\u0055",48,_ega .U );_fde !=nil {return nil ,0,_fde ;};if len (_eec )> 127{_eec =_eec [:127];};_ggd ,_cd :=_dcf .alg12 (_ega ,_eec );if _cd !=nil {return nil ,0,_cd ;};var (_ae []byte ;
|
|
_ead []byte ;_ce []byte ;);var _fc Permissions ;if len (_ggd )!=0{_fc =PermOwner ;_agc :=make ([]byte ,len (_eec )+8+48);_gcd :=copy (_agc ,_eec );_gcd +=copy (_agc [_gcd :],_ega .O [40:48]);copy (_agc [_gcd :],_ega .U [0:48]);_ae =_agc ;_ead =_ega .OE ;
|
|
_ce =_ega .U [0:48];}else {_ggd ,_cd =_dcf .alg11 (_ega ,_eec );if _cd ==nil &&len (_ggd )==0{_ggd ,_cd =_dcf .alg11 (_ega ,[]byte (""));};if _cd !=nil {return nil ,0,_cd ;}else if len (_ggd )==0{return nil ,0,nil ;};_fc =_ega .P ;_aab :=make ([]byte ,len (_eec )+8);
|
|
_ba :=copy (_aab ,_eec );copy (_aab [_ba :],_ega .U [40:48]);_ae =_aab ;_ead =_ega .UE ;_ce =nil ;};if _agg :=_ecb ("\u0061\u006c\u00672\u0061","\u004b\u0065\u0079",32,_ead );_agg !=nil {return nil ,0,_agg ;};_ead =_ead [:32];_fed ,_cd :=_dcf .alg2b (_ega .R ,_ae ,_eec ,_ce );
|
|
if _cd !=nil {return nil ,0,_cd ;};_afa ,_cd :=_ff .NewCipher (_fed [:32]);if _cd !=nil {return nil ,0,_cd ;};_cde :=make ([]byte ,_ff .BlockSize );_ada :=_c .NewCBCDecrypter (_afa ,_cde );_dbc :=make ([]byte ,32);_ada .CryptBlocks (_dbc ,_ead );if _ega .R ==5{return _dbc ,_fc ,nil ;
|
|
};_cd =_dcf .alg13 (_ega ,_dbc );if _cd !=nil {return nil ,0,_cd ;};return _dbc ,_fc ,nil ;};
|
|
|
|
// NewHandlerR6 creates a new standard security handler for R=5 and R=6.
|
|
func NewHandlerR6 ()StdHandler {return stdHandlerR6 {}};func _ecd (_gbd []byte ,_aabd int ){_bbc :=_aabd ;for _bbc < len (_gbd ){copy (_gbd [_bbc :],_gbd [:_bbc ]);_bbc *=2;};};const (PermOwner =Permissions (_bbb .MaxUint32 );PermPrinting =Permissions (1<<2);
|
|
PermModify =Permissions (1<<3);PermExtractGraphics =Permissions (1<<4);PermAnnotate =Permissions (1<<5);PermFillForms =Permissions (1<<8);PermDisabilityExtract =Permissions (1<<9);PermRotateInsert =Permissions (1<<10);PermFullPrintQuality =Permissions (1<<11);
|
|
);type ecbDecrypter ecb ;type ecb struct{_fg _c .Block ;_ea int ;};func (_ca *ecbDecrypter )CryptBlocks (dst ,src []byte ){if len (src )%_ca ._ea !=0{_bfe .Log .Error ("\u0045\u0052\u0052\u004f\u0052:\u0020\u0045\u0043\u0042\u0020\u0064\u0065\u0063\u0072\u0079\u0070\u0074\u003a \u0069\u006e\u0070\u0075\u0074\u0020\u006e\u006f\u0074\u0020\u0066\u0075\u006c\u006c\u0020\u0062\u006c\u006f\u0063\u006b\u0073");
|
|
return ;};if len (dst )< len (src ){_bfe .Log .Error ("\u0045R\u0052\u004fR\u003a\u0020\u0045C\u0042\u0020\u0064\u0065\u0063\u0072\u0079p\u0074\u003a\u0020\u006f\u0075\u0074p\u0075\u0074\u0020\u0073\u006d\u0061\u006c\u006c\u0065\u0072\u0020t\u0068\u0061\u006e\u0020\u0069\u006e\u0070\u0075\u0074");
|
|
return ;};for len (src )> 0{_ca ._fg .Decrypt (dst ,src [:_ca ._ea ]);src =src [_ca ._ea :];dst =dst [_ca ._ea :];};};func (_eade stdHandlerR6 )alg12 (_aea *StdEncryptDict ,_eacg []byte )([]byte ,error ){if _gae :=_ecb ("\u0061\u006c\u00671\u0032","\u0055",48,_aea .U );
|
|
_gae !=nil {return nil ,_gae ;};if _gea :=_ecb ("\u0061\u006c\u00671\u0032","\u004f",48,_aea .O );_gea !=nil {return nil ,_gea ;};_ege :=make ([]byte ,len (_eacg )+8+48);_bcb :=copy (_ege ,_eacg );_bcb +=copy (_ege [_bcb :],_aea .O [32:40]);_bcb +=copy (_ege [_bcb :],_aea .U [0:48]);
|
|
_ebfg ,_gcdf :=_eade .alg2b (_aea .R ,_ege ,_eacg ,_aea .U [0:48]);if _gcdf !=nil {return nil ,_gcdf ;};_ebfg =_ebfg [:32];if !_a .Equal (_ebfg ,_aea .O [:32]){return nil ,nil ;};return _ebfg ,nil ;};func _ecb (_bcf ,_dcg string ,_ed int ,_ee []byte )error {if len (_ee )< _ed {return errInvalidField {Func :_bcf ,Field :_dcg ,Exp :_ed ,Got :len (_ee )};
|
|
};return nil ;};func _bff (_ffa _c .Block )_c .BlockMode {return (*ecbEncrypter )(_gaf (_ffa ))};func (_feb stdHandlerR6 )alg2b (R int ,_gecb ,_gcga ,_aeb []byte )([]byte ,error ){if R ==5{return _ded (_gecb );};return _gde (_gecb ,_gcga ,_aeb );};func (_dd *ecbEncrypter )BlockSize ()int {return _dd ._ea };
|
|
func (_eb stdHandlerR4 )alg4 (_bgf []byte ,_cgb []byte )([]byte ,error ){_eee ,_bbbb :=_g .NewCipher (_bgf );if _bbbb !=nil {return nil ,_d .New ("\u0066a\u0069l\u0065\u0064\u0020\u0072\u0063\u0034\u0020\u0063\u0069\u0070\u0068");};_fff :=[]byte (_da );
|
|
_dcbf :=make ([]byte ,len (_fff ));_eee .XORKeyStream (_dcbf ,_fff );return _dcbf ,nil ;};func (_efc stdHandlerR4 )alg7 (_be *StdEncryptDict ,_dgcf []byte )([]byte ,error ){_cag :=_efc .alg3Key (_be .R ,_dgcf );_fbe :=make ([]byte ,len (_be .O ));if _be .R ==2{_cbc ,_eca :=_g .NewCipher (_cag );
|
|
if _eca !=nil {return nil ,_d .New ("\u0066\u0061\u0069\u006c\u0065\u0064\u0020\u0063\u0069\u0070\u0068\u0065\u0072");};_cbc .XORKeyStream (_fbe ,_be .O );}else if _be .R >=3{_fdad :=append ([]byte {},_be .O ...);for _geff :=0;_geff < 20;_geff ++{_cba :=append ([]byte {},_cag ...);
|
|
for _dgb :=0;_dgb < len (_cag );_dgb ++{_cba [_dgb ]^=byte (19-_geff );};_eef ,_abc :=_g .NewCipher (_cba );if _abc !=nil {return nil ,_d .New ("\u0066\u0061\u0069\u006c\u0065\u0064\u0020\u0063\u0069\u0070\u0068\u0065\u0072");};_eef .XORKeyStream (_fbe ,_fdad );
|
|
_fdad =append ([]byte {},_fbe ...);};}else {return nil ,_d .New ("\u0069n\u0076\u0061\u006c\u0069\u0064\u0020R");};_bcg ,_eac :=_efc .alg6 (_be ,_fbe );if _eac !=nil {return nil ,nil ;};return _bcg ,nil ;};
|
|
|
|
// GenerateParams is the algorithm opposite to alg2a (R>=5).
|
|
// It generates U,O,UE,OE,Perms fields using AESv3 encryption.
|
|
// There is no algorithm number assigned to this function in the spec.
|
|
// It expects R, P and EncryptMetadata fields to be set.
|
|
func (_fdgg stdHandlerR6 )GenerateParams (d *StdEncryptDict ,opass ,upass []byte )([]byte ,error ){_bbaf :=make ([]byte ,32);if _ ,_aeg :=_b .ReadFull (_ga .Reader ,_bbaf );_aeg !=nil {return nil ,_aeg ;};d .U =nil ;d .O =nil ;d .UE =nil ;d .OE =nil ;d .Perms =nil ;
|
|
if len (upass )> 127{upass =upass [:127];};if len (opass )> 127{opass =opass [:127];};if _bgd :=_fdgg .alg8 (d ,_bbaf ,upass );_bgd !=nil {return nil ,_bgd ;};if _fea :=_fdgg .alg9 (d ,_bbaf ,opass );_fea !=nil {return nil ,_fea ;};if d .R ==5{return _bbaf ,nil ;
|
|
};if _fdef :=_fdgg .alg10 (d ,_bbaf );_fdef !=nil {return nil ,_fdef ;};return _bbaf ,nil ;};func (_geb stdHandlerR4 )alg3 (R int ,_fb ,_cf []byte )([]byte ,error ){var _cca []byte ;if len (_cf )> 0{_cca =_geb .alg3Key (R ,_cf );}else {_cca =_geb .alg3Key (R ,_fb );
|
|
};_def ,_dgce :=_g .NewCipher (_cca );if _dgce !=nil {return nil ,_d .New ("\u0066a\u0069l\u0065\u0064\u0020\u0072\u0063\u0034\u0020\u0063\u0069\u0070\u0068");};_cbb :=_geb .paddedPass (_fb );_dgd :=make ([]byte ,len (_cbb ));_def .XORKeyStream (_dgd ,_cbb );
|
|
if R >=3{_gad :=make ([]byte ,len (_cca ));for _eg :=0;_eg < 19;_eg ++{for _bffe :=0;_bffe < len (_cca );_bffe ++{_gad [_bffe ]=_cca [_bffe ]^byte (_eg +1);};_aba ,_gcg :=_g .NewCipher (_gad );if _gcg !=nil {return nil ,_d .New ("\u0066a\u0069l\u0065\u0064\u0020\u0072\u0063\u0034\u0020\u0063\u0069\u0070\u0068");
|
|
};_aba .XORKeyStream (_dgd ,_dgd );};};return _dgd ,nil ;};func _bc (_gc _c .Block )_c .BlockMode {return (*ecbDecrypter )(_gaf (_gc ))};func (_efb stdHandlerR4 )alg2 (_fe *StdEncryptDict ,_ag []byte )[]byte {_bfe .Log .Trace ("\u0061\u006c\u0067\u0032");
|
|
_cc :=_efb .paddedPass (_ag );_gac :=_bg .New ();_gac .Write (_cc );_gac .Write (_fe .O );var _fda [4]byte ;_bf .LittleEndian .PutUint32 (_fda [:],uint32 (_fe .P ));_gac .Write (_fda [:]);_bfe .Log .Trace ("\u0067o\u0020\u0050\u003a\u0020\u0025\u0020x",_fda );
|
|
_gac .Write ([]byte (_efb .ID0 ));_bfe .Log .Trace ("\u0074\u0068\u0069\u0073\u002e\u0052\u0020\u003d\u0020\u0025d\u0020\u0065\u006e\u0063\u0072\u0079\u0070t\u004d\u0065\u0074\u0061\u0064\u0061\u0074\u0061\u0020\u0025\u0076",_fe .R ,_fe .EncryptMetadata );
|
|
if (_fe .R >=4)&&!_fe .EncryptMetadata {_gac .Write ([]byte {0xff,0xff,0xff,0xff});};_gb :=_gac .Sum (nil );if _fe .R >=3{_gac =_bg .New ();for _ffe :=0;_ffe < 50;_ffe ++{_gac .Reset ();_gac .Write (_gb [0:_efb .Length /8]);_gb =_gac .Sum (nil );};};if _fe .R >=3{return _gb [0:_efb .Length /8];
|
|
};return _gb [0:5];};func _gde (_gdff ,_ebf ,_bgff []byte )([]byte ,error ){var (_edb ,_gff ,_acd _e .Hash ;);_edb =_bb .New ();_dbd :=make ([]byte ,64);_dfc :=_edb ;_dfc .Write (_gdff );K :=_dfc .Sum (_dbd [:0]);_ffde :=make ([]byte ,64*(127+64+48));_eeb :=func (_dad int )([]byte ,error ){_gec :=len (_ebf )+len (K )+len (_bgff );
|
|
_aad :=_ffde [:_gec ];_agcf :=copy (_aad ,_ebf );_agcf +=copy (_aad [_agcf :],K [:]);_agcf +=copy (_aad [_agcf :],_bgff );if _agcf !=_gec {_bfe .Log .Error ("E\u0052\u0052\u004f\u0052\u003a\u0020u\u006e\u0065\u0078\u0070\u0065\u0063t\u0065\u0064\u0020\u0072\u006f\u0075\u006ed\u0020\u0069\u006e\u0070\u0075\u0074\u0020\u0073\u0069\u007ae\u002e");
|
|
return nil ,_d .New ("\u0077\u0072\u006f\u006e\u0067\u0020\u0073\u0069\u007a\u0065");};K1 :=_ffde [:_gec *64];_ecd (K1 ,_gec );_ffef ,_ddf :=_cbd (K [0:16]);if _ddf !=nil {return nil ,_ddf ;};_cae :=_c .NewCBCEncrypter (_ffef ,K [16:32]);_cae .CryptBlocks (K1 ,K1 );
|
|
E :=K1 ;_bbf :=0;for _cef :=0;_cef < 16;_cef ++{_bbf +=int (E [_cef ]%3);};var _feg _e .Hash ;switch _bbf %3{case 0:_feg =_edb ;case 1:if _gff ==nil {_gff =_ef .New384 ();};_feg =_gff ;case 2:if _acd ==nil {_acd =_ef .New ();};_feg =_acd ;};_feg .Reset ();
|
|
_feg .Write (E );K =_feg .Sum (_dbd [:0]);return E ,nil ;};for _cab :=0;;{E ,_cff :=_eeb (_cab );if _cff !=nil {return nil ,_cff ;};_gdg :=E [len (E )-1];_cab ++;if _cab >=64&&_gdg <=uint8 (_cab -32){break ;};};return K [:32],nil ;};func (_cbcg stdHandlerR6 )alg13 (_ffbg *StdEncryptDict ,_afc []byte )error {if _cdc :=_ecb ("\u0061\u006c\u00671\u0033","\u004b\u0065\u0079",32,_afc );
|
|
_cdc !=nil {return _cdc ;};if _cggc :=_ecb ("\u0061\u006c\u00671\u0033","\u0050\u0065\u0072m\u0073",16,_ffbg .Perms );_cggc !=nil {return _cggc ;};_dcd :=make ([]byte ,16);copy (_dcd ,_ffbg .Perms [:16]);_cdb ,_dec :=_ff .NewCipher (_afc [:32]);if _dec !=nil {return _dec ;
|
|
};_dce :=_bc (_cdb );_dce .CryptBlocks (_dcd ,_dcd );if !_a .Equal (_dcd [9:12],[]byte ("\u0061\u0064\u0062")){return _d .New ("\u0064\u0065\u0063o\u0064\u0065\u0064\u0020p\u0065\u0072\u006d\u0069\u0073\u0073\u0069o\u006e\u0073\u0020\u0061\u0072\u0065\u0020\u0069\u006e\u0076\u0061\u006c\u0069\u0064");
|
|
};_ccd :=Permissions (_bf .LittleEndian .Uint32 (_dcd [0:4]));if _ccd !=_ffbg .P {return _d .New ("\u0070\u0065r\u006d\u0069\u0073\u0073\u0069\u006f\u006e\u0073\u0020\u0076\u0061\u006c\u0069\u0064\u0061\u0074\u0069\u006f\u006e\u0020\u0066\u0061il\u0065\u0064");
|
|
};var _ddee bool ;if _dcd [8]=='T'{_ddee =true ;}else if _dcd [8]=='F'{_ddee =false ;}else {return _d .New ("\u0064\u0065\u0063\u006f\u0064\u0065\u0064 \u006d\u0065\u0074a\u0064\u0061\u0074\u0061 \u0065\u006e\u0063\u0072\u0079\u0070\u0074\u0069\u006f\u006e\u0020\u0066\u006c\u0061\u0067\u0020\u0069\u0073\u0020\u0069\u006e\u0076\u0061\u006c\u0069\u0064");
|
|
};if _ddee !=_ffbg .EncryptMetadata {return _d .New ("\u006d\u0065t\u0061\u0064\u0061\u0074a\u0020\u0065n\u0063\u0072\u0079\u0070\u0074\u0069\u006f\u006e \u0076\u0061\u006c\u0069\u0064\u0061\u0074\u0069\u006f\u006e\u0020\u0066a\u0069\u006c\u0065\u0064");
|
|
};return nil ;};func (_fbb stdHandlerR6 )alg11 (_fcf *StdEncryptDict ,_add []byte )([]byte ,error ){if _ccc :=_ecb ("\u0061\u006c\u00671\u0031","\u0055",48,_fcf .U );_ccc !=nil {return nil ,_ccc ;};_dgbb :=make ([]byte ,len (_add )+8);_gafb :=copy (_dgbb ,_add );
|
|
_gafb +=copy (_dgbb [_gafb :],_fcf .U [32:40]);_gdd ,_bcdc :=_fbb .alg2b (_fcf .R ,_dgbb ,_add ,nil );if _bcdc !=nil {return nil ,_bcdc ;};_gdd =_gdd [:32];if !_a .Equal (_gdd ,_fcf .U [:32]){return nil ,nil ;};return _gdd ,nil ;};func (_ec *ecbEncrypter )CryptBlocks (dst ,src []byte ){if len (src )%_ec ._ea !=0{_bfe .Log .Error ("\u0045\u0052\u0052\u004f\u0052:\u0020\u0045\u0043\u0042\u0020\u0065\u006e\u0063\u0072\u0079\u0070\u0074\u003a \u0069\u006e\u0070\u0075\u0074\u0020\u006e\u006f\u0074\u0020\u0066\u0075\u006c\u006c\u0020\u0062\u006c\u006f\u0063\u006b\u0073");
|
|
return ;};if len (dst )< len (src ){_bfe .Log .Error ("\u0045R\u0052\u004fR\u003a\u0020\u0045C\u0042\u0020\u0065\u006e\u0063\u0072\u0079p\u0074\u003a\u0020\u006f\u0075\u0074p\u0075\u0074\u0020\u0073\u006d\u0061\u006c\u006c\u0065\u0072\u0020t\u0068\u0061\u006e\u0020\u0069\u006e\u0070\u0075\u0074");
|
|
return ;};for len (src )> 0{_ec ._fg .Encrypt (dst ,src [:_ec ._ea ]);src =src [_ec ._ea :];dst =dst [_ec ._ea :];};};func (_daaf stdHandlerR6 )alg10 (_abfb *StdEncryptDict ,_gbbd []byte )error {if _bfg :=_ecb ("\u0061\u006c\u00671\u0030","\u004b\u0065\u0079",32,_gbbd );
|
|
_bfg !=nil {return _bfg ;};_adb :=uint64 (uint32 (_abfb .P ))|(_bbb .MaxUint32 <<32);Perms :=make ([]byte ,16);_bf .LittleEndian .PutUint64 (Perms [:8],_adb );if _abfb .EncryptMetadata {Perms [8]='T';}else {Perms [8]='F';};copy (Perms [9:12],"\u0061\u0064\u0062");
|
|
if _ ,_bcd :=_b .ReadFull (_ga .Reader ,Perms [12:16]);_bcd !=nil {return _bcd ;};_ebb ,_fgf :=_cbd (_gbbd [:32]);if _fgf !=nil {return _fgf ;};_gffb :=_bff (_ebb );_gffb .CryptBlocks (Perms ,Perms );_abfb .Perms =Perms [:16];return nil ;};
|
|
|
|
// Authenticate implements StdHandler interface.
|
|
func (_dcgc stdHandlerR4 )Authenticate (d *StdEncryptDict ,pass []byte )([]byte ,Permissions ,error ){_bfe .Log .Trace ("\u0044\u0065b\u0075\u0067\u0067\u0069n\u0067\u0020a\u0075\u0074\u0068\u0065\u006e\u0074\u0069\u0063a\u0074\u0069\u006f\u006e\u0020\u002d\u0020\u006f\u0077\u006e\u0065\u0072 \u0070\u0061\u0073\u0073");
|
|
_fgbe ,_gee :=_dcgc .alg7 (d ,pass );if _gee !=nil {return nil ,0,_gee ;};if _fgbe !=nil {_bfe .Log .Trace ("\u0074h\u0069\u0073\u002e\u0061u\u0074\u0068\u0065\u006e\u0074i\u0063a\u0074e\u0064\u0020\u003d\u0020\u0054\u0072\u0075e");return _fgbe ,PermOwner ,nil ;
|
|
};_bfe .Log .Trace ("\u0044\u0065bu\u0067\u0067\u0069n\u0067\u0020\u0061\u0075the\u006eti\u0063\u0061\u0074\u0069\u006f\u006e\u0020- \u0075\u0073\u0065\u0072\u0020\u0070\u0061s\u0073");_fgbe ,_gee =_dcgc .alg6 (d ,pass );if _gee !=nil {return nil ,0,_gee ;
|
|
};if _fgbe !=nil {_bfe .Log .Trace ("\u0074h\u0069\u0073\u002e\u0061u\u0074\u0068\u0065\u006e\u0074i\u0063a\u0074e\u0064\u0020\u003d\u0020\u0054\u0072\u0075e");return _fgbe ,d .P ,nil ;};return nil ,0,nil ;};func (_dcb errInvalidField )Error ()string {return _db .Sprintf ("\u0025s\u003a\u0020e\u0078\u0070\u0065\u0063t\u0065\u0064\u0020%\u0073\u0020\u0066\u0069\u0065\u006c\u0064\u0020\u0074o \u0062\u0065\u0020%\u0064\u0020b\u0079\u0074\u0065\u0073\u002c\u0020g\u006f\u0074 \u0025\u0064",_dcb .Func ,_dcb .Field ,_dcb .Exp ,_dcb .Got );
|
|
}; |