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

refactor: extract logic from cert manager to use cases #128

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

Nelsonochoam
Copy link
Contributor

Description of changes:
Now we have use cases in place we can start extracting logic from the cert manager into use cases. Eventually certManager will not exist since it is just acting as a proxy for application logic and we already have a construct that better first that logic (use cases)

Why is this change necessary:
Continuation on the refactor work we have been doing

How was this change tested:
Ensure tests are passing

}

@SuppressWarnings("PMD.AvoidCatchingGenericException")
private Pair<PrivateKey, X509Certificate[]> getCertificateChain(URI privateKeyUri, URI certChainUri) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a temporary spot for this we ideally don't have this logic inside use cases

@Nelsonochoam Nelsonochoam requested review from jbutler, vaibhavmurkute, jcosentino11 and MikeDombo and removed request for jbutler September 16, 2022 20:24
@Nelsonochoam Nelsonochoam marked this pull request as ready for review September 16, 2022 20:25
certificateStore.setCaCertificateChain(result.getB());
configuration.updateCACertificates(
Collections.singletonList(CertificateHelper.toPem(certificateStore.getCaCertificateChain())));
} catch (CertificateEncodingException | KeyStoreException | IOException e) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about InvalidCertificateAuthorityException ?

@github-actions
Copy link

Unit Tests Coverage Report

File Coverage Lines Branches
All files 69% 76% 61%
com.aws.greengrass.clientdevices.auth.infra.NetworkState 36% 36% 0%
com.aws.greengrass.clientdevices.auth.infra.NetworkState$ConnectionState 100% 100% 0%
com.aws.greengrass.clientdevices.auth.infra.NetworkState$1 20% 20% 0%
com.aws.greengrass.clientdevices.auth.PermissionEvaluationUtils 78% 82% 74%
com.aws.greengrass.clientdevices.auth.PermissionEvaluationUtils$Operation 100% 100% 0%
com.aws.greengrass.clientdevices.auth.PermissionEvaluationUtils$Resource 100% 100% 0%
com.aws.greengrass.clientdevices.auth.CertificateManager 78% 91% 64%
com.aws.greengrass.clientdevices.auth.ClientDevicesAuthService 79% 90% 68%
com.aws.greengrass.clientdevices.auth.DeviceAuthClient 70% 76% 64%
com.aws.greengrass.clientdevices.auth.iot.registry.ThingRegistry 100% 100% 100%
com.aws.greengrass.clientdevices.auth.iot.registry.RegistryConfig 0% 0% 0%
com.aws.greengrass.clientdevices.auth.iot.registry.CertificateRegistry$1 75% 100% 50%
com.aws.greengrass.clientdevices.auth.iot.registry.CertificateRegistry 82% 89% 75%
com.aws.greengrass.clientdevices.auth.iot.registry.ThingRegistry$1 75% 100% 50%
com.aws.greengrass.clientdevices.auth.certificate.ClientCertificateGenerator 96% 93% 100%
com.aws.greengrass.clientdevices.auth.certificate.CertificateHelper 77% 99% 55%
com.aws.greengrass.clientdevices.auth.certificate.CertificateStore 74% 84% 64%
com.aws.greengrass.clientdevices.auth.certificate.CertificateExpiryMonitor 77% 88% 67%
com.aws.greengrass.clientdevices.auth.certificate.ServerCertificateGenerator 95% 90% 100%
com.aws.greengrass.clientdevices.auth.certificate.CertificateGenerator 70% 90% 50%
com.aws.greengrass.clientdevices.auth.certificate.CertificateStore$CAType 100% 100% 0%
com.aws.greengrass.clientdevices.auth.certificate.CertificateExpiryMonitor$CertRotationDecider 90% 100% 80%
com.aws.greengrass.clientdevices.auth.certificate.CertificatesConfig 100% 100% 100%
com.aws.greengrass.ipc.IPCUtils 58% 67% 50%
com.aws.greengrass.ipc.VerifyClientDeviceIdentityOperationHandler 64% 79% 50%
com.aws.greengrass.ipc.GetClientDeviceAuthTokenOperationHandler 87% 98% 75%
com.aws.greengrass.ipc.AuthorizeClientDeviceActionOperationHandler 80% 93% 67%
com.aws.greengrass.ipc.SubscribeToCertificateUpdatesOperationHandler 77% 87% 67%
com.aws.greengrass.clientdevices.auth.session.SessionConfig 92% 100% 83%
com.aws.greengrass.clientdevices.auth.session.SessionManager$1 100% 100% 100%
com.aws.greengrass.clientdevices.auth.session.MqttSessionFactory 100% 100% 100%
com.aws.greengrass.clientdevices.auth.session.SessionCreator 100% 100% 100%
com.aws.greengrass.clientdevices.auth.session.SessionManager 88% 100% 75%
com.aws.greengrass.clientdevices.auth.session.SessionImpl 94% 89% 100%
com.aws.greengrass.clientdevices.auth.session.SessionCreator$SessionFactorySingleton 100% 100% 0%
com.aws.greengrass.clientdevices.auth.session.MqttSessionFactory$MqttCredential 100% 100% 0%
com.aws.greengrass.clientdevices.auth.certificate.handlers.CACertificateChainChangedHandler 100% 100% 0%
com.aws.greengrass.clientdevices.auth.certificate.handlers.CAConfigurationChangedHandler 100% 100% 100%
com.aws.greengrass.clientdevices.auth.certificate.usecases.ConfigureManagedCertificateAuthority 77% 77% 0%
com.aws.greengrass.clientdevices.auth.certificate.usecases.ConfigureCustomCertificateAuthority 63% 76% 50%
com.aws.greengrass.clientdevices.auth.certificate.usecases.RegisterCertificateAuthorityUseCase 67% 67% 0%
com.aws.greengrass.clientdevices.auth.configuration.AuthorizationPolicyStatement$Effect 100% 100% 0%
com.aws.greengrass.clientdevices.auth.configuration.GroupManager 89% 94% 83%
com.aws.greengrass.clientdevices.auth.configuration.ConfigurationFormatVersion 100% 100% 0%
com.aws.greengrass.clientdevices.auth.configuration.CAConfiguration 97% 100% 94%
com.aws.greengrass.clientdevices.auth.configuration.RuntimeConfiguration 100% 100% 0%
com.aws.greengrass.clientdevices.auth.configuration.CDAConfiguration 95% 100% 90%
com.aws.greengrass.clientdevices.auth.configuration.GroupDefinition 75% 100% 50%
com.aws.greengrass.clientdevices.auth.configuration.ExpressionVisitor 84% 94% 75%
com.aws.greengrass.clientdevices.auth.configuration.GroupConfiguration 90% 95% 86%
com.aws.greengrass.clientdevices.auth.api.ClientDevicesAuthServiceApi 82% 65% 100%
com.aws.greengrass.clientdevices.auth.api.Result 90% 90% 0%
com.aws.greengrass.clientdevices.auth.api.DomainEvents 100% 100% 100%
com.aws.greengrass.clientdevices.auth.api.UseCases 69% 88% 50%
com.aws.greengrass.clientdevices.auth.api.DomainEvent 0% 0% 0%
com.aws.greengrass.clientdevices.auth.api.GetCertificateRequestOptions$CertificateType 100% 100% 0%
com.aws.greengrass.clientdevices.auth.api.Result$Status 100% 100% 0%
com.aws.greengrass.clientdevices.auth.connectivity.usecases.GetConnectivityInformationUseCase 100% 100% 0%
com.aws.greengrass.clientdevices.auth.connectivity.usecases.RecordConnectivityChangesUseCase 100% 100% 100%
com.aws.greengrass.clientdevices.auth.session.attribute.StringLiteralAttribute 100% 100% 0%
com.aws.greengrass.clientdevices.auth.session.attribute.WildcardSuffixAttribute 88% 100% 75%
com.aws.greengrass.clientdevices.auth.util.ResizableLinkedBlockingQueue 90% 80% 100%
com.aws.greengrass.clientdevices.auth.util.ParseIPAddress 90% 95% 84%
com.aws.greengrass.clientdevices.auth.certificate.events.CACertificateChainChanged 100% 100% 0%
com.aws.greengrass.clientdevices.auth.iot.IotAuthClient$Default 83% 86% 80%
com.aws.greengrass.clientdevices.auth.iot.Thing 100% 100% 100%
com.aws.greengrass.clientdevices.auth.iot.Certificate 100% 100% 0%
com.aws.greengrass.clientdevices.auth.iot.Component 67% 67% 0%
com.aws.greengrass.clientdevices.auth.connectivity.CISShadowMonitor 61% 77% 46%
com.aws.greengrass.clientdevices.auth.connectivity.RecordConnectivityChangesResponse 100% 100% 100%
com.aws.greengrass.clientdevices.auth.connectivity.HostAddress 67% 67% 0%
com.aws.greengrass.clientdevices.auth.connectivity.RecordConnectivityChangesRequest 100% 100% 0%
com.aws.greengrass.clientdevices.auth.connectivity.ConnectivityInformation 100% 100% 100%
com.aws.greengrass.clientdevices.auth.configuration.parser.RuleExpressionConstants 100% 100% 0%
com.aws.greengrass.clientdevices.auth.configuration.parser.TokenMgrError 22% 32% 12%
com.aws.greengrass.clientdevices.auth.configuration.parser.RuleExpressionTokenManager 61% 65% 58%
com.aws.greengrass.clientdevices.auth.configuration.parser.ASTStart 33% 33% 0%
com.aws.greengrass.clientdevices.auth.configuration.parser.ASTAnd 67% 67% 0%
com.aws.greengrass.clientdevices.auth.configuration.parser.Token 58% 58% 0%
com.aws.greengrass.clientdevices.auth.configuration.parser.RuleExpressionDefaultVisitor 0% 0% 0%
com.aws.greengrass.clientdevices.auth.configuration.parser.ASTOr 67% 67% 0%
com.aws.greengrass.clientdevices.auth.configuration.parser.SimpleCharStream 28% 31% 25%
com.aws.greengrass.clientdevices.auth.configuration.parser.RuleExpressionTreeConstants 0% 0% 0%
com.aws.greengrass.clientdevices.auth.configuration.parser.JJTRuleExpressionState 67% 65% 70%
com.aws.greengrass.clientdevices.auth.configuration.parser.ASTThing 67% 67% 0%
com.aws.greengrass.clientdevices.auth.configuration.parser.RuleExpression 63% 63% 62%
com.aws.greengrass.clientdevices.auth.configuration.parser.SimpleNode 27% 35% 19%

Minimum allowed coverage is 50%

Generated by 🐒 cobertura-action against fa055d7

}

@SuppressWarnings("PMD.AvoidCatchingGenericException")
private Pair<PrivateKey, X509Certificate[]> getCertificateChain(URI privateKeyUri, URI certChainUri) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getKeyAndCertificateChain?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True, I will change in the next PR


topics = Topics.of(new Context(), CLIENT_DEVICES_AUTH_SERVICE_NAME, null);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

context must always be closed at the end of a test. It starts a thread and we don't want that to run forever. Make sure you always shutdown any context you create.

@SuppressWarnings("PMD.AvoidCatchingGenericException")
private Pair<PrivateKey, X509Certificate[]> getCertificateChain(URI privateKeyUri, URI certChainUri) {
// TODO: Move retry logic out of useCases
RetryUtils.RetryConfig retryConfig = RetryUtils.RetryConfig.builder()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this retry eventually gives up, then what happens?

200ms * 3 may not be enough time for some providers to initalize.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 to this. I've commented on this several times as well. Since this is just a refactor, we can probably tackle that in a follow up. We'll want an event listener that listens to config update events and handles retries

@@ -116,22 +120,27 @@ void GIVEN_customCAConfiguration_WHEN_configureCustomCA_THEN_returnsCustomCA() t
URI privateKeyUri = new URI("file:///private.key");
URI certificateUri = new URI("file:///certificate.pem");

Topics configurationTopics = Topics.of(new Context(), CLIENT_DEVICES_AUTH_SERVICE_NAME, null);
configurationTopics.lookup(CONFIGURATION_CONFIG_KEY, CERTIFICATE_AUTHORITY_TOPIC, CA_PRIVATE_KEY_URI)
Topics topics = Topics.of(new Context(), CLIENT_DEVICES_AUTH_SERVICE_NAME, null);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

likewise, close context

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants