Skip to content

Commit

Permalink
Support OpenSSL 1.0. Thanks to Miloslav Trmac for figuring out how to…
Browse files Browse the repository at this point in the history
… fix test_smime.py.

git-svn-id: http://svn.osafoundation.org/m2crypto/trunk@721 2715db39-9adf-0310-9c64-84f055769b4b
  • Loading branch information
heikki committed Feb 13, 2010
1 parent 8d98b12 commit 29abb4e
Show file tree
Hide file tree
Showing 15 changed files with 213 additions and 126 deletions.
9 changes: 7 additions & 2 deletions CHANGES
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
0.21
----
- Support OpenSSL 1.0. Thanks to Miloslav Trmac for figuring out how to fix
test_smime.py
- Rename m2.engine_init to engine_init_error so that
ENGINE_init and ENGINE_finish can be exposed, thanks to Erlo

0.20.2 - 2009-10-06
-------------------
- (Re)Enable configuration and use with OpenSSL 0.9.7g and older by disabling
RSA PSS methods when using such old OpenSSL, thanks to Stef Walter
- Rename m2.engine_init to engine_init_error so that
ENGINE_init and ENGINE_finish can be exposed, thanks to Erlo

0.20.1 - 2009-08-27
-------------------
Expand Down
2 changes: 2 additions & 0 deletions LICENCE
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ All rights reserved.
Portions copyright (c) 2005-2006 Vrije Universiteit Amsterdam.
All rights reserved.

Copyright (c) 2008-2010 Heikki Toivonen. All rights reserved.

Permission to use, copy, modify, and distribute this software and its
documentation for any purpose and without fee is hereby granted,
provided that the above copyright notice appear in all copies and that
Expand Down
2 changes: 1 addition & 1 deletion M2Crypto/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
Portions created by Open Source Applications Foundation (OSAF) are
Copyright (C) 2004-2007 OSAF. All Rights Reserved.
Copyright 2008-2009 Heikki Toivonen. All rights reserved.
Copyright 2008-2010 Heikki Toivonen. All rights reserved.
"""

version_info = (0, 21)
Expand Down
2 changes: 1 addition & 1 deletion SWIG/_aes.i
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ PyObject *AES_crypt(const AES_KEY *key, PyObject *in, int outlen, int op) {
AES_encrypt((const unsigned char *)in, out, key);
else
AES_decrypt((const unsigned char *)in, out, key);
return PyString_FromStringAndSize(out, outlen);
return PyString_FromStringAndSize((char*)out, outlen);
}

int AES_type_check(AES_KEY *key) {
Expand Down
11 changes: 7 additions & 4 deletions SWIG/_evp.i
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ Copyright (c) 1999 Ng Pheng Siong. All rights reserved.
Portions Copyright (c) 2004-2007 Open Source Applications Foundation.
Author: Heikki Toivonen
Copyright (c) 2009-2010 Heikki Toivonen. All rights reserved.
*/

%include <openssl/opensslconf.h>
Expand Down Expand Up @@ -180,7 +183,7 @@ PyObject *pkcs5_pbkdf2_hmac_sha1(PyObject *pass,

PKCS5_PBKDF2_HMAC_SHA1(passbuf, passlen, saltbuf, saltlen, iter,
keylen, key);
ret = PyString_FromStringAndSize(key, keylen);
ret = PyString_FromStringAndSize((char*)key, keylen);
OPENSSL_cleanse(key, keylen);
return ret;
}
Expand Down Expand Up @@ -339,7 +342,7 @@ PyObject *bytes_to_key(const EVP_CIPHER *cipher, EVP_MD *md,
klen = EVP_BytesToKey(cipher, md, (unsigned char *)sbuf,
(unsigned char *)dbuf, dlen, iter,
key, NULL); /* Since we are not returning IV no need to derive it */
ret = PyString_FromStringAndSize(key, klen);
ret = PyString_FromStringAndSize((char*)key, klen);
return ret;
}

Expand Down Expand Up @@ -435,7 +438,7 @@ PyObject *sign_final(EVP_MD_CTX *ctx, EVP_PKEY *pkey) {
PyErr_SetString(_evp_err, ERR_reason_error_string(ERR_get_error()));
return NULL;
}
ret = PyString_FromStringAndSize(sigbuf, siglen);
ret = PyString_FromStringAndSize((char*)sigbuf, siglen);
OPENSSL_cleanse(sigbuf, siglen);
OPENSSL_free(sigbuf);
return ret;
Expand Down Expand Up @@ -513,7 +516,7 @@ PyObject *pkey_as_der(EVP_PKEY *pkey) {
PyErr_SetString(PyExc_ValueError, "EVP_PKEY as DER failed");
return NULL;
}
der = PyString_FromStringAndSize(pp, len);
der = PyString_FromStringAndSize((char*)pp, len);
OPENSSL_free(pp);
return der;
}
Expand Down
16 changes: 16 additions & 0 deletions SWIG/_m2crypto.i
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
*
* Portions created by Open Source Applications Foundation (OSAF) are
* Copyright (C) 2004-2006 OSAF. All Rights Reserved.
*
* Copyright (c) 2009-2010 Heikki Toivonen. All rights reserved.
*
*/

%module(threads=1) _m2crypto
Expand Down Expand Up @@ -38,6 +41,19 @@ static PyObject *ssl_set_tmp_rsa_cb_func;
#define CONST098
#endif

/* Bring in STACK_OF macro definition */
%include <openssl/safestack.h>

/* Bring in LHASH_OF macro definition */
/* XXX Can't include lhash.h where LHASH_OF is defined, because it includes
XXX stdio.h etc. which we fail to include. So we have to (re)define
XXX LHASH_OF here instead.
%include <openssl/lhash.h>
*/
#if OPENSSL_VERSION_NUMBER >= 0x10000000L
#define LHASH_OF(type) struct lhash_st_##type
#endif

%include constraints.i
%include _threads.i
%include _lib.i
Expand Down
22 changes: 12 additions & 10 deletions SWIG/_pkcs7.i
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
/* Copyright (c) 2000 Ng Pheng Siong. All rights reserved. */
/* Copyright (c) 2000 Ng Pheng Siong. All rights reserved.
* Copyright (c) 2009-2010 Heikki Toivonen. All rights reserved.
*/
/* $Id$ */

%{
Expand All @@ -12,7 +14,7 @@
%apply Pointer NONNULL { EVP_CIPHER * };
%apply Pointer NONNULL { EVP_PKEY * };
%apply Pointer NONNULL { PKCS7 * };
%apply Pointer NONNULL { STACK * };
%apply Pointer NONNULL { STACK_OF(X509) * };
%apply Pointer NONNULL { X509 * };

%rename(pkcs7_new) PKCS7_new;
Expand Down Expand Up @@ -54,8 +56,8 @@ void smime_init(PyObject *smime_err) {

%threadallow pkcs7_encrypt;
%inline %{
PKCS7 *pkcs7_encrypt(STACK *stack, BIO *bio, EVP_CIPHER *cipher, int flags) {
return PKCS7_encrypt((STACK_OF(X509) *)stack, bio, cipher, flags);
PKCS7 *pkcs7_encrypt(STACK_OF(X509) *stack, BIO *bio, EVP_CIPHER *cipher, int flags) {
return PKCS7_encrypt(stack, bio, cipher, flags);
}

PyObject *pkcs7_decrypt(PKCS7 *pkcs7, EVP_PKEY *pkey, X509 *cert, int flags) {
Expand Down Expand Up @@ -96,14 +98,14 @@ PKCS7 *pkcs7_sign0(X509 *x509, EVP_PKEY *pkey, BIO *bio, int flags) {

%threadallow pkcs7_sign1;
%inline %{
PKCS7 *pkcs7_sign1(X509 *x509, EVP_PKEY *pkey, STACK *stack, BIO *bio, int flags) {
return PKCS7_sign(x509, pkey, (STACK_OF(X509) *)stack, bio, flags);
PKCS7 *pkcs7_sign1(X509 *x509, EVP_PKEY *pkey, STACK_OF(X509) *stack, BIO *bio, int flags) {
return PKCS7_sign(x509, pkey, stack, bio, flags);
}
%}

%threadallow pkcs7_verify1;
%inline %{
PyObject *pkcs7_verify1(PKCS7 *pkcs7, STACK *stack, X509_STORE *store, BIO *data, int flags) {
PyObject *pkcs7_verify1(PKCS7 *pkcs7, STACK_OF(X509) *stack, X509_STORE *store, BIO *data, int flags) {
int outlen;
char *outbuf;
BIO *bio;
Expand All @@ -113,7 +115,7 @@ PyObject *pkcs7_verify1(PKCS7 *pkcs7, STACK *stack, X509_STORE *store, BIO *data
PyErr_SetString(PyExc_MemoryError, "pkcs7_verify1");
return NULL;
}
if (!PKCS7_verify(pkcs7, (STACK_OF(X509) *)stack, store, data, bio, flags)) {
if (!PKCS7_verify(pkcs7, stack, store, data, bio, flags)) {
PyErr_SetString(_pkcs7_err, ERR_reason_error_string(ERR_get_error()));
BIO_free(bio);
return NULL;
Expand All @@ -131,7 +133,7 @@ PyObject *pkcs7_verify1(PKCS7 *pkcs7, STACK *stack, X509_STORE *store, BIO *data
return ret;
}

PyObject *pkcs7_verify0(PKCS7 *pkcs7, STACK *stack, X509_STORE *store, int flags) {
PyObject *pkcs7_verify0(PKCS7 *pkcs7, STACK_OF(X509) *stack, X509_STORE *store, int flags) {
return pkcs7_verify1(pkcs7, stack, store, NULL, flags);
}
%}
Expand Down Expand Up @@ -229,7 +231,7 @@ int smime_crlf_copy(BIO *in, BIO *out) {
}

/* return STACK_OF(X509)* */
STACK *pkcs7_get0_signers(PKCS7 *p7, STACK *certs, int flags) {
STACK_OF(X509) *pkcs7_get0_signers(PKCS7 *p7, STACK_OF(X509) *certs, int flags) {
return PKCS7_get0_signers(p7, certs, flags);
}

Expand Down
6 changes: 4 additions & 2 deletions SWIG/_rand.i
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* Copyright (c) 1999-2004 Ng Pheng Siong. All rights reserved. */
/* Copyright (c) 1999-2004 Ng Pheng Siong. All rights reserved.
* Copyright (c) 2009-2010 Heikki Toivonen. All rights reserved.
*/
/* $Id$ */

%module _rand
Expand Down Expand Up @@ -87,7 +89,7 @@ PyObject *rand_pseudo_bytes(int n) {
Py_INCREF(Py_None);
return Py_None;
} else {
PyTuple_SET_ITEM(tuple, 0, PyString_FromStringAndSize(blob, n));
PyTuple_SET_ITEM(tuple, 0, PyString_FromStringAndSize((char*)blob, n));
PyMem_Free(blob);
PyTuple_SET_ITEM(tuple, 1, PyInt_FromLong((long)ret));
return tuple;
Expand Down
33 changes: 18 additions & 15 deletions SWIG/_ssl.i
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
/*
** Portions created by Open Source Applications Foundation (OSAF) are
** Copyright (C) 2004-2005 OSAF. All Rights Reserved.
**
** Copyright (c) 2009-2010 Heikki Toivonen. All rights reserved.
**
*/
/* $Id$ */

Expand All @@ -17,13 +20,17 @@
%apply Pointer NONNULL { SSL_CTX * };
%apply Pointer NONNULL { SSL * };
%apply Pointer NONNULL { SSL_CIPHER * };
%apply Pointer NONNULL { STACK * };
%apply Pointer NONNULL { STACK_OF(SSL_CIPHER) * };
%apply Pointer NONNULL { STACK_OF(X509) * };
%apply Pointer NONNULL { BIO * };
%apply Pointer NONNULL { DH * };
%apply Pointer NONNULL { RSA * };
%apply Pointer NONNULL { EVP_PKEY *};
%apply Pointer NONNULL { PyObject *pyfunc };

%rename(ssl_get_ciphers) SSL_get_ciphers;
extern STACK_OF(SSL_CIPHER) *SSL_get_ciphers(const SSL *ssl);

%rename(ssl_get_version) SSL_get_version;
extern const char *SSL_get_version(CONST SSL *);
%rename(ssl_get_error) SSL_get_error;
Expand Down Expand Up @@ -668,28 +675,24 @@ int ssl_cipher_get_bits(SSL_CIPHER *c) {
return SSL_CIPHER_get_bits(c, NULL);
}

STACK *ssl_get_ciphers(SSL *ssl) {
return (STACK *)SSL_get_ciphers(ssl);
}

int sk_ssl_cipher_num(STACK *stack) {
return sk_num(stack);
int sk_ssl_cipher_num(STACK_OF(SSL_CIPHER) *stack) {
return sk_SSL_CIPHER_num(stack);
}

SSL_CIPHER *sk_ssl_cipher_value(STACK *stack, int idx) {
return (SSL_CIPHER *)sk_value(stack, idx);
SSL_CIPHER *sk_ssl_cipher_value(STACK_OF(SSL_CIPHER) *stack, int idx) {
return sk_SSL_CIPHER_value(stack, idx);
}

STACK *ssl_get_peer_cert_chain(SSL *ssl) {
return (STACK *)SSL_get_peer_cert_chain(ssl);
STACK_OF(X509) *ssl_get_peer_cert_chain(SSL *ssl) {
return SSL_get_peer_cert_chain(ssl);
}

int sk_x509_num(STACK *stack) {
return sk_num(stack);
int sk_x509_num(STACK_OF(X509) *stack) {
return sk_X509_num(stack);
}

X509 *sk_x509_value(STACK *stack, int idx) {
return (X509 *)sk_value(stack, idx);
X509 *sk_x509_value(STACK_OF(X509) *stack, int idx) {
return sk_X509_value(stack, idx);
}
%}

Expand Down
6 changes: 4 additions & 2 deletions SWIG/_util.i
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
/* Copyright (c) 1999-2002 Ng Pheng Siong. All rights reserved. */
/* Copyright (c) 1999-2002 Ng Pheng Siong. All rights reserved.
* Copyright (c) 2009-2010 Heikki Toivonen. All rights reserved.
*/
/* $Id$ */

%{
Expand Down Expand Up @@ -48,7 +50,7 @@ PyObject *util_string_to_hex(PyObject *blob) {
PyErr_SetString(_util_err, ERR_reason_error_string(ERR_get_error()));
return NULL;
}
obj = PyString_FromStringAndSize(ret, len);
obj = PyString_FromStringAndSize((char*)ret, len);
OPENSSL_free(ret);
return obj;
}
Expand Down
Loading

0 comments on commit 29abb4e

Please sign in to comment.