Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

inline localhost certificate into go file #318

Merged
merged 3 commits into from
Jul 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions grpctesting/certs/gen_cert.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,10 @@

openssl req -x509 -sha256 -nodes -newkey rsa:2048 -days 3650 -keyout localhost.key -out localhost.crt

cat <<EOF > localhost.go
package certs

var LocalhostKey []byte = []byte(\`$(cat localhost.key)\`)

var LocalhostCert []byte = []byte(\`$(cat localhost.crt)\`)
EOF
54 changes: 54 additions & 0 deletions grpctesting/certs/localhost.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package certs

var LocalhostKey []byte = []byte(`-----BEGIN RSA PRIVATE KEY-----
MIIEowIBAAKCAQEA2uDY9N8eGScSGAr/DIeFxyCrytqCkYvqVPYqrZv4VOZvyfak
Un7bW4q8zeNWwj64sU0al7Bz8KBmAM7raLnkvkZxmXUCls+Yw8BgXQr+1aDvYYd0
JIVJvQqQd1oNXQeZs6GXfalCXh9mhHkJIHOm2ynk2GtS81NQik7ZMg+W3qygeK8O
40vbnYxqq2zkvub1dztxuApUzLmuXxLZRo+3faZZetNZ1eMCuqyqzibDRwcYhr3a
soC8d+6wWFobwV5AX7h7+qnS6mclESkN7FHMZT1r3OEvix012ry74xl79ploae8d
1dkR45C1DEaxwHYz7zJgP5IOXfKcv6KJhgEiYwIDAQABAoIBAEC/gQ63LhUsvKqG
HjrboFRussM4bqWVqUVm6Osgl46t+GXbY3LP+h4TZZTWaqTdnw88CuDSnwmQuXwF
uhfp3eP3vMUzmwd38+38a8U6anZRvF6yjkX7c/v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CWxvY2FsaG9zdIIJAOizA5bposrzMAwGA1UdEwQFMAMBAf8wDQYJKoZI
hvcNAQELBQADggEBADFmrqug4HYCtcy2F61o53vXIJQ6SyGwPCE5gOq07tkEz2id
oKcb2qNF1Zh+lOQ9GkvMkfzop0a4nhW8ra28gEBwhESS/aGKc7/isZN4ZKyy9JvJ
taTmVgXGp8s0w5dCXqDf3YU3XpdF53J1R7dyEfey3nEjMPRj/Ebs7rmpfRzOI4cX
6SJWJ71ShXK/IZbSVfobTzRdmAlz7uiwp2OVveGqcpQk46wgVoduwrC2hCe4wI6y
Dlo/GLmyCVlIiPaNA32sw+lca02Z5EXcQutRov2R/lUfoUCS/gOjCD7hVZXSRo+9
tFmGR8IuQDFseOW7CWTWqkiwu9F80HXmovboMKQ=
-----END CERTIFICATE-----`)
16 changes: 10 additions & 6 deletions grpctesting/interceptor_suite.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package grpctesting

import (
"context"
"crypto/tls"
"flag"
"net"
"path"
Expand All @@ -17,6 +18,7 @@ import (
"google.golang.org/grpc"
"google.golang.org/grpc/credentials"

"github.com/grpc-ecosystem/go-grpc-middleware/v2/grpctesting/certs"
"github.com/grpc-ecosystem/go-grpc-middleware/v2/grpctesting/testpb"
)

Expand Down Expand Up @@ -62,11 +64,9 @@ func (s *InterceptorTestSuite) SetupSuite() {
s.serverAddr = s.ServerListener.Addr().String()
require.NoError(s.T(), err, "must be able to allocate a port for serverListener")
if *flagTls {
creds, err := credentials.NewServerTLSFromFile(
path.Join(getTestingCertsPath(), "localhost.crt"),
path.Join(getTestingCertsPath(), "localhost.key"),
)
require.NoError(s.T(), err, "failed reading server credentials for localhost.crt")
localhostCert, err := tls.X509KeyPair(certs.LocalhostCert, certs.LocalhostKey)
require.NoError(s.T(), err, "failed loading server credentials for localhostCert")
creds := credentials.NewServerTLSFromCert(&localhostCert)
s.ServerOpts = append(s.ServerOpts, grpc.Creds(creds))
}
// This is the point where we hook up the interceptor
Expand Down Expand Up @@ -96,7 +96,11 @@ func (s *InterceptorTestSuite) SetupSuite() {
}
}()

<-s.serverRunning
select {
case <-s.serverRunning:
case <-time.After(2 * time.Second):
s.T().Fatal("server failed to start before deadline")
}
}

func (s *InterceptorTestSuite) RestartServer(delayedStart time.Duration) <-chan bool {
Expand Down