Source file
src/crypto/x509/x509_test_import.go
1
2
3
4
5
6
7
8
9
10 package main
11
12 import (
13 "crypto/rand"
14 "crypto/x509"
15 "crypto/x509/pkix"
16 "encoding/pem"
17 "math/big"
18 "strings"
19 "time"
20 )
21
22 func main() {
23 block, _ := pem.Decode([]byte(pemPrivateKey))
24 rsaPriv, err := x509.ParsePKCS1PrivateKey(block.Bytes)
25 if err != nil {
26 panic("Failed to parse private key: " + err.Error())
27 }
28
29 template := x509.Certificate{
30 SerialNumber: big.NewInt(1),
31 Subject: pkix.Name{
32 CommonName: "test",
33 Organization: []string{"Σ Acme Co"},
34 },
35 NotBefore: time.Unix(1000, 0),
36 NotAfter: time.Unix(100000, 0),
37 KeyUsage: x509.KeyUsageCertSign,
38 }
39
40 if _, err = x509.CreateCertificate(rand.Reader, &template, &template, &rsaPriv.PublicKey, rsaPriv); err != nil {
41 panic("failed to create certificate with basic imports: " + err.Error())
42 }
43 }
44
45 var pemPrivateKey = testingKey(`-----BEGIN RSA TESTING KEY-----
46 MIIBOgIBAAJBALKZD0nEffqM1ACuak0bijtqE2QrI/KLADv7l3kK3ppMyCuLKoF0
47 fd7Ai2KW5ToIwzFofvJcS/STa6HA5gQenRUCAwEAAQJBAIq9amn00aS0h/CrjXqu
48 /ThglAXJmZhOMPVn4eiu7/ROixi9sex436MaVeMqSNf7Ex9a8fRNfWss7Sqd9eWu
49 RTUCIQDasvGASLqmjeffBNLTXV2A5g4t+kLVCpsEIZAycV5GswIhANEPLmax0ME/
50 EO+ZJ79TJKN5yiGBRsv5yvx5UiHxajEXAiAhAol5N4EUyq6I9w1rYdhPMGpLfk7A
51 IU2snfRJ6Nq2CQIgFrPsWRCkV+gOYcajD17rEqmuLrdIRexpg8N1DOSXoJ8CIGlS
52 tAboUGBxTDq3ZroNism3DaMIbKPyYrAqhKov1h5V
53 -----END RSA TESTING KEY-----
54 `)
55
56 func testingKey(s string) string { return strings.ReplaceAll(s, "TESTING KEY", "PRIVATE KEY") }
57
View as plain text