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 proxy authentication #826

Closed
wintermute766 opened this issue Jun 26, 2020 · 6 comments
Closed

Add proxy authentication #826

wintermute766 opened this issue Jun 26, 2020 · 6 comments
Labels
enhancement Indicates new feature requests feature:other Involves a feature that doesn't fit in existing categories

Comments

@wintermute766
Copy link
Contributor

wintermute766 commented Jun 26, 2020

Problem description

It would be very useful to publish artifacts for those who are behind a corporate proxy that requires authentication. Because now all attempts result with 407 HTTP error. So I built plugin with this feature locally and it worked fine for me. Apparently it will be useful to add this feature to the main repo. I provided the example code and the full patch in the potential solutions section.

Potential [solutions/workarounds]

private fun buildTransport(): HttpTransport {
    val trustStore: String? = System.getProperty("javax.net.ssl.trustStore", null)
    val trustStorePassword: String? =
            System.getProperty("javax.net.ssl.trustStorePassword", null)

    return if (trustStore == null) {
        createHttpTransport()
    } else {
        val ks = KeyStore.getInstance(KeyStore.getDefaultType())
        FileInputStream(trustStore).use { fis ->
            ks.load(fis, trustStorePassword?.toCharArray())
        }
        NetHttpTransport.Builder().trustCertificates(ks).build()
    }
}

private fun createHttpTransport() : HttpTransport {
    val protocols = arrayOf("http", "https")
    for (protocol in protocols) {
        val proxyHost = System.getProperty("$protocol.proxyHost")
        val proxyUser = System.getProperty("$protocol.proxyUser")
        val proxyPassword = System.getProperty("$protocol.proxyPassword");
        if (proxyHost == null || proxyUser == null || proxyPassword == null) {
            return GoogleNetHttpTransport.newTrustedTransport()
        }
        val defaultProxyPort = if (protocol == "http") "80" else "443"
        val proxyPort = Integer.parseInt(System.getProperty("$protocol.proxyPort", defaultProxyPort))
        val credentials = BasicCredentialsProvider()
        credentials.setCredentials(
                AuthScope(proxyHost, proxyPort),
                UsernamePasswordCredentials(proxyUser, proxyPassword)
        )
        val httpClient = ApacheHttpTransport.newDefaultHttpClientBuilder()
                .setProxyAuthenticationStrategy(ProxyAuthenticationStrategy.INSTANCE)
                .setDefaultCredentialsProvider(credentials)
                .build()
        return ApacheHttpTransport(httpClient)
    }
    return GoogleNetHttpTransport.newTrustedTransport()
}

Full Patch:

Add_proxy_authentication.txt

Additional context

@wintermute766 wintermute766 added the enhancement Indicates new feature requests label Jun 26, 2020
@SUPERCILEX
Copy link
Collaborator

Pretty sure we support proxies:

@SUPERCILEX
Copy link
Collaborator

@wintermute766
Copy link
Contributor Author

I meant something like this
GoogleContainerTools/jib#1337
Because as I said before the problem I struggled with was the 407 HTTP error, not SSLHandshakeException
https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/407

@SUPERCILEX
Copy link
Collaborator

In the interest of transparency, I'll tell you that I don't know much of anything about proxies. If you want to submit a PR so that this plugin works with your use case, please do so! That said, I won't be working on this since I don't know enough about proxies.

@stale
Copy link

stale bot commented Jul 6, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the waiting-for-reply Indicates that an issue or pull request needs more information label Jul 6, 2020
@wintermute766
Copy link
Contributor Author

Yeah, sorry that was my first intention, but I tried to push to the original project, not the forked one. So I couldn't do it because of insufficient permissions. And I decided that the default option to communicate with the developer is to create an issue.

@stale stale bot removed the waiting-for-reply Indicates that an issue or pull request needs more information label Jul 10, 2020
@wintermute766 wintermute766 reopened this Jul 10, 2020
@SUPERCILEX SUPERCILEX added the feature:other Involves a feature that doesn't fit in existing categories label Jul 14, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Indicates new feature requests feature:other Involves a feature that doesn't fit in existing categories
Projects
None yet
Development

No branches or pull requests

2 participants