Просмотр исходного кода

Verify IP identifier contains valid IP

Herman Slatman 5 лет назад
Родитель
Сommit
a0e92f8e99
1 измененных файлов с 5 добавлено и 0 удалено
  1. 5 0
      acme/api/order.go

+ 5 - 0
acme/api/order.go

@@ -5,6 +5,7 @@ import (
 	"crypto/x509"
 	"crypto/x509"
 	"encoding/base64"
 	"encoding/base64"
 	"encoding/json"
 	"encoding/json"
+	"net"
 	"net/http"
 	"net/http"
 	"strings"
 	"strings"
 	"time"
 	"time"
@@ -31,6 +32,9 @@ func (n *NewOrderRequest) Validate() error {
 		if !(id.Type == "dns" || id.Type == "ip") {
 		if !(id.Type == "dns" || id.Type == "ip") {
 			return acme.NewError(acme.ErrorMalformedType, "identifier type unsupported: %s", id.Type)
 			return acme.NewError(acme.ErrorMalformedType, "identifier type unsupported: %s", id.Type)
 		}
 		}
+		if id.Type == "ip" && net.ParseIP(id.Value) == nil {
+			return acme.NewError(acme.ErrorMalformedType, "%s is not a valid IP address", id.Value)
+		}
 	}
 	}
 	return nil
 	return nil
 }
 }
@@ -85,6 +89,7 @@ func (h *Handler) NewOrder(w http.ResponseWriter, r *http.Request) {
 			"failed to unmarshal new-order request payload"))
 			"failed to unmarshal new-order request payload"))
 		return
 		return
 	}
 	}
+
 	if err := nor.Validate(); err != nil {
 	if err := nor.Validate(); err != nil {
 		api.WriteError(w, err)
 		api.WriteError(w, err)
 		return
 		return