I have this code working fine. I am signing with an USB eToken. But after copying and pasting the PEM output of this code in the https://lapo.it/asn1js/ the trust chain is not shown. This eToken was provided by a CA and thus it has a trust chain of the signature. What's wrong?
lib = pkcs11.lib('/usr/lib/libeToken.so.9')
for slot in lib.get_slots():
try:
token = slot.get_token()
with token.open(user_pin='****') as session:
priv = session.get_key(object_class=pkcs11.constants.ObjectClass.PRIVATE_KEY)
pub = session.get_key(object_class=pkcs11.constants.ObjectClass.PUBLIC_KEY)
tbs = TbsCertificate({
'version': 'v1',
'serial_number': 1,
'issuer': Name.build({
'common_name': 'Test Certificate',
}),
'subject': Name.build({
'common_name': 'Test Certificate',
}),
'signature': {
'algorithm': 'sha256_rsa',
'parameters': None,
},
'validity': {
'not_before': Time({
'utc_time': datetime.datetime(2017, 1, 1, 0, 0),
}),
'not_after': Time({
'utc_time': datetime.datetime(2038, 12, 31, 23, 59),
}),
},
'subject_public_key_info': {
'algorithm': {
'algorithm': 'rsa',
'parameters': None,
},
'public_key': RSAPublicKey.load(encode_rsa_public_key(pub)),
}
})
# Sign the TBS Certificate
value = priv.sign(tbs.dump(),
mechanism=Mechanism.SHA256_RSA_PKCS)
cert = Certificate({
'tbs_certificate': tbs,
'signature_algorithm': {
'algorithm': 'sha256_rsa',
'parameters': None,
},
'signature_value': value,
})
print(pem.armor('CERTIFICATE', cert.dump()).decode())
except TokenNotPresent:
pass