Questions tagged [m2crypto]
M2Crypto is the most complete Python wrapper for OpenSSL featuring RSA, DSA, DH, HMACs, message digests, symmetric ciphers (including AES); SSL functionality to implement clients and servers; HTTPS extensions to Python's httplib, urllib, and xmlrpclib; unforgeable HMAC'ing AuthCookies for web session management; FTP/TLS client and server; S/MIME; ZServerSSL.
m2crypto
273
questions
344
votes
13
answers
855k
views
How do I update a Python package?
I'm running Ubuntu 9:10 and a package called M2Crypto is installed (version is 0.19.1). I need to download, build and install the latest version of the M2Crypto package (0.20.2).
The 0.19.1 package ...
57
votes
11
answers
106k
views
How to generate SSH key pairs with Python
I'm attempting to write a script to generate SSH Identity key pairs for me.
from M2Crypto import RSA
key = RSA.gen_key(1024, 65337)
key.save_key("/tmp/my.key", cipher=None)
The file /tmp/my.key ...
51
votes
7
answers
31k
views
Trouble installing m2crypto with pip on OS X / macOS
pip install m2crypto
Generates the following output:
building 'M2Crypto.__m2crypto' extension
swigging SWIG/_m2crypto.i to SWIG/_m2crypto_wrap.c
swig -python -I/System/Library/Frameworks/Python....
41
votes
3
answers
79k
views
How can I retrieve the TLS/SSL peer certificate of a remote host using python?
I need to scan through a list of IPs and retrieve the common name from the certificate on that IP (for every IP that allows port 443 connections). I have been able to successfully do this using the ...
21
votes
3
answers
45k
views
How do I install M2Crypto on Ubuntu?
I'm trying to build and install M2Crypto on Ubuntu 10.04 LTS. I downloaded and untarred M2Crypto-0.20.2.tar, and from the M2Crypto-0.20.2 directory I tried python setup.py build. I got an error ...
18
votes
5
answers
13k
views
Install m2crypto on a virtualenv without system packages
I have created a virtual environment without the system packages with python's virtualenv in Ubuntu and installed m2crypto, but when I execute a shell and I try to import M2Crypto i get the following ...
18
votes
5
answers
36k
views
How to validate / verify an X509 Certificate chain of trust in Python?
I am working on implementing a web application that utilizes an API. During a response, the API server sends over a link to an X509 certificate (in PEM format, composed of a signing certificate and ...
17
votes
6
answers
26k
views
How to Install M2crypto on Windows
After installing OpenSSL, downloading the pre-built Swig executable, and ensuring the openssl libraries are located in the default c:\pkg, pip install m2crypto results in:
...
C:\Program Files (x86)\...
15
votes
2
answers
19k
views
Sign CSR from client using CA root certificate in python
I am new to python and still learning it so my question can be little naive. Please bear with it ;)
The problem is client will be sending CSR and I want to sign it with my CA root certificate and ...
15
votes
1
answer
2k
views
Getting PKCS7 signer chain in python
I have PKCS7 message which is signed. It contains a data and a signing certificate (with the whole chain of trust).
I have a code which uses m2crypto to get a certificate out of it.
bio = BIO....
14
votes
1
answer
2k
views
EXP(ORT) ciphers and M2Crypto/OpenSSL
I am having a hard time running a M2Crypto SSLServer with EXPORT grade ciphers.
LOW/MEDIUM/HIGH grade ciphers work without any problems, but EXPORT just won't. Also, when OpenSSL is run in a server ...
13
votes
7
answers
40k
views
pip install m2crypto error
$sudo pip3 install m2crypto
Collecting m2crypto
Using cached M2Crypto-0.26.0.tar.gz
Requirement already satisfied: typing in /usr/local/lib/python3.5/dist-packages (from m2crypto)
Installing ...
13
votes
4
answers
24k
views
How do I verify an SSL certificate in python?
I need to verify that a certificate was signed by my custom CA. Using OpenSSL command-line utilities this is easy to do:
# Custom CA file: ca-cert.pem
# Cert signed by above CA: bob.cert
$ openssl ...
11
votes
3
answers
30k
views
How to generate strong one time session key for AES in python
I am using M2Crypto's AES for encrypting message, but confused about how to generate a strong random session key and of what length. Does M2Crypto provide any function for generation random key.
11
votes
2
answers
1k
views
Trying to verify SHA1 message signature using Python. What am I doing wrong?
I'm attempting to verify the SHA1 signature of a message by downloading a certificate from a website and extracting its public key. There's a few bits of sample code elsewhere on SO (here and here), ...
10
votes
6
answers
18k
views
Installing M2Crypto on CentOS
I am trying to install M2Crypto on CentOS by compiling from the source.
i am doing a python setup.py build
But I get the following error,
/usr/local/lib/python2.6/distutils/dist.py:266: UserWarning:...
10
votes
1
answer
16k
views
On certificates, what type should E-mail addresses be when in subjectAltName
Little bit of background:
I'm building a certificate authority using M2Crypto and Django, so please think twice before voting to close this as off topic! :)
My approach is that end-users are ...
9
votes
4
answers
843
views
_shutdown AttributeError (ignored) when linting code that uses M2Crypto
I'm running lint as follows:
$ python -m pylint.lint m2test.py
with this code:
import M2Crypto
def f():
M2Crypto.RSA.new_pub_key("").as_pem(cipher=None).split("\n")
The lint output ends with:
...
7
votes
5
answers
11k
views
M2Crypto Encrypt/Decrypt using AES256
Can someone provide me code to encrypt / decrypt using m2crypto aes256 CBC using Python
7
votes
4
answers
11k
views
How to get Python m2Crypto to work with virtualenv?
I'm trying to install M2Crypto so that I can generate pkey in my web app. My hosting requirements dictate that I must use pip to install any dependencies. Installing m2crypto at the system level is ...
7
votes
2
answers
15k
views
Create self signed SSL certificates in Python
I am trying to generate self signed SSL certificates using Python, so that it is platform independent. My target is the *.pem format.
I found this script that generates certificates, but no ...
6
votes
1
answer
10k
views
Verify signature with pyopenssl
I believe that since this question, pyOpenSSL has started supporting the verification of signatures (as of pyOpenSSL 0.11.
I am working on a project which was started by someone else using M2Crypto. ...
6
votes
3
answers
9k
views
How to get the signed content from a PKCS7 envelop with M2Crypto?
I need to get the digest of a PKCS#7 envelop to manually check it.
Usually when you want to validate the signature of a pkcs#7 envelop you do that:
from M2Crypto import SMIME, X509, BIO
sm_obj = ...
6
votes
1
answer
495
views
M2Crypto bad performance to decrypt and verify big email
The input : big multipart signed and encrypted email (~10MB) done with openssl.
Decrypting the file seems to be fast enough.
Getting the decrypted information to verify them is MORE than long. It ...
5
votes
2
answers
12k
views
Implement OpenSSL AES Encryption in Python
I'm trying to implement the following in Python:
openssl enc -e -aes-256-cbc -base64 -k "Secret Passphrase" -in plaintext.txt -out ciphertext.txt
openssl enc -d -aes-256-cbc -base64 -k "Secret ...
5
votes
2
answers
4k
views
How can I load a password-protected private key from a .pem file with M2Crypto?
I have a password-protected private key in a .pem file; I want to use it to sign requests to a remote server. I'm able to load the key and enter the passphrase after being prompted for it:
python
>...
5
votes
2
answers
5k
views
Extract userCertificate from PKCS7 envelop in python
Ok, I am trying to verify data from PKCS7 envelop using Python.
I have the working code in Java: http://nyal.developpez.com/tutoriel/java/bouncycastle/#L4.2
What I want is first get the certificate ...
5
votes
2
answers
3k
views
M2crypto signature "algorithm"
These two codes provide the same signature, which is expected:
code1:
from M2Crypto import RSA, EVP
import base64, hashlib
text = "some text"
pkey = EVP.load_key("mykey.pem") #"mykey.pem" was ...
5
votes
2
answers
6k
views
Validating SAML signature in python
I need to implement authentication in python from a 3rd party by using SAML2. I have looked into pysaml2 and found that to be quite confusing, and decided to give M2Crypto a chance after I found this ...
5
votes
2
answers
4k
views
How do I use m2crypto to validate a X509 certificate chain in a non-SSL setting
I'm trying to figure out how to, using m2crypto, validate the chain of trust from a public key version of a X509 certificate back to one of a set of known root CA's when the chain may be arbitrarily ...
5
votes
1
answer
1k
views
What happens during a python module install? Can I just copy the module source to site-packages?
I'm having trouble installing M2Crypto on my shared webhost account with pip. Can I just copy the module's source into site-packages, or does pip do something extra?
5
votes
3
answers
3k
views
How can I verify an X509 certificate in python including a CRL check?
I'm trying to verify an X509 certificate using python. In particular I need to check CRLs when I do it.
Now, you can use m2crypto to do this, but I can't find an option corresponding to openssl's -...
5
votes
0
answers
614
views
How to sign and send a Mimultipart message in python?
Typically, sending a message with attachments is performed like this in python.
import smtplib
from os.path import basename
from email.mime.application import MIMEApplication
from email.mime....
5
votes
0
answers
743
views
private encrypt (generate signature) using cryptography/ pycrypto as generated by M2Crypto
I am trying to generate a signature for a payload. My tech stack is in Python3.6, which provides library like cryptography or pycrypto. Problem is, I am unable to recreate the function private_encrypt ...
5
votes
0
answers
1k
views
Sign a soap Message through Python
I am struggling to Sign a XML soap message with a private key . I have done it in Java in the past , but having a very hard time in doing it through Python. I have kept a template XML in home ...
5
votes
1
answer
1k
views
Extract signing certs from a PKCS7 SignedData structure with m2crypto
I am trying to use M2Crypto to extract the signing certificates from a Windows PE file. According to the MS specification the data is stored in a PKCS#7 SignedData structure (stored in ASN.1 format, ...
4
votes
3
answers
6k
views
problems installing M2Crypto on Mint: follow-up
I asked a question here regarding installing the M2Crypto python library in Mint. That question was answered successfully and I was able to build and install M2Crypto. However, I am not able to use ...
4
votes
2
answers
5k
views
easy_install M2Crypto failing on Windows platform
I am attempting to install M2Crypto on a Windows XP platform. I have Python, easy_install and SWIG installed, but when I attempt to easy_install M2Crypto I get the following:
SWIG\_m2crypto.i(31) : ...
4
votes
2
answers
2k
views
Python x509 get_serial_number() return incorrect value
I'm trying to get the serial number of a x509 with M2cryto the problem is that returns me different values to openssl.
from python
>>> from M2Crypto import X509
>>> cer = X509....
4
votes
1
answer
2k
views
How to extract RSA public exponent using python M2Crypto
I have the following piece of code that extract a host leaf certificate and the certificate RSA public key:
c = ssock.getpeercert(True)
x509 = M2Crypto.X509.load_cert_der_string(c)
publickey=x509....
4
votes
2
answers
5k
views
M2Crypto Error Installing on Windows
I'm trying to install the M2Crypto on Python26 in Windows, but I am getting the below error.
error: command 'swig.exe' failed: No such file or directory
This error occurs both using the "Easy ...
4
votes
1
answer
1k
views
Adding server certificate validation to httplib.HTTPSConnection
I've found that httplib.HTTPSConnection doesn't perform an automatic server certificate check. As far as I've understood the problem, I need to add that functionality manually, e.g. by subclassing ...
4
votes
1
answer
1k
views
How to recreate the following signing cmd-line OpenSSL call using M2Crypto in Python?
This works perfectly in command-line, I would like to do the same using M2Crypto in Python code.
openssl smime -binary -sign -signer certificate.pem -inkey key.pem \
-in some_file....
4
votes
1
answer
3k
views
verify data signature generated with openssl, using crypto++
I have a server, running under python, signing a message sha256 digest using m2crypto
I use a public and private RSA key generated by openssl CLI. On the server side everythgin is OK
Python code :
...
4
votes
1
answer
2k
views
Unable to install M2Crypto package
I am using Win7 64 bit machine with Python 2.7 installed. I have installed swigwin 3.0.5. When I do "pip install M2Crypto" I got the following errors:
SWIG\_m2crypto.i(30) : Error: Unable to find '...
4
votes
2
answers
845
views
error in importing M2Crypto Mac OS X
when I try to import M2Crypto in python, I get following error:
I'm using Mac OS X, python 2.7
ImportError: dlopen(/Users/armita/.python-eggs/M2Crypto-0.22.3-py2.7-macosx-10.9-intel.egg-tmp/M2Crypto/...
3
votes
1
answer
4k
views
Loading a DER-encoded RSA key using M2Crypto
The method M2Crypto.RSA.RSA().save_key_der() can be used to save a key in the DER format. However, I do not see a corresponding method M2Crypto.RSA.load_key_der() as I would expect.
Is there a way to ...
3
votes
1
answer
1k
views
Generating SHA-256 hash in Python 2.4 using M2Crypto
Is it possible to generate a SHA-256 hash using M2Crypto? Python 2.4's SHA module doesn't support 256, so I started using PyCrypto, only to find out that PyCrypto doesn't support PKCS#5 (needed ...
3
votes
1
answer
828
views
Where is Python support for PEM + RSA + DES3?
I need a Python library that supports PEM files and both RSA signing and DES3 encryption. pycrypto doesn't seem to support PEM, and its mechanism for loading existing keys is undocumented and cryptic. ...
3
votes
2
answers
11k
views
Installing M2Crypto on Windows
I am trying to install M2Crypto on a Windows 7 machine using easy_install. However, I get the following error:
SWIG_m2crypto.i(31) : Error: Unable to find 'openssl\opensslv.h'
SWIG_m2crypto.i(45) ...