Skip to content

public_key: Fix IP address name constraint handling - #11389

Open
u3s wants to merge 1 commit into
erlang:maintfrom
u3s:kuba/public_key/ipaddress_constraint_fix/OTP-20266
Open

public_key: Fix IP address name constraint handling#11389
u3s wants to merge 1 commit into
erlang:maintfrom
u3s:kuba/public_key/ipaddress_constraint_fix/OTP-20266

Conversation

@u3s

@u3s u3s commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

The atom 'ipAdress' (typo since R13B03) in pubkey_cert.erl did not match the ASN.1 decoder's 'iPAddress', making IP-based name constraints non-functional. Rename to correct atom.

Also fixes 'iPAdress' variant in is_valid_subject_alt_name/1.

@u3s
u3s requested a review from IngelaAndin July 24, 2026 08:07
@u3s u3s self-assigned this Jul 24, 2026
@u3s u3s added the team:PS Assigned to OTP team PS label Jul 24, 2026
@github-actions

github-actions Bot commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

CT Test Results

  2 files   18 suites   6m 4s ⏱️
313 tests 305 ✅ 8 💤 0 ❌
330 runs  322 ✅ 8 💤 0 ❌

Results for commit b9831af.

♻️ This comment has been updated with latest results.

To speed up review, make sure that you have read Contributing to Erlang/OTP and that all checks pass.

See the TESTING and DEVELOPMENT HowTo guides for details about how to run test locally.

Artifacts

// Erlang/OTP Github Action Bot

The atom 'ipAdress' (typo since R13B03) in pubkey_cert.erl did not
match the ASN.1 decoder's 'iPAddress', making IP-based name constraints
non-functional. Additionally, the old implementation expected list values
but the decoder produces binaries. Rewrite to work with binary data
natively.

Also fixes 'iPAdress' variant in is_valid_subject_alt_name/1.
@u3s
u3s force-pushed the kuba/public_key/ipaddress_constraint_fix/OTP-20266 branch from ab2be64 to b9831af Compare July 24, 2026 08:15
@u3s u3s added the testing currently being tested, tag is used by OTP internal CI label Jul 24, 2026

@IngelaAndin IngelaAndin Aug 18, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested fix:

ip_constraint_intersection(IpMask1, IpMask2) ->
    {Ip1, Mask1} = split_ip_mask(IpMask1),
    {Ip2, Mask2} = split_ip_mask(IpMask2),
    case {contains(Ip1, Mask1, Ip2, Mask2),
          contains(Ip2, Mask2, Ip1, Mask1)} of
        {true, true} ->
            %% Identical subnets
            {ok, IpMask1};
        {true, false} ->
            %% Subnet1 contains Subnet2 — Subnet2 is narrower
            {ok, IpMask2};
        {false, true} ->
            %% Subnet2 contains Subnet1 — Subnet1 is narrower
            {ok, IpMask1};
        {false, false} ->
            empty
    end.

%% Subnet IP1/Mask1 contains subnet IP2/Mask2 iff:
%%   1. Mask1 is broader (Mask1 band Mask2 == Mask1), AND
%%   2. IP2's network falls in IP1 (IP2 band Mask1 == IP1)
contains(Ip1, Mask1, Ip2, Mask2) ->
    band_list(Mask1, Mask2) =:= Mask1 andalso
    band_list(Ip2, Mask1) =:= Ip1.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

team:PS Assigned to OTP team PS testing currently being tested, tag is used by OTP internal CI

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants