// Generate generates an attestation report with the provided
// nonce 'nonce' and manifests and descriptions 'metadata'. The manifests and
// descriptions must be raw JWS tokens in the JWS JSON full serialization
// format. Takes a list of 'measurements' and accompanying 'measurementParams',
// which must be arrays of the same length. The 'measurements' must
// implement the attestation report 'Measurer' interface providing
// a method for collecting the measurements from a hardware or software
// interface
Generate generates an attestation report with the provided
nonce 'nonce' and manifests and descriptions 'metadata'. The manifests and
descriptions must be raw JWS tokens in the JWS JSON full serialization
format. Takes a list of 'measurements' and accompanying 'measurementParams',
which must be arrays of the same length. The 'measurements' must
implement the attestation report 'Measurer' interface providing
a method for collecting the measurements from a hardware or software
interface
// Generate generates an attestation report with the provided // nonce ' nonce ' and manifests and descriptions ' metadata ' . The manifests and // descriptions must be raw JWS tokens in the JWS JSON full serialization // format . Takes a list of ' measurements ' and accompanying ' measurementParams ' // which must be arrays of the same length . The ' measurements ' must // implement the attestation report ' Measurer ' interface providing // a method for collecting the measurements from a hardware or software // interface
func Generate(nonce []byte, metadata [][]byte, measurements []Measurement, measurementParams []MeasurementParams) ArJws {
	ar := ArJws{
		Type: "Attestation Report",
	}
	if len(nonce) > 32 {
		log.Warn("Generate Attestation Report: Nonce exceeds maximum length of 32 bytes")
		return ar
	}
	ar.Nonce = hex.EncodeToString(nonce)
	log.Debug("Adding manifests and descriptions to Attestation Report..")
	log.Trace("Parsing ", len(metadata), " meta-data objects..")
	numManifests := 0
	for i := 0; i < len(metadata); i++ {
		jws, err := jose.ParseSigned(string(metadata[i]))
		if err != nil {
			log.Warnf("Failed to parse metadata object %v: %v", i, err)
			continue
		}
		data := jws.UnsafePayloadWithoutVerification()
		t := new(JSONType)
		err = json.Unmarshal(data, t)
		if err != nil {
			log.Warnf("Failed to unmarshal data from metadata object %v: %v", i, err)
			continue
		}
		switch t.Type {
		case "App Manifest":
			log.Debug("Adding App Manifest")
			ar.AppManifests = append(ar.AppManifests, jws.FullSerialize())
			numManifests++
		case "OS Manifest":
			log.Debug("Adding OS Manifest")
			ar.OsManifest = jws.FullSerialize()
			numManifests++
		case "RTM Manifest":
			log.Debug("Adding RTM Manifest")
			ar.RtmManifest = jws.FullSerialize()
			numManifests++
		case "Device Description":
			log.Debug("Adding Device Description")
			ar.DeviceDescription = jws.FullSerialize()
		case "Company Description":
			log.Debug("Adding Company Description")
			ar.CompanyDescription = jws.FullSerialize()
		default:
			log.Warn("Unknown manifest type ", t.Type)
		}
	}
	if numManifests == 0 {
		log.Warn("Did not find any manifests for the attestation report")
	} else {
		log.Debug("Added ", numManifests, " manifests to attestation report")
	}
	if len(measurements) != len(measurementParams) {
		log.Warn("Internal Error: length of measurements does not match length of measuremt params. Will not add measurements to attestation report")
		return ar
	}
	for i, m := range measurements {
		measurer, ok := m.(Measurer)
		if !ok {
			log.Warn("Internal Error: Measurement does not implement Measurer. Will not add measurement to attestation report")
			continue
		}
		log.Trace("Getting measurements from measurement interface..")
		data, err := measurer.Measure(measurementParams[i])
		if err != nil {
			log.Warnf("Failed to get measurements: %v", err)
			return ar
		}
		if tpmData, ok := data.(TpmMeasurement); ok {
			ar.TpmM = tpmData
		} else if SwData, ok := data.(SwMeasurement); ok {
			ar.SWM = append(ar.SWM, SwData)
		} else {
			log.Error("Error: Unsupported measurement interface type")
		}
	}
	log.Trace("Finished attestation report generation")
	return ar
}
func Generate ( nonce [ ] byte , metadata [ ] [ ] byte , measurements [ ] Measurement , measurementParams [ ] MeasurementParams ) ArJws { ar := ArJws { Type : " " , } if len ( nonce ) > 32 { log . Warn ( " " ) return ar } ar . Nonce = hex . EncodeToString ( nonce ) log . Debug ( " " ) log . Trace ( " " , len ( metadata ) , " " ) numManifests := 0 for i := 0 ; i < len ( metadata ) ; i ++ { jws , err := jose . ParseSigned ( string ( metadata [ i ] ) ) if err != nil { log . Warnf ( " " , i , err ) continue } data := jws . UnsafePayloadWithoutVerification ( ) t := new ( JSONType ) err = json . Unmarshal ( data , t ) if err != nil { log . Warnf ( " " , i , err ) continue } switch t . Type { case " " : log . Debug ( " " ) ar . AppManifests = append ( ar . AppManifests , jws . FullSerialize ( ) ) numManifests ++ case " " : log . Debug ( " " ) ar . OsManifest = jws . FullSerialize ( ) numManifests ++ case " " : log . Debug ( " " ) ar . RtmManifest = jws . FullSerialize ( ) numManifests ++ case " " : log . Debug ( " " ) ar . DeviceDescription = jws . FullSerialize ( ) case " " : log . Debug ( " " ) ar . CompanyDescription = jws . FullSerialize ( ) default : log . Warn ( " " , t . Type ) } } if numManifests == 0 { log . Warn ( " " ) } else { log . Debug ( " " , numManifests , " " ) } if len ( measurements ) != len ( measurementParams ) { log . Warn ( " " ) return ar } for i , m := range measurements { measurer , ok := m . ( Measurer ) if ! ok { log . Warn ( " " ) continue } log . Trace ( " " ) data , err := measurer . Measure ( measurementParams [ i ] ) if err != nil { log . Warnf ( " " , err ) return ar } if tpmData , ok := data . ( TpmMeasurement ) ; ok { ar . TpmM = tpmData } else if SwData , ok := data . ( SwMeasurement ) ; ok { ar . SWM = append ( ar . SWM , SwData ) } else { log . Error ( " " ) } } log . Trace ( " " ) return ar }
Generate generates an attestation report with the provided
nonce 'nonce' and manifests and descriptions 'metadata'.
Generate generates an attestation report with the provided nonce ' nonce ' and manifests and descriptions ' metadata ' .
// Create attestation report object which will be filled with the attestation // data or sent back incomplete in case errors occur // Retrieve the manifests and descriptions // Extract plain payload (i.e. the manifest/description itself) out of base64-encoded // JSON Web Signature // Unmarshal the Type field of the JSON file to determine the type for // later processing // Add the measurements of the platform to the attestation report. // The methods for retrieving the data are implemented in the wrappers // for the specific hardware or software module, such as the TPM module // This actually collects the measurements. The methods are implemented // in the respective module (e.g. tpm module) // Check the type of the measurements and add it to the attestation report