*** M2Crypto/SMIME.py Sat Mar 31 04:09:38 2001 --- M2Crypto/SMIME.py Wed Jun 12 11:49:04 2002 *************** *** 54,59 **** --- 54,64 ---- def write_der(self, bio): return m2.pkcs7_write_bio_der(self.pkcs7, bio._ptr()) + def get_cert_chain(self): + """If the pkcs7 blob is decrypted, return the included + certificate chain""" + cert_chain = m2.pkcs7_get_cert_chain(self.pkcs7) + return [X509.X509(cert) for cert in cert_chain] def load_pkcs7(p7file): bio = m2.bio_new_file(p7file, 'r') *** swig/_pkcs7.i Sat Jul 21 03:06:24 2001 --- swig/_pkcs7.i Wed Jun 12 11:47:57 2002 *************** *** 143,148 **** --- 143,178 ---- return tuple; } + /* Given a decrypted PKCS7 structure containing a signature, will + return a list representing the included certificate chain */ + PyObject *pkcs7_get_cert_chain(PKCS7 *p7) { + STACK_OF(X509) *certs = NULL; + X509 *x; + PyObject *list, *_x; + int num_certs, i; + + certs = p7->d.sign->cert; + + if (certs != NULL) + { + num_certs = sk_X509_num(certs); + if (!(list = PyList_New(num_certs))) { + PyErr_SetString(PyExc_RuntimeError, "pkcs7_get_cert_chain: PyList_new"); + return NULL; + } + for (i = 0; i < num_certs; i++) { + x = sk_X509_value(certs, i); + _x = SWIG_NewPointerObj((void *)x, SWIGTYPE_p_X509); + PyList_SET_ITEM(list, i, _x); + } + return list; + } else { + Py_INCREF(Py_None); + return Py_None; + } + + } + PKCS7 *pkcs7_read_bio(BIO *bio) { return PEM_read_bio_PKCS7(bio, NULL, NULL, NULL); }