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

Added support to read multiple public keys from a PEM file #22

Merged

Conversation

greenantdotcom
Copy link
Contributor

For a usecase where we may have multiple public keys that our content might have been signed with, we wanted to put multiple public keys into a single file, much like you may have multiple SSL certs in a chain file.

This method parses out any data between -----BEGIN PUBLIC KEY----- and -----END PUBLIC KEY-----, and then uses publicKeyFromPEMString() to try to parse it.

Tests added for a really insane usecases, an empty string, and reading one of the test private keys for fun. All added code has 100% coverage, and the new method is commented.

@@ -220,6 +220,57 @@ public class SwiftyRSA: NSObject {
return try addKey(data, isPublic: false)
}

/// The regular expression used to find public key armor
let publicKeyRegexp : NSRegularExpression! = {
Copy link
Contributor

Choose a reason for hiding this comment

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

Love the caching of the regex here. However we should avoid forced-unwraps at all costs. Can you make publicKeyRegexp an optional, and guard it in publicKeysFromString?

@ldiqual
Copy link
Contributor

ldiqual commented Jul 18, 2016

@greenantdotcom Thanks a lot! This is great. Added a couple comments inline. Can you also update the CHANGELOG.md so we keep track of changes? Thank you.

@greenantdotcom greenantdotcom force-pushed the convenience-pub-key-reading branch from defe8aa to db67bdb Compare July 18, 2016 23:45
For a usecase where we may have multiple public keys that our content might have been signed with, we wanted to put multiple public keys into a single file, much like you may have multiple SSL certs in a chain file.

This method parses out any data between `-----BEGIN PUBLIC KEY-----`  and `-----END PUBLIC KEY-----`, and then uses `publicKeyFromPEMString` to try to parse it.

Tests added for a really insane usecases, an empty string, and reading one of the test private keys for fun. All added code has 100% coverage, and the new method is commented.
@greenantdotcom greenantdotcom force-pushed the convenience-pub-key-reading branch from db67bdb to 1aa9a06 Compare July 19, 2016 00:17
@greenantdotcom
Copy link
Contributor Author

@ldiqual Should be done!

@ldiqual
Copy link
Contributor

ldiqual commented Jul 21, 2016

@greenantdotcom Perfect! I'm merging this now. Thank you so much for implementing this. I've sent you an invite to join the SwiftyRSA maintainers group -- no pressure to accept! Feel free to get back to me if you have any question.

@ldiqual ldiqual merged commit a397596 into TakeScoop:master Jul 21, 2016
ldiqual added a commit that referenced this pull request Sep 15, 2016
* Make SwiftyRSA compile with Swift 3.0

* Fixed all errors + warnings

* Fix spelling

* Added support to read multiple public keys from a PEM file (#22)

For a usecase where we may have multiple public keys that our content might have been signed with, we wanted to put multiple public keys into a single file, much like you may have multiple SSL certs in a chain file.

This method parses out any data between `-----BEGIN PUBLIC KEY-----`  and `-----END PUBLIC KEY-----`, and then uses `publicKeyFromPEMString` to try to parse it.

Tests added for a really insane usecases, an empty string, and reading one of the test private keys for fun. All added code has 100% coverage, and the new method is commented.

* Added targets for watchOS and tvOS (#23)

- Added additional targets for watchOS and tvOS platforms
- Tests pass on tvOS
- Changed the master `SwiftyRSA.h` file to pull in Foundation and not UIKit/Cocoa since those frameworks aren't needed
- The current CI pipeline doesn't assume multiple targets/schemes, so I refactored `.travis.yml` to allow for AppleTV, iOS, and watchOS targets, and based on how Alamofire does theirs for multiple platform support
- Updated `podspec` to show multiple platform support
    - Also raised iOS version to 8.3 since Travis platform doesn't seem to have support for iOS 8.0-8.2

* Updated changelog

* Bump to 0.4.0

* Update to Xcode 8.0 beta 4

* Migrate to Xcode 8 beta 6

* Don't reduce maximum block size when padding is `none`
Closes #29

* Update CHANGELOG.md

#29

* Fix OSStatus -34018 on iOS 10

* Update travis to support xcode 8
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.

2 participants