File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1010Supports both RSA and ECDSA objects.
1111
1212The classes below are wrappers for the ASN.1 objects defined in x509.py.
13- For instance, here is what you could do in order to modify the serial of
14- 'cert' and then resign it with whatever 'key'::
13+ For instance, here is what you could do in order to modify the subject public
14+ key info of a 'cert' and then resign it with whatever 'key'::
1515
16- f = open('cert.der')
17- c = X509_Cert(f.read())
16+ from scapy.layers.tls.cert import *
17+ cert = Cert("cert.der")
18+ k = PrivKeyRSA() # generate a private key
19+ cert.setSubjectPublicKeyFromPrivateKey(k)
20+ cert.resignWith(k)
21+ cert.export("newcert.pem")
22+ k.export("mykey.pem")
23+
24+ One could also edit arguments like the serial number, as such::
25+
26+ from scapy.layers.tls.cert import *
27+ c = Cert("mycert.pem")
1828 c.tbsCertificate.serialNumber = 0x4B1D
19- k = PrivKey('key.pem')
20- new_x509_cert = k.resignCert(c)
29+ k = PrivKey("mykey.pem") # import an existing private key
30+ c.resignWith(k)
31+ c.export("newcert.pem")
32+
33+ To export the public key of a private key::
34+
35+ k = PrivKey("mykey.pem")
36+ k.pubkey.export("mypubkey.pem")
2137
2238No need for obnoxious openssl tweaking anymore. :)
2339"""
You can’t perform that action at this time.
0 commit comments