-
-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fixup! Implement Certificate Revocation List
- Loading branch information
1 parent
a61b9d4
commit 00a37d1
Showing
28 changed files
with
399 additions
and
110 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
//go:build test | ||
// +build test | ||
|
||
package service_test | ||
|
||
import ( | ||
"context" | ||
"crypto/ecdsa" | ||
"crypto/elliptic" | ||
"crypto/rand" | ||
"crypto/tls" | ||
"testing" | ||
"time" | ||
|
||
pbCA "github.com/plgd-dev/hub/v2/certificate-authority/pb" | ||
coapgwTest "github.com/plgd-dev/hub/v2/coap-gateway/test" | ||
pkgGrpc "github.com/plgd-dev/hub/v2/pkg/net/grpc" | ||
"github.com/plgd-dev/hub/v2/test" | ||
"github.com/plgd-dev/hub/v2/test/config" | ||
oauthTest "github.com/plgd-dev/hub/v2/test/oauth-server/test" | ||
"github.com/stretchr/testify/require" | ||
"google.golang.org/grpc" | ||
"google.golang.org/grpc/credentials" | ||
) | ||
|
||
func TestCertificateWithCRL(t *testing.T) { | ||
coapgwCfg := coapgwTest.MakeConfig(t) | ||
coapgwCfg.APIs.COAP.TLS.Enabled = new(bool) | ||
*coapgwCfg.APIs.COAP.TLS.Enabled = true | ||
coapgwCfg.APIs.COAP.TLS.Embedded.ClientCertificateRequired = true | ||
shutdown := setUp(t, coapgwCfg) | ||
defer shutdown() | ||
|
||
ctx, cancel := context.WithTimeout(context.Background(), time.Second*30*20) | ||
defer cancel() | ||
tokenWithoutDeviceID := oauthTest.GetDefaultAccessToken(t) | ||
ctx = pkgGrpc.CtxWithToken(ctx, tokenWithoutDeviceID) | ||
conn, err := grpc.NewClient(config.CERTIFICATE_AUTHORITY_HOST, grpc.WithTransportCredentials(credentials.NewTLS(&tls.Config{ | ||
RootCAs: test.GetRootCertificatePool(t), | ||
}))) | ||
require.NoError(t, err) | ||
caClient := pbCA.NewCertificateAuthorityClient(conn) | ||
|
||
signerKey, err := ecdsa.GenerateKey(elliptic.P256(), rand.Reader) | ||
require.NoError(t, err) | ||
cg := coapgwTest.NewCACertificateGenerator(caClient, signerKey) | ||
|
||
crt, err := cg.GetIdentityCertificate(ctx, CertIdentity) | ||
require.NoError(t, err) | ||
tlsConfig := &tls.Config{ | ||
Certificates: []tls.Certificate{crt}, | ||
InsecureSkipVerify: true, | ||
} | ||
co := testCoapDialWithHandler(t, makeTestCoapHandler(t), WithTLSConfig(tlsConfig)) | ||
require.NotEmpty(t, co) | ||
testSignUp(t, CertIdentity, co) | ||
_ = co.Close() | ||
|
||
// revoke all certs for device | ||
resp, err := caClient.DeleteSigningRecords(ctx, &pbCA.DeleteSigningRecordsRequest{ | ||
DeviceIdFilter: []string{CertIdentity}, | ||
}) | ||
require.NoError(t, err) | ||
require.Equal(t, int64(1), resp.Count) | ||
// sign-up with revoked cert should fail | ||
co = testCoapDialWithHandler(t, makeTestCoapHandler(t), WithTLSConfig(tlsConfig)) | ||
require.NotEmpty(t, co) | ||
_, err = doSignUp(t, CertIdentity, co) | ||
_ = co.Close() | ||
require.Error(t, err) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.