Skip to content

Commit 60db71b

Browse files
committed
apiHandlerv2 : make sure register request is signed
This change makes sure that the register request is signed with onboarding cert, that is the only purpose of onboarding cert. Signed-off-by: Shahriyar Jalayeri <[email protected]>
1 parent 7813c42 commit 60db71b

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

pkg/server/apiHandlerv2.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,12 @@ func (h *apiHandlerv2) register(w http.ResponseWriter, r *http.Request) {
419419
http.Error(w, http.StatusText(http.StatusBadRequest), http.StatusBadRequest)
420420
return
421421
}
422+
if len(b.SenderCertHash) == 0 {
423+
log.Printf("no SenderCertHash in AuthContainer")
424+
http.Error(w, http.StatusText(http.StatusUnauthorized), http.StatusUnauthorized)
425+
return
426+
}
427+
422428
onBoardCertDecoded, err := base64.StdEncoding.DecodeString(string(b.GetSenderCert()))
423429
if err != nil {
424430
log.Printf("error decoding SenderCert: %v", err)
@@ -431,6 +437,23 @@ func (h *apiHandlerv2) register(w http.ResponseWriter, r *http.Request) {
431437
http.Error(w, http.StatusText(http.StatusBadRequest), http.StatusBadRequest)
432438
return
433439
}
440+
441+
// at least one of the certs should be the onboarding cert
442+
for _, cert := range onboardCert {
443+
payload := b.ProtectedPayload.GetPayload()
444+
hashedPayload := sha256.Sum256(payload)
445+
err = verifySignature(b.SignatureHash, hashedPayload[:], cert)
446+
if err == nil {
447+
log.Printf("signature verification passed")
448+
break
449+
}
450+
}
451+
if err != nil {
452+
log.Printf("signature verification failed: %v", err)
453+
http.Error(w, http.StatusText(http.StatusUnauthorized), http.StatusUnauthorized)
454+
return
455+
}
456+
434457
if len(onboardCert) == 0 {
435458
log.Println("no certificates parsed from SenderCert")
436459
http.Error(w, http.StatusText(http.StatusBadRequest), http.StatusBadRequest)

0 commit comments

Comments
 (0)