...

Source file src/github.com/sigstore/rekor/pkg/pki/ssh/e2e_test.go

Documentation: github.com/sigstore/rekor/pkg/pki/ssh

     1  //
     2  // Copyright 2022 The Sigstore Authors.
     3  //
     4  // Licensed under the Apache License, Version 2.0 (the "License");
     5  // you may not use this file except in compliance with the License.
     6  // You may obtain a copy of the License at
     7  //
     8  //     http://www.apache.org/licenses/LICENSE-2.0
     9  //
    10  // Unless required by applicable law or agreed to in writing, software
    11  // distributed under the License is distributed on an "AS IS" BASIS,
    12  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  // See the License for the specific language governing permissions and
    14  // limitations under the License.
    15  
    16  //go:build e2e
    17  
    18  package ssh
    19  
    20  import (
    21  	"github.com/sigstore/rekor/pkg/util"
    22  	"io/ioutil"
    23  	"path/filepath"
    24  	"strings"
    25  	"testing"
    26  )
    27  
    28  func TestSSH(t *testing.T) {
    29  	td := t.TempDir()
    30  	// Create a keypair
    31  	keyPath := filepath.Join(td, "id_rsa")
    32  	pubPath := filepath.Join(td, "id_rsa.pub")
    33  
    34  	if err := ioutil.WriteFile(pubPath, []byte(publicKey), 0600); err != nil {
    35  		t.Fatal(err)
    36  	}
    37  	if err := ioutil.WriteFile(keyPath, []byte(privateKey), 0600); err != nil {
    38  		t.Fatal(err)
    39  	}
    40  
    41  	// Create a random artifact and sign it.
    42  	artifactPath := filepath.Join(td, "artifact")
    43  	sigPath := filepath.Join(td, "signature.sig")
    44  	artifact := util.CreateArtifact(t, artifactPath)
    45  
    46  	sig := SSHSign(t, strings.NewReader(artifact))
    47  	if err := ioutil.WriteFile(sigPath, []byte(sig), 0600); err != nil {
    48  		t.Fatal(err)
    49  	}
    50  
    51  	// Now upload to the log!
    52  	out := util.RunCli(t, "upload", "--artifact", artifactPath, "--signature", sigPath,
    53  		"--public-key", pubPath, "--pki-format", "ssh")
    54  	util.OutputContains(t, out, "Created entry at")
    55  
    56  	uuid := util.GetUUIDFromUploadOutput(t, out)
    57  
    58  	out = util.RunCli(t, "verify", "--artifact", artifactPath, "--signature", sigPath,
    59  		"--public-key", pubPath, "--pki-format", "ssh")
    60  	util.OutputContains(t, out, "Inclusion Proof")
    61  
    62  	out = util.RunCli(t, "search", "--public-key", pubPath, "--pki-format", "ssh")
    63  	util.OutputContains(t, out, uuid)
    64  }
    65  

View as plain text