ahs9 / eds-checker
Installs: 9
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
pkg:composer/ahs9/eds-checker
Requires
- php: ~7.1.0 || ~7.2.0 || ~7.3.0 || ~7.4.0 || ~8.0.0 || ~8.1.0
- fgrosse/phpasn1: ^2.4
README
Installation
$ composer require ahs9/eds-checker
Usage
Use this library to compare user-data (from DB or from POST) with data in certificate (electronic digital signature).
Examples
Creating template
Certificates have different structure. Template shows to parser where user-data is. If template will be deep not enough,
parser will find duplicates of oid. For example, certificate has several keys 1.2.643.3.131.1.1
.
OID duplicates will throw exception. Template example:
$template = [ ParserAsn::TEMPLATE_SEQUENCE => [ ParserAsn::TEMPLATE_ARRAY => [ 0 => [ ParserAsn::TEMPLATE_ARRAY => [ 0 => null, 1 => null, 2 => null, 3 => null, 4 => null, 5 => ParserAsn::TEMPLATE_RESULT ] ] ] ] ];
Creating parser-object
$parser = new ParserAsn( $signature, // base64 encoded binary certificate [ CertificateItem::OID_INN, CertificateItem::OID_SURNAME, CertificateItem::OID_GIVEN_NAME, ], $template );
Debugging template
For debugging your template use ParserAsn::getSplitedAsn(). You can dump result when you fill out the template step by step. Every step of template should deepen the ASN object. You need to get a part of certificate with no duplicates of oid.
$template = [ ParserAsn::TEMPLATE_SEQUENCE => [] ]; var_dump($parser->getSplitedAsn());
then
$template = [ ParserAsn::TEMPLATE_SEQUENCE => [ ParserAsn::TEMPLATE_ARRAY => [ 0 => [] ] ] ]; var_dump($parser->getSplitedAsn());
deeper and deeper until you get user-data
Getting parse-result
$certificateData = $parser->getComparedData();
Creating data-object for comparing from post
$userData = new ComparedData( [ CertificateItem::OID_INN => $post['inn'], CertificateItem::OID_SURNAME => $post['surname'] CertificateItem::OID_GIVEN_NAME => $post['secondName'] . ' ' . $post['lastName'] ] );
Comparing
$checker = new Checker($userData, $certificateData); if (!$checker->compare()) { var_dump($checker->getErrors()); } // do staff