Commit 43612f20 authored by Guillermo Sanz López's avatar Guillermo Sanz López
Browse files

changes needs to review

parent 660d0353
Loading
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -36,7 +36,7 @@ fi

echo "🚀 [1/5] Preparing temporary environment for CAPIF at $CAPIF_DIR..."
rm -rf "$CAPIF_DIR"
git clone "$CAPIF_REPO_URL" "$CAPIF_DIR" > "$LOG_FILE" 2>&1
git clone --branch OCF169-register-hostname-and-certificate-cn "$CAPIF_REPO_URL" "$CAPIF_DIR" > "$LOG_FILE" 2>&1

cd "$CAPIF_DIR/services"

@@ -49,7 +49,7 @@ echo "⏳ [3/5] Waiting for all CAPIF services to be running..."
# Expected CAPIF containers (names as shown in docker ps)
EXPECTED_CONTAINERS=(
  services-mock-server-1
  services-register-1
  register
  services-mongo_register_express-1
  services-mongo_register-1
  services-api-provider-management-1
+2 −2
Original line number Diff line number Diff line
@@ -35,10 +35,10 @@ docker build --no-cache "$PROJECT_ROOT" -t $IMAGE_NAME -f "$SCRIPT_DIR/Dockerfil
echo "🚀 Running container: $CONTAINER_NAME in network: $NETWORK_NAME..."

docker run \
  --rm \
  -it \
  --name $CONTAINER_NAME \
  --network $NETWORK_NAME \
  $IMAGE_NAME
  $IMAGE_NAME /bin/bash

# ----------------------------
# Done
+1 −1
Original line number Diff line number Diff line
{
  "capif_host": "capifcore",
  "register_host": "services-register-1",
  "register_host": "register",
  "capif_https_port": "443",
  "capif_register_port": "8080",
  "capif_username": "custom_user",
+1 −1
Original line number Diff line number Diff line
{
  "capif_host": "capifcore",
  "register_host": "services-register-1",
  "register_host": "register",
  "capif_https_port": "443",
  "capif_register_port": "8080",
  "capif_username": "custom_user",
+41 −2
Original line number Diff line number Diff line
@@ -358,11 +358,44 @@ class capif_provider_connector:
            "Saving CAPIF CA root file and getting auth token with user and password given by the CAPIF administrator")

        try:
            self.logger.debug(f"Retrieving server certificate from {self.capif_register_host}:{self.capif_register_port}...")
            server_cert_pem = ssl.get_server_certificate(
                (self.capif_register_host, int(self.capif_register_port))
            )

            temp_server_cert_path = os.path.join(self.provider_folder, "server_temp.crt")
            with open(temp_server_cert_path, "w") as f:
                f.write(server_cert_pem)
            self.logger.info(f"Server certificate saved at {temp_server_cert_path}")

            # EXTRAER bloque CA 
            ca_cert_path = os.path.join(self.provider_folder, "ca_from_server.crt")
            with open(temp_server_cert_path, "r") as f:
                pem_data = f.read()

            # Separar bloques -----BEGIN CERTIFICATE----- ... -----END CERTIFICATE-----
            blocks = pem_data.strip().split("-----END CERTIFICATE-----")
            if len(blocks) > 1:
                ca_block = blocks[-2].strip() + "\n-----END CERTIFICATE-----\n"
                with open(ca_cert_path, "w") as f:
                    f.write(ca_block)
                self.logger.debug(f"Extracted CA certificate saved at {ca_cert_path}")
            else:
                self.logger.warning(
                    "Server certificate did not contain multiple PEM blocks; using entire file for verification."
                )
                ca_cert_path = temp_server_cert_path

            self.logger.debug(f"CA verification using: {ca_cert_path}")
            
            response = None

            response = requests.get(
                url,
                headers={"Content-Type": "application/json"},
                auth=HTTPBasicAuth(self.capif_provider_username,
                                   self.capif_provider_password),
                # verify=ca_cert_path,
                verify=False,
                timeout=10
            )
@@ -381,8 +414,14 @@ class capif_provider_connector:
            return response_payload

        except requests.exceptions.RequestException as e:
            if "response" in locals() and response is not None:
                self.logger.error(
                    f"Error acquiring authorization: {e} - Response: {response.text}"
                )
            else:
                self.logger.error(
                f"Error acquiring authorization: {e} - Response: {response.text}")
                    f"Error acquiring authorization before receiving a response: {e}"
                )
            raise

    def onboard_provider(self, supp_features="0") -> None: