Generate TLS certificate request for testing
()
| 52 | |
| 53 | |
| 54 | def gen_cert(): |
| 55 | """ |
| 56 | Generate TLS certificate request for testing |
| 57 | """ |
| 58 | |
| 59 | req, key = gen_req() |
| 60 | pub_key = req.get_pubkey() |
| 61 | subject = req.get_subject() |
| 62 | cert = X509.X509() |
| 63 | # noinspection PyTypeChecker |
| 64 | cert.set_serial_number(1) |
| 65 | cert.set_version(2) |
| 66 | cert.set_subject(subject) |
| 67 | t = int(time.time()) |
| 68 | now = ASN1.ASN1_UTCTIME() |
| 69 | now.set_time(t) |
| 70 | now_plus_year = ASN1.ASN1_UTCTIME() |
| 71 | now_plus_year.set_time(t + 60 * 60 * 24 * 365) |
| 72 | cert.set_not_before(now) |
| 73 | cert.set_not_after(now_plus_year) |
| 74 | issuer = X509.X509_Name() |
| 75 | issuer.C = 'US' |
| 76 | issuer.CN = 'minifi-listen' |
| 77 | cert.set_issuer(issuer) |
| 78 | cert.set_pubkey(pub_key) |
| 79 | cert.sign(key, 'sha256') |
| 80 | |
| 81 | return cert, key |
| 82 | |
| 83 | |
| 84 | def gen_req(): |
no test coverage detected