mirror of
https://github.com/google/go-attestation.git
synced 2025-06-16 05:58:19 +00:00
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:
55
attributecert/attributecert_test.go
Normal file
55
attributecert/attributecert_test.go
Normal 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)
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user