| 1 | // |
| 2 | // Copyright 2021 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 | package sshscip-go gomod github.com/sigstore/sigstore . `github.com/sigstore/sigstore/pkg/signature/ssh`/ |
| 17 | |
| 18 | import ( |
| 19 | "bytesscip-go gomod github.com/golang/go/src go1.25.0 bytes/" |
| 20 | "osscip-go gomod github.com/golang/go/src go1.25.0 os/" |
| 21 | "os/execscip-go gomod github.com/golang/go/src go1.25.0 `os/exec`/" |
| 22 | "path/filepathscip-go gomod github.com/golang/go/src go1.25.0 `path/filepath`/" |
| 23 | "stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/" |
| 24 | "testingscip-go gomod github.com/golang/go/src go1.25.0 testing/" |
| 25 | |
| 26 | "golang.org/x/crypto/sshscip-go gomod golang.org/x/crypto v0.54.0 `golang.org/x/crypto/ssh`/" |
| 27 | ) |
| 28 | |
| 29 | var ( |
| 30 | // Generated with "ssh-keygen -C [email protected] -f id_rsa" |
| 31 | sshPrivateKeyscip-go gomod github.com/sigstore/sigstore . `github.com/sigstore/sigstore/pkg/signature/ssh`/sshPrivateKey. = `-----BEGIN OPENSSH PRIVATE KEY----- |
| 32 | b3BlbnNzaC1rZXktdjEAAAAABG5vbmUAAAAEbm9uZQAAAAAAAAABAAABlwAAAAdzc2gtcn |
| 33 | NhAAAAAwEAAQAAAYEA16H5ImoRO7mr41r8Z8JFBdu6jIM+6XU8M0r9F81RuhLYqzr9zw1n |
| 34 | LeGCqFxPXNBK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ieDQmgwZzSX/v |
| 62 | ZiGsOIKa6cR37eKvOJSjVrHsAUzdtYrmi8P2gvAUFWyzXobAtpzHcWrwWkOEIm04G0OGXb |
| 63 | J46hfIX3f45E5EKXvFzexGgVOD2I7hAAAAwQDhniYAizfW9YfG7UJWekkl42xMP7Cb8b0W |
| 64 | SindSIuE8bFTukV1yxbmNZp/f0pKvn/DWc2n0I0bwSGZpy8BCY46RKKB2DYQavY/tGcC1N |
| 65 | AynKuvbtWs11A0mTXmq3WwHVXQDozMwJ2nnHpm0UHspPuHqkYpurlP+xoFsocaQ9QwITyp |
| 66 | lL4qHtXBEzaT8okkcGZBHdSx3gk4TzCsEDOP7ZZPLq42lpKMK10zFPTMd0maXtJDYKU/b4 |
| 67 | gAATvvPoylyYUAAAAOdGVzdEByZWtvci5kZXYBAgMEBQ== |
| 68 | -----END OPENSSH PRIVATE KEY----- |
| 69 | ` |
| 70 | sshPublicKeyscip-go gomod github.com/sigstore/sigstore . `github.com/sigstore/sigstore/pkg/signature/ssh`/sshPublicKey. = `ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQDXofkiahE7uavjWvxnwkUF27qMgz7pdTwzSv0XzVG6EtirOv3PDWct4YKoXE9c0EqbxnIfYEKwEextdvB7zkgwczdJSHxf/18jQumLn/FuoCmugVSk1H5Qli/qzwBpaTnOk3WuakGuoYUl8ZAokKKgOKLA0aZJ1WRQ2ZCZggA3EkwNZiY17y9Q6HqdgQcH6XN8aAMADNVJdMAJb33hSRJjjsAPTmzBTishP8lYDoGRSsSE7/8XRBCEV5E4I8mI9GElcZwV/1KJx98mpH8QvMzXM1idFcwPRtt1NTAOshwgUU0Fu1x8lU5RQIa6ZKW36qNQLvLxy/BscC7B/mdLptoDs/ot9NimUXZcgCR1a2Q3o7Wi6jIgcgJcyV10Nba81ol4RdN4qPHnVZIzuo+dBkqwG3CMtB4Rj84+Qi+7zyU01hIPreoxQDXaayiGPBUUIiAlW9gsiuRWJzNnu3cvuWDLVfQIkjh7Wug58z+v2NOJ7IMdyERillhzDcvVHaq14+U= [email protected] |
| 71 | ` |
| 72 | // Generated with "ssh-keygen -C [email protected] -f id_rsa" |
| 73 | otherSSHPrivateKeyscip-go gomod github.com/sigstore/sigstore . `github.com/sigstore/sigstore/pkg/signature/ssh`/otherSSHPrivateKey. = `-----BEGIN OPENSSH PRIVATE KEY----- |
| 74 | b3BlbnNzaC1rZXktdjEAAAAABG5vbmUAAAAEbm9uZQAAAAAAAAABAAABlwAAAAdzc2gtcn |
| 75 | NhAAAAAwEAAQAAAYEAw/WCSWC9TEvCQOwO+T68EvNa3OSIv1Y0+sT8uSvyjPyEO0+p0t8C |
| 76 | g/zy67vOxiQpU5jN6MItjXAjMmeCm8GKMt6gk+cDoaAev/ZfjuzSL7RayExpmhBleh2X3G |
| 77 | KLkkXF9ABFNchlTqSLOZiEjDoNpbFv16KT1sE6CqW8DjxXQkQk9JK65hLH+BxeWMNCEJVa |
| 78 | Cma4X04aJmC7zJAi5yGeeT0SKVqMohavF90O6XiYFCQHuwXPPyHfocqgudmXnozz+6D6ax |
| 79 | JKZMwQsNp3WKumOjlzWnxBCCB1l2jN6Rag8aJ2277iMFXRwjTL/8jaEsW4KkysDf0GjV2/ |
| 80 | iqbr0q5b0arDYbv7CrGBR+uH0wGz/Zog1x5iZANObhZULpDrLVJidEMc27HXBb7PMsNDy7 |
| 81 | BGYRB1yc0d0y83p8mUqvOlWSArxn1WnAZO04pAgTrclrhEh4ZXOkn2Sn82eu3DpQ8inkol |
| 82 | Y4IfnhIfbOIeemoUNq1tOUquhow9GLRM6INieHLBAAAFkPPnA1jz5wNYAAAAB3NzaC1yc2 |
| 83 | EAAAGBAMP1gklgvUxLwkDsDvk+vBLzWtzkiL9WNPrE/Lkr8oz8hDtPqdLfAoP88uu7zsYk |
| 84 | KVOYzejCLY1wIzJngpvBijLeoJPnA6GgHr/2X47s0i+0WshMaZoQZXodl9xii5JFxfQART |
| 85 | XIZU6kizmYhIw6DaWxb9eik9bBOgq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rfp5PLJlo70P5lXS8u2QPbo4/KQJmQmsIX18LDyU2zRtNA |
| 100 | C2WfBiHSZV+guLhmHms9S5gQYKt2T5OnY/W0tmnInx9lmFCMC+XKS1iSQ2o433IrtCPQJp |
| 101 | IXZd59OQpO9QjJABgJIDtXxFIXt45qpXduDPJuggrhg81stOwAAADBAPX73u/CY+QUPts+ |
| 102 | LV185Z4mZ2y+qu2ZMCAU3BnpHktGZZ1vFN1Xq9o8KdnuPZ+QJRdO8eKMWpySqrIdIbTYLm |
| 103 | 9nXmVH0uNECIEAvdU+wgKeR+BSHxCRVuTF4YSygmNadgH/z+oRWLgOblGo2ywFBoXsIAKQ |
| 104 | paNu1MFGRUmhz67+dcpkkBUDRU9loAgBKexMo8D9vkR0YiHLOUjCrtmEZRNm0YRZt0gQhD |
| 105 | ZSD1fOH0fZDcCVNpGP2zqAKos4EGLnkwAAAMEAy/AuLtPKA2u9oCA8e18ZnuQRAi27FBVU |
| 106 | rU2D7bMg1eS0IakG8v0gE9K6WdYzyArY1RoKB3ZklK5VmJ1cOcWc2x3Ejc5jcJgc8cC6lZ |
| 107 | wwjpE8HfWL1kIIYgPdcexqFc+l6MdgH6QMKU3nLg1LsM4v5FEldtk/2dmnw620xnFfstpF |
| 108 | VxSZNdKrYfM/v9o6sRaDRqSfH1dG8BvkUxPznTAF+JDxBENcKXYECcq9f6dcl1w5IEnNTD |
| 109 | Wry/EKQvgvOUjbAAAAFG90aGVyLXRlc3RAcmVrb3IuZGV2AQIDBAUG |
| 110 | -----END OPENSSH PRIVATE KEY----- |
| 111 | ` |
| 112 | otherSSHPublicKeyscip-go gomod github.com/sigstore/sigstore . `github.com/sigstore/sigstore/pkg/signature/ssh`/otherSSHPublicKey. = `ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQDD9YJJYL1MS8JA7A75PrwS81rc5Ii/VjT6xPy5K/KM/IQ7T6nS3wKD/PLru87GJClTmM3owi2NcCMyZ4KbwYoy3qCT5wOhoB6/9l+O7NIvtFrITGmaEGV6HZfcYouSRcX0AEU1yGVOpIs5mISMOg2lsW/XopPWwToKpbwOPFdCRCT0krrmEsf4HF5Yw0IQlVoKZrhfThomYLvMkCLnIZ55PRIpWoyiFq8X3Q7peJgUJAe7Bc8/Id+hyqC52ZeejPP7oPprEkpkzBCw2ndYq6Y6OXNafEEIIHWXaM3pFqDxonbbvuIwVdHCNMv/yNoSxbgqTKwN/QaNXb+KpuvSrlvRqsNhu/sKsYFH64fTAbP9miDXHmJkA05uFlQukOstUmJ0QxzbsdcFvs8yw0PLsEZhEHXJzR3TLzenyZSq86VZICvGfVacBk7TikCBOtyWuESHhlc6SfZKfzZ67cOlDyKeSiVjgh+eEh9s4h56ahQ2rW05Sq6GjD0YtEzog2J4csE= [email protected] |
| 113 | ` |
| 114 | |
| 115 | // Generated with ssh-keygen -C [email protected] -t ed25519 -f id_ed25519 |
| 116 | ed25519PrivateKeyscip-go gomod github.com/sigstore/sigstore . `github.com/sigstore/sigstore/pkg/signature/ssh`/ed25519PrivateKey. = `-----BEGIN OPENSSH PRIVATE KEY----- |
| 117 | b3BlbnNzaC1rZXktdjEAAAAABG5vbmUAAAAEbm9uZQAAAAAAAAABAAAAMwAAAAtzc2gtZW |
| 118 | QyNTUxOQAAACBB45zRHxPPFtabwS3Vd6Lb9vMe+tIHZj2qN5VQ+bgLfQAAAJgyRa3cMkWt |
| 119 | 3AAAAAtzc2gtZWQyNTUxOQAAACBB45zRHxPPFtabwS3Vd6Lb9vMe+tIHZj2qN5VQ+bgLfQ |
| 120 | AAAED7y4N/DsVnRQiBZNxEWdsJ9RmbranvtQ3X9jnb6gFed0HjnNEfE88W1pvBLdV3otv2 |
| 121 | 8x760gdmPao3lVD5uAt9AAAADnRlc3RAcmVrb3IuZGV2AQIDBAUGBw== |
| 122 | -----END OPENSSH PRIVATE KEY----- |
| 123 | ` |
| 124 | ed25519PublicKeyscip-go gomod github.com/sigstore/sigstore . `github.com/sigstore/sigstore/pkg/signature/ssh`/ed25519PublicKey. = `ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIEHjnNEfE88W1pvBLdV3otv28x760gdmPao3lVD5uAt9 [email protected] |
| 125 | ` |
| 126 | ) |
| 127 | |
| 128 | func TestFromOpenSSHscip-go gomod github.com/sigstore/sigstore . `github.com/sigstore/sigstore/pkg/signature/ssh`/TestFromOpenSSH().(t *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Tscip-go gomod github.com/golang/go/src go1.25.0 testing/T#) { |
| 129 | otherPub, _, _, _, err := sshscip-go gomod golang.org/x/crypto v0.54.0 `golang.org/x/crypto/ssh`/.ParseAuthorizedKeyscip-go gomod golang.org/x/crypto v0.54.0 `golang.org/x/crypto/ssh`/ParseAuthorizedKey().([]byte(otherSSHPublicKeyscip-go gomod github.com/sigstore/sigstore . `github.com/sigstore/sigstore/pkg/signature/ssh`/otherSSHPublicKey.)) |
| 130 | if err != nil { |
| 131 | t.Fatalscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatal().(err) |
| 132 | } |
| 133 | // pub, _, _, _, err := ssh.ParseAuthorizedKey([]byte(sshPublicKey)) |
| 134 | // if err != nil { |
| 135 | // t.Fatal(err) |
| 136 | // } |
| 137 | for _, tt := range []struct { |
| 138 | name string |
| 139 | pub string |
| 140 | priv string |
| 141 | }{ |
| 142 | { |
| 143 | name: "rsa", |
| 144 | pub: sshPublicKeyscip-go gomod github.com/sigstore/sigstore . `github.com/sigstore/sigstore/pkg/signature/ssh`/sshPublicKey., |
| 145 | priv: sshPrivateKeyscip-go gomod github.com/sigstore/sigstore . `github.com/sigstore/sigstore/pkg/signature/ssh`/sshPrivateKey., |
| 146 | }, |
| 147 | { |
| 148 | name: "ed25519", |
| 149 | pub: ed25519PublicKeyscip-go gomod github.com/sigstore/sigstore . `github.com/sigstore/sigstore/pkg/signature/ssh`/ed25519PublicKey., |
| 150 | priv: ed25519PrivateKeyscip-go gomod github.com/sigstore/sigstore . `github.com/sigstore/sigstore/pkg/signature/ssh`/ed25519PrivateKey., |
| 151 | }, |
| 152 | } { |
| 153 | if _, err := execscip-go gomod github.com/golang/go/src go1.25.0 `os/exec`/.LookPathscip-go gomod github.com/golang/go/src go1.25.0 `os/exec`/LookPath().("ssh-keygen"); err != nil { |
| 154 | t.Skipscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Skip().("skip TestFromOpenSSH: missing ssh-keygen in PATH") |
| 155 | } |
| 156 | t.Runscip-go gomod github.com/golang/go/src go1.25.0 testing/T#Run().(tt.name, func(t *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Tscip-go gomod github.com/golang/go/src go1.25.0 testing/T#) { |
| 157 | tt := tt |
| 158 | |
| 159 | // Test that a signature from the cli can validate here. |
| 160 | td := t.TempDirscip-go gomod github.com/golang/go/src go1.25.0 testing/common#TempDir().() |
| 161 | |
| 162 | data := []byte("hello, ssh world") |
| 163 | dataPath := writescip-go gomod github.com/sigstore/sigstore . `github.com/sigstore/sigstore/pkg/signature/ssh`/write().(t, data, td, "data") |
| 164 | |
| 165 | privPath := writescip-go gomod github.com/sigstore/sigstore . `github.com/sigstore/sigstore/pkg/signature/ssh`/write().(t, []byte(tt.priv), td, "id") |
| 166 | writescip-go gomod github.com/sigstore/sigstore . `github.com/sigstore/sigstore/pkg/signature/ssh`/write().(t, []byte(tt.pub), td, "id.pub") |
| 167 | |
| 168 | sigPath := dataPath + ".sig" |
| 169 | runscip-go gomod github.com/sigstore/sigstore . `github.com/sigstore/sigstore/pkg/signature/ssh`/run().(t, nil, "ssh-keygen", "-Y", "sign", "-n", "file", "-f", privPath, dataPath) |
| 170 | |
| 171 | sigBytes, err := osscip-go gomod github.com/golang/go/src go1.25.0 os/.ReadFilescip-go gomod github.com/golang/go/src go1.25.0 os/ReadFile().(sigPath) |
| 172 | if err != nil { |
| 173 | t.Fatalscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatal().(err) |
| 174 | } |
| 175 | pub, _, _, _, err := sshscip-go gomod golang.org/x/crypto v0.54.0 `golang.org/x/crypto/ssh`/.ParseAuthorizedKeyscip-go gomod golang.org/x/crypto v0.54.0 `golang.org/x/crypto/ssh`/ParseAuthorizedKey().([]byte(tt.pub)) |
| 176 | if err != nil { |
| 177 | t.Fatalscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatal().(err) |
| 178 | } |
| 179 | if err := Verifyscip-go gomod github.com/sigstore/sigstore . `github.com/sigstore/sigstore/pkg/signature/ssh`/Verify().(bytesscip-go gomod github.com/golang/go/src go1.25.0 bytes/.NewReaderscip-go gomod github.com/golang/go/src go1.25.0 bytes/NewReader().(data), sigBytes, pub); err != nil { |
| 180 | t.Errorscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Error().(err) |
| 181 | } |
| 182 | |
| 183 | // It should not verify if we check against another public key |
| 184 | if err := Verifyscip-go gomod github.com/sigstore/sigstore . `github.com/sigstore/sigstore/pkg/signature/ssh`/Verify().(bytesscip-go gomod github.com/golang/go/src go1.25.0 bytes/.NewReaderscip-go gomod github.com/golang/go/src go1.25.0 bytes/NewReader().(data), sigBytes, otherPub); err == nil { |
| 185 | t.Errorscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Error().("expected error with incorrect key") |
| 186 | } |
| 187 | |
| 188 | // It should not verify if the data is tampered |
| 189 | if err := Verifyscip-go gomod github.com/sigstore/sigstore . `github.com/sigstore/sigstore/pkg/signature/ssh`/Verify().(stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/.NewReaderscip-go gomod github.com/golang/go/src go1.25.0 strings/NewReader().("bad data"), sigBytes, pub); err == nil { |
| 190 | t.Errorscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Error().("expected error with incorrect data") |
| 191 | } |
| 192 | }) |
| 193 | } |
| 194 | } |
| 195 | |
| 196 | func TestToOpenSSHscip-go gomod github.com/sigstore/sigstore . `github.com/sigstore/sigstore/pkg/signature/ssh`/TestToOpenSSH().(t *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Tscip-go gomod github.com/golang/go/src go1.25.0 testing/T#) { |
| 197 | for _, tt := range []struct { |
| 198 | name string |
| 199 | pub string |
| 200 | priv string |
| 201 | }{ |
| 202 | { |
| 203 | name: "rsa", |
| 204 | pub: sshPublicKeyscip-go gomod github.com/sigstore/sigstore . `github.com/sigstore/sigstore/pkg/signature/ssh`/sshPublicKey., |
| 205 | priv: sshPrivateKeyscip-go gomod github.com/sigstore/sigstore . `github.com/sigstore/sigstore/pkg/signature/ssh`/sshPrivateKey., |
| 206 | }, |
| 207 | { |
| 208 | name: "ed25519", |
| 209 | pub: ed25519PublicKeyscip-go gomod github.com/sigstore/sigstore . `github.com/sigstore/sigstore/pkg/signature/ssh`/ed25519PublicKey., |
| 210 | priv: ed25519PrivateKeyscip-go gomod github.com/sigstore/sigstore . `github.com/sigstore/sigstore/pkg/signature/ssh`/ed25519PrivateKey., |
| 211 | }, |
| 212 | } { |
| 213 | if _, err := execscip-go gomod github.com/golang/go/src go1.25.0 `os/exec`/.LookPathscip-go gomod github.com/golang/go/src go1.25.0 `os/exec`/LookPath().("ssh-keygen"); err != nil { |
| 214 | t.Skipscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Skip().("skip TestToOpenSSH: missing ssh-keygen in PATH") |
| 215 | } |
| 216 | t.Runscip-go gomod github.com/golang/go/src go1.25.0 testing/T#Run().(tt.name, func(t *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Tscip-go gomod github.com/golang/go/src go1.25.0 testing/T#) { |
| 217 | tt := tt |
| 218 | // Test that a signature from here can validate in the CLI. |
| 219 | td := t.TempDirscip-go gomod github.com/golang/go/src go1.25.0 testing/common#TempDir().() |
| 220 | |
| 221 | data := []byte("hello, ssh world") |
| 222 | writescip-go gomod github.com/sigstore/sigstore . `github.com/sigstore/sigstore/pkg/signature/ssh`/write().(t, data, td, "data") |
| 223 | |
| 224 | armored, err := Signscip-go gomod github.com/sigstore/sigstore . `github.com/sigstore/sigstore/pkg/signature/ssh`/Sign().(tt.priv, bytesscip-go gomod github.com/golang/go/src go1.25.0 bytes/.NewReaderscip-go gomod github.com/golang/go/src go1.25.0 bytes/NewReader().(data)) |
| 225 | if err != nil { |
| 226 | t.Fatalscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatal().(err) |
| 227 | } |
| 228 | |
| 229 | sigPath := writescip-go gomod github.com/sigstore/sigstore . `github.com/sigstore/sigstore/pkg/signature/ssh`/write().(t, armored, td, "oursig") |
| 230 | |
| 231 | // Create an allowed_signers file with two keys to check against. |
| 232 | allowedSigner := "[email protected] " + tt.pub + "\n" |
| 233 | allowedSigner += "[email protected] " + otherSSHPublicKeyscip-go gomod github.com/sigstore/sigstore . `github.com/sigstore/sigstore/pkg/signature/ssh`/otherSSHPublicKey. + "\n" |
| 234 | allowedSigners := writescip-go gomod github.com/sigstore/sigstore . `github.com/sigstore/sigstore/pkg/signature/ssh`/write().(t, []byte(allowedSigner), td, "allowed_signer") |
| 235 | |
| 236 | // We use the correct principal here so it should work. |
| 237 | runscip-go gomod github.com/sigstore/sigstore . `github.com/sigstore/sigstore/pkg/signature/ssh`/run().(t, data, "ssh-keygen", "-Y", "verify", "-f", allowedSigners, |
| 238 | "-I", "[email protected]", "-n", "file", "-s", sigPath) |
| 239 | |
| 240 | // Just to be sure, check against the other public key as well. |
| 241 | runErrscip-go gomod github.com/sigstore/sigstore . `github.com/sigstore/sigstore/pkg/signature/ssh`/runErr().(t, data, "ssh-keygen", "-Y", "verify", "-f", allowedSigners, |
| 242 | "-I", "[email protected]", "-n", "file", "-s", sigPath) |
| 243 | |
| 244 | // It should error if we run it against other data |
| 245 | data = []byte("other data!") |
| 246 | runErrscip-go gomod github.com/sigstore/sigstore . `github.com/sigstore/sigstore/pkg/signature/ssh`/runErr().(t, data, "ssh-keygen", "-Y", "check-novalidate", "-n", "file", "-s", sigPath) |
| 247 | }) |
| 248 | } |
| 249 | } |
| 250 | |
| 251 | func TestRoundTripscip-go gomod github.com/sigstore/sigstore . `github.com/sigstore/sigstore/pkg/signature/ssh`/TestRoundTrip().(t *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Tscip-go gomod github.com/golang/go/src go1.25.0 testing/T#) { |
| 252 | data := []byte("my good data to be signed!") |
| 253 | |
| 254 | // Create one extra signature for all the tests. |
| 255 | otherSig, err := Signscip-go gomod github.com/sigstore/sigstore . `github.com/sigstore/sigstore/pkg/signature/ssh`/Sign().(otherSSHPrivateKeyscip-go gomod github.com/sigstore/sigstore . `github.com/sigstore/sigstore/pkg/signature/ssh`/otherSSHPrivateKey., bytesscip-go gomod github.com/golang/go/src go1.25.0 bytes/.NewReaderscip-go gomod github.com/golang/go/src go1.25.0 bytes/NewReader().(data)) |
| 256 | if err != nil { |
| 257 | t.Fatalscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatal().(err) |
| 258 | } |
| 259 | otherPub, _, _, _, err := sshscip-go gomod golang.org/x/crypto v0.54.0 `golang.org/x/crypto/ssh`/.ParseAuthorizedKeyscip-go gomod golang.org/x/crypto v0.54.0 `golang.org/x/crypto/ssh`/ParseAuthorizedKey().([]byte(otherSSHPublicKeyscip-go gomod github.com/sigstore/sigstore . `github.com/sigstore/sigstore/pkg/signature/ssh`/otherSSHPublicKey.)) |
| 260 | if err != nil { |
| 261 | t.Fatalscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatal().(err) |
| 262 | } |
| 263 | |
| 264 | for _, tt := range []struct { |
| 265 | name string |
| 266 | pub string |
| 267 | priv string |
| 268 | }{ |
| 269 | { |
| 270 | name: "rsa", |
| 271 | pub: sshPublicKeyscip-go gomod github.com/sigstore/sigstore . `github.com/sigstore/sigstore/pkg/signature/ssh`/sshPublicKey., |
| 272 | priv: sshPrivateKeyscip-go gomod github.com/sigstore/sigstore . `github.com/sigstore/sigstore/pkg/signature/ssh`/sshPrivateKey., |
| 273 | }, |
| 274 | { |
| 275 | name: "ed25519", |
| 276 | pub: ed25519PublicKeyscip-go gomod github.com/sigstore/sigstore . `github.com/sigstore/sigstore/pkg/signature/ssh`/ed25519PublicKey., |
| 277 | priv: ed25519PrivateKeyscip-go gomod github.com/sigstore/sigstore . `github.com/sigstore/sigstore/pkg/signature/ssh`/ed25519PrivateKey., |
| 278 | }, |
| 279 | } { |
| 280 | t.Runscip-go gomod github.com/golang/go/src go1.25.0 testing/T#Run().(tt.name, func(t *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Tscip-go gomod github.com/golang/go/src go1.25.0 testing/T#) { |
| 281 | tt := tt |
| 282 | sig, err := Signscip-go gomod github.com/sigstore/sigstore . `github.com/sigstore/sigstore/pkg/signature/ssh`/Sign().(tt.priv, bytesscip-go gomod github.com/golang/go/src go1.25.0 bytes/.NewReaderscip-go gomod github.com/golang/go/src go1.25.0 bytes/NewReader().(data)) |
| 283 | if err != nil { |
| 284 | t.Fatalscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatal().(err) |
| 285 | } |
| 286 | |
| 287 | pub, _, _, _, err := sshscip-go gomod golang.org/x/crypto v0.54.0 `golang.org/x/crypto/ssh`/.ParseAuthorizedKeyscip-go gomod golang.org/x/crypto v0.54.0 `golang.org/x/crypto/ssh`/ParseAuthorizedKey().([]byte(tt.pub)) |
| 288 | if err != nil { |
| 289 | t.Fatalscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatal().(err) |
| 290 | } |
| 291 | // Check the signature against that data and public key |
| 292 | if err := Verifyscip-go gomod github.com/sigstore/sigstore . `github.com/sigstore/sigstore/pkg/signature/ssh`/Verify().(bytesscip-go gomod github.com/golang/go/src go1.25.0 bytes/.NewReaderscip-go gomod github.com/golang/go/src go1.25.0 bytes/NewReader().(data), sig, pub); err != nil { |
| 293 | t.Errorscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Error().(err) |
| 294 | } |
| 295 | |
| 296 | // Now check it against invalid data. |
| 297 | if err := Verifyscip-go gomod github.com/sigstore/sigstore . `github.com/sigstore/sigstore/pkg/signature/ssh`/Verify().(stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/.NewReaderscip-go gomod github.com/golang/go/src go1.25.0 strings/NewReader().("invalid data!"), sig, pub); err == nil { |
| 298 | t.Errorscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Error().("expected error!") |
| 299 | } |
| 300 | |
| 301 | // Now check it against the wrong key. |
| 302 | if err := Verifyscip-go gomod github.com/sigstore/sigstore . `github.com/sigstore/sigstore/pkg/signature/ssh`/Verify().(bytesscip-go gomod github.com/golang/go/src go1.25.0 bytes/.NewReaderscip-go gomod github.com/golang/go/src go1.25.0 bytes/NewReader().(data), sig, otherPub); err == nil { |
| 303 | t.Errorscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Error().("expected error!") |
| 304 | } |
| 305 | |
| 306 | // Now check it against an invalid signature data. |
| 307 | if err := Verifyscip-go gomod github.com/sigstore/sigstore . `github.com/sigstore/sigstore/pkg/signature/ssh`/Verify().(bytesscip-go gomod github.com/golang/go/src go1.25.0 bytes/.NewReaderscip-go gomod github.com/golang/go/src go1.25.0 bytes/NewReader().(data), []byte("invalid signature!"), pub); err == nil { |
| 308 | t.Errorscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Error().("expected error!") |
| 309 | } |
| 310 | |
| 311 | // Once more, use the wrong signature and check it against the original (wrong public key) |
| 312 | if err := Verifyscip-go gomod github.com/sigstore/sigstore . `github.com/sigstore/sigstore/pkg/signature/ssh`/Verify().(bytesscip-go gomod github.com/golang/go/src go1.25.0 bytes/.NewReaderscip-go gomod github.com/golang/go/src go1.25.0 bytes/NewReader().(data), otherSig, pub); err == nil { |
| 313 | t.Errorscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Error().("expected error!") |
| 314 | } |
| 315 | // It should work against the correct public key. |
| 316 | if err := Verifyscip-go gomod github.com/sigstore/sigstore . `github.com/sigstore/sigstore/pkg/signature/ssh`/Verify().(bytesscip-go gomod github.com/golang/go/src go1.25.0 bytes/.NewReaderscip-go gomod github.com/golang/go/src go1.25.0 bytes/NewReader().(data), otherSig, otherPub); err != nil { |
| 317 | t.Errorscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Error().(err) |
| 318 | } |
| 319 | }) |
| 320 | } |
| 321 | } |
| 322 | |
| 323 | func writescip-go gomod github.com/sigstore/sigstore . `github.com/sigstore/sigstore/pkg/signature/ssh`/write().(t *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Tscip-go gomod github.com/golang/go/src go1.25.0 testing/T#, d []byte, fp ...string) string { |
| 324 | p := filepathscip-go gomod github.com/golang/go/src go1.25.0 `path/filepath`/.Joinscip-go gomod github.com/golang/go/src go1.25.0 `path/filepath`/Join().(fp...) |
| 325 | if err := osscip-go gomod github.com/golang/go/src go1.25.0 os/.WriteFilescip-go gomod github.com/golang/go/src go1.25.0 os/WriteFile().(p, d, 0o600); err != nil { |
| 326 | t.Fatalscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatal().(err) |
| 327 | } |
| 328 | return p |
| 329 | } |
| 330 | |
| 331 | func runscip-go gomod github.com/sigstore/sigstore . `github.com/sigstore/sigstore/pkg/signature/ssh`/run().(t *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Tscip-go gomod github.com/golang/go/src go1.25.0 testing/T#, stdin []byte, args ...string) { |
| 332 | t.Helperscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Helper().() |
| 333 | /* #nosec */ |
| 334 | cmd := execscip-go gomod github.com/golang/go/src go1.25.0 `os/exec`/.Commandscip-go gomod github.com/golang/go/src go1.25.0 `os/exec`/Command().(args[0], args[1:]...) |
| 335 | cmd.Stdinscip-go gomod github.com/golang/go/src go1.25.0 `os/exec`/Cmd#Stdin. = bytesscip-go gomod github.com/golang/go/src go1.25.0 bytes/.NewReaderscip-go gomod github.com/golang/go/src go1.25.0 bytes/NewReader().(stdin) |
| 336 | out, err := cmd.CombinedOutputscip-go gomod github.com/golang/go/src go1.25.0 `os/exec`/Cmd#CombinedOutput().() |
| 337 | t.Logfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Logf().("cmd %v: %s", cmd, string(out)) |
| 338 | if err != nil { |
| 339 | t.Fatalscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatal().(err) |
| 340 | } |
| 341 | } |
| 342 | |
| 343 | func runErrscip-go gomod github.com/sigstore/sigstore . `github.com/sigstore/sigstore/pkg/signature/ssh`/runErr().(t *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Tscip-go gomod github.com/golang/go/src go1.25.0 testing/T#, stdin []byte, args ...string) { |
| 344 | t.Helperscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Helper().() |
| 345 | /* #nosec */ |
| 346 | cmd := execscip-go gomod github.com/golang/go/src go1.25.0 `os/exec`/.Commandscip-go gomod github.com/golang/go/src go1.25.0 `os/exec`/Command().(args[0], args[1:]...) |
| 347 | cmd.Stdinscip-go gomod github.com/golang/go/src go1.25.0 `os/exec`/Cmd#Stdin. = bytesscip-go gomod github.com/golang/go/src go1.25.0 bytes/.NewReaderscip-go gomod github.com/golang/go/src go1.25.0 bytes/NewReader().(stdin) |
| 348 | out, err := cmd.CombinedOutputscip-go gomod github.com/golang/go/src go1.25.0 `os/exec`/Cmd#CombinedOutput().() |
| 349 | t.Logfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Logf().("cmd %v: %s", cmd, string(out)) |
| 350 | if err == nil { |
| 351 | t.Fatalscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatal().("expected error") |
| 352 | } |
| 353 | } |