Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Role requesting certs #251

Merged
merged 16 commits into from
Dec 9, 2024
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
cviecco marked this conversation as resolved.
Show resolved Hide resolved
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
Copy link
Member

@rgooch rgooch Dec 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/dont/don't want/
s/rolerequsting/rolerequesting/


/// 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
Loading