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

Implement Certificate Revocation List #1379

Draft
wants to merge 8 commits into
base: main
Choose a base branch
from
Draft

Conversation

Danielius1922
Copy link
Member

@Danielius1922 Danielius1922 commented Sep 23, 2024

This pull request includes several changes to the certificate authority's codebase, focusing on improving the handling of signing records and enhancing documentation. The most important changes include adding validation for CredentialStatus, updating documentation to reflect the new functionality, and correcting typographical errors.

Code Enhancements:

Documentation Updates:

Typographical Corrections:

Minor Changes:

These changes collectively enhance the robustness of the certificate authority's functionality and improve the clarity of its documentation.

Copy link
Contributor

coderabbitai bot commented Sep 23, 2024

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@Danielius1922 Danielius1922 force-pushed the adam/feature/crl branch 4 times, most recently from 165ae68 to 549b38e Compare September 27, 2024 13:49
Comment on lines 126 to 127
if err != nil {
// TODO: what to do here? remove the new signing record? restore the original?
Copy link
Member

@jkralik jkralik Sep 27, 2024

Choose a reason for hiding this comment

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

At first you need to add cerficate to CRL list. And when it success then you try to replace with a new certificate . It can fails when someone make parallel update. In this case you will return error. And when all steps are succeed than you return ok. You don't touch CRL even replace fails. But if you insert serial number to CRL slice it must not exist there.

Copy link
Member Author

Choose a reason for hiding this comment

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

I need an additional request to mongo that way though, which I wanted to avoid, but I guess there is no way around it.

Copy link

sonarcloud bot commented Oct 2, 2024

}

var rl store.RevocationList
err := s.Collection(revocationListCol).FindOne(ctx, filter, opts...).Decode(&rl)

Check failure

Code scanning / CodeQL

Database query built from user-controlled sources High

This query depends on a
user-provided value
.

Copilot Autofix AI about 4 hours ago

To fix the problem, we need to ensure that the issuerID is safely embedded into the MongoDB query using parameterized queries. The MongoDB Go driver supports this by using BSON documents for query parameters. We will modify the GetRevocationList function to ensure that the issuerID is properly validated and embedded into the query.

  1. Ensure that the issuerID is validated as a UUID before being used in the query.
  2. Use the validated issuerID directly in the BSON query filter.
Suggested changeset 1
certificate-authority/store/mongodb/revocationList.go

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/certificate-authority/store/mongodb/revocationList.go b/certificate-authority/store/mongodb/revocationList.go
--- a/certificate-authority/store/mongodb/revocationList.go
+++ b/certificate-authority/store/mongodb/revocationList.go
@@ -158,2 +158,5 @@
 func (s *Store) GetRevocationList(ctx context.Context, issuerID string, includeExpired bool) (*store.RevocationList, error) {
+	if _, err := uuid.Parse(issuerID); err != nil {
+		return nil, errors.New("invalid issuerID")
+	}
 	now := time.Now().UnixNano()
EOF
@@ -158,2 +158,5 @@
func (s *Store) GetRevocationList(ctx context.Context, issuerID string, includeExpired bool) (*store.RevocationList, error) {
if _, err := uuid.Parse(issuerID); err != nil {
return nil, errors.New("invalid issuerID")
}
now := time.Now().UnixNano()
Copilot is powered by AI and may make mistakes. Always verify output.
},
}}})
}
cur, err := s.Collection(revocationListCol).Aggregate(ctx, pl)

Check failure

Code scanning / CodeQL

Database query built from user-controlled sources High

This query depends on a
user-provided value
.

Copilot Autofix AI about 4 hours ago

To fix the problem, we need to use parameterized queries instead of directly embedding user input into the query. This can be achieved by using MongoDB's parameterized query capabilities. Specifically, we will replace the direct embedding of query.IssuerID with a parameterized approach.

  1. Modify the MongoDB query construction to use parameterized queries.
  2. Ensure that the issuerID is passed as a parameter to the query.
Suggested changeset 1
certificate-authority/store/mongodb/revocationList.go

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/certificate-authority/store/mongodb/revocationList.go b/certificate-authority/store/mongodb/revocationList.go
--- a/certificate-authority/store/mongodb/revocationList.go
+++ b/certificate-authority/store/mongodb/revocationList.go
@@ -52,5 +52,4 @@
 	}
-	pl := mongo.Pipeline{
-		bson.D{{Key: mongodb.Match, Value: bson.D{{Key: "_id", Value: query.IssuerID}}}},
-	}
+	matchStage := bson.D{{Key: mongodb.Match, Value: bson.D{{Key: "_id", Value: query.IssuerID}}}}
+	pl := mongo.Pipeline{matchStage}
 	if len(cmap) > 0 {
EOF
@@ -52,5 +52,4 @@
}
pl := mongo.Pipeline{
bson.D{{Key: mongodb.Match, Value: bson.D{{Key: "_id", Value: query.IssuerID}}}},
}
matchStage := bson.D{{Key: mongodb.Match, Value: bson.D{{Key: "_id", Value: query.IssuerID}}}}
pl := mongo.Pipeline{matchStage}
if len(cmap) > 0 {
Copilot is powered by AI and may make mistakes. Always verify output.
}
opts := options.FindOneAndUpdate().SetReturnDocument(options.After)
var updatedRL store.RevocationList
if err = s.Collection(revocationListCol).FindOneAndUpdate(ctx, filter, update, opts).Decode(&updatedRL); err != nil {

Check failure

Code scanning / CodeQL

Database query built from user-controlled sources High

This query depends on a
user-provided value
.

Copilot Autofix AI about 4 hours ago

To fix the problem, we should use parameterized queries or ensure that the user input is properly sanitized before being used in the MongoDB query. In this case, since MongoDB queries are constructed using BSON, we can ensure that the issuerID is safely embedded by using a parameterized approach.

  1. Modify the UpdateRevocationList function to use a parameterized query for the issuerID.
  2. Ensure that the issuerID is properly validated and sanitized before being used in the query.
Suggested changeset 1
certificate-authority/store/mongodb/revocationList.go

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/certificate-authority/store/mongodb/revocationList.go b/certificate-authority/store/mongodb/revocationList.go
--- a/certificate-authority/store/mongodb/revocationList.go
+++ b/certificate-authority/store/mongodb/revocationList.go
@@ -133,3 +133,3 @@
 	filter := bson.M{
-		"_id":           query.IssuerID,
+		"_id":           bson.D{{Key: "$eq", Value: query.IssuerID}},
 		store.NumberKey: number.String(),
EOF
@@ -133,3 +133,3 @@
filter := bson.M{
"_id": query.IssuerID,
"_id": bson.D{{Key: "$eq", Value: query.IssuerID}},
store.NumberKey: number.String(),
Copilot is powered by AI and may make mistakes. Always verify output.
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.

2 participants