Skip to content

Commit bdfacb6

Browse files
authored
Update TLS doc (#4788)
1 parent 316945f commit bdfacb6

1 file changed

Lines changed: 22 additions & 6 deletions

File tree

scapy/layers/tls/cert.py

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,30 @@
1010
Supports both RSA and ECDSA objects.
1111
1212
The 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
2238
No need for obnoxious openssl tweaking anymore. :)
2339
"""

0 commit comments

Comments
 (0)