blob: adb6509ea2ca6c7454d29c39652004e3000b1cc5 [file] [log] [blame]
Jean-Paul Calderone897bc252008-02-18 20:50:23 -05001/*
2 * crypto.h
3 *
Jean-Paul Calderone8671c852011-03-02 19:26:20 -05004 * Copyright (C) AB Strakt
5 * See LICENSE for details.
Jean-Paul Calderone897bc252008-02-18 20:50:23 -05006 *
7 * Exports from crypto.c.
8 * See the file RATIONALE for a short explanation of why this module was written.
9 *
10 * Reviewed 2001-07-23
11 *
Jean-Paul Calderone897bc252008-02-18 20:50:23 -050012 */
13#ifndef PyOpenSSL_CRYPTO_H_
14#define PyOpenSSL_CRYPTO_H_
15
16#include <Python.h>
Jason R. Coombs7301d8c2011-03-25 22:17:57 -040017/* Work around a bug in OpenSSL 1.0.0 which is caused by winsock.h being
18 included (from dtls1.h) too late by the OpenSSL header files, overriding
19 the fixes (in ossl_typ.h) for symbol clashes caused by this OS header
20 file.
21
22 In order to have those fixes still take effect, we include winsock.h
23 here, prior to including any OpenSSL header files.
24
25 */
26#ifdef _WIN32
27# include "winsock.h"
28#endif
29
Jean-Paul Calderone897bc252008-02-18 20:50:23 -050030#include "x509.h"
31#include "x509name.h"
32#include "netscape_spki.h"
33#include "x509store.h"
34#include "x509req.h"
35#include "pkey.h"
36#include "x509ext.h"
37#include "pkcs7.h"
38#include "pkcs12.h"
Rick Dean536ba022009-07-24 23:57:27 -050039#include "crl.h"
40#include "revoked.h"
Jean-Paul Calderone897bc252008-02-18 20:50:23 -050041#include "../util.h"
42
43extern PyObject *crypto_Error;
44
Jean-Paul Calderone897bc252008-02-18 20:50:23 -050045#define crypto_X509_New_NUM 0
46#define crypto_X509_New_RETURN crypto_X509Obj *
47#define crypto_X509_New_PROTO (X509 *, int)
48
49#define crypto_X509Req_New_NUM 1
50#define crypto_X509Req_New_RETURN crypto_X509ReqObj *
51#define crypto_X509Req_New_PROTO (X509_REQ *, int)
52
53#define crypto_X509Store_New_NUM 2
54#define crypto_X509Store_New_RETURN crypto_X509StoreObj *
55#define crypto_X509Store_New_PROTO (X509_STORE *, int)
56
57#define crypto_PKey_New_NUM 3
58#define crypto_PKey_New_RETURN crypto_PKeyObj *
59#define crypto_PKey_New_PROTO (EVP_PKEY *, int)
60
61#define crypto_X509Name_New_NUM 4
62#define crypto_X509Name_New_RETURN crypto_X509NameObj *
63#define crypto_X509Name_New_PROTO (X509_NAME *, int)
64
65#define crypto_X509Extension_New_NUM 5
66#define crypto_X509Extension_New_RETURN crypto_X509ExtensionObj *
Rick Dean47262da2009-07-08 16:17:17 -050067#define crypto_X509Extension_New_PROTO (char *, int, char *, crypto_X509Obj *, crypto_X509Obj *)
Jean-Paul Calderone897bc252008-02-18 20:50:23 -050068
69#define crypto_PKCS7_New_NUM 6
70#define crypto_PKCS7_New_RETURN crypto_PKCS7Obj *
71#define crypto_PKCS7_New_PROTO (PKCS7 *, int)
72
73#define crypto_NetscapeSPKI_New_NUM 7
74#define crypto_NetscapeSPKI_New_RETURN crypto_NetscapeSPKIObj *
75#define crypto_NetscapeSPKI_New_PROTO (NETSCAPE_SPKI *, int)
76
77#define crypto_API_pointers 8
78
Jean-Paul Calderonebf82f572010-08-11 22:40:44 -040079#if defined(PY3) || defined(crypto_MODULE)
Jean-Paul Calderone897bc252008-02-18 20:50:23 -050080
Jean-Paul Calderonedb33e632010-10-31 23:45:30 -040081#ifdef _WIN32
82#define EXPORT __declspec(dllexport)
83#else
84#define EXPORT
85#endif
86
87extern EXPORT crypto_X509_New_RETURN crypto_X509_New crypto_X509_New_PROTO;
88extern EXPORT crypto_X509Name_New_RETURN crypto_X509Name_New crypto_X509Name_New_PROTO;
Jean-Paul Calderone897bc252008-02-18 20:50:23 -050089extern crypto_X509Req_New_RETURN crypto_X509Req_New crypto_X509Req_New_PROTO;
Jean-Paul Calderonedb33e632010-10-31 23:45:30 -040090extern EXPORT crypto_X509Store_New_RETURN crypto_X509Store_New crypto_X509Store_New_PROTO;
Jean-Paul Calderone897bc252008-02-18 20:50:23 -050091extern crypto_PKey_New_RETURN crypto_PKey_New crypto_PKey_New_PROTO;
92extern crypto_X509Extension_New_RETURN crypto_X509Extension_New crypto_X509Extension_New_PROTO;
93extern crypto_PKCS7_New_RETURN crypto_PKCS7_New crypto_PKCS7_New_PROTO;
94extern crypto_NetscapeSPKI_New_RETURN crypto_NetscapeSPKI_New crypto_NetscapeSPKI_New_PROTO;
95
Jean-Paul Calderone7b643a92010-08-28 14:40:58 -040096int crypto_byte_converter(PyObject *input, void *output);
97
Jean-Paul Calderone897bc252008-02-18 20:50:23 -050098#else /* crypto_MODULE */
99
100extern void **crypto_API;
101
102#define crypto_X509_New \
103 (*(crypto_X509_New_RETURN (*)crypto_X509_New_PROTO) crypto_API[crypto_X509_New_NUM])
104#define crypto_X509Name_New \
105 (*(crypto_X509Name_New_RETURN (*)crypto_X509Name_New_PROTO) crypto_API[crypto_X509Name_New_NUM])
106#define crypto_X509Req_New \
107 (*(crypto_X509Req_New_RETURN (*)crypto_X509Req_New_PROTO) crypto_API[crypto_X509Req_New_NUM])
108#define crypto_X509Store_New \
109 (*(crypto_X509Store_New_RETURN (*)crypto_X509Store_New_PROTO) crypto_API[crypto_X509Store_New_NUM])
110#define crypto_PKey_New \
111 (*(crypto_PKey_New_RETURN (*)crypto_PKey_New_PROTO) crypto_API[crypto_PKey_New_NUM])
112#define crypto_X509Extension_New\
113 (*(crypto_X509Extension_New_RETURN (*)crypto_X509Extension_New_PROTO) crypto_API[crypto_X509Extension_New_NUM])
114#define crypto_PKCS7_New \
115 (*(crypto_PKCS7_New_RETURN (*)crypto_PKCS7_New_PROTO) crypto_API[crypto_PKCS7_New_NUM])
116#define crypto_NetscapeSPKI_New \
117 (*(crypto_NetscapeSPKI_New_RETURN (*)crypto_NetscapeSPKI_New_PROTO) crypto_API[crypto_NetscapeSPKI_New_NUM])
118
119#define import_crypto() \
120{ \
121 PyObject *crypto_module = PyImport_ImportModule("OpenSSL.crypto"); \
122 if (crypto_module != NULL) { \
123 PyObject *crypto_dict, *crypto_api_object; \
124 crypto_dict = PyModule_GetDict(crypto_module); \
125 crypto_api_object = PyDict_GetItemString(crypto_dict, "_C_API"); \
126 if (PyCObject_Check(crypto_api_object)) { \
127 crypto_API = (void **)PyCObject_AsVoidPtr(crypto_api_object); \
128 } \
129 } \
130}
131
132#endif /* crypto_MODULE */
133
Jean-Paul Calderone2685e432009-04-01 12:58:26 -0400134/* Define a new type for emitting text. Hopefully these don't collide with
135 * future official OpenSSL constants, but the switch statement of
136 * dump_certificate() will alert us if it matters.
137 */
Rick Dean5b7b6372009-04-01 11:34:06 -0500138#ifndef X509_FILETYPE_TEXT
139#define X509_FILETYPE_TEXT (58)
140#endif
141
Jean-Paul Calderone897bc252008-02-18 20:50:23 -0500142#endif /* PyOpenSSL_CRYPTO_H_ */