unipdf/common/license/license.go
2020-10-19 10:58:10 +00:00

16 lines
15 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 license helps manage commercial licenses and check if they are valid for the version of unidoc used.
package license ;import (_g "crypto";_ea "crypto/rand";_gf "crypto/rsa";_ag "crypto/sha512";_a "crypto/x509";_d "encoding/base64";_ec "encoding/json";_fb "encoding/pem";_c "fmt";_fd "github.com/unidoc/unipdf/v3/common";_ef "io/ioutil";_f "os";_bg "strings";_b "time";);const _ff ="\u000a\u002d\u002d\u002d\u002d\u002d\u0042\u0045\u0047\u0049\u004e \u0050\u0055\u0042\u004c\u0049\u0043\u0020\u004b\u0045Y\u002d\u002d\u002d\u002d\u002d\u000a\u004d\u0049I\u0042\u0049\u006a\u0041NB\u0067\u006b\u0071\u0068\u006b\u0069G\u0039\u0077\u0030\u0042\u0041\u0051\u0045\u0046A\u0041\u004f\u0043\u0041\u0051\u0038\u0041\u004d\u0049\u0049\u0042\u0043\u0067\u004b\u0043\u0041\u0051\u0045A\u006dF\u0055\u0069\u0079\u0064\u0037\u0062\u0035\u0058\u006a\u0070\u006b\u0050\u0035\u0052\u0061\u0070\u0034\u0077\u000a\u0044\u0063\u0031d\u0079\u007a\u0049\u0051\u0034\u004c\u0065\u006b\u0078\u0072\u0076\u0079\u0074\u006e\u0045\u004d\u0070\u004e\u0055\u0062\u006f\u0036i\u0041\u0037\u0034\u0056\u0038\u0072\u0075\u005a\u004f\u0076\u0072\u0053\u0063\u0073\u0066\u0032\u0051\u0065\u004e9\u002f\u0071r\u0055\u0047\u0038\u0071\u0045\u0062\u0055\u0057\u0064\u006f\u0045\u0059\u0071+\u000a\u006f\u0074\u0046\u004e\u0041\u0046N\u0078\u006c\u0047\u0062\u0078\u0062\u0044\u0048\u0063\u0064\u0047\u0056\u0061\u004d\u0030\u004f\u0058\u0064\u0058g\u0044y\u004c5\u0061\u0049\u0045\u0061\u0067\u004c\u0030\u0063\u0035\u0070\u0077\u006a\u0049\u0064\u0050G\u0049\u006e\u0034\u0036\u0066\u0037\u0038\u0065\u004d\u004a\u002b\u004a\u006b\u0064\u0063\u0070\u0044\n\u0044\u004a\u0061\u0071\u0059\u0058d\u0072\u007a5\u004b\u0065\u0073\u0068\u006aS\u0069\u0049\u0061\u0061\u0037\u006d\u0065\u006e\u0042\u0049\u0041\u0058\u0053\u0034\u0055\u0046\u0078N\u0066H\u0068\u004e\u0030\u0048\u0043\u0059\u005a\u0059\u0071\u0051\u0047\u0037\u0062K+\u0073\u0035\u0072R\u0048\u006f\u006e\u0079\u0064\u004eW\u0045\u0047\u000a\u0048\u0038M\u0079\u0076\u00722\u0070\u0079\u0061\u0032K\u0072\u004d\u0075m\u0066\u006d\u0041\u0078\u0055\u0042\u0036\u0066\u0065\u006e\u0043\u002f4\u004f\u0030\u0057\u00728\u0067\u0066\u0050\u004f\u0055\u0038R\u0069\u0074\u006d\u0062\u0044\u0076\u0051\u0050\u0049\u0052\u0058\u004fL\u0034\u0076\u0054B\u0072\u0042\u0064\u0062a\u0041\u000a9\u006e\u0077\u004e\u0050\u002b\u0069\u002f\u002f\u0032\u0030\u004d\u00542\u0062\u0078\u006d\u0065\u0057\u0042\u002b\u0067\u0070\u0063\u0045\u0068G\u0070\u0058\u005a7\u0033\u0033\u0061\u007a\u0051\u0078\u0072\u0043\u0033\u004a\u0034\u0076\u0033C\u005a\u006d\u0045\u004eS\u0074\u0044\u004b\u002f\u004b\u0044\u0053\u0050\u004b\u0055\u0047\u0066\u00756\u000a\u0066\u0077I\u0044\u0041\u0051\u0041\u0042\u000a\u002d\u002d\u002d\u002d\u002dE\u004e\u0044\u0020\u0050\u0055\u0042\u004c\u0049\u0043 \u004b\u0045Y\u002d\u002d\u002d\u002d\u002d\n";func (_bbf *LicenseKey )ToString ()string {_db :=_c .Sprintf ("\u004ci\u0063e\u006e\u0073\u0065\u0020\u0049\u0064\u003a\u0020\u0025\u0073\u000a",_bbf .LicenseId );_db +=_c .Sprintf ("\u0043\u0075s\u0074\u006f\u006de\u0072\u0020\u0049\u0064\u003a\u0020\u0025\u0073\u000a",_bbf .CustomerId );_db +=_c .Sprintf ("\u0043u\u0073t\u006f\u006d\u0065\u0072\u0020N\u0061\u006de\u003a\u0020\u0025\u0073\u000a",_bbf .CustomerName );_db +=_c .Sprintf ("\u0054i\u0065\u0072\u003a\u0020\u0025\u0073\n",_bbf .Tier );_db +=_c .Sprintf ("\u0043r\u0065a\u0074\u0065\u0064\u0020\u0041\u0074\u003a\u0020\u0025\u0073\u000a",_fd .UtcTimeFormat (_bbf .CreatedAt ));if _bbf .ExpiresAt ==nil {_db +=_c .Sprintf ("\u0045x\u0070i\u0072\u0065\u0073\u0020\u0041t\u003a\u0020N\u0065\u0076\u0065\u0072\u000a");}else {_db +=_c .Sprintf ("\u0045x\u0070i\u0072\u0065\u0073\u0020\u0041\u0074\u003a\u0020\u0025\u0073\u000a",_fd .UtcTimeFormat (*_bbf .ExpiresAt ));};_db +=_c .Sprintf ("\u0043\u0072\u0065\u0061\u0074\u006f\u0072\u003a\u0020\u0025\u0073\u0020<\u0025\u0073\u003e\u000a",_bbf .CreatorName ,_bbf .CreatorEmail );return _db ;};func (_cg *LicenseKey )getExpiryDateToCompare ()_b .Time {if _cg .Trial {return _b .Now ().UTC ();};return _fd .ReleasedAt ;};var _egd =MakeUnlicensedKey ();func (_dd *LicenseKey )Validate ()error {if len (_dd .LicenseId )< 10{return _c .Errorf ("i\u006e\u0076\u0061\u006c\u0069\u0064 \u006c\u0069\u0063\u0065\u006e\u0073\u0065\u003a\u0020L\u0069\u0063\u0065n\u0073e\u0020\u0049\u0064");};if len (_dd .CustomerId )< 10{return _c .Errorf ("\u0069\u006e\u0076\u0061l\u0069\u0064\u0020\u006c\u0069\u0063\u0065\u006e\u0073\u0065:\u0020C\u0075\u0073\u0074\u006f\u006d\u0065\u0072 \u0049\u0064");};if len (_dd .CustomerName )< 1{return _c .Errorf ("\u0069\u006e\u0076\u0061\u006c\u0069\u0064\u0020\u006c\u0069c\u0065\u006e\u0073\u0065\u003a\u0020\u0043u\u0073\u0074\u006f\u006d\u0065\u0072\u0020\u004e\u0061\u006d\u0065");};if _bbg .After (_dd .CreatedAt ){return _c .Errorf ("\u0069\u006e\u0076\u0061\u006c\u0069\u0064\u0020\u006c\u0069\u0063\u0065\u006e\u0073\u0065\u003a\u0020\u0043\u0072\u0065\u0061\u0074\u0065\u0064 \u0041\u0074\u0020\u0069\u0073 \u0069\u006ev\u0061\u006c\u0069\u0064");};if _dd .ExpiresAt ==nil {_ddg :=_dd .CreatedAt .AddDate (1,0,0);if _ac .After (_ddg ){_ddg =_ac ;};_dd .ExpiresAt =&_ddg ;};if _dd .CreatedAt .After (*_dd .ExpiresAt ){return _c .Errorf ("i\u006e\u0076\u0061\u006c\u0069\u0064\u0020\u006c\u0069\u0063\u0065\u006e\u0073\u0065\u003a\u0020\u0043\u0072\u0065\u0061\u0074\u0065\u0064\u0020\u0041\u0074 \u0063a\u006e\u006e\u006f\u0074 \u0062\u0065 \u0047\u0072\u0065\u0061\u0074\u0065\u0072\u0020\u0074\u0068\u0061\u006e\u0020\u0045\u0078\u0070\u0069\u0072\u0065\u0073\u0020\u0041\u0074");};if _dd .isExpired (){return _c .Errorf ("\u0069\u006e\u0076\u0061\u006c\u0069\u0064\u0020l\u0069\u0063\u0065ns\u0065\u003a\u0020\u0054\u0068\u0065 \u006c\u0069\u0063\u0065\u006e\u0073\u0065\u0020\u0068\u0061\u0073\u0020\u0061\u006c\u0072e\u0061\u0064\u0079\u0020\u0065\u0078\u0070\u0069r\u0065\u0064");};if len (_dd .CreatorName )< 1{return _c .Errorf ("\u0069\u006ev\u0061\u006c\u0069\u0064\u0020\u006c\u0069\u0063\u0065\u006e\u0073\u0065\u003a\u0020\u0043\u0072\u0065\u0061\u0074\u006f\u0072\u0020na\u006d\u0065");};if len (_dd .CreatorEmail )< 1{return _c .Errorf ("\u0069\u006e\u0076\u0061\u006c\u0069\u0064\u0020\u006c\u0069c\u0065\u006e\u0073\u0065\u003a\u0020\u0043r\u0065\u0061\u0074\u006f\u0072\u0020\u0065\u006d\u0061\u0069\u006c");};if _dd .CreatedAt .After (_fag ){if !_dd .UniPDF {return _c .Errorf ("\u0069\u006e\u0076\u0061\u006c\u0069\u0064 \u006c\u0069\u0063e\u006e\u0073\u0065:\u0020\u0054h\u0069\u0073\u0020\u0055\u006e\u0069D\u006fc \u006b\u0065\u0079\u0020\u0069\u0073\u0020\u0069\u006e\u0076\u0061\u006c\u0069\u0064\u0020\u0066\u006f\u0072\u0020\u0055\u006e\u0069\u0050\u0044\u0046\u002e");};};return nil ;};type LicenseKey struct{LicenseId string `json:"license_id"`;CustomerId string `json:"customer_id"`;CustomerName string `json:"customer_name"`;Tier string `json:"tier"`;CreatedAt _b .Time `json:"-"`;CreatedAtInt int64 `json:"created_at"`;ExpiresAt *_b .Time `json:"-"`;ExpiresAtInt int64 `json:"expires_at"`;CreatedBy string `json:"created_by"`;CreatorName string `json:"creator_name"`;CreatorEmail string `json:"creator_email"`;UniPDF bool `json:"unipdf"`;UniOffice bool `json:"unioffice"`;Trial bool `json:"trial"`;};var _bbg =_b .Date (2010,1,1,0,0,0,0,_b .UTC );func GetLicenseKey ()*LicenseKey {if _egd ==nil {return nil ;};_gfe :=*_egd ;return &_gfe ;};func (_agf *LicenseKey )TypeToString ()string {if _agf .Tier ==LicenseTierUnlicensed {return "\u0055\u006e\u006c\u0069\u0063\u0065\u006e\u0073\u0065\u0064";};if _agf .Tier ==LicenseTierCommunity {return "\u0041\u0047PL\u0076\u0033\u0020O\u0070\u0065\u006e\u0020Sou\u0072ce\u0020\u0043\u006f\u006d\u006d\u0075\u006eit\u0079\u0020\u004c\u0069\u0063\u0065\u006es\u0065";};if _agf .Tier ==LicenseTierIndividual ||_agf .Tier =="\u0069\u006e\u0064i\u0065"{return "\u0043\u006f\u006dm\u0065\u0072\u0063\u0069a\u006c\u0020\u004c\u0069\u0063\u0065\u006es\u0065\u0020\u002d\u0020\u0049\u006e\u0064\u0069\u0076\u0069\u0064\u0075\u0061\u006c";};return "\u0043\u006fm\u006d\u0065\u0072\u0063\u0069\u0061\u006c\u0020\u004c\u0069\u0063\u0065\u006e\u0073\u0065\u0020\u002d\u0020\u0042\u0075\u0073\u0069ne\u0073\u0073";};func _ce (_bb string ,_be string )([]byte ,error ){_eaf :="\u000a\u002b\u000a";_ba :="\u000d\u000a\u002b\r\u000a";_dc :=_bg .Index (_be ,_eaf );if _dc ==-1{_dc =_bg .Index (_be ,_ba );if _dc ==-1{return nil ,_c .Errorf ("\u0069\u006e\u0076al\u0069\u0064\u0020\u0069\u006e\u0070\u0075\u0074\u002c \u0073i\u0067n\u0061t\u0075\u0072\u0065\u0020\u0073\u0065\u0070\u0061\u0072\u0061\u0074\u006f\u0072");};};_gc :=_be [:_dc ];_efed :=_dc +len (_eaf );_agc :=_be [_efed :];if _gc ==""||_agc ==""{return nil ,_c .Errorf ("\u0069n\u0076\u0061l\u0069\u0064\u0020\u0069n\u0070\u0075\u0074,\u0020\u006d\u0069\u0073\u0073\u0069\u006e\u0067\u0020or\u0069\u0067\u0069n\u0061\u006c \u006f\u0072\u0020\u0073\u0069\u0067n\u0061\u0074u\u0072\u0065");};_cbd ,_ee :=_d .StdEncoding .DecodeString (_gc );if _ee !=nil {return nil ,_c .Errorf ("\u0069\u006e\u0076\u0061li\u0064\u0020\u0069\u006e\u0070\u0075\u0074\u0020\u006f\u0072\u0069\u0067\u0069\u006ea\u006c");};_bf ,_ee :=_d .StdEncoding .DecodeString (_agc );if _ee !=nil {return nil ,_c .Errorf ("\u0069\u006e\u0076al\u0069\u0064\u0020\u0069\u006e\u0070\u0075\u0074\u0020\u0073\u0069\u0067\u006e\u0061\u0074\u0075\u0072\u0065");};_bee ,_ :=_fb .Decode ([]byte (_bb ));if _bee ==nil {return nil ,_c .Errorf ("\u0050\u0075\u0062\u004b\u0065\u0079\u0020\u0066\u0061\u0069\u006c\u0065\u0064");};_ed ,_ee :=_a .ParsePKIXPublicKey (_bee .Bytes );if _ee !=nil {return nil ,_ee ;};_eb :=_ed .(*_gf .PublicKey );if _eb ==nil {return nil ,_c .Errorf ("\u0050u\u0062\u004b\u0065\u0079\u0020\u0063\u006f\u006e\u0076\u0065\u0072s\u0069\u006f\u006e\u0020\u0066\u0061\u0069\u006c\u0065\u0064");};_cdf :=_ag .New ();_cdf .Write (_cbd );_cdfc :=_cdf .Sum (nil );_ee =_gf .VerifyPKCS1v15 (_eb ,_g .SHA512 ,_cdfc ,_bf );if _ee !=nil {return nil ,_ee ;};return _cbd ,nil ;};const (_cd ="\u002d\u002d\u002d--\u0042\u0045\u0047\u0049\u004e\u0020\u0055\u004e\u0049D\u004fC\u0020L\u0049C\u0045\u004e\u0053\u0045\u0020\u004b\u0045\u0059\u002d\u002d\u002d\u002d\u002d";_cb ="\u002d\u002d\u002d\u002d\u002d\u0045\u004e\u0044\u0020\u0055\u004e\u0049\u0044\u004f\u0043 \u004cI\u0043\u0045\u004e\u0053\u0045\u0020\u004b\u0045\u0059\u002d\u002d\u002d\u002d\u002d";);func MakeUnlicensedKey ()*LicenseKey {_cec :=LicenseKey {};_cec .CustomerName ="\u0055\u006e\u006c\u0069\u0063\u0065\u006e\u0073\u0065\u0064";_cec .Tier =LicenseTierUnlicensed ;_cec .CreatedAt =_b .Now ().UTC ();_cec .CreatedAtInt =_cec .CreatedAt .Unix ();return &_cec ;};const _eefb ="U\u004eI\u0050\u0044\u0046\u005f\u0043\u0055\u0053\u0054O\u004d\u0045\u0052\u005fNA\u004d\u0045";const (LicenseTierUnlicensed ="\u0075\u006e\u006c\u0069\u0063\u0065\u006e\u0073\u0065\u0064";LicenseTierCommunity ="\u0063o\u006d\u006d\u0075\u006e\u0069\u0074y";LicenseTierIndividual ="\u0069\u006e\u0064\u0069\u0076\u0069\u0064\u0075\u0061\u006c";LicenseTierBusiness ="\u0062\u0075\u0073\u0069\u006e\u0065\u0073\u0073";);var _fag =_b .Date (2019,6,6,0,0,0,0,_b .UTC );func _ca (_eef string )(LicenseKey ,error ){var _aee LicenseKey ;_cf ,_ad :=_de (_cd ,_cb ,_eef );if _ad !=nil {return _aee ,_ad ;};_aadc ,_ad :=_ce (_ff ,_cf );if _ad !=nil {return _aee ,_ad ;};_ad =_ec .Unmarshal (_aadc ,&_aee );if _ad !=nil {return _aee ,_ad ;};_aee .CreatedAt =_b .Unix (_aee .CreatedAtInt ,0);if _aee .ExpiresAtInt > 0{_dea :=_b .Unix (_aee .ExpiresAtInt ,0);_aee .ExpiresAt =&_dea ;};return _aee ,nil ;};func (_da *LicenseKey )IsLicensed ()bool {return _da .Tier !=LicenseTierUnlicensed };func (_gg *LicenseKey )isExpired ()bool {return _gg .getExpiryDateToCompare ().After (*_gg .ExpiresAt )};func _de (_ced string ,_bfd string ,_bd string )(string ,error ){_geg :=_bg .Index (_bd ,_ced );if _geg ==-1{return "",_c .Errorf ("\u0068\u0065a\u0064\u0065\u0072 \u006e\u006f\u0074\u0020\u0066\u006f\u0075\u006e\u0064");};_fe :=_bg .Index (_bd ,_bfd );if _fe ==-1{return "",_c .Errorf ("\u0066\u006fo\u0074\u0065\u0072 \u006e\u006f\u0074\u0020\u0066\u006f\u0075\u006e\u0064");};_edf :=_geg +len (_ced )+1;return _bd [_edf :_fe -1],nil ;};
// SetLicenseKey sets and validates the license key.
func SetLicenseKey (content string ,customerName string )error {_dg ,_dgg :=_ca (content );if _dgg !=nil {_fd .Log .Error ("\u004c\u0069c\u0065\u006e\u0073\u0065\u0020\u0063\u006f\u0064\u0065\u0020\u0064\u0065\u0063\u006f\u0064\u0065\u0020\u0065\u0072\u0072\u006f\u0072: \u0025\u0076",_dgg );return _dgg ;};if _bg .ToLower (_dg .CustomerName )!=_bg .ToLower (customerName ){_fd .Log .Error ("L\u0069ce\u006es\u0065 \u0063\u006f\u0064\u0065\u0020i\u0073\u0073\u0075e\u0020\u002d\u0020\u0043\u0075s\u0074\u006f\u006de\u0072\u0020\u006e\u0061\u006d\u0065\u0020\u006d\u0069\u0073\u006da\u0074\u0063\u0068, e\u0078\u0070\u0065\u0063\u0074\u0065d\u0020\u0027\u0025\u0073\u0027\u002c\u0020\u0062\u0075\u0074\u0020\u0067o\u0074 \u0027\u0025\u0073\u0027",customerName ,_dg .CustomerName );return _c .Errorf ("\u0063\u0075\u0073\u0074\u006fm\u0065\u0072\u0020\u006e\u0061\u006d\u0065\u0020\u006d\u0069\u0073\u006d\u0061t\u0063\u0068\u002c\u0020\u0065\u0078\u0070\u0065\u0063\u0074\u0065\u0064\u0020\u0027\u0025\u0073\u0027\u002c\u0020\u0062\u0075\u0074\u0020\u0067\u006f\u0074\u0020\u0027\u0025\u0073'",customerName ,_dg .CustomerName );};_dgg =_dg .Validate ();if _dgg !=nil {_fd .Log .Error ("\u004c\u0069\u0063\u0065\u006e\u0073e\u0020\u0063\u006f\u0064\u0065\u0020\u0076\u0061\u006c\u0069\u0064\u0061\u0074i\u006f\u006e\u0020\u0065\u0072\u0072\u006fr\u003a\u0020\u0025\u0076",_dgg );return _dgg ;};_egd =&_dg ;return nil ;};const _fbf ="\u0055\u004e\u0049\u0050DF\u005f\u004c\u0049\u0043\u0045\u004e\u0053\u0045\u005f\u0050\u0041\u0054\u0048";var _ac =_b .Date (2020,1,1,0,0,0,0,_b .UTC );func init (){_daf :=_f .Getenv (_fbf );_ceg :=_f .Getenv (_eefb );if len (_daf )==0||len (_ceg )==0{return ;};_aeg ,_agb :=_ef .ReadFile (_daf );if _agb !=nil {_fd .Log .Error ("\u0055\u006eab\u006c\u0065\u0020t\u006f\u0020\u0072\u0065ad \u006cic\u0065\u006e\u0073\u0065\u0020\u0063\u006fde\u0020\u0066\u0069\u006c\u0065\u003a\u0020%\u0076",_agb );return ;};_agb =SetLicenseKey (string (_aeg ),_ceg );if _agb !=nil {_fd .Log .Error ("\u0055\u006e\u0061b\u006c\u0065\u0020\u0074o\u0020\u006c\u006f\u0061\u0064\u0020\u006ci\u0063\u0065\u006e\u0073\u0065\u0020\u0063\u006f\u0064\u0065\u003a\u0020\u0025\u0076",_agb );return ;};};func _ge (_bgc string ,_ae []byte )(string ,error ){_aa ,_ :=_fb .Decode ([]byte (_bgc ));if _aa ==nil {return "",_c .Errorf ("\u0050\u0072\u0069\u0076\u004b\u0065\u0079\u0020\u0066a\u0069\u006c\u0065\u0064");};_aad ,_fba :=_a .ParsePKCS1PrivateKey (_aa .Bytes );if _fba !=nil {return "",_fba ;};_fa :=_ag .New ();_fa .Write (_ae );_gb :=_fa .Sum (nil );_eg ,_fba :=_gf .SignPKCS1v15 (_ea .Reader ,_aad ,_g .SHA512 ,_gb );if _fba !=nil {return "",_fba ;};_fg :=_d .StdEncoding .EncodeToString (_ae );_fg +="\u000a\u002b\u000a";_fg +=_d .StdEncoding .EncodeToString (_eg );return _fg ,nil ;};