ahs9/eds-checker

There is no license information available for the latest version (1.0) of this package.

1.0 2022-08-25 09:59 UTC

This package is auto-updated.

Last update: 2024-04-26 06:48:19 UTC


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