-
Notifications
You must be signed in to change notification settings - Fork 82
Develop mosi42630 #515
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
Develop mosi42630 #515
Conversation
Signed-off-by: nagendra0721 <[email protected]>
Signed-off-by: nagendra0721 <[email protected]>
WalkthroughAdds support for COSE Sign1 tagged and untagged formats: new error codes, DTO flags to control COSE tag inclusion, controller method rename to Changes
Sequence Diagram(s)sequenceDiagram
participant Client
participant Controller as CoseSignController
participant Service as CoseSignatureServiceImpl
participant Parser as CBORDecoder
rect rgba(100,150,200,0.5)
Note over Client,Parser: COSE Sign1 sign/verify flow with optional tag
Client->>Controller: POST /coseSign1 (includeCOSETag / isCOSETagIncluded)
Controller->>Service: coseSign1 / coseVerify1(requestDto)
alt Signing flow
Service->>Service: decode Base64URL -> byte[]
Service->>Service: signCose1(payloadBytes, includeCoseTag)
Service->>Controller: ResponseWrapper(encoded COSE Sign1)
else Verification flow
Service->>Parser: decode CBOR(bytes)
alt isCOSETagIncluded == true
Service->>Service: parseTaggedCoseSign1(decoder)
else isCOSETagIncluded == false
Service->>Service: parseUntaggedCoseSign1(decoder)
end
Service->>Service: verify signature & payload bytes
Service-->>Controller: ResponseWrapper(result)
end
Controller-->>Client: HTTP response
end
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 1 | ❌ 2❌ Failed checks (1 warning, 1 inconclusive)
✅ Passed checks (1 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
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.
Actionable comments posted: 1
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
kernel/kernel-keymanager-service/src/main/java/io/mosip/kernel/signature/service/impl/CoseSignatureServiceImpl.java (1)
108-127: Guard Base64URL decoding failures.
Line 116 decodes Base64URL outside error handling; the precedingisDataValid()check only validates that the input is non-null and non-empty, not that it is valid Base64URL. Malformed input will throwIllegalArgumentExceptionand surface as a 500 error instead of returningINVALID_INPUT. Wrap the decode in try-catch and map decoding failures toRequestException, consistent with patterns already used elsewhere in the codebase (e.g.,SignatureUtil.java:411,CryptomanagerUtils.java:266).🛠️ Suggested fix
- byte[] payload = CryptoUtil.decodeURLSafeBase64(base64Payload); + byte[] payload; + try { + payload = CryptoUtil.decodeURLSafeBase64(base64Payload); + } catch (IllegalArgumentException e) { + LOGGER.error(SignatureConstant.SESSIONID, SignatureConstant.COSE_SIGN, SignatureConstant.BLANK, + "Provided Data to sign is not valid Base64URL.", e); + throw new RequestException(SignatureErrorCode.INVALID_INPUT.getErrorCode(), + SignatureErrorCode.INVALID_INPUT.getErrorMessage()); + }
🤖 Fix all issues with AI agents
In
`@kernel/kernel-keymanager-service/src/main/java/io/mosip/kernel/signature/service/impl/CoseSignatureServiceImpl.java`:
- Around line 637-669: The parseTaggedCoseSign1 method currently casts and
returns cborTaggedItem.getTagContent() outside the try which allows
ClassCastException to bypass intended error handling and the broad catch
swallows a previously thrown RequestException; move the cast-and-return of
COSESign1 into the try block, catch and rethrow RequestException separately
(i.e., add a catch (RequestException re) { throw re; }) and catch specific
exceptions (ClassCastException, IOException, COSEException, etc.) afterwards to
throw TAGGED_COSE_SIGN1 while logging the exception object (LOGGER.error(...,
e)). Do the same in parseUntaggedCoseSign1: include the exception object in
LOGGER.error calls and ensure you catch and rethrow RequestException if created,
and map other specific exceptions to UNTAGGED_COSE_SIGN1 so stack traces and
root causes are preserved.
🧹 Nitpick comments (1)
kernel/kernel-keymanager-service/src/main/java/io/mosip/kernel/signature/controller/CoseSignController.java (1)
59-61: Consider backward-compatibility for the renamed endpoint.
Line 60 switches tocoseSign1; if/coseSignhad consumers, consider a deprecated alias or documented migration path.
...r-service/src/main/java/io/mosip/kernel/signature/service/impl/CoseSignatureServiceImpl.java
Show resolved
Hide resolved
Signed-off-by: nagendra0721 <[email protected]>
Signed-off-by: nagendra0721 <[email protected]>
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.
Actionable comments posted: 0
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
kernel/kernel-keymanager-service/src/main/java/io/mosip/kernel/signature/service/impl/CoseSignatureServiceImpl.java (1)
182-197: CWT tag is skipped when includeCOSETag=false.With
isCwt=true, the early return bypasses the outer CWT tag, yielding invalid CWT output when the caller opts out of the COSE tag.🛠️ Proposed fix
byte[] coseBytes = coseSign1.encode(); CBORDecoder decoder = new CBORDecoder(coseBytes); CBORItem coseItem = decoder.next(); - -if (!includeCoseTag) - return coseItem.encode(); - -CBORTaggedItem sign1Tagged = new CBORTaggedItem(SignatureConstant.COSE_SIGN1_TAG, coseItem); - -if (isCwt) { - CBORTaggedItem cwtTagged = new CBORTaggedItem(SignatureConstant.CWT_SIGN_TAG, sign1Tagged); - return cwtTagged.encode(); -} else { - return sign1Tagged.encode(); -} +CBORItem item = coseItem; +if (includeCoseTag) { + item = new CBORTaggedItem(SignatureConstant.COSE_SIGN1_TAG, item); +} +if (isCwt) { + CBORTaggedItem cwtTagged = new CBORTaggedItem(SignatureConstant.CWT_SIGN_TAG, item); + return cwtTagged.encode(); +} +return item.encode();
Signed-off-by: nagendra0721 <[email protected]>
Summary by CodeRabbit
New Features
Bug Fixes
Documentation
Tests
✏️ Tip: You can customize this high-level summary in your review settings.