# Step by step to generate sample self-signed X.509 certificate chain and sign data with PKCS7 structure
This readme demonstrates how to generate 3-layer X.509 certificate chain (RootCA -> IntermediateCA -> SigningCert) with OpenSSL commands, and user MUST set a UNIQUE Subject Name ("Common Name") on these three different certificates.
## How to generate a self-signed X.509 certificate chain via OPENSSL
* Set OPENSSL environment.
NOTE: Below steps are required for Windows. Linux may already have the OPENSSL environment correctly.
set OPENSSL_HOME=c:\home\openssl\openssl-[version]
set OPENSSL_CONF=%OPENSSL_HOME%\apps\openssl.cnf
When a user uses OpenSSL (req or ca command) to generate the certificates, OpenSSL will use the openssl.cnf file as the configuration data (can use “-config path/to/openssl.cnf” to describe the specific config file).
The user need check the openssl.cnf file, to find your CA path setting, e.g. check if the path exists in [ CA_default ] section.
[ CA_default ]
dir = ./demoCA # Where everything is kept
You may need the following steps for initialization:
OpenSSL will apply the options from the specified sections in openssl.cnf when creating certificates or certificate signing requests. Make sure your configuration in openssl.cnf is correct and rational for certificate constraints.
The following sample sections were used when generating test certificates in this readme.
...
[ req ]
default_bits = 2048
default_keyfile = privkey.pem
distinguished_name = req_distinguished_name
attributes = req_attributes
x509_extensions = v3_ca # The extensions to add to the self signed cert