Git Product home page Git Product logo

Comments (2)

ericchiang avatar ericchiang commented on May 4, 2024

I believe /dev/tpm0 only allows one client to access it at a time. If you're running TrouSerS or some other deamon this could be the issue.

Do you have a /dev/tpmrm0? That allows multiple clients. What version of the TPM are you accessing?

from go-attestation.

eduardolfalcao avatar eduardolfalcao commented on May 4, 2024

Hi @ericchiang

I`m sorry for the late response.
I updated the OS of my VM to ubuntu 20.04.01 LTS and that error simply disappeared.
I'm running swtpm v0.3.1.

However, instead, I'm facing an error while activating credential.
The error:

root@ubuntu:/home/ubuntu# go run example.go
2020/12/08 19:48:58 Failed to activate credential: handle 2, error code 0xa : the type of the value is not appropriate for the use
exit status 1

When running this piece of code:
`
package main
import (
"crypto/subtle"
"log"
"github.com/google/go-attestation/attest"
)

    func ExampleAK() {
            tpm, err := attest.OpenTPM(nil)
            if err != nil {
                    log.Fatalf("Failed to open the TPM: %v", err)
            }
            defer tpm.Close()

            // Create a new AK.
            ak, err := tpm.NewAK(nil)
            if err != nil {
                    log.Fatalf("Failed to create AK: %v", err)
            }
            // Save a re-loadable representation to blob.
            blob, err := ak.Marshal()
            if err != nil {
                    log.Fatalf("Failed to marshal AK: %v", err)
            }
            // Close our handle to the AK.
            if err := ak.Close(tpm); err != nil {
                    log.Fatalf("Failed to close AK: %v", err)
            }

            // Re-load the created AK from the blob.
            ak, err = tpm.LoadAK(blob)
            if err != nil {
                    log.Fatalf("Failed to load AK: %v", err)
            }
            if err := ak.Close(tpm); err != nil {
                    log.Fatalf("Failed to close AK: %v", err)
            }
    }

    func ExampleAK_credentialActivation() {
            tpm, err := attest.OpenTPM(nil)
            if err != nil {
                    log.Fatalf("Failed to open TPM: %v", err)
            }
            defer tpm.Close()
    
            // Create a new AK.
            ak, err := tpm.NewAK(nil)
            if err != nil {
                    log.Fatalf("Failed to create AK: %v", err)
            }
            defer ak.Close(tpm)
    
            // Read the EK.
            ek, err := tpm.EKs()
            if err != nil {
                    log.Fatalf("Failed to enumerate EKs: %v", err)
            }
    
            // Read parameters necessary to generate a challenge.
            ap := ak.AttestationParameters()
    
            // Generate a credential activation challenge (usually done on the server).
            activation := attest.ActivationParameters{
                    TPMVersion: tpm.Version(),
                    EK:         ek[0].Public,
                    AK:         ap,
            }
            secret, challenge, err := activation.Generate()
            if err != nil {
                    log.Fatalf("Failed to generate activation challenge: %v", err)
            }
    
            // Challenge the AK & EK properties to recieve the decrypted secret.
            decrypted, err := ak.ActivateCredential(tpm, *challenge)
            if err != nil {
                    log.Fatalf("Failed to activate credential: %v", err)
            }
    
            // Check that the AK completed the challenge (usually done on the server).
            if subtle.ConstantTimeCompare(secret, decrypted) == 0 {
                    log.Fatal("Activation response did not match secret")
            }
    }
    
    func main() {
            ExampleAK()
            ExampleAK_credentialActivation()
    }

`

Best regards

from go-attestation.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.