@@ -153,13 +153,16 @@ func DecodeKey(pemBytes []byte) (*Key, error) {
153153}
154154
155155// Creates a Storage Key, or return the loaded storage key
156- func CreateSRK (tpm transport.TPMCloser ) (* tpm2.AuthHandle ,* tpm2.TPMTPublic ,error ) {
156+ func CreateSRK (tpm transport.TPMCloser , ownerPassword [] byte ) (* tpm2.AuthHandle ,* tpm2.TPMTPublic ,error ) {
157157srk := tpm2.CreatePrimary {
158- PrimaryHandle :tpm2 .TPMRHOwner ,
158+ PrimaryHandle : tpm2.AuthHandle {
159+ Handle :tpm2 .TPMRHOwner ,
160+ Auth :tpm2 .PasswordAuth (ownerPassword ),
161+ },
159162InSensitive : tpm2.TPM2BSensitiveCreate {
160163Sensitive :& tpm2.TPMSSensitiveCreate {
161164UserAuth : tpm2.TPM2BAuth {
162- Buffer : []byte (nil ),
165+ Buffer : []byte ("" ),
163166},
164167},
165168},
@@ -230,7 +233,7 @@ func createRSAKey(bits tpm2.TPMKeyBits, sha tpm2.TPMAlgID) tpm2.TPM2B[tpm2.TPMTP
230233})
231234}
232235
233- func CreateKey (tpm transport.TPMCloser ,keytype tpm2.TPMAlgID ,bits int ,pin []byte ,comment string ) (* Key ,error ) {
236+ func CreateKey (tpm transport.TPMCloser ,keytype tpm2.TPMAlgID ,bits int ,ownerPassword [] byte , pin []byte ,comment string ) (* Key ,error ) {
234237rsaBits := []int {2048 }
235238ecdsaBits := []int {256 ,384 ,521 }
236239
@@ -258,7 +261,7 @@ func CreateKey(tpm transport.TPMCloser, keytype tpm2.TPMAlgID, bits int, pin []b
258261return nil ,fmt .Errorf ("unsupported key type" )
259262}
260263
261- srkHandle ,srkPublic ,err := CreateSRK (tpm )
264+ srkHandle ,srkPublic ,err := CreateSRK (tpm , ownerPassword )
262265if err != nil {
263266return nil ,fmt .Errorf ("failed creating SRK: %v" ,err )
264267}
@@ -296,8 +299,7 @@ func CreateKey(tpm transport.TPMCloser, keytype tpm2.TPMAlgID, bits int, pin []b
296299emptyAuth = false
297300}
298301
299- var createRsp * tpm2.CreateResponse
300- createRsp ,err = createKey .Execute (tpm ,
302+ createRsp ,err := createKey .Execute (tpm ,
301303tpm2 .HMAC (tpm2 .TPMAlgSHA256 ,16 ,
302304tpm2 .AESEncryption (128 ,tpm2 .EncryptIn ),
303305tpm2 .Salted (srkHandle .Handle ,* srkPublic )))
@@ -315,7 +317,7 @@ func CreateKey(tpm transport.TPMCloser, keytype tpm2.TPMAlgID, bits int, pin []b
315317return & Key {tpmkey },nil
316318}
317319
318- func ImportKey (tpm transport.TPMCloser ,pk any ,pin []byte ,comment string ) (* Key ,error ) {
320+ func ImportKey (tpm transport.TPMCloser ,ownerPassword [] byte , pk any ,pin []byte ,comment string ) (* Key ,error ) {
319321var public tpm2.TPMTPublic
320322var sensitive tpm2.TPMTSensitive
321323var unique tpm2.TPMUPublicID
@@ -419,7 +421,7 @@ func ImportKey(tpm transport.TPMCloser, pk any, pin []byte, comment string) (*Ke
419421return nil ,fmt .Errorf ("unsupported key type" )
420422}
421423
422- srkHandle ,srkPublic ,err := CreateSRK (tpm )
424+ srkHandle ,srkPublic ,err := CreateSRK (tpm , ownerPassword )
423425if err != nil {
424426return nil ,fmt .Errorf ("failed creating SRK: %v" ,err )
425427}
@@ -434,7 +436,7 @@ func ImportKey(tpm transport.TPMCloser, pk any, pin []byte, comment string) (*Ke
434436emptyAuth = false
435437}
436438
437- // We need the sizecalcualted in the buffer, so we do this serialization dance
439+ // We need the sizecalculated in the buffer, so we do this serialization dance
438440l := tpm2 .Marshal (tpm2.TPM2BPrivate {Buffer :tpm2 .Marshal (sensitive )})
439441
440442pubbytes := tpm2 .New2B (public )
@@ -483,8 +485,8 @@ func LoadKeyWithParent(tpm transport.TPMCloser, parent tpm2.AuthHandle, key *Key
483485},nil
484486}
485487
486- func LoadKey (tpm transport.TPMCloser ,key * Key ) (* tpm2.AuthHandle ,error ) {
487- srkHandle ,_ ,err := CreateSRK (tpm )
488+ func LoadKey (tpm transport.TPMCloser ,ownerPassword [] byte , key * Key ) (* tpm2.AuthHandle ,error ) {
489+ srkHandle ,_ ,err := CreateSRK (tpm , ownerPassword )
488490if err != nil {
489491return nil ,err
490492}
@@ -571,7 +573,7 @@ func newRSASigScheme(digest tpm2.TPMAlgID) tpm2.TPMTSigScheme {
571573}
572574}
573575
574- func Sign (tpm transport.TPMCloser ,key * Key ,digest []byte ,auth []byte ,digestalg tpm2.TPMAlgID ) ([]byte ,error ) {
576+ func Sign (tpm transport.TPMCloser ,ownerPassword [] byte , key * Key ,digest []byte ,auth []byte ,digestalg tpm2.TPMAlgID ) ([]byte ,error ) {
575577var digestlength int
576578
577579switch digestalg {
@@ -587,7 +589,7 @@ func Sign(tpm transport.TPMCloser, key *Key, digest []byte, auth []byte, digesta
587589return nil ,fmt .Errorf ("incorrect checksum length. expected %v got %v" ,digestlength ,len (digest ))
588590}
589591
590- srkHandle ,srkPublic ,err := CreateSRK (tpm )
592+ srkHandle ,srkPublic ,err := CreateSRK (tpm , ownerPassword )
591593if err != nil {
592594return nil ,fmt .Errorf ("failed creating SRK: %v" ,err )
593595}
@@ -649,10 +651,10 @@ func Sign(tpm transport.TPMCloser, key *Key, digest []byte, auth []byte, digesta
649651
650652// ChangeAuth changes the object authn header to something else
651653// notice this changes the private blob inside the key in-place.
652- func ChangeAuth (tpm transport.TPMCloser ,key * Key ,oldpin ,newpin []byte ) (* Key ,error ) {
654+ func ChangeAuth (tpm transport.TPMCloser ,ownerPassword [] byte , key * Key ,oldpin ,newpin []byte ) (* Key ,error ) {
653655var err error
654656
655- srkHandle ,_ ,err := CreateSRK (tpm )
657+ srkHandle ,_ ,err := CreateSRK (tpm , ownerPassword )
656658if err != nil {
657659return nil ,fmt .Errorf ("failed creating SRK: %v" ,err )
658660}