-
Notifications
You must be signed in to change notification settings - Fork 51
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
Take TLS Certificates by string #10
Comments
What is the format of the String you want to pass? PEM? PKCS12? If PEM, do you also have the key in String form? If PKCS12, I assume you'll also have the password, correct? Trying to figure out if this is going to be a Linux only feature or available on macOS as well. Any assistance here is greatly appreciated... |
@billabt I believe we get a PEM from Bluemix. Everything we get is in one base64 string which I can send to you directly. |
BlueSSLService v0.12.13 contains the new configuration API and the underlying support. However, it's only been tested minimally. Please let me know if you have any problems with it and open a new issue. If you do run into problems, it would be helpful if you can supply a standalone test case and attach it to the new issue. Thanks. |
Thanks, @billabt ! We will check it out and see if it works for our MongoKitten branch. Regarding the cross platform issue- is there any way to get a pk12 out of a string that's in PEM format all by using Swift and your tools? |
I'm still looking at the best way to implement on macOS. I assumed you needed it first on Linux so that's why I released that implementation as soon as it was done rather than wait for the macOS version. I think it'll be possible but I've some more research to do... |
Actually since it's not really done until we get or don't get the macOS version, I'm going to re-open the issue. So if there are problems, just use this issue... Thanks. |
I'm unsure of why, but I'm getting a seg fault in SSLService.swift here.
I'm leveraging the new init method here. |
I need more info... Backtrace? Standalone (outside Bluemix) reproducible scenario? |
Here is the backtrace I believe:
To reproduce, clone my branch of TodoList-MongoDB.
Then run on Linux and you should get a segmentation fault. I can send you my mongoDB credentials if needed. |
I tried doing what you suggested and I'm unable to get it working. Can you narrow it down to simpler test case that illustrates the problem? It'd be extremely helpful. Otherwise, because of my other project commitments outside Swift@IBM (plus still on the mend from a bout with pneumonia), I'm not sure when I'll be able to get to it... |
In reviewing the code, I found a potential issue with the handling of the passed string. I'm not sure if it'll fix your problem but it's probably worth trying. v0.12.15. |
I still seem to have issues with v0.12.15. I will try to get a simple example together. |
I was able to reproduce the problem and determine the cause. The last set of changes before this, changed the way closed sockets were being handled. This caused a problem where the SSLService was being deinitialized too early. The latest BlueSocket and BlueSSLService correct this problem. |
@billabt Everything appears to be working on Linux, including Bluemix deployment. Thanks a lot. |
Support for SSL is available on macOS using a PKCS12. If you're talking about doing it via the same mechanism as on Linux using a PEM formatted string, I don't think we're gonna be able to do it. There doesn't appear (at least that I can find) a way of configuring Secure Transport using a PEM formatted string but I'm still looking. |
Ideally, of course, we would want to be able to handle the PEM that Bluemix gives us and get it working on Mac. But maybe this isn't a deal breaker- since, probably macOS users will be using a development environment, and can probably do the PEM to PKCS12 conversion on the command line. The steps taken could be:
|
Yes, that's definitely a possibility. But, before you go down that road (unless it's time critical), give me a few more days to explore being able to use the PEM string... |
@billabt Just wanted to check in to see if you have had time to explore options of using the PEM string on macOS? Let us know if we can help. |
@tfrank64 Haven't had the chance. Been working on BlueRSA and a BlueSSLService issue... It's still in my queue. |
@billabt Any updates? I can't figure out a way to do it via Apple's Certificate Key and Trust Services. |
So far, neither can I... 😝 |
@billabt Would it be possible to do with OpenSSL? |
So, to answer my own question: It is possible with OpenSSL - it's just a mess. Here's my solution (feel free to use it however you'd like - I'm releasing the code and instructions into the public domain).
#import <Foundation/Foundation.h>
#import <openssl/safestack.h>
#import <openssl/x509.h>
#import <openssl/objects.h>
@interface X509_STACK_CREATOR:NSObject
- (STACK_OF(X509))createStack:(NSArray*)certificates;
@end
@implementation X509_STACK_CREATOR
- (STACK_OF(X509)) createStack:(NSArray*)certificates{
STACK_OF(X509) *stack = NULL;
stack = sk_X509_new_null();
for(int i = 0; i < [certificates count]; i++){
X509 *certificate = (__bridge X509 *)([certificates objectAtIndex:i]);
sk_X509_push(stack, certificate);
}
return *stack;
}
@end
func toEVP(privateKey: SecKey) throws -> UnsafeMutablePointer<EVP_PKEY>? {
var error: Unmanaged<CFError>?
guard let privateKeyData = SecKeyCopyExternalRepresentation(privateKey, &error) as NSData? else {
throw error!.takeRetainedValue() as Error
}
var rsaPrivateKey: UnsafeMutablePointer<RSA>?
var privateKeyBytes: UnsafePointer<UInt8>? = privateKeyData.bytes.assumingMemoryBound(to: UInt8.self)
d2i_RSAPrivateKey(&rsaPrivateKey, &privateKeyBytes, privateKeyData.length)
var evpPrivateKey = EVP_PKEY_new()
EVP_PKEY_set1_RSA(evpPrivateKey, rsaPrivateKey)
return evpPrivateKey
}
Sadly, it seems to give a bad access error during the PKCS12 creation. I probably messed up with the ObjC code. |
I've done this before in another application and inside BlueSSLService when running on Linux. However, to incorporate it into BlueSSLService, it would require linking to both the macOS libraries and OpenSSL when running on macOS. This is an unnecessary burden (the OpenSSL) for most apps. Probably better to do it on a case by case basis with an extension to BlueSSLService. |
Due to lack of support in the macOS Security module, this will unfortunately fall into the category of won't fix. However, in those cases where it's absolutely necessary and you don't mind the bloat, you can use the method described by @benaubin above. If someone has another suggestion, I'd be more than happen to try it. |
Right now the library assumes a file that contains the certificate. It would be helpful to have the library also take a String that's Base64 encoded, as well. Bluemix users will receive a Base64 string for their certificate through the Bluemix environment variables to be used to connect with MongoDB, for instance.
The text was updated successfully, but these errors were encountered: