From cc2483fa7b1e75c59cfc68420a9073d75e1eb2ed Mon Sep 17 00:00:00 2001 From: Bas Kloosterman Date: Thu, 1 Jun 2023 11:59:53 +0200 Subject: [PATCH] Rename certgen -> cryptoutil --- {certgen => cryptoutil}/certgen.go | 2 +- dvzaservice/main.go | 4 ++-- dvzaservice/openapisrv.go | 6 +++--- his/openapiclient.go | 4 ++-- his/srv.go | 10 +++++----- sharedmodel/auth.go | 4 ++-- sharedmodel/registration.go | 4 ++-- whiteboxservice/main.go | 5 +++-- whiteboxservice/openapisrv.go | 8 ++++---- 9 files changed, 24 insertions(+), 23 deletions(-) rename {certgen => cryptoutil}/certgen.go (99%) diff --git a/certgen/certgen.go b/cryptoutil/certgen.go similarity index 99% rename from certgen/certgen.go rename to cryptoutil/certgen.go index f1e9d61..4576334 100644 --- a/certgen/certgen.go +++ b/cryptoutil/certgen.go @@ -1,4 +1,4 @@ -package certgen +package cryptoutil import ( "bytes" diff --git a/dvzaservice/main.go b/dvzaservice/main.go index 3daa0b9..4cabe58 100644 --- a/dvzaservice/main.go +++ b/dvzaservice/main.go @@ -12,8 +12,8 @@ import ( "google.golang.org/grpc" "google.golang.org/grpc/credentials" - "src.whiteboxsystems.nl/DECOZO/okapidemo/certgen" "src.whiteboxsystems.nl/decozo/okapi" + "src.whiteboxsystems.nl/decozo/okapidemo/cryptoutil" ) var rpcPort = "9999" @@ -25,7 +25,7 @@ func loadCert() *tls.Certificate { _, err := os.Stat("certs/client.crt") if err != nil { - _, _, certPem, keyPem, err := certgen.GenCert("dvza", "dvza") + _, _, certPem, keyPem, err := cryptoutil.GenCert("dvza", "dvza") if err != nil { panic(err) diff --git a/dvzaservice/openapisrv.go b/dvzaservice/openapisrv.go index c9006bd..b303a94 100644 --- a/dvzaservice/openapisrv.go +++ b/dvzaservice/openapisrv.go @@ -13,8 +13,8 @@ import ( "google.golang.org/grpc/status" "google.golang.org/protobuf/types/known/structpb" "gorm.io/gorm" - "src.whiteboxsystems.nl/DECOZO/okapidemo/certgen" "src.whiteboxsystems.nl/decozo/okapi" + "src.whiteboxsystems.nl/decozo/okapidemo/cryptoutil" "src.whiteboxsystems.nl/decozo/okapidemo/dvzaservice/model" "src.whiteboxsystems.nl/decozo/okapidemo/sharedmodel" ) @@ -59,7 +59,7 @@ func requireConnection(db *gorm.DB, ctx context.Context) (*sharedmodel.Connectio if mtls, ok := p.AuthInfo.(credentials.TLSInfo); ok { item := mtls.State.PeerCertificates[0] log.Println("request certificate subject:", item.Subject) - pk, err := certgen.PublicKeyToJWK(item.PublicKey) + pk, err := cryptoutil.PublicKeyToJWK(item.PublicKey) if err != nil { return nil, errNotAuthorized } @@ -240,7 +240,7 @@ func (srv *OkAPIServer) CompleteRegistration( if mtls, ok := p.AuthInfo.(credentials.TLSInfo); ok { item := mtls.State.PeerCertificates[0] - pk, err := certgen.PublicKeyToJWK(item.PublicKey) + pk, err := cryptoutil.PublicKeyToJWK(item.PublicKey) if err != nil { return nil, errNotAuthorized } diff --git a/his/openapiclient.go b/his/openapiclient.go index 4d706c7..025b0c6 100644 --- a/his/openapiclient.go +++ b/his/openapiclient.go @@ -11,8 +11,8 @@ import ( "google.golang.org/grpc/credentials" "google.golang.org/protobuf/types/known/structpb" "gorm.io/gorm" - "src.whiteboxsystems.nl/DECOZO/okapidemo/certgen" "src.whiteboxsystems.nl/decozo/okapi" + "src.whiteboxsystems.nl/decozo/okapidemo/cryptoutil" "src.whiteboxsystems.nl/decozo/okapidemo/his/model" "src.whiteboxsystems.nl/decozo/okapidemo/sharedmodel" ) @@ -88,7 +88,7 @@ func (srv *HISServer) register(addr string) (*model.ServiceProvider, error) { return nil, err } - jwkBytes, err := certgen.PublicKeyToJWKJson(certgen.ExtractPublicKey(srv.clientCert.PrivateKey)) + jwkBytes, err := cryptoutil.PublicKeyToJWKJson(cryptoutil.ExtractPublicKey(srv.clientCert.PrivateKey)) if err != nil { return nil, err diff --git a/his/srv.go b/his/srv.go index 5bc7632..b998b3f 100644 --- a/his/srv.go +++ b/his/srv.go @@ -18,8 +18,8 @@ import ( "github.com/gin-gonic/gin" "google.golang.org/grpc/credentials" "gorm.io/gorm" - "src.whiteboxsystems.nl/DECOZO/okapidemo/certgen" "src.whiteboxsystems.nl/decozo/okapi" + "src.whiteboxsystems.nl/decozo/okapidemo/cryptoutil" "src.whiteboxsystems.nl/decozo/okapidemo/his/model" "src.whiteboxsystems.nl/decozo/okapidemo/sharedmodel" ) @@ -28,7 +28,7 @@ func loadCert() *tls.Certificate { _, err := os.Stat("certs/client.crt") if err != nil { - _, _, certPem, keyPem, err := certgen.GenCert("whitebox", "whitebox") + _, _, certPem, keyPem, err := cryptoutil.GenCert("whitebox", "whitebox") if err != nil { panic(err) @@ -266,7 +266,7 @@ func (srv *HISServer) Authenticate(c *gin.Context) { raw := "" method := "" if len(c.Request.TLS.PeerCertificates) > 0 { - jwk, err := certgen.PublicKeyToJWK(c.Request.TLS.PeerCertificates[0].PublicKey) + jwk, err := cryptoutil.PublicKeyToJWK(c.Request.TLS.PeerCertificates[0].PublicKey) if err != nil { log.Printf("Error extracting public key JKW: %v", err) @@ -568,7 +568,7 @@ func (srv *HISServer) GetPatient(c *gin.Context) { return } - f, err := os.Open(path.Join("./data/patients", patient.FileBase+".edi")) + f, err := os.Open(path.Join("./patients", patient.FileBase+".edi")) if err != nil { c.Error(err) return @@ -599,7 +599,7 @@ func (srv *HISServer) GetFHIRPatient(c *gin.Context) { return } - f, err := os.Open(path.Join("./data/patients", patient.FileBase+".fhir.json")) + f, err := os.Open(path.Join("./patients", patient.FileBase+".fhir.json")) if err != nil { c.Error(err) return diff --git a/sharedmodel/auth.go b/sharedmodel/auth.go index e6dde26..7b3094d 100644 --- a/sharedmodel/auth.go +++ b/sharedmodel/auth.go @@ -6,8 +6,8 @@ import ( "google.golang.org/protobuf/types/known/structpb" "gorm.io/gorm" - "src.whiteboxsystems.nl/DECOZO/okapidemo/certgen" "src.whiteboxsystems.nl/decozo/okapi" + "src.whiteboxsystems.nl/decozo/okapidemo/cryptoutil" ) const AuthMethodDecozoMTLS = "http://decozo.org/proto/auth/mtls" @@ -56,7 +56,7 @@ func NewAuthConfig(cfg *okapi.ProtocolAuthConfiguration) *AuthConfig { authConfig.Raw, _ = cfg.GetConfiguration().AsMap()["token"].(string) case AuthMethodDecozoMTLS: k, _ := cfg.GetConfiguration().AsMap()["publicKey"].(string) - jwk, _ := certgen.StringToJWK(k) + jwk, _ := cryptoutil.StringToJWK(k) if jwk != nil { rawBytes, _ := jwk.Thumbprint(crypto.SHA256) authConfig.Raw = fmt.Sprintf("%X", rawBytes) diff --git a/sharedmodel/registration.go b/sharedmodel/registration.go index 5b4b367..73edebf 100644 --- a/sharedmodel/registration.go +++ b/sharedmodel/registration.go @@ -5,8 +5,8 @@ import ( "fmt" "gorm.io/gorm" - "src.whiteboxsystems.nl/DECOZO/okapidemo/certgen" "src.whiteboxsystems.nl/decozo/okapi" + "src.whiteboxsystems.nl/decozo/okapidemo/cryptoutil" ) type RegistrationStatus string @@ -35,7 +35,7 @@ func (r *Registration) SetAuthConfig(cfg *okapi.XISAuthConfiguration) error { switch cfg.Method { case okapi.XISAuthMethod_mTLS: - k, err := certgen.StringToJWK(cfg.GetMtlsConfiguration().GetPublicKey()) + k, err := cryptoutil.StringToJWK(cfg.GetMtlsConfiguration().GetPublicKey()) if err != nil { return err diff --git a/whiteboxservice/main.go b/whiteboxservice/main.go index de057de..046ed6a 100644 --- a/whiteboxservice/main.go +++ b/whiteboxservice/main.go @@ -12,8 +12,8 @@ import ( "google.golang.org/grpc" "google.golang.org/grpc/credentials" - "src.whiteboxsystems.nl/DECOZO/okapidemo/certgen" "src.whiteboxsystems.nl/decozo/okapi" + "src.whiteboxsystems.nl/decozo/okapidemo/cryptoutil" ) var rpcPort = "8888" @@ -27,7 +27,7 @@ func loadCert() *tls.Certificate { _, err := os.Stat("certs/client.crt") if err != nil { - _, _, certPem, keyPem, err := certgen.GenCert("whitebox", "whitebox") + _, _, certPem, keyPem, err := cryptoutil.GenCert("whitebox", "whitebox") if err != nil { panic(err) @@ -77,6 +77,7 @@ func main() { if ext := os.Getenv("EXT_ADDR"); ext != "" { extRpcAddr = ext + ":" + rpcPort } + openapisrv := NewServer() openapisrv.LoadData("./data/data.db") opts := []grpc.ServerOption{ diff --git a/whiteboxservice/openapisrv.go b/whiteboxservice/openapisrv.go index 6f95946..fd03d57 100644 --- a/whiteboxservice/openapisrv.go +++ b/whiteboxservice/openapisrv.go @@ -14,8 +14,8 @@ import ( "google.golang.org/grpc/status" "google.golang.org/protobuf/types/known/structpb" "gorm.io/gorm" - "src.whiteboxsystems.nl/DECOZO/okapidemo/certgen" "src.whiteboxsystems.nl/decozo/okapi" + "src.whiteboxsystems.nl/decozo/okapidemo/cryptoutil" "src.whiteboxsystems.nl/decozo/okapidemo/sharedmodel" "src.whiteboxsystems.nl/decozo/okapidemo/whiteboxservice/model" ) @@ -61,7 +61,7 @@ func requireConnection(db *gorm.DB, ctx context.Context) (*sharedmodel.Connectio if mtls, ok := p.AuthInfo.(credentials.TLSInfo); ok { item := mtls.State.PeerCertificates[0] log.Println("request certificate subject:", item.Subject) - pk, err := certgen.PublicKeyToJWK(item.PublicKey) + pk, err := cryptoutil.PublicKeyToJWK(item.PublicKey) if err != nil { return nil, errNotAuthorized } @@ -224,7 +224,7 @@ func (srv *OkAPIServer) CompleteRegistration( if mtls, ok := p.AuthInfo.(credentials.TLSInfo); ok { item := mtls.State.PeerCertificates[0] - pk, err := certgen.PublicKeyToJWK(item.PublicKey) + pk, err := cryptoutil.PublicKeyToJWK(item.PublicKey) if err != nil { return nil, errNotAuthorized } @@ -307,7 +307,7 @@ func (srv *OkAPIServer) EnableService( AuthConfig: sharedmodel.NewAuthConfig(in.Fetch.Auth), } - publicKey, err := certgen.PublicKeyToJWKJson(certgen.ExtractPublicKey(srv.clientCert.PrivateKey)) + publicKey, err := cryptoutil.PublicKeyToJWKJson(cryptoutil.ExtractPublicKey(srv.clientCert.PrivateKey)) if err != nil { return nil, fmt.Errorf("Error retrieving pub key: %v", err)