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

OCPBUGS-27214: ccoctl - use proxy when validating CloudFront URL #654

Merged
merged 1 commit into from Feb 6, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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