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

Unable to Connect to OPC UA Server - Error: BadCertificateUriInvalid (0x80170000u) #44

Open
tomytjandra opened this issue Mar 4, 2025 · 0 comments

Comments

@tomytjandra
Copy link

Description:

I'm encountering an issue while attempting to connect to an OPC UA server using the client library. The connection fails with the following error:

public const uint BadCertificateUriInvalid = 0x80170000u;
// The certificate may not be used for the requested operation.

Code Snippet:

package main

import (
	"context"
	"fmt"
	"log"
	"os"
	"github.com/awcullen/opcua/client"
	"github.com/awcullen/opcua/ua"
)

var (
	OPCUA_URL        = getEnv("OPCUA_URL", "")
	OPCUA_USER       = getEnv("OPCUA_USER", "")
	OPCUA_PASSWORD   = getEnv("OPCUA_USER", "")
)

// Environment variable helper
func getEnv(key, defaultValue string) string {
	if value, exists := os.LookupEnv(key); exists {
		return value
	}
	return defaultValue
}

func main() {
	fmt.Printf("Attempting to connect to OPC UA server at %s...\n", OPCUA_URL)

	ctx := context.Background()
	c, err := client.Dial(ctx, OPCUA_URL,
		client.WithSecurityPolicyURI("", ua.MessageSecurityModeNone),
		client.WithUserNameIdentity(OPCUA_USER, OPCUA_PASSWORD),
		client.WithInsecureSkipVerify(),
	)
	if err != nil {
		log.Fatalf("❌ Failed to connect: %v", err)
	}
	fmt.Println("✅ Successfully connected to OPC UA server!")

	defer func() {
		c.Close(ctx)
		fmt.Println("🔌 Disconnected from OPC UA server.")
	}()
}

Attempts:
I have tried the following but still encountered the same error:

  1. Ignore server certificate verification using WithInsecureSkipVerify() → Failed
  2. Attempted anonymous connection (without authentication) → Failed
  3. Generated a self-signed certificate (cert.pem and key.pem) → Failed

Is there any specific configuration required on the client or server side to bypass this certificate validation issue? Any guidance would be appreciated.

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

No branches or pull requests

1 participant