// ProvisionTpm creates EK, AK, and TLS key. Then, it performs the credential
// activation via a remote CA server and retrieves the resulting AK and TLS Key
// certificates from the server and stores the encrypted blobs and the
// certificates on disk.
ProvisionTpm creates EK, AK, and TLS key. Then, it performs the credential
activation via a remote CA server and retrieves the resulting AK and TLS Key
certificates from the server and stores the encrypted blobs and the
certificates on disk.
// ProvisionTpm creates EK AK and TLS key . Then it performs the credential // activation via a remote CA server and retrieves the resulting AK and TLS Key // certificates from the server and stores the encrypted blobs and the // certificates on disk .
func ProvisionTpm(provServerURL string, paths *Paths, certParams [][]byte, keyConfig string) error {
	log.Info("Provisioning TPM (might take a while)..")
	if tpm == nil {
		return fmt.Errorf("Failed to provision TPM - TPM is not openend")
	}
	tpmInfo, err := getTpmInfo()
	if err != nil {
		return fmt.Errorf("Failed to retrieve TPM Info - %v", err)
	}
	ek, ak, tlsKey, err = createKeys(tpm, keyConfig)
	if err != nil {
		return fmt.Errorf("Activate Credential failed: createKeys returned %v", err)
	}
	secret, err := activateCredential(tpm, *ak, ek[0], tpmInfo, provServerURL)
	if err != nil {
		return fmt.Errorf("Activate Credential failed: activateCredential returned %v", err)
	}
	certs, err := requestTpmCerts(provServerURL, secret, certParams)
	if err != nil {
		return fmt.Errorf("Activate Credential failed: requestAkCert returned %v", err)
	}
	log.Tracef("New AK Cert %v: %v", paths.AkCert, string(certs.AkCert))
	log.Tracef("New TLS Key Cert %v: %v", paths.TLSCert, string(certs.TLSCert))
	log.Tracef("New Device Sub CA Cert %v: %v", paths.DeviceSubCa, string(certs.DeviceSubCaCert))
	log.Tracef("New Device CA Cert %v: %v", paths.Ca, string(certs.CaCert))
	if err := ioutil.WriteFile(paths.AkCert, certs.AkCert, 0644); err != nil {
		return fmt.Errorf("Activate Credential failed: WriteFile %v returned %v", paths.AkCert, err)
	}
	if err := ioutil.WriteFile(paths.TLSCert, certs.TLSCert, 0644); err != nil {
		return fmt.Errorf("Activate Credential failed: WriteFile %v returned %v", paths.TLSCert, err)
	}
	if err := ioutil.WriteFile(paths.DeviceSubCa, certs.DeviceSubCaCert, 0644); err != nil {
		return fmt.Errorf("Activate Credential failed: WriteFile %v returned %v", paths.DeviceSubCa, err)
	}
	if err := ioutil.WriteFile(paths.Ca, certs.CaCert, 0644); err != nil {
		return fmt.Errorf("Activate Credential failed: WriteFile %v returned %v", paths.Ca, err)
	}
	akBytes, err := ak.Marshal()
	if err != nil {
		return fmt.Errorf("Activate Credential failed: Marshal AK returned %v", err)
	}
	if err := ioutil.WriteFile(paths.Ak, akBytes, 0644); err != nil {
		return fmt.Errorf("Activate Credential failed: WriteFile %v returned %v", paths.Ak, err)
	}
	tlsKeyBytes, err := tlsKey.Marshal()
	if err != nil {
		return fmt.Errorf("Activate Credential failed: Marshal TLS Key returned %v", err)
	}
	if err := ioutil.WriteFile(paths.TLSKey, tlsKeyBytes, 0644); err != nil {
		return fmt.Errorf("Activate Credential failed: WriteFile %v returned %v", paths.TLSKey, err)
	}
	return nil
}
func ProvisionTpm ( provServerURL string , paths * Paths , certParams [ ] [ ] byte , keyConfig string ) error { log . Info ( " " ) if tpm == nil { return fmt . Errorf ( " " ) } tpmInfo , err := getTpmInfo ( ) if err != nil { return fmt . Errorf ( " " , err ) } ek , ak , tlsKey , err = createKeys ( tpm , keyConfig ) if err != nil { return fmt . Errorf ( " " , err ) } secret , err := activateCredential ( tpm , * ak , ek [ 0 ] , tpmInfo , provServerURL ) if err != nil { return fmt . Errorf ( " " , err ) } certs , err := requestTpmCerts ( provServerURL , secret , certParams ) if err != nil { return fmt . Errorf ( " " , err ) } log . Tracef ( " " , paths . AkCert , string ( certs . AkCert ) ) log . Tracef ( " " , paths . TLSCert , string ( certs . TLSCert ) ) log . Tracef ( " " , paths . DeviceSubCa , string ( certs . DeviceSubCaCert ) ) log . Tracef ( " " , paths . Ca , string ( certs . CaCert ) ) if err := ioutil . WriteFile ( paths . AkCert , certs . AkCert , 0644 ) ; err != nil { return fmt . Errorf ( " " , paths . AkCert , err ) } if err := ioutil . WriteFile ( paths . TLSCert , certs . TLSCert , 0644 ) ; err != nil { return fmt . Errorf ( " " , paths . TLSCert , err ) } if err := ioutil . WriteFile ( paths . DeviceSubCa , certs . DeviceSubCaCert , 0644 ) ; err != nil { return fmt . Errorf ( " " , paths . DeviceSubCa , err ) } if err := ioutil . WriteFile ( paths . Ca , certs . CaCert , 0644 ) ; err != nil { return fmt . Errorf ( " " , paths . Ca , err ) } akBytes , err := ak . Marshal ( ) if err != nil { return fmt . Errorf ( " " , err ) } if err := ioutil . WriteFile ( paths . Ak , akBytes , 0644 ) ; err != nil { return fmt . Errorf ( " " , paths . Ak , err ) } tlsKeyBytes , err := tlsKey . Marshal ( ) if err != nil { return fmt . Errorf ( " " , err ) } if err := ioutil . WriteFile ( paths . TLSKey , tlsKeyBytes , 0644 ) ; err != nil { return fmt . Errorf ( " " , paths . TLSKey , err ) } return nil }
ProvisionTpm creates EK, AK, and TLS key.
ProvisionTpm creates EK AK and TLS key .
// Return challenge to server // Store the certificates on disk // Store the encrypted AK blob on disk // Store the encrypted TLS Key blob on disk