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

Convert EC signature data and use unified verify #4

Merged
merged 2 commits into from
Nov 28, 2018

Conversation

onevcat
Copy link
Member

@onevcat onevcat commented Nov 26, 2018

This PR removes the workaround used for ECDSA verification. Previously, there was a mistake on extra bit prefixing (we thought we need to prefix 0x00 when the first bit is above than 0x70, but actually it should be 0x80).

It turns out that the . ecdsaSignatureMessageX962SHA256 algorithm works well for the new SecKeyVerifySignature API, as long as we convert the raw {r,s} signature data to DER-encoded format. So it is no need to make the verifying method seperated anymore.

@codecov-io
Copy link

Codecov Report

Merging #4 into master will decrease coverage by 0.37%.
The diff coverage is 86.11%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master       #4      +/-   ##
==========================================
- Coverage    84.2%   83.83%   -0.38%     
==========================================
  Files         150      150              
  Lines        5781     5771      -10     
==========================================
- Hits         4868     4838      -30     
- Misses        913      933      +20
Impacted Files Coverage Δ
LineSDK/LineSDK/Crypto/CryptoError.swift 0% <0%> (ø) ⬆️
LineSDK/LineSDK/Crypto/CryptoData.swift 85.71% <100%> (-0.88%) ⬇️
LineSDK/LineSDK/Crypto/CryptoAlgorithm.swift 20% <100%> (-80%) ⬇️
LineSDK/LineSDK/Crypto/Algorithms/ECDSA.swift 50% <100%> (-20.97%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update bad5f0e...4b01d05. Read the comment docs.


// For byte >= 0x80 (first bit is 1), prefix 0x00 to make Security framework happy.
if rBytes.first! >= UInt8(0x80) {
rBytes = [0x00] + rBytes
Copy link
Contributor

Choose a reason for hiding this comment

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

Guess this is doing the Signed big-endian encoding of minimal length 👍
Reference: https://crypto.stackexchange.com/a/1797 🙇

Copy link
Member Author

Choose a reason for hiding this comment

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

It depends on the implementation detail of the security framework/algorithm we are using. Here for Security.framework, we need to do so, otherwise, the signature is not accepted.

Copy link
Contributor

@eJamesLin eJamesLin left a comment

Choose a reason for hiding this comment

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

👍 🙇

Copy link

@rmundo rmundo left a comment

Choose a reason for hiding this comment

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

My preference would be to use subdata(in:) and insert(_:at:) to manipulate Data directly, but this is also very clear. LGTM~

@onevcat onevcat merged commit 5c1cccf into master Nov 28, 2018
@onevcat onevcat deleted the fix/unified-verify branch November 28, 2018 12:24
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.

4 participants