go-ora icon indicating copy to clipboard operation
go-ora copied to clipboard

SSL connection without using wallet.

Open abd-770 opened this issue 11 months ago • 4 comments

I'm trying to connect to Oracle DB with SSL without using wallet and I'm getting "tls: handshake failure" Below is my code. Can anyone try to help me on this case.

package main
import (
	"context"
	"crypto/rsa"
	"crypto/tls"
	"crypto/x509"
	"database/sql"
	"fmt"
	"io/ioutil"
	"net"

	go_ora "github.com/sijms/go-ora/v2"
)

func main() {

	host := hostname
	username := username
	password := password
	sid := sidName

	port := portnumber

	ssl := true
	sslVerify := false

	var tlsConfig *tls.Config
	sslCertPath := "/Users/certificate.pem"
	sslCert, err := ioutil.ReadFile(sslCertPath)
	if err != nil {
		fmt.Println("failed to read SSL certificate file: ", err)
		return
	}

	tlsConfig = &tls.Config{
		RootCAs: x509.NewCertPool(),
	}

	if !tlsConfig.RootCAs.AppendCertsFromPEM(sslCert) {
		fmt.Println("Invalid SSL certificate format")
	}

	urlOptions := map[string]string{
		"TRACE FILE": "trace.log",
		"SID":        sid,
		"ssl":        fmt.Sprintf("%t", ssl),
		"ssl verify": fmt.Sprintf("%t", sslVerify),
	}

	connectionString := go_ora.BuildUrl(host, port, "", username, password, urlOptions)

	db, err := sql.Open("oracle", connectionString)
	if err != nil {
		panic(fmt.Errorf("error in sql.Open: %w", err))
	}
	defer func() {
		err = db.Close()
		if err != nil {
			fmt.Println("Can't close connection: ", err)
		}
	}()

	err = db.Ping()
	if err != nil {
		panic(fmt.Errorf("error pinging db: %w", err))
	}
	fmt.Println(connectionString)
}


abd-770 avatar Mar 15 '24 06:03 abd-770