refactor: only accept certificate as base64, remove cert_path field
- RegisterInput now only has cert_file (base64 content) - Removed cert_path fallback and raw map parsing - Clean struct-based JSON unmarshaling
This commit is contained in:
parent
9c4f11d7c7
commit
3ede32ef20
|
|
@ -17,7 +17,7 @@ import (
|
||||||
|
|
||||||
type RegisterInput struct {
|
type RegisterInput struct {
|
||||||
CertName string `json:"cert_name"`
|
CertName string `json:"cert_name"`
|
||||||
CertFileBase64 string `json:"cert_file"`
|
CertFile string `json:"cert_file"`
|
||||||
PasswordEncrypted string `json:"password_encrypted"`
|
PasswordEncrypted string `json:"password_encrypted"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -72,7 +72,7 @@ func (h *Handler) RegisterCert(w http.ResponseWriter, r *http.Request) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if input.CertName == "" || input.CertFileBase64 == "" || input.PasswordEncrypted == "" {
|
if input.CertName == "" || input.CertFile == "" || input.PasswordEncrypted == "" {
|
||||||
w.Header().Set("Content-Type", "application/json")
|
w.Header().Set("Content-Type", "application/json")
|
||||||
w.Write([]byte(`{"success":false,"error":"missing_fields"}`))
|
w.Write([]byte(`{"success":false,"error":"missing_fields"}`))
|
||||||
return
|
return
|
||||||
|
|
@ -94,7 +94,7 @@ func (h *Handler) RegisterCert(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
plainPass := string(plainPassBytes)
|
plainPass := string(plainPassBytes)
|
||||||
|
|
||||||
validation := cert.ValidateP12(input.CertFileBase64, plainPass)
|
validation := cert.ValidateP12(input.CertFile, plainPass)
|
||||||
if !validation.Valid {
|
if !validation.Valid {
|
||||||
resp, _ := json.Marshal(map[string]interface{}{
|
resp, _ := json.Marshal(map[string]interface{}{
|
||||||
"success": false,
|
"success": false,
|
||||||
|
|
@ -106,7 +106,7 @@ func (h *Handler) RegisterCert(w http.ResponseWriter, r *http.Request) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
tempPath, err := h.cert.StoreFromBase64(input.CertName, input.CertFileBase64)
|
tempPath, err := h.cert.StoreFromBase64(input.CertName, input.CertFile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
h.cert.DeleteTemp(tempPath)
|
h.cert.DeleteTemp(tempPath)
|
||||||
w.Header().Set("Content-Type", "application/json")
|
w.Header().Set("Content-Type", "application/json")
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue