...

Source file src/github.com/google/certificate-transparency-go/x509/x509_test_import.go

Documentation: github.com/google/certificate-transparency-go/x509

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

View as plain text