ylly/certsign

PHP Library for CertSign by CertEurope

1.6.1 2021-11-17 16:04 UTC

This package is auto-updated.

Last update: 2024-05-17 21:51:05 UTC


README

This library allows you to easily implement CertSign by CertEurope into your project.

Build Status

Require :

  • PHP 5.4+
  • PHP CURL
  • PHP GD
  • PHP compiled with FreeType support, else the provided image generation service will fallback to standard text

Limitations :

  • Only SYNC sign mode is implemented

Installation :

composer require ylly/certsign

Usage :

Convert the certificate

This library use a PEM certificate, as CertSign provide a P12 file, you need to convert this certificate into the PEM

You will need to enter the certificate's password (you can use the -passin 'pass:my_password' argument)

openssl pkcs12 -in cert.p12 -out cert.pem

Create a signator

The signator manage authentication and signature

You can create a signator from a YAML config file

$signator = SignatorFactory::createFromYamlFile('/path/to/config.yml');

Or from an key-value array of configuration

$signator = SignatorFactory::createFromArray($configArray);

Fill user informations and documents

The users informations and documents are stored in a signature request

$signature = Signature::create()->setImage('/path/to/sign.png', false);
//$signature = Signature::create()->setImage('BASE64');
//$signature = Signature::create()->setImage(new Image(...));

$request = Request::create()
    ->setHolder('Firstname', 'Lastname', 'certsign@ylly.fr', '0601020304')
    ->addDocument('Document-1', '/path/to/doc.pdf', $signature, false)
    ->addDocument('Document-2', 'BASE64', $signature);

Sign documents

You have two ways to sign documents, with or without authentication

The authentication can be handled by email or SMS

With authentication (OTP)

$request->setOTP('0601020304'); // Will send a SMS
//$request->setOTP('certsign@ylly.fr'); // Will send an Email

// Generate the order, returns the order ID
$orderId = $signator->createOrder($request);

// Send the OTP, can be reused to generate a new OTP
$signator->validate($orderId);

// Create the signature request with the documents and signature image
$signator->createRequest($request, $orderId);

// Enter OTP given by SMS or Email, will return false if the code is invalid
// Returns the signed documents
$documents = $signator->sign($orderId, 'MyOTP');

Without authentication (Direct sign)

// Generate the order, returns the order ID
$orderId = $signator->createOrder($request);

// Create the signature request with the documents and signature image
$signator->createRequest($request, $orderId);

// Returns the signed documents
$documents = $signator->sign($orderId);

Configuration file :

env: test # or prod
cert: /etc/ssl/certsign.pem
cert_password: password
proxy: locahost:8080 # optionnal web proxy

Advanced usage :

A Log interface is provided to manage outputed logs, you can register your listener on the signator

class Listener implement LogListenerInterface
{
    public function recieve($level, $message)
    {
        // do something
    }
}

$signator->addListener(new Listener());

Instead of using a static image, you can generate a simple image using the following scripts :

$image = new Image(100, 50, new Color(255, 255, 255));
$image->setStyle(new TextStyle(0, 0, 12, 2, new Color(0, 0, 0));
$image->addText('SignText');