Facing connectivity issue with neo4j and go language

Hi All,

Actually my neo4j db is in client vm. So i am using certs mentioned in neo4j.conf to get connection while doing that getting below error. Since i am trying to connect with neo4j which is at client vm i dont know the password. when i log in system and give neo4j it will redirect to neo4j command line i tried to get password but getting grant related errors from neo4j.
Error :
Unable to retrieve routing table from ocua.prodapt.com:7687: Server error: [Neo.ClientError.Security.Unauthorized] The client is unauthorized due to authentication failure.

Can anyone tell me whether there is anything wrong in the code i have used:
code i have used:
package main

import (
"crypto/tls"
"log"
"net/http"

"github.com/neo4j/neo4j-go-driver/neo4j"

)

func main() {
// Load your custom certificates
cert, err := tls.LoadX509KeyPair("/certs/Host.crt", "/certs/Host.key")
if err != nil {
log.Fatal(err)
}

// Create a custom TLS configuration
tlsConfig := &tls.Config{
	InsecureSkipVerify: false, // Set this to true for testing (not recommended for production)
	Certificates:       []tls.Certificate{cert},
}

// Set up a custom HTTP client with the custom transport
customTransport := &http.Transport{
	TLSClientConfig: tlsConfig,
}

http.DefaultTransport = customTransport

// Create a Neo4j driver with custom TLS configuration
driver, err := neo4j.NewDriver(
	"bolt+routing://ocua.prodapt.com:7687",
	neo4j.BasicAuth("assure1", "", ""),
)

if err != nil {
	log.Fatalf("Driver configuration Error: %v", err)
}
defer driver.Close()

log.Printf("Driver configuration: %v", driver)

session, err := driver.NewSession(neo4j.SessionConfig{})
if err != nil {
	log.Fatalf("Session Error: %v", err)
}
defer session.Close()

log.Printf("Session opened: %v", session)

result, err := session.ReadTransaction(func(tx neo4j.Transaction) (interface{}, error) {
	result, err := tx.Run("MATCH (n) RETURN n LIMIT 10", nil)
	if err != nil {
		return nil, err
	}
	var records []interface{}
	for result.Next() {
		record := result.Record()
		records = append(records, record)
	}
	return records, err
})

if err != nil {
	log.Fatalf("Query Error: %v", err)
}

log.Printf("Result: %v", result)

if result != nil {
	records := result.([]interface{})
	for _, record := range records {
		log.Printf("%#v", record)
	}
}

}

Hello, you're using a very old version of the go driver (v1.x).
The import should be github.com/neo4j/neo4j-go-driver/v5/neo4j and the bolt+routing URI scheme has been replaced with neo4j.

Hi , I have done changes accordingly this time i got a different error from server.
Error : TransactionExecutionLimit: timeout (exceeded max retry time: 30s) after 5 attempts, last error: ConnectivityError: Unable to retrieve routing table from ocua.prodapt.com:7687: EOF
exit status 1.

code i have used: package main

import (
"crypto/tls"
"log"
"net/http"

"github.com/neo4j/neo4j-go-driver/v5/neo4j"

)

func main() {
// Load your custom certificates
cert, err := tls.LoadX509KeyPair("/certs/Host.crt", "/certs/Host.key")
if err != nil {
log.Fatal(err)
}

// Create a custom TLS configuration
tlsConfig := &tls.Config{
	InsecureSkipVerify: false, // Set this to true for testing (not recommended for production)
	Certificates:       []tls.Certificate{cert},
}

// Set up a custom HTTP client with the custom transport
customTransport := &http.Transport{
	TLSClientConfig: tlsConfig,
}

http.DefaultTransport = customTransport

// Create a Neo4j driver with custom TLS configuration
driver, err := neo4j.NewDriver(
	"neo4j://ocua.prodapt.com:7687",
	neo4j.BasicAuth("assure1", "", ""),
)

if err != nil {
	log.Fatalf("Driver configuration Error: %v", err)
}
defer driver.Close()

log.Printf("Driver configuration: %v", driver)

// Create a session
session := driver.NewSession(neo4j.SessionConfig{})
defer session.Close()

log.Printf("Session opened: %v", session)

result, err := session.ReadTransaction(func(tx neo4j.Transaction) (interface{}, error) {
	result, err := tx.Run("MATCH (n) RETURN n LIMIT 10", nil)
	if err != nil {
		return nil, err
	}
	var records []interface{}
	for result.Next() {
		record := result.Record()
		records = append(records, record)
	}
	return records, err
})

if err != nil {
	log.Fatalf("Query Error: %v", err)
}

log.Printf("Result: %v", result)

if result != nil {
	records := result.([]interface{})
	for _, record := range records {
		log.Printf("%#v", record)
	}
}

}

My neo4j db is in cloud so i am using certs trying to make ssl connection from my local. Do i need to do any changes in the code please let me know .

Thanks in advance

Just to be 100% sure: did you remove the password out of the snippet for confidentiality reasons?
If not, I don't think you can set an empty password for a user.

Actually, I don't know the password as its in client's vm, I can get into neo4j cli using a1neo4j command. From the cli I got to know I logged in as user assure1. I have done similar connection with MySQL using certs there I have used user as assure1 and set password as empty here I was able to get connection. So, I am trying same with neo4j. If we can't get the connection without knowing proper credentials Is there any other alternate way to get connection with neo4j only using ssl certs (User-assure1.crt, User-assure1.key and BundleCA.crt). I have access to these ssl certs from client's vm.

Hi. As far as I'm aware, neo4j currently does not support authentication with client certificates.

Maybe ask the client for the password? If they don't know either, but you're able to get into a cypher shell, you can change the password.

ALTER USER assure1 SET PASSWORD 'mynewpassword'

After changing the password it worked actually thank you