gitee.com/ks-custle/core-gm@v0.0.0-20230922171213-b83bdd97b62c/x509/x509_test_import.go (about)

     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  // +build ignore
     7  
     8  // This file is run by the x509 tests to ensure that a program with minimal
     9  // imports can sign certificates without errors resulting from missing hash
    10  // functions.
    11  package main
    12  
    13  import (
    14  	"crypto/rand"
    15  	"crypto/x509/pkix"
    16  	"encoding/pem"
    17  	"gitee.com/ks-custle/core-gm/x509"
    18  	"math/big"
    19  	"strings"
    20  	"time"
    21  )
    22  
    23  func main() {
    24  	block, _ := pem.Decode([]byte(pemPrivateKey))
    25  	rsaPriv, err := x509.ParsePKCS1PrivateKey(block.Bytes)
    26  	if err != nil {
    27  		panic("Failed to parse private key: " + err.Error())
    28  	}
    29  
    30  	template := x509.Certificate{
    31  		SerialNumber: big.NewInt(1),
    32  		Subject: pkix.Name{
    33  			CommonName:   "test",
    34  			Organization: []string{"Σ Acme Co"},
    35  		},
    36  		NotBefore: time.Unix(1000, 0),
    37  		NotAfter:  time.Unix(100000, 0),
    38  		KeyUsage:  x509.KeyUsageCertSign,
    39  	}
    40  
    41  	if _, err = x509.CreateCertificate(rand.Reader, &template, &template, &rsaPriv.PublicKey, rsaPriv); err != nil {
    42  		panic("failed to create certificate with basic imports: " + err.Error())
    43  	}
    44  }
    45  
    46  var pemPrivateKey = testingKey(`-----BEGIN RSA TESTING KEY-----
    47  MIIBOgIBAAJBALKZD0nEffqM1ACuak0bijtqE2QrI/KLADv7l3kK3ppMyCuLKoF0
    48  fd7Ai2KW5ToIwzFofvJcS/STa6HA5gQenRUCAwEAAQJBAIq9amn00aS0h/CrjXqu
    49  /ThglAXJmZhOMPVn4eiu7/ROixi9sex436MaVeMqSNf7Ex9a8fRNfWss7Sqd9eWu
    50  RTUCIQDasvGASLqmjeffBNLTXV2A5g4t+kLVCpsEIZAycV5GswIhANEPLmax0ME/
    51  EO+ZJ79TJKN5yiGBRsv5yvx5UiHxajEXAiAhAol5N4EUyq6I9w1rYdhPMGpLfk7A
    52  IU2snfRJ6Nq2CQIgFrPsWRCkV+gOYcajD17rEqmuLrdIRexpg8N1DOSXoJ8CIGlS
    53  tAboUGBxTDq3ZroNism3DaMIbKPyYrAqhKov1h5V
    54  -----END RSA TESTING KEY-----
    55  `)
    56  
    57  func testingKey(s string) string { return strings.ReplaceAll(s, "TESTING KEY", "PRIVATE KEY") }