-
Notifications
You must be signed in to change notification settings - Fork 16
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
Introduce x509 DID method with PKI validation. #3446
Conversation
Added support for x509 DID method including a new resolver and PKI validation. Adjusted metadata handling in key resolution across the codebase to include x509 specific fields and validation logic. - Added support for did:x509 as a new DID resolver. - Enabled validation of did:x509 VCs and VPs. - Added corresponding tests.
The previous code initialized a new variable instead of assigning to the existing 'err' variable. This change corrects the assignment, ensuring proper error handling during the DID resolution process.
Refactored resolver by moving X.509 related utilities to a new file. Added comprehensive validation for Subject Alternative Names (SANs). This enhances reliability and modularity.
Introduce specific error constants for `did:x509` parsing and validation failures. Refactor handling of PEM blocks, certificate chain validation, and policy checks to utilize these new error types and provide clearer messages.
Introduced functions to generate certificate chains and templates in `x509_test_utils.go` to aid in testing certificate-based operations. Additionally, added extensive resolver tests in `resolver_test.go` to validate various scenarios and ensure correct functionality.
Removed unnecessary closing braces from resolver_test.go to improve code readability and maintain a clean structure. This change does not affect the logic or functionality of the tests.
Extracted the logic for creating root, intermediate, and signing certificates into separate helper functions to reduce code complexity. Additionally, removed unused imports and the redundant DebugUnmarshall function to clean up the codebase.
Replaced explicit X509 header fields with a generic JwtProtectedHeaders map for better flexibility and reduced redundancy. Added the map to the metadata of all cases.
To prevent a name clash with the cert package.
Refactored the x509 DID resolver to introduce specific constants for subject and SAN policies, replacing magic strings. Implemented more detailed error handling and validation functions. Added extensive tests to cover new SAN and subject policy validation cases, ensuring robust handling of various attributes.
Extended the error handling in the resolver by distinguishing between SAN and subject policy errors. This provides clearer diagnosis and debugging for issues related to subject policies.
Replace custom unescapeValue function with url.QueryUnescape for more reliable URL decoding and error handling. Additionally, expand test cases to cover various scenarios involving malformed and partial URL inputs.
This update introduces two new subject policies: State (ST) and Street (STREET). The resolver now checks these policies, and corresponding tests have been added to validate the correct behavior. The test utilities have also been updated to include sample data for these fields.
Updated `x509_test_utils.go` and `resolver_test.go` to use generic, non-specific example domains and email addresses. This standardizes the test cases and avoids reliance on real-world domain names.
Renamed `forEachSAN` to `forEachSan` to maintain consistent camelCase naming convention across the codebase. This change affects the function definition, as well as all its invocations and documentation comments.
Co-authored-by: reinkrul <[email protected]>
Updated test names to provide clearer, more specific descriptions of each test's focus. This improves code readability and helps identify test purposes at a glance.
Implemented a new utility function `ExtractProtectedHeaders` for extracting protected headers from JWTs in the `didx509` package. Refactored the `verifier` package to use this new utility, enhancing code reuse and maintainability.
Added input validation to the ExtractProtectedHeaders function to ensure only valid JWT strings are processed. Updated the test cases to match the new expected behavior. This change helps prevent errors and makes the function more robust.
Separated subject and SAN policy validation into distinct functions. This improves code readability and facilitates easier maintenance by isolating the logic for each type of policy validation. Also, extracted SAN alternative name handling to a dedicated function for better structure.
This commit introduces `validation.go` to handle X.509 certificate validation based on specific policies. It moves existing validation logic from `resolver.go` to `validation.go`, consolidating it and making `ValidatePolicy` a shared function. Additionally, unit tests are updated to reflect these changes.
Co-authored-by: Gerard Snaauw <[email protected]>
Removed redundant .Return(nil) calls from validator's Validate method expectations across various resolver tests. This cleanup simplifies the code and clarifies the intent of the tests without altering their functionality.
This is missing an e2e-test. Certificate revocation is currently not checked. The An e2e-test should show
|
Refactor error handling in x509 utilities to use custom error variables, improving clarity. Added comprehensive test cases for functions including certificate parsing, SAN processing, and certificate chain building, enhancing coverage and robustness.
Implemented tests for the ResolveMetadata struct to verify the behavior of GetProtectedHeaderString and GetProtectedHeaderChain methods. This ensures correct functionality for different input scenarios, including cases where headers do not exist or values are of incorrect types.
* master: (72 commits) PKI add ValidateStrict (#3531) PEX: Return capture group for matched patterns (#3526) Schedule CodeQL twice a week (#3525) change cron schedule (#3524) Add gh action for CodeQL schedule (#3523) Bump github.com/lestrrat-go/jwx/v2 from 2.1.1 to 2.1.2 (#3520) docs: v6 release date (#3519) status codes for discovery client (#3513) Require SQL connection string in strictmode (#3517) Fix duplicate discovery results (#3515) Bump github.com/chromedp/chromedp from 0.11.0 to 0.11.1 (#3514) fix duplicate search results for wildcard param (#3512) Bump github.com/Azure/azure-sdk-for-go/sdk/security/keyvault/azkeys (#3511) remove network migration and optimize network event retry (#3510) secure outgoing http client with max connections (#3508) make gen-mocks (#3509) Bump github.com/Azure/azure-sdk-for-go/sdk/azcore from 1.15.0 to 1.16.0 (#3506) fix invalid keyReference migration objects (#3504) Bump go.uber.org/mock from 0.4.0 to 0.5.0 (#3507) Bump github.com/nats-io/nats-server/v2 from 2.10.21 to 2.10.22 (#3505) ... # Conflicts: # vcr/test.go # vdr/legacy_integration_test.go # vdr/vdr.go # vdr/vdr_test.go
Replaced calls to Validate with ValidateStrict to enhance the strictness of PKI validation across the validation of x509. This change ensures more strict validation checks are applied for the x509 credentials.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- refer to which spec is implemented in godoc comment
- copyrights
- godoc on public vars/functions/structs/methods
This commit includes the GPLv3 license headers at the beginning of all source files in the `vdr/didx509` directory. This ensures legal and licensing clarity for the project's usage and distribution.
Detailed descriptions were added for constants, error messages, and functions across multiple files for better code readability and maintainability. These comments provide context and explanations for the defined elements, making the intent and usage clearer for future developers and documentation purposes.
Refactored the ValidatePolicy function to lowercase the initial letter, adhering to Go's convention for unexported functions.
…dHeaderChain Added documentation for both GetProtectedHeaderString and GetProtectedHeaderChain methods in ResolveMetadata to describe workings of these methods.
Documented that the resolve method to adheres to the DID:x509 v1.0 Draft specification. Notable changes include the implementation of the "otherName" SAN policy and support for "serialNumber" in the "subject" policy. The "eku" policy remains unimplemented.
This commit moves the ExtractProtectedHeaders to the crypto package where it located together with other JWS/JWT related methods.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Last comments:
- add did:x509 to the supported DID methods in
docs/pages/integrating/supported-protocols-formats.rst
- run
go fmt vdr/vdr.go
to fix the code climate issue
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wait for it....
Let me try it out before merging.
Updated functions to handle multiple SAN OtherName values in certificates and modified tests accordingly. Refactored validation logic to accommodate lists of SAN OtherName values.
* master: Bump github.com/golang-jwt/jwt/v4 from 4.5.0 to 4.5.1 (#3538)
Extend the documentation to include did:x509 format under supported protocols. Note that it supports resolving except for the "eku" policy type, with additional handling for the "san" "otherName" policy.
The file |
Aligned the pkiValidator field with other struct fields for better readability. This change improves code consistency and maintains clean code standards.
The command |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't want to hold this one up longer than needed. We can finetune the logic in a later phase, since this feature is still very experimental.
The testcases did not take in account that there could be other types of otherName attributes, like the class 2, tag 2 alternative host name. This commit fixes that issue.
I did some end-to-end testing and some issues where found & fixed:
|
Added support for x509 DID method including a new resolver and PKI validation. Adjusted metadata handling in key resolution across the codebase to include x509 specific fields and validation logic.