Skip to content

Commit

Permalink
Merge pull request #136 from shjala/register.with.onb.cert
Browse files Browse the repository at this point in the history
apiHandlerv2 : make sure register request is signed
  • Loading branch information
eriknordmark authored Jan 15, 2025
2 parents 7813c42 + 60db71b commit 350e236
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions pkg/server/apiHandlerv2.go
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,12 @@ func (h *apiHandlerv2) register(w http.ResponseWriter, r *http.Request) {
http.Error(w, http.StatusText(http.StatusBadRequest), http.StatusBadRequest)
return
}
if len(b.SenderCertHash) == 0 {
log.Printf("no SenderCertHash in AuthContainer")
http.Error(w, http.StatusText(http.StatusUnauthorized), http.StatusUnauthorized)
return
}

onBoardCertDecoded, err := base64.StdEncoding.DecodeString(string(b.GetSenderCert()))
if err != nil {
log.Printf("error decoding SenderCert: %v", err)
Expand All @@ -431,6 +437,23 @@ func (h *apiHandlerv2) register(w http.ResponseWriter, r *http.Request) {
http.Error(w, http.StatusText(http.StatusBadRequest), http.StatusBadRequest)
return
}

// at least one of the certs should be the onboarding cert
for _, cert := range onboardCert {
payload := b.ProtectedPayload.GetPayload()
hashedPayload := sha256.Sum256(payload)
err = verifySignature(b.SignatureHash, hashedPayload[:], cert)
if err == nil {
log.Printf("signature verification passed")
break
}
}
if err != nil {
log.Printf("signature verification failed: %v", err)
http.Error(w, http.StatusText(http.StatusUnauthorized), http.StatusUnauthorized)
return
}

if len(onboardCert) == 0 {
log.Println("no certificates parsed from SenderCert")
http.Error(w, http.StatusText(http.StatusBadRequest), http.StatusBadRequest)
Expand Down

0 comments on commit 350e236

Please sign in to comment.