| 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. |
| 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 |
MIICXQIBAAKBgQCw0YNSqI9T1VFvRsIOejZ9feiKz1SgGfbe9Xq5tEzt2yJCsbyg |
| 47 |
+xtcuCswNhdqY5A1ZN7G60HbL4/Hh/TlLhFJ4zNHVylz9mDDx3yp4IIcK2lb566d |
| 48 |
fTD0B5EQ9Iqub4twLUdLKQCBfyhmJJvsEqKxm4J4QWgI+Brh/Pm3d4piPwIDAQAB |
| 49 |
AoGASC6fj6TkLfMNdYHLQqG9kOlPfys4fstarpZD7X+fUBJ/H/7y5DzeZLGCYAIU |
| 50 |
+QeAHWv6TfZIQjReW7Qy00RFJdgwFlTFRCsKXhG5x+IB+jL0Grr08KbgPPDgy4Jm |
| 51 |
xirRHZVtU8lGbkiZX+omDIU28EHLNWL6rFEcTWao/tERspECQQDp2G5Nw0qYWn7H |
| 52 |
Wm9Up1zkUTnkUkCzhqtxHbeRvNmHGKE7ryGMJEk2RmgHVstQpsvuFY4lIUSZEjAc |
| 53 |
DUFJERhFAkEAwZH6O1ULORp8sHKDdidyleYcZU8L7y9Y3OXJYqELfddfBgFUZeVQ |
| 54 |
duRmJj7ryu0g0uurOTE+i8VnMg/ostxiswJBAOc64Dd8uLJWKa6uug+XPr91oi0n |
| 55 |
OFtM+xHrNK2jc+WmcSg3UJDnAI3uqMc5B+pERLq0Dc6hStehqHjUko3RnZECQEGZ |
| 56 |
eRYWciE+Cre5dzfZkomeXE0xBrhecV0bOq6EKWLSVE+yr6mAl05ThRK9DCfPSOpy |
| 57 |
F6rgN3QiyCA9J/1FluUCQQC5nX+PTU1FXx+6Ri2ZCi6EjEKMHr7gHcABhMinZYOt |
| 58 |
N59pra9UdVQw9jxCU9G7eMyb0jJkNACAuEwakX3gi27b |
| 59 |
-----END RSA TESTING KEY----- |
| 60 |
`) |
| 61 |
|
| 62 |
func testingKey(s string) string { return strings.ReplaceAll(s, "TESTING KEY", "PRIVATE KEY") } |