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

3 - Linux key support and associated tests passing OK #6

Merged
merged 3 commits into from
Dec 21, 2017
Merged

3 - Linux key support and associated tests passing OK #6

merged 3 commits into from
Dec 21, 2017

Conversation

gtaban
Copy link
Contributor

@gtaban gtaban commented Dec 15, 2017

Add functionality for key support for Linux.

Enable the following 14 key-based tests which run OK on Linux:

test_public_initWithData
test_public_initWithCertData
test_public_initWithCertData2
test_public_initWithBase64String
test_public_initWithBase64StringWhichContainsNewLines
test_public_initWithPEMString
test_public_initWithPEMName
test_public_initWithDERName
test_publicKeysFromEmptyPEMFileReturnsEmptyArray
test_public_initWithCertificateName
test_public_initWithCertificateName2
test_private_initWithPEMString
test_private_initWithPEMName
test_private_initWithDERName

Description

Motivation and Context

How Has This Been Tested?

Linux 16.04 OpenSSL 1.0.2g

Checklist:

  • I have submitted a CLA form
  • If applicable, I have updated the documentation accordingly.
  • If applicable, I have added tests to cover my changes.

Enable the following 14 key-based tests which run OK on Linux:

test_public_initWithData
test_public_initWithCertData
test_public_initWithCertData2
test_public_initWithBase64String
test_public_initWithBase64StringWhichContainsNewLines
test_public_initWithPEMString
test_public_initWithPEMName
test_public_initWithDERName
test_publicKeysFromEmptyPEMFileReturnsEmptyArray
test_public_initWithCertificateName
test_public_initWithCertificateName2
test_private_initWithPEMString
test_private_initWithPEMName
test_private_initWithDERName
@billabt billabt merged commit 471c095 into Kitura:master Dec 21, 2017
@billabt
Copy link
Collaborator

billabt commented Dec 21, 2017

I made some minor changes to exploit common code and eliminate some redundancy. Also, the XXXX_initWithPEMStringHeaderless tests should be enabled and working on Linux as well. They test the case where a PEM string is passed that's already been stripped. This can happen when the PEM is created on Linux and then used on macOS. The problem is with this piece of code...

	public class func createPublicKey(withPEM pemString: String) throws -> PublicKey {
		
        #if os(Linux)
			
            // OpenSSL takes the full PEM format...
            let keyData = pemString.data(using: String.Encoding.utf8)!

            return try PublicKey(with: keyData)
            
        #else
			
            // Get the Base64 representation of the PEM encoded string after stripping off the PEM markers
            let base64String = try CryptorRSA.base64String(for: pemString)
            
            return try createPublicKey(withBase64: base64String)
			
        #endif
	}

In the statement

let keyData = pemString.data(using: String.Encoding.utf8)!

you are explicitly force unwrapping the object. This is the point where the test is failing on Linux with the following exception:

fatal error: unexpectedly found nil while unwrapping an Optional value

Once you fix that, the headerless tests should work.

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