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

Add custom verifier to hostname verification by HTTP client #3610

Merged

Conversation

LakshiAthapaththu
Copy link

@LakshiAthapaththu LakshiAthapaththu commented Jul 13, 2023

Purpose

As explained in wso2/product-is#16181 localhost is not required to be added as a SAN in the certificate even in the flows which use localhost as the internal hostname ( eg: Self registration flow). But currently when localhost is not available as a SAN, some internal API calls fail. Sometimes back a fix has been implemented to ignore localhost verification in wso2/carbon-identity-framework#4262 by introducing a custom verifier to the HTTP client. But in two places this customized HTTP client is not used and therefore self-registration gets failed. As these places are in two different modules, the HTTP client with custom hostname verification has been moved to the kernel as a util method through this PR. Further, we expect to use the same HTTP client for any internal API calls to avoid such issues in the future.

Goals

Resolves the issue of self-registration flow does not work when localhost is removed from the SAN.

Approach

From this PR, an HTTP client creation with customized hostname verification (introduced in wso2/carbon-identity-framework#4262) logic is moved to the Kernal.

Further as per the issue wso2/product-is#16182 when hostname and internal hostname are changed according to option 2 in https://is.docs.wso2.com/en/latest/deploy/change-the-hostname/ an error is observed. This is because even when the hostname and CN are equal when we give a list of subject alternative names, the hostname is validated against the SAN. A fix is added to resolve that issue as well.

Documentation

wso2/product-is#16255

Related PRs

wso2/carbon-identity-framework#4794

core/org.wso2.carbon.utils/pom.xml Outdated Show resolved Hide resolved
*
* @return HttpClientBuilder.
*/
public static HttpClientBuilder getHTTPClientWithCustomHostNameVerifier() {
Copy link
Contributor

Choose a reason for hiding this comment

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

how about createClientWithCustomVerifier?

if (isValidCommonNames && !ArrayUtils.contains(subjectAlternativeNames, commonNames[0])) {
subjectAltsWithLocalhosts = ArrayUtils.add(subjectAltsWithLocalhosts, commonNames[0]);
}
this.verify(hostname, commonNames, subjectAltsWithLocalhosts, false);
Copy link
Contributor

Choose a reason for hiding this comment

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

shouldn't this be super.verify?


String[] subjectAltsWithLocalhosts = ArrayUtils.addAll(subjectAlternativeNames, LOCALHOSTS);

boolean isValidCommonNames = Optional.ofNullable(commonNames)
Copy link
Contributor

Choose a reason for hiding this comment

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

let's rename to hasValidCommonNames

parent/pom.xml Outdated
Comment on lines 1929 to 1932
<groupId>org.wso2.orbit.org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>${commons-lang3.orbit.version}</version>
</dependency>
Copy link
Contributor

Choose a reason for hiding this comment

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

I think commons lang library should already be available. Do we need need lang3 APIs for the ArrayUtils ops? Wouldn't the existing ones be enough?

@jenkins-is-staging
Copy link

PR builder started
Link: https://github.com/wso2/product-is/actions/runs/5583544562

@jenkins-is-staging
Copy link

PR builder completed
Link: https://github.com/wso2/product-is/actions/runs/5583544562
Status: success

Copy link

@jenkins-is-staging jenkins-is-staging left a comment

Choose a reason for hiding this comment

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

Approving the pull request based on the successful pr build https://github.com/wso2/product-is/actions/runs/5583544562

@LakshiAthapaththu LakshiAthapaththu merged commit 12ac33c into wso2:4.9.x Jul 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants