Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > M2Crypto: X509.X509_Extension_Stack() throws AssertionError

Reply
Thread Tools

M2Crypto: X509.X509_Extension_Stack() throws AssertionError

 
 
Matthias Güntert
Guest
Posts: n/a
 
      08-03-2009
Hello python-list members

Why is the following code snippet throwing an AssertionError? Is that
behavior a bug within X509.X509_Extension_Stack()? How would you suggest
popping every element from the stack?

Regards,
Matthias Güntert

-------------------------------------------------
from M2Crypto import X509

if __name__ == '__main__':
cert_extension_stack = X509.X509_Extension_Stack()

cert_extension_1 = X509.new_extension("basicConstraints",
"CA:FALSE")
cert_extension_1.set_critical()

cert_extension_2 = X509.new_extension("keyUsage", "101000000")
cert_extension_2.set_critical()

cert_extension_3 = X509.new_extension("subjectAlternativeName",
"DNS:www.mydomain.tld")

print cert_extension_stack.push(cert_extension_1)
print cert_extension_stack.push(cert_extension_2)
print cert_extension_stack.push(cert_extension_3)

print cert_extension_stack.pop()
-------------------------------------------------

-------------------------------------------------
Traceback (most recent call last):
File "test.py", line 18, in <module>
print cert_extension_stack.pop()
File "/usr/lib64/python2.6/site-packages/M2Crypto/X509.py", line 159,
in pop
assert len(self.pystack) == 0
AssertionError
1
2
3
-------------------------------------------------

 
Reply With Quote
 
 
 
 
Heikki Toivonen
Guest
Posts: n/a
 
      08-03-2009
Matthias Güntert wrote:
> Why is the following code snippet throwing an AssertionError? Is that
> behavior a bug within X509.X509_Extension_Stack()? How would you suggest
> popping every element from the stack?
>
> cert_extension_2 = X509.new_extension("keyUsage", "101000000")


Maybe your OpenSSL is too old. keyUsage needs to be defined in OpenSSL
obj_dat.h file for this to work.

> cert_extension_3 = X509.new_extension("subjectAlternativeName",
> "DNS:www.mydomain.tld")


And I believe you mispelled this, try subjectAltName.

With the change in spelling for subjectAltName your test passes for me
using OpenSSL 1.0.0beta3 and M2Crypto 0.20beta with the (still
incomplete) patch to make M2Crypto work with OpenSSL 1.0:
https://bugzilla.osafoundation.org/s...g.cgi?id=12855

--
Heikki Toivonen - http://heikkitoivonen.net
 
Reply With Quote
 
 
 
 
Matthias Güntert
Guest
Posts: n/a
 
      08-04-2009

> > cert_extension_2 = X509.new_extension("keyUsage", "101000000")

>
> Maybe your OpenSSL is too old. keyUsage needs to be defined in OpenSSL
> obj_dat.h file for this to work.


I am using OpenSSL version 0.9.8k-fips which is the latest version.

I replaced:
cert_extension_2 = X509.new_extension("keyUsage", "101000000")
with:
cert_extension_2 = X509.new_extension("keyUsage", "keyCertSign,
cRLSign")

which worked for me.

Also I found an easy way to iterate through the extension stack using:

cert = X509.X509()
for e in cert_extension_stack:
cert.add_ext(e)

> > cert_extension_3 = X509.new_extension("subjectAlternativeName",
> > "DNS:www.mydomain.tld")


> And I believe you mispelled this, try subjectAltName.


Changing "subjectAlternativeName" to "subjectAltName" did the trick.

Thank you!

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Newbie SWMixer / numpy help - AssertionError Peter Chant Python 2 02-08-2009 09:32 PM
AssertionError not caught? LX Python 3 02-02-2009 03:01 AM
Use of AssertionError Joshua Cranmer Java 9 12-31-2007 03:37 PM
AssertionError in pickle's memoize function Michael Hohn Python 3 10-31-2004 03:13 PM
JSR014 prototype and AssertionError Wolfgang Jeltsch Java 1 12-19-2003 08:38 PM



Advertisments