1 // -*- Mode: C++; -*- 2 // Package : omniORBpy 3 // pysslTP.cc Created on: 2002/09/06 4 // Author : Duncan Grisby (dgrisby) 5 // 6 // Copyright (C) 2002 Apasphere Ltd. 7 // 8 // This file is part of the omniORBpy library 9 // 10 // The omniORBpy library is free software; you can redistribute it 11 // and/or modify it under the terms of the GNU Lesser General 12 // Public License as published by the Free Software Foundation; 13 // either version 2.1 of the License, or (at your option) any later 14 // version. 15 // 16 // This library is distributed in the hope that it will be useful, 17 // but WITHOUT ANY WARRANTY; without even the implied warranty of 18 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 // GNU Lesser General Public License for more details. 20 // 21 // You should have received a copy of the GNU Lesser General Public 22 // License along with this library. If not, see http://www.gnu.org/licenses/ 23 // 24 // Description: 25 // SSL transport library 26 27 #ifdef __WIN32__ 28 # define DLL_EXPORT _declspec(dllexport) 29 #else 30 # define DLL_EXPORT 31 #endif 32 33 #if defined(__VMS) 34 # include <Python.h> 35 #else 36 # include PYTHON_INCLUDE 37 #endif 38 39 #include <omniORB4/CORBA.h> 40 #include <omniORB4/sslContext.h> 41 42 #include "../omnipy_sysdep.h" 43 44 extern "C" { 45 46 static char certificate_authority_file_doc[] = 47 "certificate_authority_file(PEM filename)\n" 48 "\n" 49 "Set the certificate authority file for SSL validation.\n" 50 "Call with no argument to retrieve the current value.\n"; 51 pysslTP_certificate_authority_file(PyObject * self,PyObject * args)52 static PyObject* pysslTP_certificate_authority_file(PyObject* self, 53 PyObject* args) 54 { 55 if (PyTuple_GET_SIZE(args) == 0) { 56 if (sslContext::certificate_authority_file) 57 return String_FromString(sslContext::certificate_authority_file); 58 else { 59 Py_INCREF(Py_None); 60 return Py_None; 61 } 62 } 63 char *name; 64 if (!PyArg_ParseTuple(args, (char*)"s", &name)) return 0; 65 66 // Leak here, but we can't do anything else about it. 67 sslContext::certificate_authority_file = CORBA::string_dup(name); 68 69 Py_INCREF(Py_None); return Py_None; 70 } 71 72 static char certificate_authority_path_doc[] = 73 "certificate_authority_path(path)\n" 74 "\n" 75 "Set the path for certificate authority files for SSL validation.\n" 76 "Call with no argument to retrieve the current value.\n"; 77 pysslTP_certificate_authority_path(PyObject * self,PyObject * args)78 static PyObject* pysslTP_certificate_authority_path(PyObject* self, 79 PyObject* args) 80 { 81 if (PyTuple_GET_SIZE(args) == 0) { 82 if (sslContext::certificate_authority_path) 83 return String_FromString(sslContext::certificate_authority_path); 84 else { 85 Py_INCREF(Py_None); 86 return Py_None; 87 } 88 } 89 char *name; 90 if (!PyArg_ParseTuple(args, (char*)"s", &name)) return 0; 91 92 // Leak here, but we can't do anything else about it. 93 sslContext::certificate_authority_path = CORBA::string_dup(name); 94 95 Py_INCREF(Py_None); return Py_None; 96 } 97 98 static char key_file_doc[] = 99 "key_file(PEM filename)\n" 100 "\n" 101 "Set the key file for SSL encryption.\n" 102 "Call with no argument to retrieve the current value.\n"; 103 pysslTP_key_file(PyObject * self,PyObject * args)104 static PyObject* pysslTP_key_file(PyObject* self, 105 PyObject* args) 106 { 107 if (PyTuple_GET_SIZE(args) == 0) { 108 if (sslContext::key_file) 109 return String_FromString(sslContext::key_file); 110 else { 111 Py_INCREF(Py_None); 112 return Py_None; 113 } 114 } 115 char *name; 116 if (!PyArg_ParseTuple(args, (char*)"s", &name)) return 0; 117 118 // Leak here, but we can't do anything else about it. 119 sslContext::key_file = CORBA::string_dup(name); 120 121 Py_INCREF(Py_None); return Py_None; 122 } 123 124 static char key_file_password_doc[] = 125 "key_file_password(password string)\n" 126 "\n" 127 "Set the password for the key file.\n" 128 "Call with no argument to retrieve the current value.\n"; 129 pysslTP_key_file_password(PyObject * self,PyObject * args)130 static PyObject* pysslTP_key_file_password(PyObject* self, 131 PyObject* args) 132 { 133 if (PyTuple_GET_SIZE(args) == 0) { 134 if (sslContext::key_file_password) 135 return String_FromString(sslContext::key_file_password); 136 else { 137 Py_INCREF(Py_None); 138 return Py_None; 139 } 140 } 141 char *pw; 142 if (!PyArg_ParseTuple(args, (char*)"s", &pw)) return 0; 143 144 // Leak here, but we can't do anything else about it. 145 sslContext::key_file_password = CORBA::string_dup(pw); 146 147 Py_INCREF(Py_None); return Py_None; 148 } 149 150 151 static PyMethodDef omnisslTP_methods[] = { 152 {(char*)"certificate_authority_file", 153 pysslTP_certificate_authority_file, METH_VARARGS, 154 certificate_authority_file_doc}, 155 156 {(char*)"certificate_authority_path", 157 pysslTP_certificate_authority_path, METH_VARARGS, 158 certificate_authority_path_doc}, 159 160 {(char*)"key_file", 161 pysslTP_key_file, METH_VARARGS, 162 key_file_doc}, 163 164 {(char*)"key_file_password", 165 pysslTP_key_file_password, METH_VARARGS, 166 key_file_password_doc}, 167 168 {0,0} 169 }; 170 171 #if (PY_VERSION_HEX < 0x03000000) 172 init_omnisslTP()173 void DLL_EXPORT init_omnisslTP() 174 { 175 PyObject* m = Py_InitModule((char*)"_omnisslTP", omnisslTP_methods); 176 } 177 178 #else 179 180 static struct PyModuleDef omnisslTPmodule = { 181 PyModuleDef_HEAD_INIT, 182 "_omnisslTP", 183 "omniORBpy SSL transport", 184 -1, 185 omnisslTP_methods, 186 NULL, 187 NULL, 188 NULL, 189 NULL 190 }; 191 192 PyMODINIT_FUNC PyInit__omnisslTP(void)193 PyInit__omnisslTP(void) 194 { 195 return PyModule_Create(&omnisslTPmodule); 196 } 197 198 #endif 199 }; 200