Skip to content

Commit

Permalink
Marshals measurements as map of uint32->hex string (#21)
Browse files Browse the repository at this point in the history
* Marshals measurements as map of strings

* Puts PCR as uint into the header
  • Loading branch information
Ruteri authored Oct 10, 2024
1 parent 07880e1 commit 62a3843
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions proxy/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"crypto/tls"
"crypto/x509/pkix"
"encoding/asn1"
"encoding/hex"
"encoding/json"
"errors"
"log/slog"
Expand Down Expand Up @@ -141,15 +142,20 @@ func (p *Proxy) getMeasurementsFromTLS(conn *tls.ConnectionState) (atlsVariant v
}

func (p *Proxy) copyMeasurementsToHeader(conn *tls.ConnectionState, header *http.Header) (int, error) {
atlsVariant, measurements, err := p.getMeasurementsFromTLS(conn)
atlsVariant, extractedMeasurements, err := p.getMeasurementsFromTLS(conn)
if err != nil {
return http.StatusTeapot, err
} else if measurements == nil {
} else if extractedMeasurements == nil {
p.log.Debug("[proxy-request: add-headers] no measurements, not adding headers")
return 0, nil
}

marshaledPcrs, err := json.Marshal(measurements)
measurementsInHeaderFormat := make(map[uint32]string, len(extractedMeasurements))
for pcr, value := range extractedMeasurements {
measurementsInHeaderFormat[pcr] = hex.EncodeToString(value)
}

marshaledPcrs, err := json.Marshal(measurementsInHeaderFormat)
if err != nil {
return http.StatusInternalServerError, errors.New("could not marshal measurement extracted from tls extension")
}
Expand Down

0 comments on commit 62a3843

Please sign in to comment.