developer tip

CredStore 쿼리 수행 오류

optionbox 2020. 9. 4. 07:11
반응형

CredStore 쿼리 수행 오류


내 앱 백엔드에 대한 API 호출을 수행하는 동안 문제가 발생했습니다. 이제 모든 연결에 다음 메시지가 표시됩니다.

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

이 문제의 원인이 무엇인지 또는 CredStore가 무엇을하는지 잘 모르겠 기 때문에 조금 길을 잃었습니다. CredStore는 iOS에서 어떤 용도로 사용됩니까?


이 오류 는 알 수없는 URLCredential에서 를 검색하려고 할 때 발생합니다 . 예 :URLCredentialStorageURLProtectionSpace

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

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

생산하다

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

보호 공간에 대한 자격 증명을 제공합니다.

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

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

다음에 자격 증명을 검색하려고하면 오류가 사라집니다.

이 문제의 원인이 무엇인지 또는 CredStore가 무엇을하는지 잘 모르겠 기 때문에 조금 길을 잃었습니다. CredStore는 iOS에서 어떤 용도로 사용됩니까?

iOS의 자격 증명 저장소를 사용하면 사용자가 인증서 기반 또는 암호 기반 자격 증명을 장치에 일시적으로 또는 영구적으로 키 체인에 안전하게 저장할 수 있습니다.

백엔드 서버에 일종의 인증이 있고 해당 서버가 앱에 대한 인증 시도를 요청하고 있다고 생각합니다 (자격 증명이 존재하지 않음).

에서 nil을 반환하는 URLCredentialStorage것이 유효한 응답이므로 무시해도됩니다.


이것은 전송 오류입니다. plist 파일에 다음과 같은 전송 권한을 추가해 보겠습니다.

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

앱에서 모든 서버에 연결할 수 있으므로 주의하십시오 . 계속하기 전에 앱 전송 보안에 대해 자세히 읽어보십시오. @kezi의 댓글보기


이 오류가 발생하면 AVPlayer를 사용할 때 주 스레드에서 .play ()를 호출하십시오.


이 같은 문제가 저에게 발생하며 API URL의 URL 끝에 "/"가 포함되어 있지 않으면 iOS가 "Authorization"값을 서버로 보내지 않는다는 것을 발견했습니다. 이로 인해 콘솔에 문제가 게시 된 것과 같은 메시지가 표시됩니다.

따라서 URL 끝에 "/"를 추가하면됩니다.

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

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.


The cause of me getting this error was due to me accidentally using two spaces between the "Bearer" and access token in my Authorization header.

Incorrect:

request.setValue("Bearer  \(accessToken)", forHTTPHeaderField: "Authorization")

Correct:

request.setValue("Bearer \(accessToken)", forHTTPHeaderField: "Authorization")

Simple mistake, but it took a while to find it.


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)

OK, I had this error, and fought with it for a long time (years) when interacting with my Ruby on Rails app.

I had default credentials set up as described in the accepted answer, but still got the error, and have been relying on a didReceiveChallenge response to supply the credentials - fortunately that worked as a work around.

But! I've just found the solution!

I was working on a hunch that that the protectedSpace fields did not match the Authorization challenge from the Ruby on Rails server - and I looked into the realm field, which seemed to be the only one that was being left undefined.

I started by printing out the server response headers, and although I was able to examine these, they did not include the WWW-Authorization field that would have included the realm field.

I thought this was maybe because my Rails app wasn't specifying the realm, so I started looking at the Rails side of things.

I found I could specify the realm in the call to,

authenticate_or_request_with_http_basic

...which I am using for HTTP Basic authentication.

I wasn't specifying a realm already, so added one,

authenticate_or_request_with_http_basic("My Rails App")

I then added the corresponding string to the protectionSpace,

NSURLProtectionSpace *protectionSpace =
    [[NSURLProtectionSpace alloc] initWithHost:@"myrailsapp.com"
        port:443
        protocol:NSURLProtectionSpaceHTTPS
        realm:@"My Rails App"
        authenticationMethod:NSURLAuthenticationMethodHTTPBasic];

Voila! That worked, and I no longer get the,

CredStore - performQuery - Error copying matching creds.  Error=-25300

Even after specifying the realm in the Rails app, I still don't see it passed in the HTTP header, I don't know why, but at least it works.


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)

The error may also be caused by a Content Security Policy (CSP) that may be too restrictive. In our case, we needed a CSP that is more or less completely open and allows everything. Keep in mind that opening the CSP can be a great security issue (depending on what exactly you're doing in the app).


I got this issue when I tried to open a http-page inside a web-view. But this page contained an popup which was opened first.

When backend team removed this popup everything became OK.


    let credentialData = "\(user):\(password)".data(using: String.Encoding.utf8)!
    let base64Credentials = credentialData.base64EncodedString(options: [])
    let headers = ["Authorization": "Basic \(base64Credentials)"]
    Alamofire.request(url, method: .get, parameters: params,encoding: URLEncoding.default,headers: headers)
                .responseJSON{
            response in
            guard let value =  response.result.value else {return}
                    print(value)
     }

참고URL : https://stackoverflow.com/questions/46099940/credstore-perform-query-error

반응형