yats.git

commit fac68605505426d8f89eac27dcc67795121d5201

Author: Paolo Lulli <paolo@lulli.net>

Remove panics

 server/grpc/grpc-tls.go | 7 +++++--
 server/rest/mtls.go | 6 ++++--


diff --git a/server/grpc/grpc-tls.go b/server/grpc/grpc-tls.go
index 4200fb6af0b9c7630865d7d895fc0b76fb54242c..cd047de72a0fab9214031f0be32cb6d8ee27252a 100644
--- a/server/grpc/grpc-tls.go
+++ b/server/grpc/grpc-tls.go
@@ -3,6 +3,7 @@
 import (
 	"context"
 	"crypto/x509"
+	"fmt"
 	"google.golang.org/grpc/credentials"
 	"google.golang.org/grpc/peer"
 )
@@ -19,12 +20,14 @@ 		//v := tlsInfo.State.VerifiedChains[0][0].Subject.CommonName
 		//fmt.Printf("%v - %v\n", peers.Addr.String(), v)
 		return extractCommonName(certificates)
 	}
-	panic("Could not extract common name")
+	fmt.Println("Could not extract common name")
+	return ""
 }
 
 func extractCommonName(certificates []*x509.Certificate) string {
 	if len(certificates) > 0 {
 		return certificates[0].Subject.CommonName
 	}
-	panic("Could not extract common name")
+	fmt.Println("Could not extract common name")
+	return ""
 }




diff --git a/server/rest/mtls.go b/server/rest/mtls.go
index 49d2a01f4bd6f1c51a14b78830863d9f9779aaab..b2836e2c91cd3f288138a6d0eb5d149e38e2289f 100644
--- a/server/rest/mtls.go
+++ b/server/rest/mtls.go
@@ -11,6 +11,7 @@
 package rest
 
 import (
+	"fmt"
 	"github.com/gin-gonic/gin"
 	"yats-server/config"
 )
@@ -21,7 +22,7 @@ 		s, done := extractCommonName(c)
 		if done {
 			return s
 		}
-		panic("Could not extract common name")
+		fmt.Println("Could not extract common name")
 	}
 	return c.Request.Header.Get("X-SSL-Client-CN")
 }
@@ -31,5 +32,6 @@ 	certificates := c.Request.TLS.PeerCertificates
 	if len(certificates) > 0 {
 		return certificates[0].Subject.CommonName, true
 	}
-	panic("Could not extract common name")
+	fmt.Println("Could not extract common name")
+	return "", false
 }