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