Skip to content

Commit

Permalink
addressing fix requests
Browse files Browse the repository at this point in the history
  • Loading branch information
cviecco committed Dec 8, 2024
1 parent 2938213 commit 987348d
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 15 deletions.
2 changes: 1 addition & 1 deletion cmd/keymasterd/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -1956,7 +1956,7 @@ func main() {
runtimeState.VerifyAuthTokenHandler)
}
serviceMux.HandleFunc(getRoleRequestingPath, runtimeState.roleRequetingCertGenHandler)
serviceMux.HandleFunc(refreshRoleRequestingCertPath, runtimeState.refreshRoleRequetingCertGenHandler)
serviceMux.HandleFunc(refreshRoleRequestingCertPath, runtimeState.refreshRoleRequestingCertGenHandler)
serviceMux.HandleFunc("/", runtimeState.defaultPathHandler)

cfg := &tls.Config{
Expand Down
23 changes: 12 additions & 11 deletions cmd/keymasterd/roleRequestingCert.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ type roleRequestingCertGenParams struct {
Role string
Duration time.Duration
RequestorNetblocks []net.IPNet
TargetNetblocks []net.IPNet
UserPub interface{}
}

Expand Down Expand Up @@ -152,8 +153,8 @@ func (state *RuntimeState) roleRequetingCertGenHandler(w http.ResponseWriter, r
return
}

// TODO: maybe add a check to ensure role certs cannot get role certs?
//
// TODO: maybe add a check to ensure no self-replication
// We dont anything to request a rolerequsting role for itself

/// Now we parse the inputs
if r.Method != "POST" {
Expand All @@ -170,7 +171,7 @@ func (state *RuntimeState) roleRequetingCertGenHandler(w http.ResponseWriter, r
userError.Error())
return
}
pemCert, cert, err := state.withParamsGenegneratRoleRequetingCert(params)
pemCert, cert, err := state.withParamsGenerateRoleRequestingCert(params)
if err != nil {
state.writeFailureResponse(w, r, http.StatusInternalServerError, "")
state.logger.Printf("Error generating cert", err)
Expand All @@ -187,7 +188,7 @@ func (state *RuntimeState) roleRequetingCertGenHandler(w http.ResponseWriter, r
return

}
func (state *RuntimeState) withParamsGenegneratRoleRequetingCert(params *roleRequestingCertGenParams) (string, *x509.Certificate, error) {
func (state *RuntimeState) withParamsGenerateRoleRequestingCert(params *roleRequestingCertGenParams) (string, *x509.Certificate, error) {
signer, caCertDer, err := state.getSignerX509CAForPublic(params.UserPub)
if err != nil {
return "", nil, fmt.Errorf("Error Finding Cert for public key: %s\n data", err)
Expand Down Expand Up @@ -276,10 +277,10 @@ func (state *RuntimeState) parseRefreshRoleCertGenParams(authData *authInfo, r *

// networks
if r.TLS == nil {
return nil, fmt.Errorf("MUST only come form certificate"), nil
return nil, fmt.Errorf("MUST only come from certificate"), nil
}
if len(r.TLS.VerifiedChains) < 1 {
return nil, fmt.Errorf("MUST only come form certificate"), nil
return nil, fmt.Errorf("MUST only come from certificate"), nil
}
userCert := r.TLS.VerifiedChains[0][0]
certNets, err := certgen.ExtractIPNetsFromIPRestrictedX509(userCert)
Expand All @@ -290,7 +291,7 @@ func (state *RuntimeState) parseRefreshRoleCertGenParams(authData *authInfo, r *
return &rvalue, nil, nil
}

func (state *RuntimeState) refreshRoleRequetingCertGenHandler(w http.ResponseWriter, r *http.Request) {
func (state *RuntimeState) refreshRoleRequestingCertGenHandler(w http.ResponseWriter, r *http.Request) {
var signerIsNull bool
state.Mutex.Lock()
signerIsNull = (state.Signer == nil)
Expand All @@ -302,15 +303,15 @@ func (state *RuntimeState) refreshRoleRequetingCertGenHandler(w http.ResponseWri
return
}

state.logger.Debugf(1, "refreshRoleRequetingCertGenHandler before auth")
state.logger.Debugf(1, "refreshRoleRequestingCertGenHandler before auth")
authData, err := state.checkAuth(w, r, AuthTypeIPCertificate)
if err != nil {
state.logger.Debugf(1, "%v", err)
state.writeFailureResponse(w, r, http.StatusInternalServerError, "")
return
}
// TODO: we need to do denylist checks here against the cert/certkey
state.logger.Debugf(1, "refreshRoleRequetingCertGenHandler: authenticated")
state.logger.Debugf(1, "refreshRoleRequestingCertGenHandler: authenticated")

w.(*instrumentedwriter.LoggingWriter).SetUsername(authData.Username)

Expand All @@ -325,12 +326,12 @@ func (state *RuntimeState) refreshRoleRequetingCertGenHandler(w http.ResponseWri
return
}
if userError != nil {
state.logger.Debugf(1, "refreshRoleRequetingCertGenHandler: error parsing params err=%s", userError)
state.logger.Debugf(1, "refreshRoleRequestingCertGenHandler: error parsing params err=%s", userError)
state.writeFailureResponse(w, r, http.StatusBadRequest,
userError.Error())
return
}
pemCert, cert, err := state.withParamsGenegneratRoleRequetingCert(params)
pemCert, cert, err := state.withParamsGenerateRoleRequestingCert(params)
if err != nil {
state.writeFailureResponse(w, r, http.StatusInternalServerError, "")
state.logger.Printf("Error generating cert", err)
Expand Down
4 changes: 2 additions & 2 deletions cmd/keymasterd/roleRequestingCert_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ func TestRefreshRoleRequetingCertGenHandler(t *testing.T) {
RequestorNetblocks: netblockList,
UserPub: userPub,
}
_, rrcert, err := state.withParamsGenegneratRoleRequetingCert(&initialrrParams)
_, rrcert, err := state.withParamsGenerateRoleRequestingCert(&initialrrParams)
if err != nil {
t.Fatal(err)
}
Expand All @@ -284,7 +284,7 @@ func TestRefreshRoleRequetingCertGenHandler(t *testing.T) {
req.TLS = connectionState

//TODO add fail value
_, err = checkRequestHandlerCode(req, state.refreshRoleRequetingCertGenHandler, http.StatusOK)
_, err = checkRequestHandlerCode(req, state.refreshRoleRequestingCertGenHandler, http.StatusOK)
if err != nil {
t.Fatal(err)
}
Expand Down
2 changes: 1 addition & 1 deletion lib/certgen/iprestricted.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ func ExtractIPNetsFromIPRestrictedX509(userCert *x509.Certificate) ([]net.IPNet,
}
}
if extension == nil {
return nil, fmt.Errorf("externsion not found")
return nil, fmt.Errorf("extension not found")
}
var ipAddressFamilyList []IpAdressFamily
_, err = asn1.Unmarshal(extension.Value, &ipAddressFamilyList)
Expand Down

0 comments on commit 987348d

Please sign in to comment.