Skip to content
This repository has been archived by the owner on Sep 3, 2020. It is now read-only.

Reproducible Crash When Encrypting/Decrypting RSA #78

Closed
Frizlab opened this issue Jan 12, 2019 · 3 comments
Closed

Reproducible Crash When Encrypting/Decrypting RSA #78

Frizlab opened this issue Jan 12, 2019 · 3 comments
Labels
bug Something isn't working
Milestone

Comments

@Frizlab
Copy link

Frizlab commented Jan 12, 2019

This simple code crashes (segfault).

import Crypto

let passphrase = "abcdef"

// From https://www.googleapis.com/oauth2/v3/certs
let key = try RSAKey.components(n: "vvAaaSpfr934Qx0ioFiWsopq7UCfLNn0zjYVbq4bvUcGSXU9kowYmQArR7WlIkjk1moffla0UV75QRaQPATva1oD5xQnnW-20haeMWTSsMgUHoN0Np9AD8ffPz-DfMJBOHIo4REL1BFFS33HSZgPl0hxJ-5UScqr4lW1JMy5XGeRho30dnmKTpakU1Oc35hFYKSea_O2SXfmbqiAkWlWkilEzgHq4pzVWiDZe4ZgfMdD4vqkSNrO_PkBFBT1mnBJztQ1h4v1jvUW-zeYYwIcPTaOX-xOTiGH9uQkcNPpe5pBrIZJqR5VNrDl_bJOmvVlhhXZSn4fkxA8kyQcZXGaTw", e: "AQAB")
let encryptedPassphrase = try RSA.encrypt(passphrase, padding: .pkcs1, key: key)
try print(RSA.decrypt(encryptedPassphrase, padding: .pkcs1, key: key))

Reproducing 100% with version 3.3.0 (5605334) of Crypto. Tested of macOS 10.14.2, with Xcode 10.1, and the standard Swift version for this Xcode version, and on Debian, with Swift 4.2.1.

@tanner0101 tanner0101 added the bug Something isn't working label Jan 14, 2019
@tanner0101
Copy link
Member

Hi @Frizlab, I've opened a PR (#79) including a fix for the crash you described here. However, the code now throws an error when attempting to decrypt the passphrase. AFAIK, this is expected since usually you encrypt with a public key and decrypt with a private key. I just wanted to check with you before changing the test to expect an error. Thanks!

@Frizlab
Copy link
Author

Frizlab commented Jan 15, 2019

Yes indeed, throwing is the expected behavior :)

tanner0101 added a commit that referenced this issue Jan 17, 2019
add test case for crash, #78
@tanner0101 tanner0101 added this to the 3.3.1 milestone Jan 17, 2019
@tanner0101
Copy link
Member

This is solved in 3.3.1. Thanks again.

# for free to subscribe to this conversation on GitHub. Already have an account? #.
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants