aws-greengrass / aws-greengrass-client-device-auth

Apache License 2.0
2 stars 3 forks source link

feat: certificate generation for client and server type #404

Closed junfuchen99 closed 1 year ago

junfuchen99 commented 1 year ago

Description of changes: Add supports for generating custom certificates from other plugins, which include

  1. An new type CLIENT_AND_SERVER in CertificateType;
  2. A new request type CustomGeneratorCertificateRequest which extends the existing request and adds a field for providing custom certificate generator
  3. Extended Certificate Manager to handle custom requests;
  4. Refactored CertificateManager to reduce duplicate codes/improve readability
  5. Added unit test.

Why is this change necessary: To allow plugin components request certificate generations from CDA.

How was this change tested:

  1. Added unit test.
  2. Manual tested with Cluster Controller component.

Any additional information or context required to review the change:

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

github-actions[bot] commented 1 year ago

Unit Tests Coverage Report

File Coverage Lines Branches
All files 73% 80% 66% :white_check_mark:
com.aws.greengrass.clientdevices.auth.PermissionEvaluationUtils 78% 82% 74% :white_check_mark:
com.aws.greengrass.clientdevices.auth.PermissionEvaluationUtils$Operation 100% 100% 0% :white_check_mark:
com.aws.greengrass.clientdevices.auth.PermissionEvaluationUtils$Resource 100% 100% 0% :white_check_mark:
com.aws.greengrass.clientdevices.auth.CertificateManager 88% 91% 85% :white_check_mark:
com.aws.greengrass.clientdevices.auth.ClientDevicesAuthService 79% 90% 67% :white_check_mark:
com.aws.greengrass.clientdevices.auth.DeviceAuthClient 73% 83% 64% :white_check_mark:
com.aws.greengrass.clientdevices.auth.certificate.ClientCertificateGenerator 95% 90% 100% :white_check_mark:
com.aws.greengrass.clientdevices.auth.certificate.CertificateHelper$ProviderType 100% 100% 0% :white_check_mark:
com.aws.greengrass.clientdevices.auth.certificate.CertificateHelper 74% 92% 56% :white_check_mark:
com.aws.greengrass.clientdevices.auth.certificate.CertificateStore 72% 85% 60% :white_check_mark:
com.aws.greengrass.clientdevices.auth.certificate.CertificateExpiryMonitor 77% 87% 67% :white_check_mark:
com.aws.greengrass.clientdevices.auth.certificate.ServerCertificateGenerator 93% 87% 100% :white_check_mark:
com.aws.greengrass.clientdevices.auth.certificate.CertificateGenerator 70% 90% 50% :white_check_mark:
com.aws.greengrass.clientdevices.auth.certificate.CertificateStore$CAType 100% 100% 0% :white_check_mark:
com.aws.greengrass.clientdevices.auth.certificate.CertificateExpiryMonitor$CertRotationDecider 90% 100% 80% :white_check_mark:
com.aws.greengrass.clientdevices.auth.certificate.CertificatesConfig 100% 100% 100% :white_check_mark:
com.aws.greengrass.clientdevices.auth.session.events.SessionCreationEvent$SessionCreationStatus 100% 100% 0% :white_check_mark:
com.aws.greengrass.clientdevices.auth.iot.usecases.VerifyIotCertificate 94% 88% 100% :white_check_mark:
com.aws.greengrass.clientdevices.auth.iot.usecases.VerifyThingAttachedToCertificate 89% 91% 88% :white_check_mark:
com.aws.greengrass.clientdevices.auth.iot.usecases.CreateIoTThingSession 88% 93% 83% :white_check_mark:
com.aws.greengrass.clientdevices.auth.iot.usecases.VerifyCertificateValidityPeriod 88% 88% 0% :white_check_mark:
com.aws.greengrass.clientdevices.auth.iot.usecases.VerifyThingAttachedToCertificate$Result$VerificationSource 100% 100% 0% :white_check_mark:
com.aws.greengrass.clientdevices.auth.certificate.infra.ClientCertificateStore 100% 100% 100% :white_check_mark:
com.aws.greengrass.clientdevices.auth.certificate.infra.BackgroundCertificateRefresh 83% 85% 82% :white_check_mark:
com.aws.greengrass.clientdevices.auth.iot.infra.ThingRegistry 92% 97% 88% :white_check_mark:
com.aws.greengrass.clientdevices.auth.certificate.usecases.ConfigureManagedCertificateAuthority 85% 85% 0% :white_check_mark:
com.aws.greengrass.clientdevices.auth.certificate.usecases.ConfigureCustomCertificateAuthority 83% 83% 0% :white_check_mark:
com.aws.greengrass.clientdevices.auth.certificate.usecases.RegisterCertificateAuthorityUseCase 65% 81% 50% :white_check_mark:
com.aws.greengrass.clientdevices.auth.configuration.MetricsConfiguration 83% 100% 67% :white_check_mark:
com.aws.greengrass.clientdevices.auth.configuration.AuthorizationPolicyStatement$Effect 100% 100% 0% :white_check_mark:
com.aws.greengrass.clientdevices.auth.configuration.GroupManager 89% 94% 83% :white_check_mark:
com.aws.greengrass.clientdevices.auth.configuration.ConfigurationFormatVersion 100% 100% 0% :white_check_mark:
com.aws.greengrass.clientdevices.auth.configuration.CAConfiguration 96% 100% 92% :white_check_mark:
com.aws.greengrass.clientdevices.auth.configuration.RuntimeConfiguration 83% 96% 70% :white_check_mark:
com.aws.greengrass.clientdevices.auth.configuration.SecurityConfiguration 80% 93% 67% :white_check_mark:
com.aws.greengrass.clientdevices.auth.configuration.CDAConfiguration 100% 100% 100% :white_check_mark:
com.aws.greengrass.clientdevices.auth.configuration.GroupDefinition 75% 100% 50% :white_check_mark:
com.aws.greengrass.clientdevices.auth.configuration.ExpressionVisitor 84% 94% 75% :white_check_mark:
com.aws.greengrass.clientdevices.auth.configuration.GroupConfiguration 90% 95% 86% :white_check_mark:
com.aws.greengrass.clientdevices.auth.api.ServiceErrorEvent 100% 100% 0% :white_check_mark:
com.aws.greengrass.clientdevices.auth.api.ClientDevicesAuthServiceApi 90% 80% 100% :white_check_mark:
com.aws.greengrass.clientdevices.auth.api.GetCertificateRequestWithGenerator 75% 100% 50% :white_check_mark:
com.aws.greengrass.clientdevices.auth.api.DomainEvents 100% 100% 100% :white_check_mark:
com.aws.greengrass.clientdevices.auth.api.AuthorizeClientDeviceActionEvent$AuthorizationStatus 100% 100% 0% :white_check_mark:
com.aws.greengrass.clientdevices.auth.api.UseCases 71% 92% 50% :white_check_mark:
com.aws.greengrass.clientdevices.auth.api.DomainEvent 100% 100% 0% :white_check_mark:
com.aws.greengrass.clientdevices.auth.api.GetCertificateRequestOptions$CertificateType 100% 100% 0% :white_check_mark:
com.aws.greengrass.clientdevices.auth.session.attribute.StringLiteralAttribute 100% 100% 0% :white_check_mark:
com.aws.greengrass.clientdevices.auth.session.attribute.WildcardSuffixAttribute 88% 100% 75% :white_check_mark:
com.aws.greengrass.clientdevices.auth.certificate.events.CertificateSubscriptionEvent$SubscriptionStatus 100% 100% 0% :white_check_mark:
com.aws.greengrass.clientdevices.auth.certificate.events.CACertificateChainChanged 100% 100% 0% :white_check_mark:
com.aws.greengrass.clientdevices.auth.iot.Certificate$Status 100% 100% 0% :white_check_mark:
com.aws.greengrass.clientdevices.auth.iot.IotAuthClient$Default 56% 47% 64% :white_check_mark:
com.aws.greengrass.clientdevices.auth.iot.Thing 87% 93% 82% :white_check_mark:
com.aws.greengrass.clientdevices.auth.iot.Certificate 78% 89% 67% :white_check_mark:
com.aws.greengrass.clientdevices.auth.iot.GreengrassV2DataClientFactory 18% 18% 0% :x:
com.aws.greengrass.clientdevices.auth.iot.CertificateRegistry 95% 90% 100% :white_check_mark:
com.aws.greengrass.clientdevices.auth.iot.Component 100% 100% 0% :white_check_mark:
com.aws.greengrass.clientdevices.auth.iot.events.VerifyClientDeviceIdentityEvent$VerificationStatus 100% 100% 0% :white_check_mark:
com.aws.greengrass.clientdevices.auth.infra.NetworkStateProvider$Default$1 100% 100% 0% :white_check_mark:
com.aws.greengrass.clientdevices.auth.infra.NetworkStateProvider$ConnectionState 100% 100% 0% :white_check_mark:
com.aws.greengrass.clientdevices.auth.infra.NetworkStateProvider$Default 75% 90% 60% :white_check_mark:
com.aws.greengrass.ipc.IPCUtils 83% 67% 100% :white_check_mark:
com.aws.greengrass.ipc.VerifyClientDeviceIdentityOperationHandler 60% 69% 50% :white_check_mark:
com.aws.greengrass.ipc.GetClientDeviceAuthTokenOperationHandler 86% 98% 75% :white_check_mark:
com.aws.greengrass.ipc.AuthorizeClientDeviceActionOperationHandler 79% 92% 67% :white_check_mark:
com.aws.greengrass.ipc.SubscribeToCertificateUpdatesOperationHandler 81% 88% 75% :white_check_mark:
com.aws.greengrass.clientdevices.auth.session.SessionConfig 92% 100% 83% :white_check_mark:
com.aws.greengrass.clientdevices.auth.session.SessionManager$1 100% 100% 100% :white_check_mark:
com.aws.greengrass.clientdevices.auth.session.MqttSessionFactory 100% 100% 100% :white_check_mark:
com.aws.greengrass.clientdevices.auth.session.SessionCreator 100% 100% 100% :white_check_mark:
com.aws.greengrass.clientdevices.auth.session.SessionManager 88% 100% 75% :white_check_mark:
com.aws.greengrass.clientdevices.auth.session.SessionImpl 100% 100% 100% :white_check_mark:
com.aws.greengrass.clientdevices.auth.session.SessionCreator$SessionFactorySingleton 100% 100% 0% :white_check_mark:
com.aws.greengrass.clientdevices.auth.session.MqttSessionFactory$MqttCredential 100% 100% 0% :white_check_mark:
com.aws.greengrass.clientdevices.auth.certificate.handlers.CACertificateChainChangedHandler 100% 100% 0% :white_check_mark:
com.aws.greengrass.clientdevices.auth.certificate.handlers.CAConfigurationChangedHandler 93% 87% 100% :white_check_mark:
com.aws.greengrass.clientdevices.auth.certificate.handlers.CertificateRotationHandler 96% 91% 100% :white_check_mark:
com.aws.greengrass.clientdevices.auth.certificate.handlers.SecurityConfigurationChangedHandler 100% 100% 0% :white_check_mark:
com.aws.greengrass.clientdevices.auth.metrics.handlers.SessionCreationEventHandler 88% 100% 75% :white_check_mark:
com.aws.greengrass.clientdevices.auth.metrics.handlers.MetricsConfigurationChangedHandler 70% 90% 50% :white_check_mark:
com.aws.greengrass.clientdevices.auth.metrics.handlers.AuthorizeClientDeviceActionsMetricHandler 88% 100% 75% :white_check_mark:
com.aws.greengrass.clientdevices.auth.metrics.handlers.VerifyClientDeviceIdentityEventHandler 88% 100% 75% :white_check_mark:
com.aws.greengrass.clientdevices.auth.metrics.handlers.CertificateSubscriptionEventHandler 83% 100% 67% :white_check_mark:
com.aws.greengrass.clientdevices.auth.metrics.handlers.ServiceErrorEventHandler 100% 100% 0% :white_check_mark:
com.aws.greengrass.clientdevices.auth.iot.dto.CertificateV1DTO$Status 100% 100% 0% :white_check_mark:
com.aws.greengrass.clientdevices.auth.connectivity.usecases.GetConnectivityInformationUseCase 100% 100% 0% :white_check_mark:
com.aws.greengrass.clientdevices.auth.connectivity.usecases.RecordConnectivityChangesUseCase 100% 100% 100% :white_check_mark:
com.aws.greengrass.clientdevices.auth.util.ResizableLinkedBlockingQueue 90% 80% 100% :white_check_mark:
com.aws.greengrass.clientdevices.auth.util.ParseIPAddress 90% 95% 84% :white_check_mark:
com.aws.greengrass.clientdevices.auth.metrics.ClientDeviceAuthMetrics 100% 100% 100% :white_check_mark:
com.aws.greengrass.clientdevices.auth.metrics.MetricsEmitter 100% 100% 100% :white_check_mark:
com.aws.greengrass.clientdevices.auth.connectivity.ConnectivityInfoCache 100% 100% 0% :white_check_mark:
com.aws.greengrass.clientdevices.auth.connectivity.CISShadowMonitor 68% 79% 57% :white_check_mark:
com.aws.greengrass.clientdevices.auth.connectivity.RecordConnectivityChangesResponse 100% 100% 100% :white_check_mark:
com.aws.greengrass.clientdevices.auth.connectivity.HostAddress 67% 67% 0% :white_check_mark:
com.aws.greengrass.clientdevices.auth.connectivity.RecordConnectivityChangesRequest 100% 100% 0% :white_check_mark:
com.aws.greengrass.clientdevices.auth.connectivity.ConnectivityInformation 100% 100% 100% :white_check_mark:
com.aws.greengrass.clientdevices.auth.configuration.parser.RuleExpressionConstants 100% 100% 0% :white_check_mark:
com.aws.greengrass.clientdevices.auth.configuration.parser.TokenMgrError 22% 32% 12% :x:
com.aws.greengrass.clientdevices.auth.configuration.parser.RuleExpressionTokenManager 61% 65% 58% :white_check_mark:
com.aws.greengrass.clientdevices.auth.configuration.parser.ASTStart 33% 33% 0% :x:
com.aws.greengrass.clientdevices.auth.configuration.parser.ASTAnd 67% 67% 0% :white_check_mark:
com.aws.greengrass.clientdevices.auth.configuration.parser.Token 58% 58% 0% :white_check_mark:
com.aws.greengrass.clientdevices.auth.configuration.parser.RuleExpressionDefaultVisitor 0% 0% 0% :x:
com.aws.greengrass.clientdevices.auth.configuration.parser.ASTOr 67% 67% 0% :white_check_mark:
com.aws.greengrass.clientdevices.auth.configuration.parser.SimpleCharStream 28% 31% 25% :x:
com.aws.greengrass.clientdevices.auth.configuration.parser.RuleExpressionTreeConstants 0% 0% 0% :x:
com.aws.greengrass.clientdevices.auth.configuration.parser.JJTRuleExpressionState 67% 65% 70% :white_check_mark:
com.aws.greengrass.clientdevices.auth.configuration.parser.ASTThing 67% 67% 0% :white_check_mark:
com.aws.greengrass.clientdevices.auth.configuration.parser.RuleExpression 63% 63% 62% :white_check_mark:
com.aws.greengrass.clientdevices.auth.configuration.parser.SimpleNode 27% 35% 19% :x:

Minimum allowed coverage is 50%

Generated by :monkey: cobertura-action against d068dfadf06bd4016e7e67cc77462c56a4230ab7

jcosentino11 commented 1 year ago

Why is all this cluster specific stuff in here? I thought you were just going to open up some of the core APIs to allow cluster to generate what it needs.

+1 i see there's different cert validity for cluster, is that a requirement? if so we could include validity as part of CDA API instead