Parámetros de M2Crypto Diffie-Hellman como .pem

¿Cuál es el equivalente M2Crypto de este comando openssl cli?

openssl dhparam -out dh.pem 2048 

Mi bash

Mirando a través de los casos de prueba, puedo generar parámetros diffie-hellman como tales:

 >>> import M2Crypto.DH >>> params = M2Crypto.DH.gen_params(2048, 2, lambda: None) 

Sin embargo, no puedo generar una representación .pem de estos parámetros.

No parece haber un método para hacerlo en el objeto DH:

 >>> help(params) Help on instance of DH in module M2Crypto.DH: class DH | Object interface to the Diffie-Hellman key exchange | protocol. | | Methods defined here: | | __del__(self) | | __getattr__(self, name) | | __init__(self, dh, _pyfree=0) | | __len__(self) | | __setattr__(self, name, value) | | check_params(self) | | compute_key(self, pubkey) | | gen_key(self) | | print_params(self, bio) | | ---------------------------------------------------------------------- | Data and other attributes defined here: | | m2_dh_free =  

print_params parece prometedor, pero no es lo que estoy buscando:

 >>> import M2Crypto.BIO >>> bio = M2Crypto.BIO.MemoryBuffer() >>> params.print_params(bio) 1 >>> print bio.read() PKCS#3 DH Parameters: (2048 bit) prime: 00:f3:97:79:b0:53:60:15:0c:26:2a:d9:01:8c:52: ef:04:74:70:2a:0d:90:8c:97:bd:a3:4a:e4:c0:b9: ab:ad:48:3c:e6:51:a3:ea:c4:66:65:11:8f:5f:f3: 05:1d:bd:c2:10:03:bc:dc:bb:bc:48:42:5b:fc:25: bd:60:ce:10:83:bf:62:85:48:bd:51:bb:cd:f6:06: 71:b1:12:55:74:a2:69:98:90:b5:51:7c:da:8a:c4: 28:be:94:ff:86:80:d9:65:aa:55:f7:f2:c4:b2:b3: b3:7d:33:a1:a8:be:dc:40:40:19:df:c8:0e:b1:ff: 03:c4:92:97:b6:47:4f:d3:6f:e3:99:63:9b:3f:58: a0:6c:46:1e:d9:c6:05:81:76:aa:5c:41:cc:fd:2a: cf:7a:e2:5a:66:ce:4d:4c:9b:f3:7c:6f:a9:85:75: f3:78:85:d5:59:31:de:03:99:c9:a7:24:a0:65:75: ac:3c:98:df:77:5b:2f:80:df:66:36:a2:ca:7e:97: 94:b8:cc:ff:8c:9b:3a:58:88:cf:a2:4b:7b:0e:0a: 1d:dc:de:97:37:0d:f4:14:89:80:f6:53:73:7d:4d: 6c:cc:71:c9:46:3f:b5:c9:05:d8:2d:69:4a:aa:9e: ce:bd:d6:33:fa:76:81:26:a2:ea:3e:d9:bc:a6:bf: 60:fb generator: 2 (0x2) 

Funcionalidad relacionada

Para demostrar que no estoy loco, el módulo RSA tiene lo que necesito para crear archivos .pem así:

 >>> import M2Crypto.RSA, M2Crypto.m2 >>> key = M2Crypto.RSA.gen_key(2048, M2Crypto.m2.RSA_F4) >>> print key.as_pem(cipher=None) -----BEGIN RSA PRIVATE KEY----- MIIEowIBAAKCAQEAnU4l0pyjeqEzzKiWFW3xeFzNveUCXY5rJpfvl0e8Mt9diEMB ealZO1+HpyRwmRAy6XTX3CTksYaCr7cRy6leF2nKTbm6Knfu9ye6kb8pbFLCjxhG ouE1tR1Dht3GquJW10pDqjWgxdyrEfjvETqpNoq1axi8WyxIJ0eM0DvYvxg5Meuj PV99AFwp8FNZJtCpWQDY9ZLYxEY9//1/ehza8MRE+TQVvmm9sAofWYSog2UVk9cf xx3YjAMINOmBboM7S2/4SbgL30mx+916hw3D1tstYW4mRi1r2EtHP9KaKf8wWqZW LDUu9DSNd/y58m78xLv5lGXNp6jgE6FyMwjZuQIDAQABAoIBAGQhm5feF3324Rc0 dRy8+ElKobhv7zqIbpKJgnyEsDqdzlbveB/ueZt+qsXtPzNfiVjsBH/giCas3cFm QhCnBfrXX2xsfiGMaHOxOWSPD5ohcDFQHZ6OxvY744EU6OJb4zV1026kZmuslMSC 9gK8mXvbfbHnc/aBUIiYVf0zKzwv+oLYTbZx0MEL3fq8jBiPlqXgHK008eruunJG gHS5WSXeDb2UKlGJZpl5sKifN3Pum7Cx0zq33hW2wFctYsJoVVNBrJyLyw2JzLbV EQ1oN6NCVWtIpKbPrd7pmwnAUuc4l+I/cY438Wh+OomXlICZvJ7yvcmuJVL9NZCR CIqz4gECgYEA0MDLmfb3/5v1ezBqDvi6yr7huCqlgcTai/1OlQeWecxUnywvtgCC W3Rf89WSzitavuFMBHqRB7zj2F2BoosZWSXib6VEatc8+s72Bm822R8/KS8CEM7S DyXMDxisDfOyeagdfXPQmGAZDloOXSdB8DcDO2uO2gxxwsr0aPcOBMECgYEAwOhz xDvbvXcTumMWBsmQXecWkG1x1YjwCN+0fU6I+EqRULzcKu6i3i48cNtfmvVL0xJp gM6e3VSM9sWIE2s1poBnsLNflVCN6ecW6iChsBXZY++rA9OvmdnROQ2Fn7xCIJ2p edtbK7tUHM3DEwyXLH8Yj6RAwjMnZr1+lNlyuvkCgYEAhBPHfhWVGWOasKOUJv7W aFrXQ4ewCef8AqB1LLONUGiojcEOOtAdqjF6WDMj3E/v7V9sklTeGBA59HZNBAOQ OShQGSVuoU6nZWS2oqGRCVTMyIjWfL3uh+j5MAADNByhKnnklrBFJXN/xuXRuryQ 6qRT5i+KRYmkHIP+mb7eXsECgYBC1QWueZJyfHugOk3aQiC696GQneovMYb/fAk6 1GeNpb/ceeHJGe3hDaGw87+Wnt8LHDjjADJ3uaAwqlSvbZgjvB6wUCSQRV01KPN+ X5nEuH0dK15TMBaJNbZPjsi5g25hgF3DsuROLVNBu2OXCOii6NFoil5JKZG//WyK Qx+FeQKBgGWT7kNTAh7zy3Bz0P6rmYe+5Om/u4aGuQ6jVIvzP3ysYWZwiYTwa5C2 CpDHaz4W2JBg3XAhVtRMZn2bW09HH3PN7lJhdzxGBlpaiS5ODdRDURbCbGoe/qPQ l4FraLtLYJ46+3JPgInVU5e48kQFnfN03yakdSzduNbxraEkJy49 -----END RSA PRIVATE KEY----- 

Información de la versión

 >>> import platform >>> print platform.release() 3.11.0-15-generic >>> import sys >>> print sys.version 2.7.5+ (default, Feb 27 2014, 19:37:08) [GCC 4.8.1] >>> import M2Crypto >>> print M2Crypto.version 0.22