{"id":347632,"date":"2023-05-19T03:00:30","date_gmt":"2023-05-19T03:00:30","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=347632"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=347632","title":{"rendered":"<span>\u0418\u043d\u0442\u0435\u0433\u0440\u0430\u0446\u0438\u044f \u0441 \u0415\u0421\u0418\u0410 v2 \u043d\u0430 Debian 11 + php 7<\/span>"},"content":{"rendered":"<div><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<p>\u041f\u0435\u0440\u0435\u0434\u043e \u043c\u043d\u043e\u0439 \u0431\u044b\u043b\u0430 \u043f\u043e\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0430 \u0437\u0430\u0434\u0430\u0447\u0430 &#171;\u0447\u0442\u043e\u0431\u044b \u043f\u043e\u0441\u0435\u0442\u0438\u0442\u0435\u043b\u0438 \u043c\u043e\u0433\u043b\u0438 \u0432\u043e\u0439\u0442\u0438 \u043d\u0430 \u0441\u0430\u0439\u0442 \u0447\u0435\u0440\u0435\u0437 \u0413\u043e\u0441\u0443\u0441\u043b\u0443\u0433\u0438&#187;. \u0417\u0430\u0434\u0430\u0447\u043a\u0430 \u043d\u0435 \u043d\u043e\u0432\u0430\u044f, \u0434\u0430\u0432\u043d\u043e \u0440\u0435\u0448\u0435\u043d\u0430. \u041d\u0430 PHP \u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442 <a href=\"https:\/\/github.com\/fr05t1k\/esia%20%D0%B8%20https:\/\/github.com\/ekapusta\/oauth2-esia\" rel=\"noopener noreferrer nofollow\">\u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438<\/a>, \u043d\u043e \u0435\u0441\u0442\u044c \u043f\u0430\u0440\u0430 \u043e\u0433\u043e\u0432\u043e\u0440\u043e\u043a.<\/p>\n<h2>\u041f\u0440\u043e\u0431\u043b\u0435\u043c\u0430 1<\/h2>\n<p>\u0421 \u044f\u043d\u0432\u0430\u0440\u044f 2020 \u0434\u043b\u044f \u0438\u043d\u0442\u0435\u0433\u0440\u0430\u0446\u0438\u0438 \u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u0413\u041e\u0421\u0422-\u0448\u0438\u0444\u0440\u043e\u0432\u0430\u043d\u0438\u0435. \u0412\u0430\u0440\u0438\u0430\u043d\u0442\u044b \u0440\u0435\u0448\u0435\u043d\u0438\u044f:<\/p>\n<ul>\n<li>\n<p>\u0434\u0435\u0440\u0433\u0430\u0442\u044c \u0432\u043d\u0435\u0448\u043d\u044e\u044e \u0443\u0442\u0438\u043b\u0438\u0442\u0443, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0443\u043c\u0435\u0435\u0442 \u0413\u041e\u0421\u0422<\/p>\n<\/li>\n<li>\n<p>\u0441\u043e\u0431\u0440\u0430\u0442\u044c php \u0441 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u043e\u0439 \u0413\u041e\u0421\u0422<\/p>\n<\/li>\n<\/ul>\n<p>\u041e\u0431\u0430 \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u0430 \u0442\u0440\u0435\u0431\u0443\u044e\u0442 \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u043b\u0438\u0446\u0435\u043d\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0433\u043e \u043a\u0440\u0438\u043f\u0442\u043e\u0433\u0440\u0430\u0444\u0438\u0447\u0435\u0441\u043a\u043e\u0433\u043e \u0441\u0440\u0435\u0434\u0441\u0442\u0432\u0430 (<a href=\"https:\/\/www.cryptopro.ru\/category\/faq\/linuxunix-0\" rel=\"noopener noreferrer nofollow\">\u041a\u0440\u0438\u043f\u0442\u043e\u041f\u0440\u043e<\/a>), \u0432 \u0440\u0430\u043c\u043a\u0430\u0445 \u0441\u0442\u0430\u0442\u044c\u0438 \u043c\u044b \u043f\u043e\u0439\u0434\u0435\u043c \u043f\u043e \u0432\u0442\u043e\u0440\u043e\u043c\u0443 \u043f\u0443\u0442\u0438. \u0412\u0435\u0441\u044c php \u043c\u043e\u0436\u043d\u043e \u043d\u0435 \u043f\u0435\u0440\u0435\u0441\u043e\u0431\u0438\u0440\u0430\u0442\u044c, \u0432\u0435\u0434\u044c \u0435\u0441\u0442\u044c \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c \u043f\u043b\u0430\u0433\u0438\u043d\u043e\u0432. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0441\u043e\u0431\u0440\u0430\u0442\u044c \u043f\u043b\u0430\u0433\u0438\u043d <a href=\"https:\/\/docs.cryptopro.ru\/cades\/phpcades\" rel=\"noopener noreferrer nofollow\">libphpcades<\/a> \u043e\u0442 \u041a\u0440\u0438\u043f\u0442\u043e\u041f\u0440\u043e. <\/p>\n<p>\u0414\u043b\u044f Debian 11 \u0438 php 7.4 <a href=\"https:\/\/docs.cryptopro.ru\/cades\/phpcades\/phpcades-install\" rel=\"noopener noreferrer nofollow\">\u0438\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u044e <\/a>\u043e\u0442 \u041a\u0440\u0438\u043f\u0442\u043e\u041f\u0440\u043e \u043c\u043d\u0435 \u043f\u0440\u0438\u0448\u043b\u043e\u0441\u044c \u0447\u0443\u0442\u044c \u0434\u043e\u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u043d\u0430\u043f\u0438\u043b\u044c\u043d\u0438\u043a\u043e\u043c. \u0428\u0430\u0433\u0438 2 \u0438 6 \u043f\u0440\u043e\u043f\u0443\u0441\u043a\u0430\u0435\u043c, \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043b\u0438\u0448\u044c \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c \u043f\u0430\u043a\u0435\u0442 php-dev. \u041f\u043e\u0441\u043b\u0435 \u044d\u0442\u043e\u0433\u043e \u043d\u0430 \u0448\u0430\u0433\u0435 7 \u0432 Makefile.unix \u043c\u043e\u0436\u043d\u043e \u0437\u0430\u0434\u0430\u0442\u044c \u043f\u0443\u0442\u044c \u043a \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043e\u0447\u043d\u044b\u043c \u0444\u0430\u0439\u043b\u0430\u043c \u0438\u0437 \u043f\u0430\u043a\u0435\u0442\u0430 php-dev<\/p>\n<p><code>PHPDIR=\/usr\/include\/php\/20190902<\/code><\/p>\n<p>\u0414\u0430\u043b\u0435\u0435 \u043d\u0430 \u0448\u0430\u0433\u0435 8 \u0441\u043a\u0430\u0447\u0438\u0432\u0430\u0435\u043c \u043f\u0430\u0442\u0447 \u0434\u043b\u044f php7 \u0438 \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u0435\u043c \u0435\u0433\u043e \u043a \u0438\u0441\u0445\u043e\u0434\u043d\u044b\u043c \u0444\u0430\u0439\u043b\u0430\u043c libphpcades :<\/p>\n<p><code>cd \/opt\/cprocsp\/src\/phpcades\/<br \/>patch -p0 &lt; \/path\/to\/php7_support.patch<\/code><\/p>\n<p>\u0428\u0430\u0433 &#171;8 \u0438 3\/4 &#171;: \u0427\u0442\u043e\u0431\u044b \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 \u0441\u043e\u0431\u0440\u0430\u043b\u0430\u0441\u044c \u043f\u043e\u0434 debian 11, <a href=\"https:\/\/cryptopro.ru\/forum2\/default.aspx?g=posts&amp;m=121907#post121907\" rel=\"noopener noreferrer nofollow\">\u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c <\/a>\u043a \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430\u043c \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440\u0430 CFLAGS \u0444\u043b\u0430\u0433<\/p>\n<p><code>-fpermissive<\/code><\/p>\n<p>\u0410 \u0438\u0437 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432 \u0441\u0431\u043e\u0440\u043a\u0438 LDFLAGS <a href=\"https:\/\/cryptopro.ru\/forum2\/default.aspx?g=posts&amp;m=129648#post129648\" rel=\"noopener noreferrer nofollow\">\u0443\u0434\u0430\u043b\u044f\u0435\u043c<\/a> \u0444\u043b\u0430\u0433<\/p>\n<p><code>-lcplib<\/code><\/p>\n<p>\u0418 \u043f\u043e\u0441\u043b\u0435 \u044d\u0442\u043e\u0433\u043e \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 \u0443\u0441\u043f\u0435\u0448\u043d\u043e \u0441\u043e\u0431\u0438\u0440\u0430\u0435\u0442\u0441\u044f. \u041f\u043e-\u0445\u043e\u0440\u043e\u0448\u0435\u043c\u0443, \u0442\u0435\u043f\u0435\u0440\u044c \u0441\u043e\u0431\u0440\u0430\u043d\u043d\u0443\u044e libphpcades.so \u043d\u0430\u0434\u043e \u0431\u044b \u043e\u0444\u043e\u0440\u043c\u0438\u0442\u044c \u0432 \u043f\u0430\u043a\u0435\u0442 deb&#8230;<\/p>\n<figure class=\"bordered full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/5d3\/1b5\/bf0\/5d31b5bf01c2ff4e6f8bc9f301e6c402.jpg\" width=\"1024\" height=\"768\"><\/figure>\n<p>\u0422\u0430\u043a \u0447\u0442\u043e \u043d\u0430 \u0448\u0430\u0433\u0435 11 \u0432\u043c\u0435\u0441\u0442\u043e \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0441\u0438\u043c\u043b\u0438\u043d\u043a\u0430 \u043c\u044b \u043f\u0440\u043e\u0441\u0442\u043e \u043a\u043e\u043f\u0438\u0440\u0443\u0435\u043c \u0441\u043e\u0431\u0440\u0430\u043d\u043d\u0443\u044e \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443 \u0432 \u043a\u043e\u043c\u043f\u0430\u043d\u0438\u044e \u043a \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u043c \u043c\u043e\u0434\u0443\u043b\u044f\u043c php<\/p>\n<p><code>cp \/opt\/cprocsp\/src\/phpcades\/libphpcades.so \/usr\/lib\/php\/20190902\/<\/code><\/p>\n<p>\u041f\u043e\u0441\u043b\u0435 \u0447\u0435\u0433\u043e \u0438\u0441\u0445\u043e\u0434\u043d\u044b\u0435 \u0444\u0430\u0439\u043b\u044b \u043d\u0430\u043c \u0443\u0436\u0435 \u043d\u0435 \u043d\u0443\u0436\u043d\u044b, \u0438\u0445 \u043c\u043e\u0436\u043d\u043e \u0443\u0434\u0430\u043b\u0438\u0442\u044c.<\/p>\n<p>\u0414\u043b\u044f \u0442\u0435\u0441\u0442\u043e\u0432\u043e\u0433\u043e \u043a\u043e\u043d\u0442\u0443\u0440\u0430 \u0415\u0421\u0418\u0410 \u0413\u041e\u0421\u0422-\u0441\u0435\u0440\u0442\u0438\u0444\u0438\u043a\u0430\u0442 \u043c\u043e\u0436\u043d\u043e <a href=\"http:\/\/testgost2012.cryptopro.ru\/certsrv\/\" rel=\"noopener noreferrer nofollow\">\u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0441\u0430\u043c\u043e\u0441\u0442\u043e\u044f\u0442\u0435\u043b\u044c\u043d\u043e<\/a>, \u0434\u043b\u044f \u043f\u0440\u043e\u043c\u044b\u0448\u043b\u0435\u043d\u043d\u043e\u0433\u043e &#8212; \u043f\u0440\u0438\u0434\u0435\u0442\u0441\u044f \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0432 \u0443\u043f\u043e\u043b\u043d\u043e\u043c\u043e\u0447\u0435\u043d\u043d\u043e\u043c \u0423\u0434\u043e\u0441\u0442\u043e\u0432\u0435\u0440\u044f\u044e\u0449\u0435\u043c \u0446\u0435\u043d\u0442\u0440\u0435 (\u041e\u0413\u0420\u041d \u0432 \u0441\u0435\u0440\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u0435 \u0434\u043e\u043b\u0436\u0435\u043d \u0441\u043e\u0432\u043f\u0430\u0434\u0430\u0442\u044c \u0441 \u041e\u0413\u0420\u041d \u0432\u0430\u0448\u0435\u0439 \u0418\u0421 \u0432 \u043f\u0440\u043e\u043c\u044b\u0448\u043b\u0435\u043d\u043d\u043e\u043c \u043a\u043e\u043d\u0442\u0443\u0440\u0435 \u0415\u0421\u0418\u0410)<\/p>\n<p>\u041b\u044e\u0431\u044b\u043c \u0441\u043f\u043e\u0441\u043e\u0431\u043e\u043c \u043f\u0435\u0440\u0435\u043d\u043e\u0441\u0438\u043c \u043a\u043b\u044e\u0447 \u0438 \u0441\u0435\u0440\u0442\u0438\u0444\u0438\u043a\u0430\u0442 \u043d\u0430\u0448\u0435\u0439 \u0418\u0421 \u0432 <code>\/var\/opt\/cprocsp\/keys\/www-data\/MYSITE.000<\/code>, \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u043e\u0441\u0442\u044b\u043c \u043a\u043e\u043f\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435\u043c, \u043c\u043e\u0436\u043d\u043e \u043a\u043e\u043c\u0430\u043d\u0434\u043e\u0439<\/p>\n<p><code>sudo -u www-data \/opt\/cprocsp\/bin\/amd64\/csptest -keycopy -contsrc '\\\\.\\FLASH\\ivanoff' -contdest '\\\\.\\HDIMAGE\\MYSITE'<\/code><\/p>\n<p>\u0414\u0430\u043b\u0435\u0435 \u0443\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u043c  \u0441\u0435\u0440\u0442\u0438\u0444\u0438\u043a\u0430\u0442 \u0438 \u0435\u0433\u043e \u0437\u0430\u043a\u0440\u044b\u0442\u044b\u0439 \u043a\u043b\u044e\u0447 \u0432 \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0435 My \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f www-data:<\/p>\n<p><code>sudo -u www-data \/opt\/cprocsp\/bin\/amd64\/certmgr -inst -store uMy -cont '\\\\.\\HDIMAGE\\MYSITE'<\/code><\/p>\n<p>\u0412 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0435 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0438 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c, \u0447\u0442\u043e \u0435\u0441\u0442\u044c \u0441\u0432\u044f\u0437\u044c \u0441\u0435\u0440\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u0430 \u0441 \u043f\u0440\u0438\u0432\u0430\u0442\u043d\u044b\u043c \u043a\u043b\u044e\u0447\u043e\u043c \u0432 \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440\u0435:<\/p>\n<p><code>PrivateKey Link     : Yes<br \/> Container           : \\\\.\\HDIMAGE\\MYSITE<\/code><\/p>\n<p>\u0423\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u043c \u043e\u0442\u043a\u0440\u044b\u0442\u044b\u0439 \u0441\u0435\u0440\u0442\u0438\u0444\u0438\u043a\u0430\u0442 \u0415\u0421\u0418\u0410 \u0432 \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440 Users \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f www-data<\/p>\n<p><code>sudo -u www-data \/opt\/cprocsp\/bin\/amd64\/certmgr -install -store uUsers -file .\/TESIA\\ GOST\\ 2012.cer<br \/>sudo -u www-data \/opt\/cprocsp\/bin\/amd64\/certmgr -install -store uUsers -file .\/GOST\\ 2012\\ PROD.cer<\/code><\/p>\n<h2>\u041f\u0440\u043e\u0431\u043b\u0435\u043c\u0430 2<\/h2>\n<p>\u0421&nbsp;\u0432\u0435\u0440\u0441\u0438\u0438 2.90&nbsp;<a href=\"https:\/\/digital.gov.ru\/ru\/documents\/6186\/\" rel=\"noopener noreferrer nofollow\">\u041c\u0435\u0442\u043e\u0434\u0438\u0447\u0435\u0441\u043a\u0438\u0445 \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0430\u0446\u0438\u0439<\/a> \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u044b\u0439 endpoint \/aas\/oauth2\/ac \u043e\u0431\u044a\u044f\u0432\u043b\u0435\u043d \u0443\u0441\u0442\u0430\u0440\u0435\u0432\u0448\u0438\u043c \u0438 \u043d\u0435&nbsp;\u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u043e\u0432\u0430\u043d \u043a&nbsp;\u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044e. \u041f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u043e \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0438\u0442\u044c \u043d\u0430 \/aas\/oauth2\/v2\/ac, \u0430&nbsp;\u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0432&nbsp;\u0443\u043a\u0430\u0437\u0430\u043d\u043d\u044b\u0445 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430\u0445 \u043d\u0435\u0442. <\/p>\n<p>\u0412\u043e\u0442 \u044d\u0442\u0438\u043c\u2011\u0442\u043e \u043c\u044b \u0441\u0435\u0439\u0447\u0430\u0441 \u0438 \u0437\u0430\u0439\u043c\u0435\u043c\u0441\u044f. \u0421\u043d\u043e\u0432\u0430 \u0434\u043e\u0441\u0442\u0430\u0435\u043c \u043d\u0430\u043f\u0438\u043b\u044c\u043d\u0438\u043a \u0438 \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u0435\u043c \u0435\u0433\u043e \u043d\u0443 \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u043a \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u0447\u043a\u0435 <a href=\"https:\/\/github.com\/fr05t1k\/esia\" rel=\"noopener noreferrer nofollow\">https:\/\/github.com\/fr05t1k\/esia<\/a><\/p>\n<p>\u0414\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u043d\u043e\u0432\u044b\u0435 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0438:<\/p>\n<pre><code class=\"php\">class Config  {   private $tokenUrlPath_V3 = 'aas\/oauth2\/v3\/te';   private $codeUrlPath_V2 = 'aas\/oauth2\/v2\/ac';   protected $ESIACertSHA1 = '01e6041097ccf5a26da1d75fdbb1e7aaee07bd2a'; \/\/ SHA1 \u0445\u044d\u0448 \u0441\u0435\u0440\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u0430 \u0415\u0421\u0418\u0410 (openssl sha1 .\/GOST\\ 2012\\ PROD.cer)   public function getTokenUrl_V3(): string  {     return $this-&gt;portalUrl . $this-&gt;tokenUrlPath_V3;  }<\/code><\/pre>\n<p>\u041d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u043c\u0435\u0442\u043e\u0434\u0430 <code>buildUrl()<\/code> \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u043c\u0435\u0442\u043e\u0434 <code>buildUrl_V2()<\/code>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u0443\u0434\u0435\u0442 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441 endpoint  \u0438\u0437 <code>$codeUrlPath_V2<\/code><\/p>\n<p>\u0412 endpoint &#171;v2\/ac&#187; \u043f\u043e\u043c\u0435\u043d\u044f\u043b\u0441\u044f \u0441\u043e\u0441\u0442\u0430\u0432 \u0438 \u043f\u043e\u0440\u044f\u0434\u043e\u043a \u043a\u043e\u043d\u043a\u0430\u0442\u0435\u043d\u0430\u0446\u0438\u0438 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432 \u0434\u043b\u044f \u0441\u043e\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044f client_secret (\u0442\u0435\u043f\u0435\u0440\u044c \u044d\u0442\u043e ClientID + Scope + Timestamp +State + RedirectURI) \u0438 \u0434\u043e\u0431\u0430\u0432\u0438\u043b\u0441\u044f client_certificate_hash.<\/p>\n<pre><code class=\"php\">class OpenId { protected $clientCertHash = null;  public function buildUrl_V2() {      $timestamp = $this-&gt;getTimeStamp();      $state = $this-&gt;buildState();      \/\/ \u0441\u043e\u0431\u0438\u0440\u0430\u0435\u043c client_secret \u043f\u043e \u043d\u043e\u0432\u044b\u043c \u043f\u0440\u0430\u0432\u0438\u043b\u0430\u043c      $message =  $this-&gt;config-&gt;getClientId()           . $this-&gt;config-&gt;getScopeString()           . $timestamp                    . $state                    . $this-&gt;config-&gt;getRedirectUrl();          \/\/ \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c \u0413\u041e\u0421\u04222012 \u0434\u043b\u044f \u043f\u043e\u0434\u043f\u0438\u0441\u0430\u043d\u0438\u044f           $this-&gt;signer = new SignerCPDataHash(           $config-&gt;getCertPath(),           \/\/ \u0434\u043b\u044f \u041a\u0440\u0438\u043f\u0442\u043e\u041f\u0440\u043e \u044d\u0442\u0438            $config-&gt;getPrivateKeyPath(),     \/\/ \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b \u043d\u0435 \u043d\u0443\u0436\u043d\u044b           $config-&gt;getPrivateKeyPassword(), \/\/ \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u0441\u0435\u0440\u0442\u0438\u0444\u0438\u043a\u0430\u0442 \u0438 \u043a\u043b\u044e\u0447           $config-&gt;getTmpPath()             \/\/ \u0438\u043c\u043f\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u044b \u0432 \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0435      );      $clientSecret = $this-&gt;signer-&gt;sign($message);      $url = $this-&gt;config-&gt;getCodeUrl_V2() . '?%s';      $params = [          'client_id' =&gt; $this-&gt;config-&gt;getClientId(),          'client_secret' =&gt; $clientSecret,          'redirect_uri' =&gt; $this-&gt;config-&gt;getRedirectUrl(),          'scope' =&gt; $this-&gt;config-&gt;getScopeString(),          'response_type' =&gt; $this-&gt;config-&gt;getResponseType(),          'state' =&gt; $state,          'access_type' =&gt; $this-&gt;config-&gt;getAccessType(),          'timestamp' =&gt; $timestamp,          'client_certificate_hash' =&gt; $this-&gt;clientCertHash, \/\/ \u0413\u041e\u0421\u0422-\u0445\u044d\u0448 \u043d\u0430\u0448\u0435\u0433\u043e \u0441\u0435\u0440\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u0430           ];      $request = http_build_query($params);            return sprintf($url, $request);  }<\/code><\/pre>\n<p>\u0414\u0430, client_certificate_hash \u043c\u043e\u0436\u043d\u043e \u0432\u044b\u0447\u0438\u0441\u043b\u0438\u0442\u044c \u043f\u0440\u0435\u0434\u043b\u0430\u0433\u0430\u0435\u043c\u043e\u0439 \u0432 \u041c\u0435\u0442\u043e\u0434\u0438\u0447\u0435\u0441\u043a\u0438\u0445 \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0430\u0446\u0438\u044f\u0445 \u0443\u0442\u0438\u043b\u0438\u0442\u043e\u0439 \u0438 \u0432\u043f\u0438\u0441\u0430\u0442\u044c \u043a\u0430\u043a \u0435\u0449\u0435 \u043e\u0434\u0438\u043d \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0438. \u0412\u043e\u0437\u043c\u043e\u0436\u043d\u043e, \u0442\u0430\u043a \u0434\u0430\u0436\u0435 \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e. \u041d\u043e \u043f\u043e\u0447\u0435\u043c\u0443 \u0431\u044b \u043d\u0435 \u043d\u0430\u0443\u0447\u0438\u0442\u044c\u0441\u044f \u0432\u044b\u0447\u0438\u0441\u043b\u044f\u0442\u044c \u0435\u0433\u043e \u0441\u0430\u043c\u043e\u0441\u0442\u043e\u044f\u0442\u0435\u043b\u044c\u043d\u043e?<\/p>\n<p>\u0418\u0442\u0430\u043a, \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u043a\u043b\u0430\u0441\u0441 SignerCPDataHash, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 libphpcades \u0434\u043b\u044f \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f \u0413\u041e\u0421\u0422 \u0445\u044d\u0448\u0430 \u0441\u0435\u0440\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u0430 \u0418\u0421 (\u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 <code>client_certificate_hash<\/code>) \u0438 \u043f\u043e\u0434\u043f\u0438\u0441\u0430\u043d\u0438\u044f <code>client_secret<\/code> \u043f\u043e \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0443 data hash.<\/p>\n<p>\u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0441\u0435\u0440\u0442\u0438\u0444\u0438\u043a\u0430\u0442 \u0441 CN=ClientID \u0438\u0437 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u043e\u0433\u043e \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0430 My \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d\u043d\u043e\u0433\u043e \u041a\u0440\u0438\u043f\u0442\u043e\u041f\u0440\u043e. <\/p>\n<pre><code class=\"php\">class SignerCPDataHash extends AbstractSignerPKCS7 implements SignerInterface {     public function sign(string $message): string     {         $store = new \\CPStore();         $store-&gt;Open(CURRENT_USER_STORE, 'My', STORE_OPEN_READ_ONLY); \/\/ \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0435 My \u0442\u0435\u043a\u0443\u0449\u0435\u0433\u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f (www-data)         $certs = $store-&gt;get_Certificates();         $certlist = $certs-&gt;Find(CERTIFICATE_FIND_SUBJECT_NAME, $this-&gt;config-&gt;getClientId(), 0); \/\/ \u0438\u0449\u0435\u043c \u0441\u0435\u0440\u0442\u0438\u0444\u0438\u043a\u0430\u0442, \u0443 \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e\u0435 Subject = \u043c\u043d\u0435\u043c\u043e\u043d\u0438\u043a\u0435 \u043d\u0430\u0448\u0435\u0439 \u0418\u0421         $cert = $certlist-&gt;Item(1);         if (!$cert) {             throw new CannotReadCertificateException('Cannot read the certificate');         }                 \/\/ \u0443 \u0441\u0435\u0440\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u0430 \u0434\u043e\u043b\u0436\u043d\u0430 \u0431\u044b\u0442\u044c \u0441\u0432\u044f\u0437\u043a\u0430 \u0441 \u0437\u0430\u043a\u0440\u044b\u0442\u044b\u043c \u043a\u043b\u044e\u0447\u043e\u043c         if (false===$cert-&gt;HasPrivateKey()) {             throw new CannotReadPrivateKeyException('Cannot read the private key');         }                  $pk=$cert-&gt;PublicKey();         $oid=$pk-&gt;get_Algorithm();                           $hd = new \\CPHashedData();             switch ($oid-&gt;get_Value()) { \/\/ https:\/\/cpdn.cryptopro.ru\/content\/csp40\/html\/group___pro_c_s_p_ex_DP8.html             case '1.2.643.7.1.1.1.1':                 $hd-&gt;set_Algorithm(CADESCOM_HASH_ALGORITHM_CP_GOST_3411_2012_256);                 break;             case '1.2.643.7.1.1.1.2':                 $hd-&gt;set_Algorithm(CADESCOM_HASH_ALGORITHM_CP_GOST_3411_2012_512);                 break;         }         $hd-&gt;set_DataEncoding(BASE64_TO_BINARY);         $hd-&gt;Hash($cert-&gt;Export(ENCODE_BASE64));               $this-&gt;clientCertHash=$hd-&gt;get_Value(); \/\/\u043f\u043e\u043b\u0443\u0447\u0438\u043b\u0438 \u0413\u041e\u0421\u0422 \u0445\u044d\u0448 \u043d\u0430\u0448\u0435\u0433\u043e \u0441\u0435\u0440\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u0430         unset($hd);          $hd = new \\CPHashedData();                 $hd-&gt;set_Algorithm(CADESCOM_HASH_ALGORITHM_CP_GOST_3411_2012_256);         $hd-&gt;set_DataEncoding(BASE64_TO_BINARY);         $hd-&gt;Hash(base64_encode($message)); \/\/ \u043f\u043e\u0441\u0447\u0438\u0442\u0430\u043b\u0438 \u0413\u041e\u0421\u0422 \u0445\u044d\u0448 \u0434\u043b\u044f $message         $rs = new \\CPRawSignature();         $shash=$rs-&gt;SignHash($hd, $cert); \/\/ https:\/\/docs.cryptopro.ru\/cades\/reference\/cadescom\/cadescom_interface\/irawsignaturesignhash :  \u041f\u043e\u0434\u043f\u0438\u0441\u044c \u0434\u043b\u044f \u043a\u043b\u044e\u0447\u0435\u0439 \u0413\u041e\u0421\u0422 \u0420 34.10-2001 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442\u0441\u044f \u043a\u0430\u043a \u043e\u043f\u0438\u0441\u0430\u043d\u043e \u0432 \u0440\u0430\u0437\u0434\u0435\u043b\u0435 2.2.2 RFC 4491 (http:\/\/tools.ietf.org\/html\/rfc4491#section-2.2.2), \u043d\u043e \u0432 \u043e\u0431\u0440\u0430\u0442\u043d\u043e\u043c \u043f\u043e\u0440\u044f\u0434\u043a\u0435 \u0431\u0430\u0439\u0442.         $signed=base64_encode(strrev(hex2bin($shash))); \/\/ \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u0438 \u043f\u043e\u0434\u043f\u0438\u0441\u0430\u043d\u043d\u044b\u0439 data hash          $sign = str_replace(\"\\n\", '', $this-&gt;urlSafe($signed));         return $sign;     } } <\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u0437\u0430\u0439\u043c\u0435\u043c\u0441\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435\u043c \u0438 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u043e\u0439 JWT \u0442\u043e\u043a\u0435\u043d\u0430:<\/p>\n<pre><code class=\"php\">    public function getToken_V3(string $code): string     {         $timestamp = $this-&gt;getTimeStamp();         $state = $this-&gt;buildState();          $this-&gt;signer = new SignerCPDataHash(             $config-&gt;getCertPath(),             $config-&gt;getPrivateKeyPath(),             $config-&gt;getPrivateKeyPassword(),             $config-&gt;getTmpPath()         );          $clientSecret = $this-&gt;signer-&gt;sign(               $this-&gt;config-&gt;getClientId()             . $this-&gt;config-&gt;getScopeString()             . $timestamp             . $state             . $this-&gt;config-&gt;getRedirectUrl();         );          $body = [             'client_id' =&gt; $this-&gt;config-&gt;getClientId(),             'code' =&gt; $code,             'grant_type' =&gt; 'authorization_code',             'client_secret' =&gt; $clientSecret,             'state' =&gt; $state,             'redirect_uri' =&gt; $this-&gt;config-&gt;getRedirectUrl(),             'scope' =&gt; $this-&gt;config-&gt;getScopeString(),             'timestamp' =&gt; $timestamp,             'token_type' =&gt; 'Bearer',             'refresh_token' =&gt; $state,             'client_certificate_hash' =&gt; $this-&gt;clientCertHash,         ];          $payload = $this-&gt;sendRequest(             new Request(                 'POST',                 $this-&gt;config-&gt;getTokenUrl_V3(),                 [                     'Content-Type' =&gt; 'application\/x-www-form-urlencoded',                 ],                 http_build_query($body)             )         );          $this-&gt;logger-&gt;debug('Payload: ', $payload);          $token = $payload['access_token'];          $chunks = explode('.', $token);         $payload = json_decode($this-&gt;base64UrlSafeDecode($chunks[1]), true);         $header = json_decode($this-&gt;base64UrlSafeDecode($chunks[0]), true);         $_token_signature  = $this-&gt;base64UrlSafeDecode($chunks[2]);          if ('JWT'==$header-&gt;typ) {             $store = new \\CPStore();                         $store-&gt;Open(CURRENT_USER_STORE, \"Users\", STORE_OPEN_READ_ONLY); \/\/ \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0435 Users             $certs = $store-&gt;get_Certificates();             $certlist = $certs-&gt;Find(CERTIFICATE_FIND_SHA1_HASH, $this-&gt;ESIACertSHA1, 0); \/\/ \u0438\u0449\u0435\u043c \u0432 \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0435 \u0441\u0435\u0440\u0442\u0438\u0444\u0438\u043a\u0430\u0442 \u0415\u0421\u0418\u0410 \u043f\u043e \u0435\u0433\u043e sha1 \u0445\u044d\u0448\u0443             $cert = $certlist-&gt;Item(1);             if (!$cert) {                  throw new CannotReadCertificateException('Cannot read the certificate');             }                                        $hd = new \\CPHashedData();                     $hd-&gt;set_DataEncoding(BASE64_TO_BINARY);             switch ($header-&gt;alg) {                case 'GOST3410_2012_256':                    $hd-&gt;set_Algorithm(CADESCOM_HASH_ALGORITHM_CP_GOST_3411_2012_256);                    break;                 case 'GOST3410_2012_512':                    $hd-&gt;set_Algorithm(CADESCOM_HASH_ALGORITHM_CP_GOST_3411_2012_512);                    break;                             default:                    throw new Exception('Invalid signature algorithm');                 }             $hd-&gt;Hash(base64_encode($chunks[0].'.'.$chunks[1]));                     $rs = new \\CPRawSignature();             $rs-&gt;VerifyHash($hd, bin2hex(strrev($_token_signature)), $cert);              \/\/\u0435\u0441\u043b\u0438 \u043f\u043e\u043f\u0430\u043b\u0438 \u043d\u0430 \u044d\u0442\u0443 \u0441\u0442\u0440\u043e\u0447\u043a\u0443, \u0437\u043d\u0430\u0447\u0438\u0442 \u043f\u043e\u0434\u043f\u0438\u0441\u044c \u0432\u0430\u043b\u0438\u0434\u043d\u0430\u044f. \u0418\u043d\u0430\u0447\u0435 \u0431\u044b \u0443\u0436\u0435 \u0431\u044b\u043b\u043e \u0432\u044b\u0437\u0432\u0430\u043d\u043e \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435.             $this-&gt;config-&gt;setOid($payload['urn:esia:sbj_id']);               $this-&gt;config-&gt;setToken($token);         } \/\/ JWT token          return $token;     }<\/code><\/pre>\n<p>\u0423\u0440\u0430. \u0423 \u043d\u0430\u0441 \u0442\u0435\u043f\u0435\u0440\u044c \u0435\u0441\u0442\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u043d\u043e\u0432\u044b\u043c\u0438 endpoint \u0415\u0421\u0418\u0410: <code>buildUrl_V2() \u0438 getToken_V3().<\/code><\/p>\n<\/div>\n<\/div>\n<p> <!----> <!----><\/div>\n<p> <!----> <!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/articles\/736178\/\"> https:\/\/habr.com\/ru\/articles\/736178\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<p>\u041f\u0435\u0440\u0435\u0434\u043e \u043c\u043d\u043e\u0439 \u0431\u044b\u043b\u0430 \u043f\u043e\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0430 \u0437\u0430\u0434\u0430\u0447\u0430 &#171;\u0447\u0442\u043e\u0431\u044b \u043f\u043e\u0441\u0435\u0442\u0438\u0442\u0435\u043b\u0438 \u043c\u043e\u0433\u043b\u0438 \u0432\u043e\u0439\u0442\u0438 \u043d\u0430 \u0441\u0430\u0439\u0442 \u0447\u0435\u0440\u0435\u0437 \u0413\u043e\u0441\u0443\u0441\u043b\u0443\u0433\u0438&#187;. \u0417\u0430\u0434\u0430\u0447\u043a\u0430 \u043d\u0435 \u043d\u043e\u0432\u0430\u044f, \u0434\u0430\u0432\u043d\u043e \u0440\u0435\u0448\u0435\u043d\u0430. \u041d\u0430 PHP \u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442 <a href=\"https:\/\/github.com\/fr05t1k\/esia%20%D0%B8%20https:\/\/github.com\/ekapusta\/oauth2-esia\" rel=\"noopener noreferrer nofollow\">\u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438<\/a>, \u043d\u043e \u0435\u0441\u0442\u044c \u043f\u0430\u0440\u0430 \u043e\u0433\u043e\u0432\u043e\u0440\u043e\u043a.<\/p>\n<h2>\u041f\u0440\u043e\u0431\u043b\u0435\u043c\u0430 1<\/h2>\n<p>\u0421 \u044f\u043d\u0432\u0430\u0440\u044f 2020 \u0434\u043b\u044f \u0438\u043d\u0442\u0435\u0433\u0440\u0430\u0446\u0438\u0438 \u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u0413\u041e\u0421\u0422-\u0448\u0438\u0444\u0440\u043e\u0432\u0430\u043d\u0438\u0435. \u0412\u0430\u0440\u0438\u0430\u043d\u0442\u044b \u0440\u0435\u0448\u0435\u043d\u0438\u044f:<\/p>\n<ul>\n<li>\n<p>\u0434\u0435\u0440\u0433\u0430\u0442\u044c \u0432\u043d\u0435\u0448\u043d\u044e\u044e \u0443\u0442\u0438\u043b\u0438\u0442\u0443, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0443\u043c\u0435\u0435\u0442 \u0413\u041e\u0421\u0422<\/p>\n<\/li>\n<li>\n<p>\u0441\u043e\u0431\u0440\u0430\u0442\u044c php \u0441 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u043e\u0439 \u0413\u041e\u0421\u0422<\/p>\n<\/li>\n<\/ul>\n<p>\u041e\u0431\u0430 \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u0430 \u0442\u0440\u0435\u0431\u0443\u044e\u0442 \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u043b\u0438\u0446\u0435\u043d\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0433\u043e \u043a\u0440\u0438\u043f\u0442\u043e\u0433\u0440\u0430\u0444\u0438\u0447\u0435\u0441\u043a\u043e\u0433\u043e \u0441\u0440\u0435\u0434\u0441\u0442\u0432\u0430 (<a href=\"https:\/\/www.cryptopro.ru\/category\/faq\/linuxunix-0\" rel=\"noopener noreferrer nofollow\">\u041a\u0440\u0438\u043f\u0442\u043e\u041f\u0440\u043e<\/a>), \u0432 \u0440\u0430\u043c\u043a\u0430\u0445 \u0441\u0442\u0430\u0442\u044c\u0438 \u043c\u044b \u043f\u043e\u0439\u0434\u0435\u043c \u043f\u043e \u0432\u0442\u043e\u0440\u043e\u043c\u0443 \u043f\u0443\u0442\u0438. \u0412\u0435\u0441\u044c php \u043c\u043e\u0436\u043d\u043e \u043d\u0435 \u043f\u0435\u0440\u0435\u0441\u043e\u0431\u0438\u0440\u0430\u0442\u044c, \u0432\u0435\u0434\u044c \u0435\u0441\u0442\u044c \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c \u043f\u043b\u0430\u0433\u0438\u043d\u043e\u0432. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0441\u043e\u0431\u0440\u0430\u0442\u044c \u043f\u043b\u0430\u0433\u0438\u043d <a href=\"https:\/\/docs.cryptopro.ru\/cades\/phpcades\" rel=\"noopener noreferrer nofollow\">libphpcades<\/a> \u043e\u0442 \u041a\u0440\u0438\u043f\u0442\u043e\u041f\u0440\u043e. <\/p>\n<p>\u0414\u043b\u044f Debian 11 \u0438 php 7.4 <a href=\"https:\/\/docs.cryptopro.ru\/cades\/phpcades\/phpcades-install\" rel=\"noopener noreferrer nofollow\">\u0438\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u044e <\/a>\u043e\u0442 \u041a\u0440\u0438\u043f\u0442\u043e\u041f\u0440\u043e \u043c\u043d\u0435 \u043f\u0440\u0438\u0448\u043b\u043e\u0441\u044c \u0447\u0443\u0442\u044c \u0434\u043e\u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u043d\u0430\u043f\u0438\u043b\u044c\u043d\u0438\u043a\u043e\u043c. \u0428\u0430\u0433\u0438 2 \u0438 6 \u043f\u0440\u043e\u043f\u0443\u0441\u043a\u0430\u0435\u043c, \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043b\u0438\u0448\u044c \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c \u043f\u0430\u043a\u0435\u0442 php-dev. \u041f\u043e\u0441\u043b\u0435 \u044d\u0442\u043e\u0433\u043e \u043d\u0430 \u0448\u0430\u0433\u0435 7 \u0432 Makefile.unix \u043c\u043e\u0436\u043d\u043e \u0437\u0430\u0434\u0430\u0442\u044c \u043f\u0443\u0442\u044c \u043a \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043e\u0447\u043d\u044b\u043c \u0444\u0430\u0439\u043b\u0430\u043c \u0438\u0437 \u043f\u0430\u043a\u0435\u0442\u0430 php-dev<\/p>\n<p><code>PHPDIR=\/usr\/include\/php\/20190902<\/code><\/p>\n<p>\u0414\u0430\u043b\u0435\u0435 \u043d\u0430 \u0448\u0430\u0433\u0435 8 \u0441\u043a\u0430\u0447\u0438\u0432\u0430\u0435\u043c \u043f\u0430\u0442\u0447 \u0434\u043b\u044f php7 \u0438 \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u0435\u043c \u0435\u0433\u043e \u043a \u0438\u0441\u0445\u043e\u0434\u043d\u044b\u043c \u0444\u0430\u0439\u043b\u0430\u043c libphpcades :<\/p>\n<p><code>cd \/opt\/cprocsp\/src\/phpcades\/<br \/>patch -p0 &lt; \/path\/to\/php7_support.patch<\/code><\/p>\n<p>\u0428\u0430\u0433 &#171;8 \u0438 3\/4 &#171;: \u0427\u0442\u043e\u0431\u044b \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 \u0441\u043e\u0431\u0440\u0430\u043b\u0430\u0441\u044c \u043f\u043e\u0434 debian 11, <a href=\"https:\/\/cryptopro.ru\/forum2\/default.aspx?g=posts&amp;m=121907#post121907\" rel=\"noopener noreferrer nofollow\">\u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c <\/a>\u043a \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430\u043c \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440\u0430 CFLAGS \u0444\u043b\u0430\u0433<\/p>\n<p><code>-fpermissive<\/code><\/p>\n<p>\u0410 \u0438\u0437 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432 \u0441\u0431\u043e\u0440\u043a\u0438 LDFLAGS <a href=\"https:\/\/cryptopro.ru\/forum2\/default.aspx?g=posts&amp;m=129648#post129648\" rel=\"noopener noreferrer nofollow\">\u0443\u0434\u0430\u043b\u044f\u0435\u043c<\/a> \u0444\u043b\u0430\u0433<\/p>\n<p><code>-lcplib<\/code><\/p>\n<p>\u0418 \u043f\u043e\u0441\u043b\u0435 \u044d\u0442\u043e\u0433\u043e \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 \u0443\u0441\u043f\u0435\u0448\u043d\u043e \u0441\u043e\u0431\u0438\u0440\u0430\u0435\u0442\u0441\u044f. \u041f\u043e-\u0445\u043e\u0440\u043e\u0448\u0435\u043c\u0443, \u0442\u0435\u043f\u0435\u0440\u044c \u0441\u043e\u0431\u0440\u0430\u043d\u043d\u0443\u044e libphpcades.so \u043d\u0430\u0434\u043e \u0431\u044b \u043e\u0444\u043e\u0440\u043c\u0438\u0442\u044c \u0432 \u043f\u0430\u043a\u0435\u0442 deb&#8230;<\/p>\n<figure class=\"bordered full-width\"><\/figure>\n<p>\u0422\u0430\u043a \u0447\u0442\u043e \u043d\u0430 \u0448\u0430\u0433\u0435 11 \u0432\u043c\u0435\u0441\u0442\u043e \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0441\u0438\u043c\u043b\u0438\u043d\u043a\u0430 \u043c\u044b \u043f\u0440\u043e\u0441\u0442\u043e \u043a\u043e\u043f\u0438\u0440\u0443\u0435\u043c \u0441\u043e\u0431\u0440\u0430\u043d\u043d\u0443\u044e \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443 \u0432 \u043a\u043e\u043c\u043f\u0430\u043d\u0438\u044e \u043a \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u043c \u043c\u043e\u0434\u0443\u043b\u044f\u043c php<\/p>\n<p><code>cp \/opt\/cprocsp\/src\/phpcades\/libphpcades.so \/usr\/lib\/php\/20190902\/<\/code><\/p>\n<p>\u041f\u043e\u0441\u043b\u0435 \u0447\u0435\u0433\u043e \u0438\u0441\u0445\u043e\u0434\u043d\u044b\u0435 \u0444\u0430\u0439\u043b\u044b \u043d\u0430\u043c \u0443\u0436\u0435 \u043d\u0435 \u043d\u0443\u0436\u043d\u044b, \u0438\u0445 \u043c\u043e\u0436\u043d\u043e \u0443\u0434\u0430\u043b\u0438\u0442\u044c.<\/p>\n<p>\u0414\u043b\u044f \u0442\u0435\u0441\u0442\u043e\u0432\u043e\u0433\u043e \u043a\u043e\u043d\u0442\u0443\u0440\u0430 \u0415\u0421\u0418\u0410 \u0413\u041e\u0421\u0422-\u0441\u0435\u0440\u0442\u0438\u0444\u0438\u043a\u0430\u0442 \u043c\u043e\u0436\u043d\u043e <a href=\"http:\/\/testgost2012.cryptopro.ru\/certsrv\/\" rel=\"noopener noreferrer nofollow\">\u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0441\u0430\u043c\u043e\u0441\u0442\u043e\u044f\u0442\u0435\u043b\u044c\u043d\u043e<\/a>, \u0434\u043b\u044f \u043f\u0440\u043e\u043c\u044b\u0448\u043b\u0435\u043d\u043d\u043e\u0433\u043e &#8212; \u043f\u0440\u0438\u0434\u0435\u0442\u0441\u044f \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0432 \u0443\u043f\u043e\u043b\u043d\u043e\u043c\u043e\u0447\u0435\u043d\u043d\u043e\u043c \u0423\u0434\u043e\u0441\u0442\u043e\u0432\u0435\u0440\u044f\u044e\u0449\u0435\u043c \u0446\u0435\u043d\u0442\u0440\u0435 (\u041e\u0413\u0420\u041d \u0432 \u0441\u0435\u0440\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u0435 \u0434\u043e\u043b\u0436\u0435\u043d \u0441\u043e\u0432\u043f\u0430\u0434\u0430\u0442\u044c \u0441 \u041e\u0413\u0420\u041d \u0432\u0430\u0448\u0435\u0439 \u0418\u0421 \u0432 \u043f\u0440\u043e\u043c\u044b\u0448\u043b\u0435\u043d\u043d\u043e\u043c \u043a\u043e\u043d\u0442\u0443\u0440\u0435 \u0415\u0421\u0418\u0410)<\/p>\n<p>\u041b\u044e\u0431\u044b\u043c \u0441\u043f\u043e\u0441\u043e\u0431\u043e\u043c \u043f\u0435\u0440\u0435\u043d\u043e\u0441\u0438\u043c \u043a\u043b\u044e\u0447 \u0438 \u0441\u0435\u0440\u0442\u0438\u0444\u0438\u043a\u0430\u0442 \u043d\u0430\u0448\u0435\u0439 \u0418\u0421 \u0432 <code>\/var\/opt\/cprocsp\/keys\/www-data\/MYSITE.000<\/code>, \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u043e\u0441\u0442\u044b\u043c \u043a\u043e\u043f\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435\u043c, \u043c\u043e\u0436\u043d\u043e \u043a\u043e\u043c\u0430\u043d\u0434\u043e\u0439<\/p>\n<p><code>sudo -u www-data \/opt\/cprocsp\/bin\/amd64\/csptest -keycopy -contsrc '\\\\.\\FLASH\\ivanoff' -contdest '\\\\.\\HDIMAGE\\MYSITE'<\/code><\/p>\n<p>\u0414\u0430\u043b\u0435\u0435 \u0443\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u043c  \u0441\u0435\u0440\u0442\u0438\u0444\u0438\u043a\u0430\u0442 \u0438 \u0435\u0433\u043e \u0437\u0430\u043a\u0440\u044b\u0442\u044b\u0439 \u043a\u043b\u044e\u0447 \u0432 \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0435 My \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f www-data:<\/p>\n<p><code>sudo -u www-data \/opt\/cprocsp\/bin\/amd64\/certmgr -inst -store uMy -cont '\\\\.\\HDIMAGE\\MYSITE'<\/code><\/p>\n<p>\u0412 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0435 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0438 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c, \u0447\u0442\u043e \u0435\u0441\u0442\u044c \u0441\u0432\u044f\u0437\u044c \u0441\u0435\u0440\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u0430 \u0441 \u043f\u0440\u0438\u0432\u0430\u0442\u043d\u044b\u043c \u043a\u043b\u044e\u0447\u043e\u043c \u0432 \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440\u0435:<\/p>\n<p><code>PrivateKey Link     : Yes<br \/> Container           : \\\\.\\HDIMAGE\\MYSITE<\/code><\/p>\n<p>\u0423\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u043c \u043e\u0442\u043a\u0440\u044b\u0442\u044b\u0439 \u0441\u0435\u0440\u0442\u0438\u0444\u0438\u043a\u0430\u0442 \u0415\u0421\u0418\u0410 \u0432 \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440 Users \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f www-data<\/p>\n<p><code>sudo -u www-data \/opt\/cprocsp\/bin\/amd64\/certmgr -install -store uUsers -file .\/TESIA\\ GOST\\ 2012.cer<br \/>sudo -u www-data \/opt\/cprocsp\/bin\/amd64\/certmgr -install -store uUsers -file .\/GOST\\ 2012\\ PROD.cer<\/code><\/p>\n<h2>\u041f\u0440\u043e\u0431\u043b\u0435\u043c\u0430 2<\/h2>\n<p>\u0421&nbsp;\u0432\u0435\u0440\u0441\u0438\u0438 2.90&nbsp;<a href=\"https:\/\/digital.gov.ru\/ru\/documents\/6186\/\" rel=\"noopener noreferrer nofollow\">\u041c\u0435\u0442\u043e\u0434\u0438\u0447\u0435\u0441\u043a\u0438\u0445 \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0430\u0446\u0438\u0439<\/a> \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u044b\u0439 endpoint \/aas\/oauth2\/ac \u043e\u0431\u044a\u044f\u0432\u043b\u0435\u043d \u0443\u0441\u0442\u0430\u0440\u0435\u0432\u0448\u0438\u043c \u0438 \u043d\u0435&nbsp;\u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u043e\u0432\u0430\u043d \u043a&nbsp;\u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044e. \u041f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u043e \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0438\u0442\u044c \u043d\u0430 \/aas\/oauth2\/v2\/ac, \u0430&nbsp;\u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0432&nbsp;\u0443\u043a\u0430\u0437\u0430\u043d\u043d\u044b\u0445 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430\u0445 \u043d\u0435\u0442. <\/p>\n<p>\u0412\u043e\u0442 \u044d\u0442\u0438\u043c\u2011\u0442\u043e \u043c\u044b \u0441\u0435\u0439\u0447\u0430\u0441 \u0438 \u0437\u0430\u0439\u043c\u0435\u043c\u0441\u044f. \u0421\u043d\u043e\u0432\u0430 \u0434\u043e\u0441\u0442\u0430\u0435\u043c \u043d\u0430\u043f\u0438\u043b\u044c\u043d\u0438\u043a \u0438 \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u0435\u043c \u0435\u0433\u043e \u043d\u0443 \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u043a \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u0447\u043a\u0435 <a href=\"https:\/\/github.com\/fr05t1k\/esia\" rel=\"noopener noreferrer nofollow\">https:\/\/github.com\/fr05t1k\/esia<\/a><\/p>\n<p>\u0414\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u043d\u043e\u0432\u044b\u0435 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0438:<\/p>\n<pre><code class=\"php\">class Config  {   private $tokenUrlPath_V3 = 'aas\/oauth2\/v3\/te';   private $codeUrlPath_V2 = 'aas\/oauth2\/v2\/ac';   protected $ESIACertSHA1 = '01e6041097ccf5a26da1d75fdbb1e7aaee07bd2a'; \/\/ SHA1 \u0445\u044d\u0448 \u0441\u0435\u0440\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u0430 \u0415\u0421\u0418\u0410 (openssl sha1 .\/GOST\\ 2012\\ PROD.cer)   public function getTokenUrl_V3(): string  {     return $this-&gt;portalUrl . $this-&gt;tokenUrlPath_V3;  }<\/code><\/pre>\n<p>\u041d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u043c\u0435\u0442\u043e\u0434\u0430 <code>buildUrl()<\/code> \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u043c\u0435\u0442\u043e\u0434 <code>buildUrl_V2()<\/code>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u0443\u0434\u0435\u0442 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441 endpoint  \u0438\u0437 <code>$codeUrlPath_V2<\/code><\/p>\n<p>\u0412 endpoint &#171;v2\/ac&#187; \u043f\u043e\u043c\u0435\u043d\u044f\u043b\u0441\u044f \u0441\u043e\u0441\u0442\u0430\u0432 \u0438 \u043f\u043e\u0440\u044f\u0434\u043e\u043a \u043a\u043e\u043d\u043a\u0430\u0442\u0435\u043d\u0430\u0446\u0438\u0438 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432 \u0434\u043b\u044f \u0441\u043e\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044f client_secret (\u0442\u0435\u043f\u0435\u0440\u044c \u044d\u0442\u043e ClientID + Scope + Timestamp +State + RedirectURI) \u0438 \u0434\u043e\u0431\u0430\u0432\u0438\u043b\u0441\u044f client_certificate_hash.<\/p>\n<pre><code class=\"php\">class OpenId { protected $clientCertHash = null;  public function buildUrl_V2() {      $timestamp = $this-&gt;getTimeStamp();      $state = $this-&gt;buildState();      \/\/ \u0441\u043e\u0431\u0438\u0440\u0430\u0435\u043c client_secret \u043f\u043e \u043d\u043e\u0432\u044b\u043c \u043f\u0440\u0430\u0432\u0438\u043b\u0430\u043c      $message =  $this-&gt;config-&gt;getClientId()           . $this-&gt;config-&gt;getScopeString()           . $timestamp                    . $state                    . $this-&gt;config-&gt;getRedirectUrl();          \/\/ \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c \u0413\u041e\u0421\u04222012 \u0434\u043b\u044f \u043f\u043e\u0434\u043f\u0438\u0441\u0430\u043d\u0438\u044f           $this-&gt;signer = new SignerCPDataHash(           $config-&gt;getCertPath(),           \/\/ \u0434\u043b\u044f \u041a\u0440\u0438\u043f\u0442\u043e\u041f\u0440\u043e \u044d\u0442\u0438            $config-&gt;getPrivateKeyPath(),     \/\/ \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b \u043d\u0435 \u043d\u0443\u0436\u043d\u044b           $config-&gt;getPrivateKeyPassword(), \/\/ \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u0441\u0435\u0440\u0442\u0438\u0444\u0438\u043a\u0430\u0442 \u0438 \u043a\u043b\u044e\u0447           $config-&gt;getTmpPath()             \/\/ \u0438\u043c\u043f\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u044b \u0432 \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0435      );      $clientSecret = $this-&gt;signer-&gt;sign($message);      $url = $this-&gt;config-&gt;getCodeUrl_V2() . '?%s';      $params = [          'client_id' =&gt; $this-&gt;config-&gt;getClientId(),          'client_secret' =&gt; $clientSecret,          'redirect_uri' =&gt; $this-&gt;config-&gt;getRedirectUrl(),          'scope' =&gt; $this-&gt;config-&gt;getScopeString(),          'response_type' =&gt; $this-&gt;config-&gt;getResponseType(),          'state' =&gt; $state,          'access_type' =&gt; $this-&gt;config-&gt;getAccessType(),          'timestamp' =&gt; $timestamp,          'client_certificate_hash' =&gt; $this-&gt;clientCertHash, \/\/ \u0413\u041e\u0421\u0422-\u0445\u044d\u0448 \u043d\u0430\u0448\u0435\u0433\u043e \u0441\u0435\u0440\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u0430           ];      $request = http_build_query($params);            return sprintf($url, $request);  }<\/code><\/pre>\n<p>\u0414\u0430, client_certificate_hash \u043c\u043e\u0436\u043d\u043e \u0432\u044b\u0447\u0438\u0441\u043b\u0438\u0442\u044c \u043f\u0440\u0435\u0434\u043b\u0430\u0433\u0430\u0435\u043c\u043e\u0439 \u0432 \u041c\u0435\u0442\u043e\u0434\u0438\u0447\u0435\u0441\u043a\u0438\u0445 \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0430\u0446\u0438\u044f\u0445 \u0443\u0442\u0438\u043b\u0438\u0442\u043e\u0439 \u0438 \u0432\u043f\u0438\u0441\u0430\u0442\u044c \u043a\u0430\u043a \u0435\u0449\u0435 \u043e\u0434\u0438\u043d \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0438. \u0412\u043e\u0437\u043c\u043e\u0436\u043d\u043e, \u0442\u0430\u043a \u0434\u0430\u0436\u0435 \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e. \u041d\u043e \u043f\u043e\u0447\u0435\u043c\u0443 \u0431\u044b \u043d\u0435 \u043d\u0430\u0443\u0447\u0438\u0442\u044c\u0441\u044f \u0432\u044b\u0447\u0438\u0441\u043b\u044f\u0442\u044c \u0435\u0433\u043e \u0441\u0430\u043c\u043e\u0441\u0442\u043e\u044f\u0442\u0435\u043b\u044c\u043d\u043e?<\/p>\n<p>\u0418\u0442\u0430\u043a, \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u043a\u043b\u0430\u0441\u0441 SignerCPDataHash, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 libphpcades \u0434\u043b\u044f \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f \u0413\u041e\u0421\u0422 \u0445\u044d\u0448\u0430 \u0441\u0435\u0440\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u0430 \u0418\u0421 (\u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 <code>client_certificate_hash<\/code>) \u0438 \u043f\u043e\u0434\u043f\u0438\u0441\u0430\u043d\u0438\u044f <code>client_secret<\/code> \u043f\u043e \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0443 data hash.<\/p>\n<p>\u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0441\u0435\u0440\u0442\u0438\u0444\u0438\u043a\u0430\u0442 \u0441 CN=ClientID \u0438\u0437 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u043e\u0433\u043e \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0430 My \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d\u043d\u043e\u0433\u043e \u041a\u0440\u0438\u043f\u0442\u043e\u041f\u0440\u043e. <\/p>\n<pre><code class=\"php\">class SignerCPDataHash extends AbstractSignerPKCS7 implements SignerInterface {     public function sign(string $message): string     {         $store = new \\CPStore();         $store-&gt;Open(CURRENT_USER_STORE, 'My', STORE_OPEN_READ_ONLY); \/\/ \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0435 My \u0442\u0435\u043a\u0443\u0449\u0435\u0433\u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f (www-data)         $certs = $store-&gt;get_Certificates();         $certlist = $certs-&gt;Find(CERTIFICATE_FIND_SUBJECT_NAME, $this-&gt;config-&gt;getClientId(), 0); \/\/ \u0438\u0449\u0435\u043c \u0441\u0435\u0440\u0442\u0438\u0444\u0438\u043a\u0430\u0442, \u0443 \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e\u0435 Subject = \u043c\u043d\u0435\u043c\u043e\u043d\u0438\u043a\u0435 \u043d\u0430\u0448\u0435\u0439 \u0418\u0421         $cert = $certlist-&gt;Item(1);         if (!$cert) {             throw new CannotReadCertificateException('Cannot read the certificate');         }                 \/\/ \u0443 \u0441\u0435\u0440\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u0430 \u0434\u043e\u043b\u0436\u043d\u0430 \u0431\u044b\u0442\u044c \u0441\u0432\u044f\u0437\u043a\u0430 \u0441 \u0437\u0430\u043a\u0440\u044b\u0442\u044b\u043c \u043a\u043b\u044e\u0447\u043e\u043c         if (false===$cert-&gt;HasPrivateKey()) {             throw new CannotReadPrivateKeyException('Cannot read the private key');         }                  $pk=$cert-&gt;PublicKey();         $oid=$pk-&gt;get_Algorithm();                           $hd = new \\CPHashedData();             switch ($oid-&gt;get_Value()) { \/\/ https:\/\/cpdn.cryptopro.ru\/content\/csp40\/html\/group___pro_c_s_p_ex_DP8.html             case '1.2.643.7.1.1.1.1':                 $hd-&gt;set_Algorithm(CADESCOM_HASH_ALGORITHM_CP_GOST_3411_2012_256);                 break;             case '1.2.643.7.1.1.1.2':                 $hd-&gt;set_Algorithm(CADESCOM_HASH_ALGORITHM_CP_GOST_3411_2012_512);                 break;         }         $hd-&gt;set_DataEncoding(BASE64_TO_BINARY);         $hd-&gt;Hash($cert-&gt;Export(ENCODE_BASE64));               $this-&gt;clientCertHash=$hd-&gt;get_Value(); \/\/\u043f\u043e\u043b\u0443\u0447\u0438\u043b\u0438 \u0413\u041e\u0421\u0422 \u0445\u044d\u0448 \u043d\u0430\u0448\u0435\u0433\u043e \u0441\u0435\u0440\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u0430         unset($hd);          $hd = new \\CPHashedData();                 $hd-&gt;set_Algorithm(CADESCOM_HASH_ALGORITHM_CP_GOST_3411_2012_256);         $hd-&gt;set_DataEncoding(BASE64_TO_BINARY);         $hd-&gt;Hash(base64_encode($message)); \/\/ \u043f\u043e\u0441\u0447\u0438\u0442\u0430\u043b\u0438 \u0413\u041e\u0421\u0422 \u0445\u044d\u0448 \u0434\u043b\u044f $message         $rs = new \\CPRawSignature();         $shash=$rs-&gt;SignHash($hd, $cert); \/\/ https:\/\/docs.cryptopro.ru\/cades\/reference\/cadescom\/cadescom_interface\/irawsignaturesignhash :  \u041f\u043e\u0434\u043f\u0438\u0441\u044c \u0434\u043b\u044f \u043a\u043b\u044e\u0447\u0435\u0439 \u0413\u041e\u0421\u0422 \u0420 34.10-2001 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442\u0441\u044f \u043a\u0430\u043a \u043e\u043f\u0438\u0441\u0430\u043d\u043e \u0432 \u0440\u0430\u0437\u0434\u0435\u043b\u0435 2.2.2 RFC 4491 (http:\/\/tools.ietf.org\/html\/rfc4491#section-2.2.2), \u043d\u043e \u0432 \u043e\u0431\u0440\u0430\u0442\u043d\u043e\u043c \u043f\u043e\u0440\u044f\u0434\u043a\u0435 \u0431\u0430\u0439\u0442.         $signed=base64_encode(strrev(hex2bin($shash))); \/\/ \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u0438 \u043f\u043e\u0434\u043f\u0438\u0441\u0430\u043d\u043d\u044b\u0439 data hash          $sign = str_replace(\"\\n\", '', $this-&gt;urlSafe($signed));         return $sign;     } } <\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u0437\u0430\u0439\u043c\u0435\u043c\u0441\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435\u043c \u0438 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u043e\u0439 JWT \u0442\u043e\u043a\u0435\u043d\u0430:<\/p>\n<pre><code class=\"php\">    public function getToken_V3(string $code): string     {         $timestamp = $this-&gt;getTimeStamp();         $state = $this-&gt;buildState();          $this-&gt;signer = new SignerCPDataHash(             $config-&gt;getCertPath(),             $config-&gt;getPrivateKeyPath(),             $config-&gt;getPrivateKeyPassword(),             $config-&gt;getTmpPath()         );          $clientSecret = $this-&gt;signer-&gt;sign(               $this-&gt;config-&gt;getClientId()             . $this-&gt;config-&gt;getScopeString()             . $timestamp             . $state             . $this-&gt;config-&gt;getRedirectUrl();         );          $body = [             'client_id' =&gt; $this-&gt;config-&gt;getClientId(),             'code' =&gt; $code,             'grant_type' =&gt; 'authorization_code',             'client_secret' =&gt; $clientSecret,             'state' =&gt; $state,             'redirect_uri' =&gt; $this-&gt;config-&gt;getRedirectUrl(),             'scope' =&gt; $this-&gt;config-&gt;getScopeString(),             'timestamp' =&gt; $timestamp,             'token_type' =&gt; 'Bearer',             'refresh_token' =&gt; $state,             'client_certificate_hash' =&gt; $this-&gt;clientCertHash,         ];          $payload = $this-&gt;sendRequest(             new Request(                 'POST',                 $this-&gt;config-&gt;getTokenUrl_V3(),                 [                     'Content-Type' =&gt; 'application\/x-www-form-urlencoded',                 ],                 http_build_query($body)             )         );          $this-&gt;logger-&gt;debug('Payload: ', $payload);          $token = $payload['access_token'];          $chunks = explode('.', $token);         $payload = json_decode($this-&gt;base64UrlSafeDecode($chunks[1]), true);         $header = json_decode($this-&gt;base64UrlSafeDecode($chunks[0]), true);<\/code><\/pre>\n<\/p>\n<\/p>\n<\/div>\n<\/div>\n<\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-347632","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/347632","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=347632"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/347632\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=347632"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=347632"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=347632"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}