First attempt at adding support for attribute certificates (#117)

Platform certificates are defined as RFC5755 attribute certificates with
various additional attributes and extensions defined in the TCG Platform
Certificate Profile. Add support for parsing them, derived from
crypto/x509. Include some test certificates and verify we parse them.
This commit is contained in:
Matthew Garrett
2019-10-27 23:12:15 -07:00
committed by GitHub
parent 43f6c42dc3
commit f5fa92f739
26 changed files with 2883 additions and 0 deletions

View File

@ -0,0 +1,55 @@
// Copyright 2019 Google Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License"); you may not
// use this file except in compliance with the License. You may obtain a copy of
// the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
// License for the specific language governing permissions and limitations under
// the License.
package attributecert
import (
"encoding/json"
"io/ioutil"
"strings"
"testing"
)
func TestParseAttributeCerts(t *testing.T) {
files, err := ioutil.ReadDir("testdata")
if err != nil {
t.Fatalf("failed to read test dir: %v", err)
}
for _, file := range files {
if strings.HasSuffix(file.Name(), ".json") {
continue
}
filename := "testdata/" + file.Name()
jsonfile := filename + ".json"
data, err := ioutil.ReadFile(filename)
if err != nil {
t.Fatalf("failed to read test data %s: %v", filename, err)
}
cert, err := ParseAttributeCertificate(data)
if err != nil {
t.Fatalf("failed to parse test data %s: %v", filename, err)
}
jsondata, err := ioutil.ReadFile(jsonfile)
if err != nil {
t.Fatalf("failed to read json test data %s: %v", jsonfile, err)
}
jsoncert, err := json.MarshalIndent(cert, "", " ")
if err != nil {
t.Fatalf("failed to marshal %s to json: %v", filename, err)
}
if string(jsondata) != string(jsoncert) {
t.Fatalf("%s fails to match test data", filename)
}
}
}