Skip to content

Commit

Permalink
OCPBUGS-27214: ccoctl - use proxy when validating CloudFront URL
Browse files Browse the repository at this point in the history
This change make support of proxy in ccoctl when getting fingerprint
from the OIDC endpoint on AWS.
  • Loading branch information
mtulio committed Feb 2, 2024
1 parent 8bca79f commit f442cd5
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions pkg/cmd/provisioning/aws/create_identity_provider.go
Expand Up @@ -3,11 +3,10 @@ package aws
import (
"bytes"
"crypto/sha1"
"crypto/tls"
"fmt"
"io/ioutil"
"log"
"net/url"
"net/http"
"os"
"path/filepath"
"strings"
Expand Down Expand Up @@ -280,21 +279,23 @@ func createIdentityProvider(client aws.Client, name, region, publicKeyPath, targ
}

func getTLSFingerprint(bucketURL string) (string, error) {
u, err := url.Parse(bucketURL)
client := http.DefaultClient
resp, err := client.Head(bucketURL)
if err != nil {
return "", err
return "", errors.Wrapf(err, "error validating TLS Fingerprint")
}
defer resp.Body.Close()

urlWithPort := fmt.Sprintf("%s:443", u.Host)

conn, err := tls.Dial("tcp", urlWithPort, &tls.Config{})
if err != nil {
return "", err
if resp.TLS == nil {
return "", errors.Wrapf(err, "unable to get TLS connection from URL %s", bucketURL)
}
if resp.TLS.PeerCertificates == nil {
return "", errors.Wrapf(err, "unable to get TLS PeerCertificates from connection URL %s", bucketURL)
}

certs := conn.ConnectionState().PeerCertificates
numCerts := len(certs)
certs := resp.TLS.PeerCertificates

numCerts := len(certs)
fingerprint := sha1.Sum(certs[numCerts-1].Raw)
var buf bytes.Buffer
for _, f := range fingerprint {
Expand Down

0 comments on commit f442cd5

Please sign in to comment.