Click here to Skip to main content
15,886,689 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi,

I'm trying to build an iOS app on my iPhone 5S using Xcode 6.1.1, and it's working fine on my iPhone device.
But one of my functions (i'm using chilkat products)from (chilkatsoft.com) requires to load a certificate (.pfx) (which is stored on my desktop), but it cannot open or read the file.
i get an error message "No such file or directory Failed to open file"

the function works as follows:

Objective-C
<pre lang="objc">
- (void)loadClientDigitalCertificateFromPFX:(int)flag
{
CkoCert *cert = [[CkoCert alloc] init];

BOOL success;

// Load from the PFX file
NSString *pfxFilename;
pfxFilename = @"/Users/user/Desktop/Rania.pfx";
NSString *pfxPassword;
pfxPassword = @"**********";

// A PFX typically contains certificates in the chain of authentication.
// The Chilkat cert object will choose the certificate w/
// private key farthest from the root authority cert.
// To access all the certificates in a PFX, use the
// Chilkat certificate store object instead.
success = [cert LoadPfxFile: pfxFilename password: pfxPassword];
if (success != YES) {
NSLog(@"%@",cert.LastErrorText);
NSLog(@"ERROR");
// return;
}

// Get some information about the digital certificate,
// then get the private key...

// DN = "Distinguished Name"
/*NSLog(@"Subject DN: %@",cert.SubjectDN);

NSLog(@"Common Name: %@",cert.SubjectCN);
NSLog(@"Issuer Common Name: %@",cert.IssuerCN);

NSLog(@"Serial Number: %@",cert.SerialNumber);*/

//*********************************************************
if(flag == 1)
// Now get the private key and Export it into an XML format
{
CkoPrivateKey *pkey;
pkey = [cert ExportPrivateKey];
if (pkey == nil ) {
NSLog(@"%@",cert.LastErrorText);
//return;
}

NSString *prvkeyXml;
// Get the private key in XML format:
prvkeyXml = [pkey GetXml];
//NSLog(@"Client Private Key: %@", prvkeyXml);
return prvkeyXml;
}
//********************************************************

else
{
// Get the public key and Export it into XML format

CkoPublicKey *pubkey;

pubkey = [cert ExportPublicKey];
if (pubkey == nil ) {
NSLog(@"%@",cert.LastErrorText);
//return;
}
NSString *pubkeyXml;
pubkeyXml = [pubkey GetXml];
//NSLog(@"Client Public Key: %@", pubkeyXml);
return pubkeyXml;
}
}
//===============================================================================

the following is the error message i get:

CSS
2015-02-16 21:46:55.749 newDGCH2[1875:812662] ChilkatLog:
  LoadPfxFile:
    DllDate: Jan 22 2015
    ChilkatVersion: 9.5.0.47
    UnlockPrefix: ********
    Architecture: Little Endian; 64-bit
    Language: IOS Objective-C
    VerboseLogging: 0
    class: Cert
    pfxPath: /Users/user/Desktop/Rania.pfx
    loadFileX:
      pathQP: /Users/user/Desktop/Rania.pfx
      fopen_failed:
        errno: 2
        osErrorMessage: No such file or directory
        Failed to open file.
        mode: r
        path: /Users/user/Desktop/Rania.pfx
      --fopen_failed
      Failed to open for read.
    --loadFileX
    Failed.
  --LoadPfxFile
--ChilkatLog

2015-02-16 21:46:55.751 newDGCH2[1875:812662] ChilkatLog:
  LoadPfxFile:
    DllDate: Jan 22 2015
    ChilkatVersion: 9.5.0.47
    UnlockPrefix: ********
    Architecture: Little Endian; 64-bit
    Language: IOS Objective-C
    VerboseLogging: 0
    class: Cert
    pfxPath: /Users/user/Desktop/Rania.pfx
    loadFileX:
      pathQP: /Users/user/Desktop/Rania.pfx
      fopen_failed:
        errno: 2
        osErrorMessage: No such file or directory
        Failed to open file.
        mode: r
        path: /Users/user/Desktop/Rania.pfx
      --fopen_failed
      Failed to open for read.
    --loadFileX
    Failed.
  --LoadPfxFile
--ChilkatLog



So, i was wondering what is the problem, can XCode open a certificate from the desktop? OR
do i have to import it from the Keychain Access or what?

i have no clue!!!!!
Can somebody please help me :)

Best Regards.
Rania
Posted

1 solution

It says there is no such file. Try "~/Desktop/Rania.pfx" as the path. If you're trying to access other user's desktop, that is not a good practice and therefore is forbidden by system security.

Also, if the code is running on your iPhone, it tries to access iPhone's desktop. Your certificate is on the Mac's desktop, isn't it?
 
Share this answer
 
v2
Comments
raniam 16-Feb-15 15:38pm    
yes the certificate is on my Mac's Desktop.

So, do you mean I have to install the certificate on my iPhone?
Vladimir Svyatski 16-Feb-15 16:06pm    
Try it and see if it does the job.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900