| 137 | } |
| 138 | |
| 139 | func writePair(t testing.TB, keyPath, certPath string, cert, caCert *x509.Certificate, key, caKey *rsa.PrivateKey) { |
| 140 | keyF, err := os.Create(keyPath) |
| 141 | assert.NilError(t, err) |
| 142 | defer keyF.Close() |
| 143 | assert.NilError(t, pem.Encode(keyF, &pem.Block{Type: "RSA PRIVATE KEY", Bytes: x509.MarshalPKCS1PrivateKey(key)})) |
| 144 | assert.NilError(t, keyF.Close()) |
| 145 | |
| 146 | certB, err := x509.CreateCertificate(rand.Reader, cert, caCert, &key.PublicKey, caKey) |
| 147 | assert.NilError(t, err) |
| 148 | certF, err := os.Create(certPath) |
| 149 | assert.NilError(t, err) |
| 150 | defer certF.Close() |
| 151 | assert.NilError(t, pem.Encode(certF, &pem.Block{Type: "CERTIFICATE", Bytes: certB})) |
| 152 | assert.NilError(t, certF.Close()) |
| 153 | } |
| 154 | |
| 155 | func serialNumber(t testing.TB) *big.Int { |
| 156 | serialNumberLimit := new(big.Int).Lsh(big.NewInt(1), 60) |