Debian Codegraph @

verify.go

raw symbols SCIP
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 sshsigscip-go gomod github.com/42wim/sshsig . `github.com/42wim/sshsig`/
17
18 import (
19 "ioscip-go gomod github.com/golang/go/src go1.23.0 io/"
20
21 "golang.org/x/crypto/sshscip-go gomod golang.org/x/crypto v0.37.0 `golang.org/x/crypto/ssh`/"
22 )
23
24 // Verify verifies the signature of the given data and the armored signature using the given public key and the namespace.
25 // If the namespace is empty, the default namespace (file) is used.
26 func Verifyscip-go gomod github.com/42wim/sshsig . `github.com/42wim/sshsig`/Verify().(message ioscip-go gomod github.com/golang/go/src go1.23.0 io/.Readerscip-go gomod github.com/golang/go/src go1.23.0 io/Reader#, armoredSignature []byte, publicKey []byte, namespace string) error {
27 if namespace == "" {
28 namespace = defaultNamespacescip-go gomod github.com/42wim/sshsig . `github.com/42wim/sshsig`/defaultNamespace.
29 }
30
31 decodedSignature, err := Decodescip-go gomod github.com/42wim/sshsig . `github.com/42wim/sshsig`/Decode().(armoredSignature)
32 if err != nil {
33 return err
34 }
35
36 desiredPk, _, _, _, err := sshscip-go gomod golang.org/x/crypto v0.37.0 `golang.org/x/crypto/ssh`/.ParseAuthorizedKeyscip-go gomod golang.org/x/crypto v0.37.0 `golang.org/x/crypto/ssh`/ParseAuthorizedKey().(publicKey)
37 if err != nil {
38 return err
39 }
40
41 // Hash the message so we can verify it against the signature.
42 h := supportedHashAlgorithmsscip-go gomod github.com/42wim/sshsig . `github.com/42wim/sshsig`/supportedHashAlgorithms.[decodedSignature.hashAlgscip-go gomod github.com/42wim/sshsig . `github.com/42wim/sshsig`/Signature#hashAlg.]()
43 if _, err := ioscip-go gomod github.com/golang/go/src go1.23.0 io/.Copyscip-go gomod github.com/golang/go/src go1.23.0 io/Copy().(h, message); err != nil {
44 return err
45 }
46 hm := h.Sumscip-go gomod github.com/golang/go/src go1.23.0 hash/Hash#Sum().(nil)
47
48 toVerify := MessageWrapperscip-go gomod github.com/42wim/sshsig . `github.com/42wim/sshsig`/MessageWrapper#{
49 Namespacescip-go gomod github.com/42wim/sshsig . `github.com/42wim/sshsig`/MessageWrapper#Namespace.: namespace,
50 HashAlgorithmscip-go gomod github.com/42wim/sshsig . `github.com/42wim/sshsig`/MessageWrapper#HashAlgorithm.: decodedSignature.hashAlgscip-go gomod github.com/42wim/sshsig . `github.com/42wim/sshsig`/Signature#hashAlg.,
51 Hashscip-go gomod github.com/42wim/sshsig . `github.com/42wim/sshsig`/MessageWrapper#Hash.: string(hm),
52 }
53 signedMessage := sshscip-go gomod golang.org/x/crypto v0.37.0 `golang.org/x/crypto/ssh`/.Marshalscip-go gomod golang.org/x/crypto v0.37.0 `golang.org/x/crypto/ssh`/Marshal().(toVerify)
54 signedMessage = append([]byte(magicHeaderscip-go gomod github.com/42wim/sshsig . `github.com/42wim/sshsig`/magicHeader.), signedMessage...)
55 return desiredPk.Verifyscip-go gomod golang.org/x/crypto v0.37.0 `golang.org/x/crypto/ssh`/PublicKey#Verify().(signedMessage, decodedSignature.signaturescip-go gomod github.com/42wim/sshsig . `github.com/42wim/sshsig`/Signature#signature.)
56 }