After extensive research:
pkcs11-tool --sign command produces a binary result of selected hashing algorithm that isn't a PKCS structure itself but can be used with a 3rd party library to generate something asn1 compliant; it's a tedious and not recommended process but it's possible to build a verifiable pkcs7-signedData signature.
openssl smime -sign command is recommended; it needs to be configured to use the pkcs11 engine with the same module as pkcs11-tool and can build the PKCS#7 structure without additional libs.
OpenSSL config file example:
openssl_conf = openssl_def
[openssl_def]
engines = engine_section
[engine_section]
pkcs11 = pkcs11_section
[pkcs11_section]
dynamic_path = /usr/lib/x86_64-linux-gnu/openssl-1.0.0/engines/pkcs11.so
engine_id = pkcs11
MODULE_PATH = ./VdsPKCS1164.so
PIN = 1234
default_algorithms = ALL
init = 1
Command to generate PKCS#7 signature example:
$ echo foobar > input.data
$ OPENSSL_CONF=./openssl.cnf openssl smime -sign -engine pkcs11 \
-md sha1 -binary -in input.data -out foo.sig -outform der \
-keyform engine -inkey id_5378 -certfile extra.cert.pem -signer cert.pem
File cert.pem (and any extra certs if required) can be extracted from the token card and converted to PEM with:
$ pkcs11-tool --module ./VdsPKCS1164.so --login --pin $PIN \
--read-object --type cert -id 5378 --output-file cert.crt
$ openssl x509 -inform der -in cert.crt -out cert.pem