151 static PyObject *
152 crypto_dump_privatekey(PyObject *spam, PyObject *args)
153 {
154 int type, ret, buf_len;
155 char *temp;
156 PyObject *buffer;
157 char *cipher_name = NULL;
158 const EVP_CIPHER *cipher = NULL;
159 PyObject *pw = NULL;
160 pem_password_cb *cb = NULL;
161 void *cb_arg = NULL;
162 BIO *bio;
163 RSA *rsa;
164 crypto_PKeyObj *pkey;
165
166 if (!PyArg_ParseTuple(args, "iO!|sO:dump_privatekey", &type,
when PyArg_ParseTuple() succeeds
taking False path
167 &crypto_PKey_Type, &pkey, &cipher_name, &pw))
168 return NULL;
169
170 if (cipher_name != NULL && pw == NULL)
when treating unknown const char * from OpenSSL/crypto/crypto.c:166 as non-NULL
taking True path
taking False path
171 {
172 PyErr_SetString(PyExc_ValueError, "Illegal number of arguments");
173 return NULL;
174 }
175 if (cipher_name != NULL)
taking True path
176 {
177 cipher = EVP_get_cipherbyname(cipher_name);
178 if (cipher == NULL)
when treating unknown const struct EVP_CIPHER * from OpenSSL/crypto/crypto.c:177 as non-NULL
taking False path
179 {
180 PyErr_SetString(PyExc_ValueError, "Invalid cipher name");
181 return NULL;
182 }
183 if (PyBytes_Check(pw))
when treating unknown struct _typeobject * from OpenSSL/crypto/crypto.c:183 as non-NULL
when considering range: 1 <= value <= 0x8000000
taking True path
184 {
185 cb = NULL;
186 cb_arg = PyBytes_AsString(pw);
when PyString_AsString() succeeds
187 }
188 else if (PyCallable_Check(pw))
189 {
190 cb = global_passphrase_callback;
191 cb_arg = pw;
192 }
193 else
194 {
195 PyErr_SetString(PyExc_TypeError, "Last argument must be string or callable");
196 return NULL;
197 }
198 }
199
200 bio = BIO_new(BIO_s_mem());
201 switch (type)
when following case 1
202 {
203 case X509_FILETYPE_PEM:
204 ret = PEM_write_bio_PrivateKey(bio, pkey->pkey, cipher, NULL, 0, cb, cb_arg);
205 if (PyErr_Occurred())
PyErr_Occurred()
taking False path
206 {
207 BIO_free(bio);
208 return NULL;
209 }
210 break;
211
212 case X509_FILETYPE_ASN1:
213 ret = i2d_PrivateKey_bio(bio, pkey->pkey);
214 break;
215
216 case X509_FILETYPE_TEXT:
217 rsa = EVP_PKEY_get1_RSA(pkey->pkey);
218 ret = RSA_print(bio, rsa, 0);
219 RSA_free(rsa);
220 break;
221
222 default:
223 PyErr_SetString(PyExc_ValueError, "type argument must be FILETYPE_PEM, FILETYPE_ASN1, or FILETYPE_TEXT");
224 BIO_free(bio);
225 return NULL;
226 }
227
228 if (ret == 0)
when considering value == (int)0 from OpenSSL/crypto/crypto.c:204
taking True path
229 {
230 BIO_free(bio);
231 exception_from_error_queue(crypto_Error);
232 return NULL;
233 }
234
235 buf_len = BIO_get_mem_data(bio, &temp);
236 buffer = PyBytes_FromStringAndSize(temp, buf_len);
237 BIO_free(bio);
238
239 return buffer;
240 }
returning (PyObject*)NULL without setting an exception
found 3 similar trace(s) to this