// // 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 sigutil ;import (_g "bytes";_cf "crypto";_ed "crypto/x509";_fd "encoding/asn1";_gb "encoding/pem";_a "errors";_e "fmt";_cg "github.com/unidoc/timestamp";_gd "github.com/unidoc/unipdf/v3/common";_ee "golang.org/x/crypto/ocsp";_fa "io";_ab "io/ioutil"; _d "net/http";_c "time";); // NewCertClient returns a new certificate client. func NewCertClient ()*CertClient {return &CertClient {HTTPClient :_gda ()}}; // NewOCSPClient returns a new OCSP client. func NewOCSPClient ()*OCSPClient {return &OCSPClient {HTTPClient :_gda (),Hash :_cf .SHA1 }}; // Get retrieves the certificate at the specified URL. func (_ea *CertClient )Get (url string )(*_ed .Certificate ,error ){if _ea .HTTPClient ==nil {_ea .HTTPClient =_gda ();};_dd ,_b :=_ea .HTTPClient .Get (url );if _b !=nil {return nil ,_b ;};defer _dd .Body .Close ();_edb ,_b :=_ab .ReadAll (_dd .Body ); if _b !=nil {return nil ,_b ;};if _gdc ,_ :=_gb .Decode (_edb );_gdc !=nil {_edb =_gdc .Bytes ;};_fg ,_b :=_ed .ParseCertificate (_edb );if _b !=nil {return nil ,_b ;};return _fg ,nil ;}; // NewTimestampRequest returns a new timestamp request based // on the specified options. func NewTimestampRequest (body _fa .Reader ,opts *_cg .RequestOptions )(*_cg .Request ,error ){if opts ==nil {opts =&_cg .RequestOptions {};};if opts .Hash ==0{opts .Hash =_cf .SHA256 ;};if !opts .Hash .Available (){return nil ,_ed .ErrUnsupportedAlgorithm ; };_ddg :=opts .Hash .New ();if _ ,_dab :=_fa .Copy (_ddg ,body );_dab !=nil {return nil ,_dab ;};return &_cg .Request {HashAlgorithm :opts .Hash ,HashedMessage :_ddg .Sum (nil ),Certificates :opts .Certificates ,TSAPolicyOID :opts .TSAPolicyOID ,Nonce :opts .Nonce },nil ; }; // NewCRLClient returns a new CRL client. func NewCRLClient ()*CRLClient {return &CRLClient {HTTPClient :_gda ()}}; // CRLClient represents a CRL (Certificate revocation list) client. // It is used to request revocation data from CRL servers. type CRLClient struct{ // HTTPClient is the HTTP client used to make CRL requests. // By default, an HTTP client with a 5 second timeout per request is used. HTTPClient *_d .Client ;}; // MakeRequest makes a CRL request to the specified server and returns the // response. If a server URL is not provided, it is extracted from the certificate. func (_ad *CRLClient )MakeRequest (serverURL string ,cert *_ed .Certificate )([]byte ,error ){if _ad .HTTPClient ==nil {_ad .HTTPClient =_gda ();};if serverURL ==""{if len (cert .CRLDistributionPoints )==0{return nil ,_a .New ("\u0063e\u0072\u0074i\u0066\u0069\u0063\u0061t\u0065\u0020\u0064o\u0065\u0073\u0020\u006e\u006f\u0074\u0020\u0073\u0070ec\u0069\u0066\u0079 \u0061\u006ey\u0020\u0043\u0052\u004c\u0020\u0073e\u0072\u0076e\u0072\u0073"); };serverURL =cert .CRLDistributionPoints [0];};_bf ,_cd :=_ad .HTTPClient .Get (serverURL );if _cd !=nil {return nil ,_cd ;};defer _bf .Body .Close ();_cfd ,_cd :=_ab .ReadAll (_bf .Body );if _cd !=nil {return nil ,_cd ;};if _ae ,_ :=_gb .Decode (_cfd ); _ae !=nil {_cfd =_ae .Bytes ;};return _cfd ,nil ;};func _gda ()*_d .Client {return &_d .Client {Timeout :5*_c .Second }}; // MakeRequest makes a OCSP request to the specified server and returns // the parsed and raw responses. If a server URL is not provided, it is // extracted from the certificate. func (_be *OCSPClient )MakeRequest (serverURL string ,cert ,issuer *_ed .Certificate )(*_ee .Response ,[]byte ,error ){if _be .HTTPClient ==nil {_be .HTTPClient =_gda ();};if serverURL ==""{if len (cert .OCSPServer )==0{return nil ,nil ,_a .New ("\u0063e\u0072\u0074i\u0066\u0069\u0063a\u0074\u0065\u0020\u0064\u006f\u0065\u0073 \u006e\u006f\u0074\u0020\u0073\u0070e\u0063\u0069\u0066\u0079\u0020\u0061\u006e\u0079\u0020\u004f\u0043S\u0050\u0020\u0073\u0065\u0072\u0076\u0065\u0072\u0073"); };serverURL =cert .OCSPServer [0];};_da ,_aag :=_ee .CreateRequest (cert ,issuer ,&_ee .RequestOptions {Hash :_be .Hash });if _aag !=nil {return nil ,nil ,_aag ;};_ga ,_aag :=_be .HTTPClient .Post (serverURL ,"\u0061p\u0070\u006c\u0069\u0063\u0061\u0074\u0069\u006f\u006e\u002f\u006fc\u0073\u0070\u002d\u0072\u0065\u0071\u0075\u0065\u0073\u0074",_g .NewReader (_da )); if _aag !=nil {return nil ,nil ,_aag ;};defer _ga .Body .Close ();_fc ,_aag :=_ab .ReadAll (_ga .Body );if _aag !=nil {return nil ,nil ,_aag ;};if _cfce ,_ :=_gb .Decode (_fc );_cfce !=nil {_fc =_cfce .Bytes ;};_edf ,_aag :=_ee .ParseResponseForCert (_fc ,cert ,issuer ); if _aag !=nil {return nil ,nil ,_aag ;};return _edf ,_fc ,nil ;}; // NewTimestampClient returns a new timestamp client. func NewTimestampClient ()*TimestampClient {return &TimestampClient {HTTPClient :_gda ()}}; // CertClient represents a X.509 certificate client. Its primary purpose // is to download certificates. type CertClient struct{ // HTTPClient is the HTTP client used to make certificate requests. // By default, an HTTP client with a 5 second timeout per request is used. HTTPClient *_d .Client ;}; // TimestampClient represents a RFC 3161 timestamp client. // It is used to obtain signed tokens from timestamp authority servers. type TimestampClient struct{ // HTTPClient is the HTTP client used to make timestamp requests. // By default, an HTTP client with a 5 second timeout per request is used. HTTPClient *_d .Client ;}; // GetIssuer retrieves the issuer of the provided certificate. func (_af *CertClient )GetIssuer (cert *_ed .Certificate )(*_ed .Certificate ,error ){for _ ,_ef :=range cert .IssuingCertificateURL {_gc ,_cfc :=_af .Get (_ef );if _cfc !=nil {_gd .Log .Debug ("\u0057\u0041\u0052\u004e\u003a\u0020\u0063\u006f\u0075\u006c\u0064\u0020\u006e\u006f\u0074 \u0064\u006f\u0077\u006e\u006c\u006f\u0061\u0064\u0020\u0069\u0073\u0073\u0075e\u0072\u0020\u0066\u006f\u0072\u0020\u0063\u0065\u0072\u0074\u0069\u0066ic\u0061\u0074\u0065\u0020\u0025\u0076\u003a\u0020\u0025\u0076",cert .Subject .CommonName ,_cfc ); continue ;};return _gc ,nil ;};return nil ,_e .Errorf ("\u0069\u0073\u0073\u0075e\u0072\u0020\u0063\u0065\u0072\u0074\u0069\u0066\u0069\u0063a\u0074e\u0020\u006e\u006f\u0074\u0020\u0066\u006fu\u006e\u0064");}; // GetEncodedToken executes the timestamp request and returns the DER encoded // timestamp token bytes. func (_cgab *TimestampClient )GetEncodedToken (serverURL string ,req *_cg .Request )([]byte ,error ){if serverURL ==""{return nil ,_e .Errorf ("\u006d\u0075\u0073\u0074\u0020\u0070r\u006f\u0076\u0069\u0064\u0065\u0020\u0074\u0069\u006d\u0065\u0073\u0074\u0061m\u0070\u0020\u0073\u0065\u0072\u0076\u0065r\u0020\u0055\u0052\u004c"); };if req ==nil {return nil ,_e .Errorf ("\u0074\u0069\u006de\u0073\u0074\u0061\u006dp\u0020\u0072\u0065\u0071\u0075\u0065\u0073t\u0020\u0063\u0061\u006e\u006e\u006f\u0074\u0020\u0062\u0065\u0020\u006e\u0069\u006c");};_eb ,_faf :=req .Marshal ();if _faf !=nil {return nil ,_faf ; };_ac :=_cgab .HTTPClient ;if _ac ==nil {_ac =_gda ();};_fdg ,_faf :=_ac .Post (serverURL ,"a\u0070\u0070\u006c\u0069\u0063\u0061t\u0069\u006f\u006e\u002f\u0074\u0069\u006d\u0065\u0073t\u0061\u006d\u0070-\u0071u\u0065\u0072\u0079",_g .NewBuffer (_eb )); if _faf !=nil {return nil ,_faf ;};defer _fdg .Body .Close ();_ff ,_faf :=_ab .ReadAll (_fdg .Body );if _faf !=nil {return nil ,_faf ;};if _fdg .StatusCode !=_d .StatusOK {return nil ,_e .Errorf ("\u0075\u006e\u0065x\u0070\u0065\u0063\u0074e\u0064\u0020\u0048\u0054\u0054\u0050\u0020s\u0074\u0061\u0074\u0075\u0073\u0020\u0063\u006f\u0064\u0065\u003a\u0020\u0025\u0064",_fdg .StatusCode ); };var _bb struct{Version _fd .RawValue ;Content _fd .RawValue ;};if _ ,_faf =_fd .Unmarshal (_ff ,&_bb );_faf !=nil {return nil ,_faf ;};return _bb .Content .FullBytes ,nil ;}; // OCSPClient represents a OCSP (Online Certificate Status Protocol) client. // It is used to request revocation data from OCSP servers. type OCSPClient struct{ // HTTPClient is the HTTP client used to make OCSP requests. // By default, an HTTP client with a 5 second timeout per request is used. HTTPClient *_d .Client ; // Hash is the hash function used when constructing the OCSP // requests. If zero, SHA-1 will be used. Hash _cf .Hash ;}; // IsCA returns true if the provided certificate appears to be a CA certificate. func (_bc *CertClient )IsCA (cert *_ed .Certificate )bool {return cert .IsCA &&_g .Equal (cert .RawIssuer ,cert .RawSubject );};