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

When joining, always retrieve the service's subject_name from the given cert #6660

Merged
merged 6 commits into from
Nov 19, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/node/identity.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#pragma once

#include "ccf/crypto/curve.h"
#include "ccf/crypto/verifier.h"
#include "ccf/node/cose_signatures_config.h"
#include "crypto/certs.h"
#include "crypto/openssl/key_pair.h"
Expand Down Expand Up @@ -91,7 +92,8 @@ namespace ccf
}

ReplicatedNetworkIdentity(const NetworkIdentity& other) :
NetworkIdentity(other.subject_name, other.cose_signatures_config)
NetworkIdentity(
ccf::crypto::get_subject_name(other.cert), other.cose_signatures_config)
{
if (type != other.type)
{
Expand Down
40 changes: 39 additions & 1 deletion tests/lts_compatibility.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
from governance import test_all_nodes_cert_renewal, test_service_cert_renewal
from infra.snp import IS_SNP
from distutils.dir_util import copy_tree
from cryptography import x509
from cryptography.hazmat.backends import default_backend

from loguru import logger as LOG

Expand Down Expand Up @@ -98,6 +100,7 @@ def test_new_service(
binary_dir,
library_dir,
version,
expected_subject_name=None,
):
if IS_SNP:
LOG.info(
Expand Down Expand Up @@ -149,6 +152,15 @@ def test_new_service(
test_all_nodes_cert_renewal(network, args, valid_from=valid_from)
test_service_cert_renewal(network, args, valid_from=valid_from)

if expected_subject_name:
LOG.info(f"Confirming subject name == {expected_subject_name}")
with primary.client() as c:
r = c.get("/node/network")
assert r.status_code == 200, r
cert_pem = r.body.json()["service_certificate"]
cert = x509.load_pem_x509_certificate(cert_pem.encode(), default_backend())
assert cert.subject.rfc4514_string() == expected_subject_name, cert

LOG.info("Apply transactions to new nodes only")
issue_activity_on_live_service(network, args)
test_random_receipts(network, args, lts=True, log_capture=[])
Expand Down Expand Up @@ -206,6 +218,8 @@ def run_code_upgrade_from(

set_js_args(args, from_install_path, to_install_path)

service_subject_name = "CN=LTS custom service name"

jwt_issuer = infra.jwt_issuer.JwtIssuer(
"https://localhost", refresh_interval=args.jwt_key_refresh_interval_s
)
Expand All @@ -225,7 +239,10 @@ def run_code_upgrade_from(
kwargs["reconfiguration_type"] = "OneTransaction"

network.start_and_open(
args, node_container_image=from_container_image, **kwargs
args,
node_container_image=from_container_image,
service_subject_name=service_subject_name,
**kwargs,
)

old_nodes = network.get_joined_nodes()
Expand Down Expand Up @@ -287,6 +304,26 @@ def run_code_upgrade_from(
version == expected_version
), f"For node {node.local_node_id}, expect version {expected_version}, got {version}"

# Verify that either custom service_subject_name was applied,
# or that a default name is used
primary, _ = network.find_primary()
with primary.client() as c:
r = c.get("/node/network")
assert r.status_code == 200, r
cert_pem = r.body.json()["service_certificate"]
cert = x509.load_pem_x509_certificate(
cert_pem.encode(), default_backend()
)
version = primary.version or args.ccf_version
if not infra.node.version_after(version, "ccf-5.0.0-dev14"):
service_subject_name = cert.subject.rfc4514_string()
LOG.info(
f"Custom subject name not supported on {version}, so falling back to default {service_subject_name}"
)
else:
LOG.info(f"Custom subject name should be supported on {version}")
assert cert.subject.rfc4514_string() == service_subject_name, cert

LOG.info("Apply transactions to hybrid network, with primary as old node")
issue_activity_on_live_service(network, args)

Expand Down Expand Up @@ -371,6 +408,7 @@ def run_code_upgrade_from(
to_binary_dir,
to_library_dir,
to_version,
service_subject_name,
)
network.get_latest_ledger_public_state()

Expand Down