~myers-1/pyopenssl/npn

« back to all changes in this revision

Viewing changes to OpenSSL/crypto/x509.c

  • Committer: Jean-Paul Calderone
  • Date: 2011-04-07 02:19:52 UTC
  • mfrom: (142.1.13 subjectAltName)
  • Revision ID: exarkun@divmod.com-20110407021952-c464twfn6f3j0uvf
Add more access to certificate extension data

Show diffs side-by-side

added added

removed removed

Lines of Context:
13
13
#include <Python.h>
14
14
#define crypto_MODULE
15
15
#include "crypto.h"
 
16
#include "x509ext.h"
16
17
 
17
18
/*
18
19
 * X.509 is a standard for digital certificates.  See e.g. the OpenSSL homepage
300
301
 
301
302
    py_pkey = crypto_PKey_New(pkey, 1);
302
303
    if (py_pkey != NULL) {
303
 
        py_pkey->only_public = 1;
 
304
        py_pkey->only_public = 1;
304
305
    }
305
306
    return (PyObject *)py_pkey;
306
307
}
685
686
    return Py_None;
686
687
}
687
688
 
 
689
static char crypto_X509_get_extension_count_doc[] = "\n\
 
690
Get the number of extensions on the certificate.\n\
 
691
\n\
 
692
@return: Number of extensions as a Python integer\n\
 
693
";
 
694
 
 
695
static PyObject *
 
696
crypto_X509_get_extension_count(crypto_X509Obj *self, PyObject *args) {
 
697
    if (!PyArg_ParseTuple(args, ":get_extension_count")) {
 
698
        return NULL;
 
699
    }
 
700
 
 
701
    return PyLong_FromLong((long)X509_get_ext_count(self->x509));
 
702
}
 
703
 
 
704
static char crypto_X509_get_extension_doc[] = "\n\
 
705
Get a specific extension of the certificate by index.\n\
 
706
\n\
 
707
@param index: The index of the extension to retrieve.\n\
 
708
@return: The X509Extension object at the specified index.\n\
 
709
";
 
710
 
 
711
static PyObject *
 
712
crypto_X509_get_extension(crypto_X509Obj *self, PyObject *args) {
 
713
    crypto_X509ExtensionObj *extobj;
 
714
    int loc;
 
715
    X509_EXTENSION *ext;
 
716
 
 
717
    if (!PyArg_ParseTuple(args, "i:get_extension", &loc)) {
 
718
        return NULL;
 
719
    }
 
720
 
 
721
    /* will return NULL if loc is outside the range of extensions,
 
722
       not registered as an error*/
 
723
    ext = X509_get_ext(self->x509, loc);
 
724
    if (!ext) {
 
725
        PyErr_SetString(PyExc_IndexError, "extension index out of bounds");
 
726
        return NULL; /* Should be reported as an IndexError ? */
 
727
    }
 
728
 
 
729
    extobj = PyObject_New(crypto_X509ExtensionObj, &crypto_X509Extension_Type);
 
730
    extobj->x509_extension = X509_EXTENSION_dup(ext);
 
731
 
 
732
    return (PyObject*)extobj;
 
733
}
 
734
 
688
735
/*
689
736
 * ADD_METHOD(name) expands to a correct PyMethodDef declaration
690
737
 *   {  'name', (PyCFunction)crypto_X509_name, METH_VARARGS }
715
762
    ADD_METHOD(subject_name_hash),
716
763
    ADD_METHOD(digest),
717
764
    ADD_METHOD(add_extensions),
 
765
    ADD_METHOD(get_extension),
 
766
    ADD_METHOD(get_extension_count),
718
767
    { NULL, NULL }
719
768
};
720
769
#undef ADD_METHOD