Skip to content

Commit

Permalink
Remove TLS cert from handshake
Browse files Browse the repository at this point in the history
  • Loading branch information
nleiva committed Jun 26, 2019
1 parent c7789f1 commit 1bc6247
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 43 deletions.
44 changes: 14 additions & 30 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package xrgrpc

import (
"crypto/tls"
"crypto/x509"
"fmt"
"io"
"net"
Expand Down Expand Up @@ -137,43 +136,28 @@ func newClientTLS(xr CiscoGrpcClient) (credentials.TransportCredentials, error)
// I am assuming xr.Domain was set with WithCert
return credentials.NewClientTLSFromFile(xr.Cert, xr.Domain)
}
// TODO: make this an input.
// If false, you need to provice the CA cert
// TODO: make skipVerify an input. If false, you need to provice the CA cert.
skipVerify := true
xr.Domain = "ems.cisco.com"

certPool := x509.NewCertPool()
// certPool := x509.NewCertPool()

// Add CA cert. FILE LOCATION CANNOT BE HARDCODED!!!!
// file := "../input/certificate/ca.cert"
// b, err := ioutil.ReadFile(file)
// if err != nil {
// return nil, fmt.Errorf("problem reading CA file %s: %s", file, err)
// }

// if !certPool.AppendCertsFromPEM(b) {
// return nil, fmt.Errorf("failed to append CA certificate")
// }
// Inspired by https://github.com/johnsiilver/getcert.
nconn, err := net.Dial("tcp", xr.Host)
if err != nil {
return nil, fmt.Errorf("problem dialing %s: %s", xr.Host, err)
}
/* file := "../input/certificate/ca.cert"
b, err := ioutil.ReadFile(file)
if err != nil {
return nil, fmt.Errorf("problem reading CA file %s: %s", file, err)
}
if !certPool.AppendCertsFromPEM(b) {
return nil, fmt.Errorf("failed to append CA certificate")
} */
config := &tls.Config{
ServerName: xr.Domain,
// ServerName: xr.Domain,
InsecureSkipVerify: skipVerify,
RootCAs: certPool,
}
tconn := tls.Client(nconn, config)
if err := tconn.Handshake(); err != nil {
return nil, fmt.Errorf("problem with TLS Handshake: %s", err)
}
for _, cert := range tconn.ConnectionState().PeerCertificates {
// fmt.Println("Cert: Common Name: ", cert.Issuer.CommonName)
// fmt.Println("Cert: Serial Number: ", cert.Issuer.SerialNumber)
certPool.AddCert(cert)
// RootCAs: certPool,
}
return credentials.NewClientTLSFromCert(certPool, xr.Domain), nil
return credentials.NewTLS(config), nil
}

// Connect will return a grpc.ClienConn to the target. TLS encryption
Expand Down
22 changes: 14 additions & 8 deletions example/configvalidateoc3/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,10 @@ func main() {

// Pause
fmt.Print("Press 'Enter' to continue...")
bufio.NewReader(os.Stdin).ReadBytes('\n')
_, err = bufio.NewReader(os.Stdin).ReadBytes('\n')
if err != nil {
log.Fatalf("problem detecting newline character: %v", err)
}

// Generate the Interface config.
// At present, ethernet-like media are identified by the value ethernetCsmacd(6).
Expand Down Expand Up @@ -127,8 +130,10 @@ func main() {

// Pause
fmt.Print("Press 'Enter' to continue...")
bufio.NewReader(os.Stdin).ReadBytes('\n')

_, err = bufio.NewReader(os.Stdin).ReadBytes('\n')
if err != nil {
log.Fatalf("problem detecting newline character: %v", err)
}
// Generate the BGP config
neighbor := &NeighborConfig{
LocalAs: 64512,
Expand All @@ -146,14 +151,15 @@ func main() {
_, err = xr.MergeConfig(ctx, conn, bgpConfig, id)
if err != nil {
log.Fatalf("failed to config %s: %v\n", r.IP, err)
} else {
fmt.Printf("\n3)\n%sBGP%s Config applied on %s (Request ID: %v)\n", blue, white, r.IP, id)
}
fmt.Printf("\n3)\n%sBGP%s Config applied on %s (Request ID: %v)\n", blue, white, r.IP, id)

// Pause
fmt.Print("Press 'Enter' to continue...")
bufio.NewReader(os.Stdin).ReadBytes('\n')

_, err = bufio.NewReader(os.Stdin).ReadBytes('\n')
if err != nil {
log.Fatalf("problem detecting newline character: %v", err)
}
// Encoding GPBKV
var e int64 = 3
id++
Expand Down Expand Up @@ -205,7 +211,7 @@ func exploreFields(f []*telemetry.TelemetryField, indent string, peer string, ok

func decodeKV(f *telemetry.TelemetryField, indent string, peer string, ok *bool) {
// This is a very specific scenario, just for this example.
color := white
var color string
switch f.GetValueByType().(type) {
case *telemetry.TelemetryField_StringValue:
switch f.GetName() {
Expand Down
4 changes: 2 additions & 2 deletions example/configvalidateoc3/peeringdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ package main
*/

// NetworkSerializer is the https://peeringdb.com/apidocs/#!/net/Network_list data model
type NetworkSerializer struct {
/* type NetworkSerializer struct {
ID int `json:"id"`
OrgID int `json:"org_id"`
Org string `json:"org"`
Expand Down Expand Up @@ -50,7 +50,7 @@ type NetworkSerializer struct {
Created string `json:"created"`
Updated string `json:"updated"`
Status string `json:"status"`
}
} */

// NetworkSerializer is the https://peeringdb.com/apidocs/#!/net/Network_list data model
//
Expand Down
2 changes: 1 addition & 1 deletion example/definetarget4/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func main() {
// Determine the ID for the transaction.
r := rand.New(rand.NewSource(time.Now().UnixNano()))
id := r.Int63n(10000)
output := "Empty"
var output string

// Manually specify target parameters.
router, err := xr.BuildRouter(
Expand Down
4 changes: 2 additions & 2 deletions sla.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,12 +230,12 @@ func setupNotifChannel(conn *grpc.ClientConn, ch chan int) {
ch <- 1
continue
case pb.SLGlobalNotifType_SL_GLOBAL_EVENT_TYPE_ERROR:
err = fmt.Errorf("%s", r.ErrStatus.String())
_ = fmt.Errorf("%s", r.ErrStatus.String())
break
case pb.SLGlobalNotifType_SL_GLOBAL_EVENT_TYPE_HEARTBEAT:
continue
default:
err = fmt.Errorf("%s", r.ErrStatus.String())
_ = fmt.Errorf("%s", r.ErrStatus.String())
return
}
}
Expand Down

0 comments on commit 1bc6247

Please sign in to comment.