I work for a company that has our servers and computer locked down tighter than … well imagine something really tight. This means I can not use composer or install it without mountains of paperwork. I am a developer, normally programming in JS and not php, but for this project I need to get CAC X509 information off smart cards. I have been at it for about 4 hours now trying to get the phpseclib to work. Mind you, I barely understand php. I am following the directions from github and the website, mainly I have downloaded and unzipped the files for 2.0 and placed them in my directory, I am following the examples from the website such as http://phpseclib.sourceforge.net/x509/2.0/examples.html#getpublickey . but when ever I do:
$x509 = new X509();
$x509->loadX509($_SERVER['SSL_CLIENT_CERT']);
echo $x509->getPublicKey();
I get the error:
Fatal error: Class ‘X509’ not found in …
I have also tried other things such as including the directory to the file like:
$x509 = new phpseclibFileX509();
$x509->loadX509($_SERVER['SSL_CLIENT_CERT']);
echo $x509->getPublicKey();
and (new phpseclib_File_X509) get the error:
Fatal error: Class ‘phpseclibFileX509’ not found in …
Please help! I have never had to do an autoload and I have a feeling this is the issue? Like the files aren’t loading? I have also done both below at separate times as well to no avail.
include'phpseclib/File/X509.php';
use phpseclibFileX509;
When I put the error log in X509 to check there I get that ASN1 not found as well.
EDIT: Also would help to know that my php version is 5.5.26
3
Answers
You need to follow standard Composer project setup instructions, Larry. After that, you follow instructions on phpseclib with Composer by doing
from within root project directory. After that you will not be required to use include/require from examples on the Sourceforge site as those do not use autoload feature of Composer – you follow this example to make use of it.
You could use the latest 1.0.x version, which doesn’t require an autoloader at all (and is still maintained):
http://sourceforge.net/projects/phpseclib/files/phpseclib1.0.18.zip/download
Alternatively, you /can/ use the latest 2.0.x version if you supply your own autoloader. http://phpseclib.sourceforge.net/2.0.html demos this:
This approach lets you use 2.0.x without needing to do composer require phpseclib/phpseclib on the CLI.
Any Composer library can be used as a stand-alone application include, and can be obtained from any computer with Composer installed, then uploaded to another machine.
Linux shell example:
This will result in a folder structure as follows:
The files
composer.json
andcomposer.lock
can be ignored. The "vendor" directory can be changed to any other name if desired. In this example, say it’s changed to the application name, "phpseclib" for clarity.In any PHP application, use the Composer downloaded library as a stand-alone include as follows: