openssl pkcs12 -in container.p12 -out key.pem -legacy -nocerts -nodes
openssl pkcs12 -in container.p12 -out certificate.pem -legacy -nokeys -nodes
openssl x509 -inform der -in certificate.cer -out certificate.pem
This requires a combination of some of the earlier demonstrated commands:
First, extract the key from the existing P12 container:
openssl pkcs12 -in container.p12 -out key.pem -legacy -nocerts -nodes
If you don't already have the certificate in a separate file, extract that from the P12 container too:
openssl pkcs12 -in container.p12 -out certificate.pem -legacy -nokeys -nodes
Then, concatenate the certificate and the intermediate certificates:
cat certificate.pem intermediate.pem > certs.pem
Finally, merge everything back in a new P12 container:
openssl pkcs12 -export -out all.p12 -inkey key.pem -in certs.pem