1// Copyright 2013 The Go Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style
3// license that can be found in the LICENSE file.
4
5//go:build ignore
6
7// This file is run by the x509 tests to ensure that a program with minimal
8// imports can sign certificates without errors resulting from missing hash
9// functions.
10package main
11
12import (
13	"crypto/rand"
14	"crypto/x509"
15	"crypto/x509/pkix"
16	"encoding/pem"
17	"math/big"
18	"strings"
19	"time"
20)
21
22func 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
45var pemPrivateKey = testingKey(`-----BEGIN RSA TESTING KEY-----
46MIIBOgIBAAJBALKZD0nEffqM1ACuak0bijtqE2QrI/KLADv7l3kK3ppMyCuLKoF0
47fd7Ai2KW5ToIwzFofvJcS/STa6HA5gQenRUCAwEAAQJBAIq9amn00aS0h/CrjXqu
48/ThglAXJmZhOMPVn4eiu7/ROixi9sex436MaVeMqSNf7Ex9a8fRNfWss7Sqd9eWu
49RTUCIQDasvGASLqmjeffBNLTXV2A5g4t+kLVCpsEIZAycV5GswIhANEPLmax0ME/
50EO+ZJ79TJKN5yiGBRsv5yvx5UiHxajEXAiAhAol5N4EUyq6I9w1rYdhPMGpLfk7A
51IU2snfRJ6Nq2CQIgFrPsWRCkV+gOYcajD17rEqmuLrdIRexpg8N1DOSXoJ8CIGlS
52tAboUGBxTDq3ZroNism3DaMIbKPyYrAqhKov1h5V
53-----END RSA TESTING KEY-----
54`)
55
56func testingKey(s string) string { return strings.ReplaceAll(s, "TESTING KEY", "PRIVATE KEY") }
57