Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CredStore Perform Query error

Tags:

ios

xcode9

This error occurs when trying to retrieve an URLCredential from URLCredentialStorage for an unknown URLProtectionSpace. e.g.

let protectionSpace = URLProtectionSpace.init(host: host, 
                                              port: port, 
                                              protocol: "http", 
                                              realm: nil, 
                                              authenticationMethod: nil)

var credential: URLCredential? = URLCredentialStorage.shared.defaultCredential(for: protectionSpace)

produces

CredStore - performQuery - Error copying matching creds.  Error=-25300, query={
    class = inet;
    "m_Limit" = "m_LimitAll";
    ptcl = http;
    "r_Attributes" = 1;
    srvr = host;
    sync = syna;
}

Give it a credential for the protection space:

let userCredential = URLCredential(user: user, 
                                   password: password, 
                                   persistence: .permanent)

URLCredentialStorage.shared.setDefaultCredential(userCredential, for: protectionSpace)

and the error goes away next time you try to retrieve the credential.

I am a little lost as I am not sure what is causing this, or what CredStore even does. What purpose does CredStore serve in iOS?

Credential storage on iOS allows users to securely store certificate-based or password-based credentials on the device either temporarily or permanently to the keychain.

I suspect that you have some sort of authentication on your backend server and that server is requesting an authentication challenge to your app (for which no credential exists).

It can probably be safely ignored as returning nil from the URLCredentialStorage is a valid response


I'm not sure why do we get this error when perform requests with Alamofire, but if you do API requests with some token in HTTP headers, you maybe don't need credentials store at all. So we can disable it for our request:

let configuration = URLSessionConfiguration.default
configuration.httpAdditionalHeaders = ourHeaders
// disable default credential store
configuration.urlCredentialStorage = nil

let manager = Alamofire.SessionManager(configuration: configuration)
...

No errors after such change.


This same issue happens to me and I found that if your API URL does not contain a "/" at the end of URL then iOS does not send "Authorization" value to the server. Due to which you will see a message like posted in question in the console.

So Simply add "/" at the end of URL

https://example.com/api/devices/

In my case, I was not initialising Stripe SDK with API key.

        STPPaymentConfiguration.shared().publishableKey = publishableKey

In case of any Stripe operation, we can print the error log, its easy to understand.

        print(error.debugDescription)

This is transport error, let's add transport permission like this in plist file:

<key>NSAppTransportSecurity</key>
    <dict>
        <key>NSAllowsArbitraryLoads</key>
        <true/>
    </dict>

Be careful as that enables connection to any server from your app. Read more on App Transport Security before proceeding. See comment by @kezi


I edited the String that contains the URL to fix this issue:

var myUrl = "http://myurl.com"
myUrl = myUrl.addingPercentEncoding(withAllowedCharacters: .urlFragmentAllowed)!

let url = URL(string: myUrl)

If you get this error, when using AVPlayer, just call .play() on main thread