func main()

in codelabs/health_data_analysis_codelab/src/uwear/workload.go [401:458]


func main() {
	fmt.Println("Initializing client...")

	tlsconfig := &tls.Config{
		// Skipping client verification of the server's certificate chain and host name since we are
		// doing custom verification using the attestation token.
		InsecureSkipVerify: true,
	}

	dialer := websocket.Dialer{
		TLSClientConfig:  tlsconfig,
		HandshakeTimeout: 5 * time.Second,
	}

	ipAddress := os.Getenv(ipAddrEnvVar)
	url := fmt.Sprintf("wss://%s:8081/connection", ipAddress)

	fmt.Printf("Attempting to dial to url %v...\n", url)
	conn, _, err := dialer.Dial(url, nil)
	if err != nil {
		fmt.Printf("Failed to dial to url %s, err %v\n", url, err)
		return
	}

	defer conn.Close()

	tokenString, ekm, err := retrieveTokenAndEKMFromConn(conn)
	if err != nil {
		fmt.Printf("Failed to retrieve token and EKM from connection: %v\n", err)
		return
	}

	fmt.Printf("token: %v\n", tokenString)

	token, err := validatePKIToken(tokenString)
	if err != nil {
		fmt.Printf("Failed to validate PKI token, err: %v\n.", err)
		return
	}
	fmt.Println("PKI token validated successfully")

	err = validateClaimsAgainstOPAPolicy(token, ekm)
	if err != nil {
		fmt.Printf("Failed to validate claims against OPA policy: %v\n", err)
		return
	}

	fmt.Println("Validated token and claims. Sending sensitive data")

	data, err := readFile(mySensitiveDataFile)
	if err != nil {
		fmt.Printf("Failed to read data from the file: %v\n", err)
	}

	conn.WriteMessage(websocket.BinaryMessage, data)
	fmt.Println("Sent payload. Closing the connection")
	conn.Close()
}