Debian Codegraph @

legacy/tpm2/credactivation/credential_activation_test.go

raw symbols SCIP
1 // Copyright (c) 2018, Google LLC All rights reserved.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 package credactivationscip-go gomod github.com/google/go-tpm . `github.com/google/go-tpm/legacy/tpm2/credactivation`/
16
17 import (
18 "bytesscip-go gomod github.com/golang/go/src go1.22 bytes/"
19 "crypto/x509scip-go gomod github.com/golang/go/src go1.22 `crypto/x509`/"
20 "encoding/base64scip-go gomod github.com/golang/go/src go1.22 `encoding/base64`/"
21 "encoding/pemscip-go gomod github.com/golang/go/src go1.22 `encoding/pem`/"
22 "testingscip-go gomod github.com/golang/go/src go1.22 testing/"
23
24 "github.com/google/go-tpm/legacy/tpm2scip-go gomod github.com/google/go-tpm . `github.com/google/go-tpm/legacy/tpm2`/"
25 )
26
27 var (
28 eccEKPubscip-go gomod github.com/google/go-tpm . `github.com/google/go-tpm/legacy/tpm2/credactivation`/eccEKPub. = []byte(`-----BEGIN PUBLIC KEY-----
29 MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEsIfixqsUp8cJBSeYDhJKCZ32eAHF
30 3rS7HdTMOnoFj1MrX+PutPTxa6SFdhWGLnhEQyfcwRni8veQX/dSP2on2w==
31 -----END PUBLIC KEY-----`)
32 rsaEKPubscip-go gomod github.com/google/go-tpm . `github.com/google/go-tpm/legacy/tpm2/credactivation`/rsaEKPub. = []byte(`-----BEGIN PUBLIC KEY-----
33 MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEArIqmuAvuIcakIEPd2hZl
34 avob21ehQ7zaHduJQNbNuKVSc1HTlvw9DkWN03b0SktcRIfsjw/omqPl60RhCx0j
35 qxsYnf5Gk4jhfCnUeQVicAqHnUGrKjMkLIGTZVOpyqBEXHsdhugw6M5HVIKyfwNO
36 KhvLZKRH8JkvtElVhLQ6E2+H83XoSpkt9oCnGPyN2Z5qRP+fhQiRylMCD8Rz8ABn
37 YVqGBBrG+2cBt/0uFLjxHx2mm/4sI/1scG5xrcrDLva9WZB40MehW5VlS6Fwqq05
38 dKtLGpk7ludjH38m2zhM5/UdKZ34skJaS/Aiyj+P5AT1BpJL2ZtjCbBdnMDUSbRF
39 1QIDAQAB
40 -----END PUBLIC KEY-----`)
41 )
42
43 type zeroReaderscip-go gomod github.com/google/go-tpm . `github.com/google/go-tpm/legacy/tpm2/credactivation`/zeroReader# struct{}
44
45 func (zeroReaderscip-go gomod github.com/google/go-tpm . `github.com/google/go-tpm/legacy/tpm2/credactivation`/zeroReader#) Readscip-go gomod github.com/google/go-tpm . `github.com/google/go-tpm/legacy/tpm2/credactivation`/zeroReader#Read().(b []byte) (int, error) {
46 for i := range b {
47 b[i] = 0
48 }
49 return len(b), nil
50 }
51
52 func mustDecodeBase64scip-go gomod github.com/google/go-tpm . `github.com/google/go-tpm/legacy/tpm2/credactivation`/mustDecodeBase64().(in string, t *testingscip-go gomod github.com/golang/go/src go1.22 testing/.Tscip-go gomod github.com/golang/go/src go1.22 testing/T#) []byte {
53 d, err := base64scip-go gomod github.com/golang/go/src go1.22 `encoding/base64`/.StdEncodingscip-go gomod github.com/golang/go/src go1.22 `encoding/base64`/StdEncoding..DecodeStringscip-go gomod github.com/golang/go/src go1.22 `encoding/base64`/Encoding#DecodeString().(in)
54 if err != nil {
55 t.Fatalscip-go gomod github.com/golang/go/src go1.22 testing/common#Fatal().(err)
56 }
57 return d
58 }
59
60 func TestCredentialActivationscip-go gomod github.com/google/go-tpm . `github.com/google/go-tpm/legacy/tpm2/credactivation`/TestCredentialActivation().(t *testingscip-go gomod github.com/golang/go/src go1.22 testing/.Tscip-go gomod github.com/golang/go/src go1.22 testing/T#) {
61 var activateTests = []struct {
62 ekPub []byte
63 expected string
64 }{
65 {
66 eccEKPubscip-go gomod github.com/google/go-tpm . `github.com/google/go-tpm/legacy/tpm2/credactivation`/eccEKPub.,
67 "AEQAIE4SquOcMAzLi7f3ru6P8nuIpSmzr8OTACXpzLo3PTOe/oBazv+fZF2JiKDZqNPNeHISCsZMdEtEfvyYjqmzZ/CB7ABEACAeGDfvDRlRiDV1cbXlVFsSLo8JZ/2nJCA+slYczpcoXgAg+CstT57xB59sS1uDVuIyQulYttdJprVoGkEDVmvcWok=",
68 },
69 {
70 rsaEKPubscip-go gomod github.com/google/go-tpm . `github.com/google/go-tpm/legacy/tpm2/credactivation`/rsaEKPub.,
71 "AEQAIFjKZAUo3Wmgxu+CqHFzsQZr7BqawtprBmpXpZa77nb5S+iN6IcSPQLCKPZMNuunv7BIb4/VJA/xjMrj8RnQbjspCwEAJcQogjACOfStYTVjmR4p61ZbTTRt7ZNG5nc6iifq+TfnyfoU+E3T6Kount4M8fSUdMWlKx5A24Ms4ndi1VYOA+s4inPusyn1X1ZCHe5tNwT1E9jpVxc0jaUAVad6Q5cOgUyAp4qvc8wmaYXcIa/PzVfa6teF4iXxNqVDAYqpdmbP68v0Hk5gRqCa/tHAdg5avE3C20DP1SSvPitumWROL6mHMooVxjsyjPnHEBLo7y/BKwezEO/15xnBvPOvWs7ARIu1KdER+zrCJX9SMCPbn4cVMfLdrX70xko7XjdhV7pXtAeUeKmmKSYE45m5ZN0h83YgHXGDjf+ynWse10okyA==",
72 },
73 }
74
75 for _, test := range activateTests {
76 p, _ := pemscip-go gomod github.com/golang/go/src go1.22 `encoding/pem`/.Decodescip-go gomod github.com/golang/go/src go1.22 `encoding/pem`/Decode().(test.ekPub)
77 public, err := x509scip-go gomod github.com/golang/go/src go1.22 `crypto/x509`/.ParsePKIXPublicKeyscip-go gomod github.com/golang/go/src go1.22 `crypto/x509`/ParsePKIXPublicKey().(p.Bytesscip-go gomod github.com/golang/go/src go1.22 `encoding/pem`/Block#Bytes.)
78 if err != nil {
79 t.Fatalscip-go gomod github.com/golang/go/src go1.22 testing/common#Fatal().(err)
80 }
81
82 aikDigest := mustDecodeBase64scip-go gomod github.com/google/go-tpm . `github.com/google/go-tpm/legacy/tpm2/credactivation`/mustDecodeBase64().("5snpf9qRfKD2Tb72eLAZqC/a/MyUhg+IvdwDZkTJK9w=", t)
83 expected := mustDecodeBase64scip-go gomod github.com/google/go-tpm . `github.com/google/go-tpm/legacy/tpm2/credactivation`/mustDecodeBase64().(test.expected, t)
84 secret := mustDecodeBase64scip-go gomod github.com/google/go-tpm . `github.com/google/go-tpm/legacy/tpm2/credactivation`/mustDecodeBase64().("AQIDBAUGBwgBAgMEBQYHCAECAwQFBgcIAQIDBAUGBwg=", t)
85
86 aikName := &tpm2scip-go gomod github.com/google/go-tpm . `github.com/google/go-tpm/legacy/tpm2`/.HashValuescip-go gomod github.com/google/go-tpm . `github.com/google/go-tpm/legacy/tpm2`/HashValue#{
87 Algscip-go gomod github.com/google/go-tpm . `github.com/google/go-tpm/legacy/tpm2`/HashValue#Alg.: tpm2scip-go gomod github.com/google/go-tpm . `github.com/google/go-tpm/legacy/tpm2`/.AlgSHA256scip-go gomod github.com/google/go-tpm . `github.com/google/go-tpm/legacy/tpm2`/AlgSHA256.,
88 Valuescip-go gomod github.com/google/go-tpm . `github.com/google/go-tpm/legacy/tpm2`/HashValue#Value.: aikDigest,
89 }
90
91 idObject, wrappedCredential, err := generatescip-go gomod github.com/google/go-tpm . `github.com/google/go-tpm/legacy/tpm2/credactivation`/generate().(aikName, public, 16, secret, zeroReaderscip-go gomod github.com/google/go-tpm . `github.com/google/go-tpm/legacy/tpm2/credactivation`/zeroReader#{})
92 if err != nil {
93 t.Fatalscip-go gomod github.com/golang/go/src go1.22 testing/common#Fatal().(err)
94 }
95 activationBlob := append(idObject, wrappedCredential...)
96
97 if !bytesscip-go gomod github.com/golang/go/src go1.22 bytes/.Equalscip-go gomod github.com/golang/go/src go1.22 bytes/Equal().(expected, activationBlob) {
98 t.Errorfscip-go gomod github.com/golang/go/src go1.22 testing/common#Errorf().("generate(%v, %v, %v) returned incorrect result", aikName, public, secret)
99 t.Logfscip-go gomod github.com/golang/go/src go1.22 testing/common#Logf().(" Got: %v", base64scip-go gomod github.com/golang/go/src go1.22 `encoding/base64`/.StdEncodingscip-go gomod github.com/golang/go/src go1.22 `encoding/base64`/StdEncoding..EncodeToStringscip-go gomod github.com/golang/go/src go1.22 `encoding/base64`/Encoding#EncodeToString().(activationBlob))
100 t.Logfscip-go gomod github.com/golang/go/src go1.22 testing/common#Logf().(" Want: %v", base64scip-go gomod github.com/golang/go/src go1.22 `encoding/base64`/.StdEncodingscip-go gomod github.com/golang/go/src go1.22 `encoding/base64`/StdEncoding..EncodeToStringscip-go gomod github.com/golang/go/src go1.22 `encoding/base64`/Encoding#EncodeToString().(expected))
101 }
102 }
103 }