github.com/meulengracht/snapd@v0.0.0-20210719210640-8bde69bcc84e/asserts/privkeys_for_test.go (about)

     1  // -*- Mode: Go; indent-tabs-mode: t -*-
     2  
     3  /*
     4   * Copyright (C) 2015 Canonical Ltd
     5   *
     6   * This program is free software: you can redistribute it and/or modify
     7   * it under the terms of the GNU General Public License version 3 as
     8   * published by the Free Software Foundation.
     9   *
    10   * This program is distributed in the hope that it will be useful,
    11   * but WITHOUT ANY WARRANTY; without even the implied warranty of
    12   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    13   * GNU General Public License for more details.
    14   *
    15   * You should have received a copy of the GNU General Public License
    16   * along with this program.  If not, see <http://www.gnu.org/licenses/>.
    17   *
    18   */
    19  
    20  package asserts_test
    21  
    22  import (
    23  	"encoding/base64"
    24  
    25  	"golang.org/x/crypto/openpgp/packet"
    26  	"golang.org/x/crypto/sha3"
    27  
    28  	"github.com/snapcore/snapd/asserts"
    29  	"github.com/snapcore/snapd/asserts/assertstest"
    30  )
    31  
    32  // private keys to use in tests
    33  var (
    34  	// use a shorter key length here for test keys because otherwise
    35  	// they take too long to generate;
    36  	// the ones that care use pregenerated keys of the right length
    37  	// or use GenerateKey directly
    38  	testPrivKey0, _               = assertstest.GenerateKey(752)
    39  	testPrivKey1, testPrivKey1RSA = assertstest.GenerateKey(752)
    40  	testPrivKey2, _               = assertstest.GenerateKey(752)
    41  
    42  	testPrivKey1SHA3_384 string
    43  )
    44  
    45  func init() {
    46  	pkt := packet.NewRSAPrivateKey(asserts.V1FixedTimestamp, testPrivKey1RSA)
    47  	h := sha3.New384()
    48  	h.Write([]byte{0x1})
    49  	err := pkt.PublicKey.Serialize(h)
    50  	if err != nil {
    51  		panic(err)
    52  	}
    53  	testPrivKey1SHA3_384 = base64.RawURLEncoding.EncodeToString(h.Sum(nil))
    54  }