Replies: 2 comments 4 replies
-
I would like to understand the problem before we refactor the code: We can see that the basic signing logics are different in COSE/Jws. And they don't share the same exported interface, neither the way performing the signing.
COSE takes in a payload, but JWS takes in a digest.
The LocalSignatureProvider should be designed for all built-in providers, COSE/Jws in this case. But it couples the the context logic of Jws and that of the algorithm(RSA/ECDSA). So if we're adding COSE support directly, it needs to handle both contexts. The same issue applies to the external plugins.
|
Beta Was this translation helpful? Give feedback.
-
@binbin-li Let's update the diagram, we have CertificateChain() under the LocalSigner interface now. |
Beta Was this translation helpful? Give feedback.
-
Backgroud
We're adding COSE built-in/external support to notation currently. For now there is a
SignatureProvider
providing the basic logic to sign the payload in bytes and aSignatureEnvelope
to wrap up functions to generate and verify signatures. However, it only supports JWS envelope/signing for now which is not generalized for a new envelope like COSE. So some refactoring are necessary to be made on it so that we can extend it to new envelopes easily.Current Provider Implementation
Code reference to provider implementation: LocalSignatureProvider
Code reference to internal envelope implementation: jwsEnvelope
COSE Implementation
The signing logic would be quite different from that for COSE which is explained in the example: COSE_Sign1
Problem
The overall signing logics for each combination of COSE/JWS and RSA/ECDSA can be simplified as below:
Problems
LocalSignatureProvider
should be designed for all signers(COSE/JWS). But the current implementation follows the workflow of a JWS signer. To support COSE signer, we need to refactor the local provider to support multiple local signers.SignatureEnvelope
struct for verification and signing in notation-go. It's better to expose those APIs wrapped in an interface for better abstraction and easier unit tests.Proposed Solution
Envelope
Envelope
interface.2.1 The internal envelope can be a JWS envelope or COSE envelope. It handles the actual signing/verifying for a specific envelope format.
2.2 The base envelope wraps up a raw signature and the internal envelope. The base envelope implements the same interface as the internal envelope. The base envelope implementation just holds the common logics shared by JWS/COSE internal envelopes.
Signer
SignatureProvider
.LocalSigner
interface embedding aSigner
interface with additionalPrivateKey()
andCertificateChain()
APIs. When the envelope needs to create a local signer, it just checks if the given signer holds theLocalSigner
interface.Diagram
Additional Refactoring
The
Signer
submodule was designed for JWS in the notation-core-go. Since we're adding COSE support and will add more files inside, it's necessary to restructure the directory as well.The directory can be refactored like the below structure:
Beta Was this translation helpful? Give feedback.
All reactions