private static KeyValuePair <NetworkCredential, CURLAUTH> GetCredentials(Uri requestUri, ICredentials credentials, KeyValuePair <string, CURLAUTH>[] validAuthTypes) { NetworkCredential nc = null; CURLAUTH curlAuthScheme = CURLAUTH.None; if (credentials != null) { // For each auth type we consider valid, try to get a credential for it. // Union together the auth types for which we could get credentials, but validate // that the found credentials are all the same, as libcurl doesn't support differentiating // by auth type. for (int i = 0; i < validAuthTypes.Length; i++) { NetworkCredential networkCredential = credentials.GetCredential(requestUri, validAuthTypes[i].Key); if (networkCredential != null) { curlAuthScheme |= validAuthTypes[i].Value; if (nc == null) { nc = networkCredential; } else if (!AreEqualNetworkCredentials(nc, networkCredential)) { throw new PlatformNotSupportedException(SR.Format(SR.net_http_unix_invalid_credential, CurlVersionDescription)); } } } } EventSourceTrace("Authentication scheme: {0}", curlAuthScheme); return(new KeyValuePair <NetworkCredential, CURLAUTH>(nc, curlAuthScheme));; }
internal void SetCredentialsOptions(KeyValuePair <NetworkCredential, CURLAUTH> credentialSchemePair) { if (credentialSchemePair.Key == null) { EventSourceTrace("Credentials cleared."); SetCurlOption(CURLoption.CURLOPT_USERNAME, IntPtr.Zero); SetCurlOption(CURLoption.CURLOPT_PASSWORD, IntPtr.Zero); return; } NetworkCredential credentials = credentialSchemePair.Key; CURLAUTH authScheme = credentialSchemePair.Value; string userName = string.IsNullOrEmpty(credentials.Domain) ? credentials.UserName : credentials.Domain + "\\" + credentials.UserName; SetCurlOption(CURLoption.CURLOPT_USERNAME, userName); SetCurlOption(CURLoption.CURLOPT_HTTPAUTH, (long)authScheme); if (credentials.Password != null) { SetCurlOption(CURLoption.CURLOPT_PASSWORD, credentials.Password); } EventSourceTrace("Credentials set."); }
private static KeyValuePair <NetworkCredential, CURLAUTH> GetCredentials(ICredentials credentials, Uri requestUri) { NetworkCredential nc = null; CURLAUTH curlAuthScheme = CURLAUTH.None; if (credentials != null) { // we collect all the schemes that are accepted by libcurl for which there is a non-null network credential. // But CurlHandler works under following assumption: // for a given server, the credentials do not vary across authentication schemes. for (int i = 0; i < s_authSchemePriorityOrder.Length; i++) { NetworkCredential networkCredential = credentials.GetCredential(requestUri, s_authenticationSchemes[i]); if (networkCredential != null) { curlAuthScheme |= s_authSchemePriorityOrder[i]; if (nc == null) { nc = networkCredential; } else if (!AreEqualNetworkCredentials(nc, networkCredential)) { throw new PlatformNotSupportedException(SR.net_http_unix_invalid_credential); } } } } VerboseTrace("curlAuthScheme = " + curlAuthScheme); return(new KeyValuePair <NetworkCredential, CURLAUTH>(nc, curlAuthScheme));; }
private void TransferCredentialsToCache(Uri serverUri, CURLAUTH serverAuthAvail) { if (_serverCredentials == null) { // No credentials, nothing to put into the cache. return; } // Get the auth types valid based on the type of the ICredentials used. We're effectively // going to intersect this (the types we allow to be used) with those the server supports // and with the credentials we have available. The best of that resulting intersection // will be added to the cache. KeyValuePair <string, CURLAUTH>[] validAuthTypes = AuthTypesPermittedByCredentialKind(_serverCredentials); lock (LockObject) { // For each auth type we allow, check whether it's one supported by the server. for (int i = 0; i < validAuthTypes.Length; i++) { // Is it supported by the server? if ((serverAuthAvail & validAuthTypes[i].Value) != 0) { // And do we have a credential for it? NetworkCredential nc = _serverCredentials.GetCredential(serverUri, validAuthTypes[i].Key); if (nc != null) { // We have a credential for it, so add it, and we're done. Debug.Assert(_credentialCache != null, "Expected non-null credential cache"); try { _credentialCache.Add(serverUri, validAuthTypes[i].Key, nc); } catch (ArgumentException) { // Ignore the case of key already present } break; } } } } }
private void AddCredentialToCache(Uri serverUri, CURLAUTH authAvail, NetworkCredential nc) { lock (LockObject) { for (int i = 0; i < s_authSchemePriorityOrder.Length; i++) { if ((authAvail & s_authSchemePriorityOrder[i]) != 0) { Debug.Assert(_credentialCache != null, "Expected non-null credential cache"); try { _credentialCache.Add(serverUri, s_authenticationSchemes[i], nc); } catch (ArgumentException) { //Ignore the case of key already present } } } } }
private void TransferCredentialsToCache(Uri serverUri, CURLAUTH serverAuthAvail) { if (_serverCredentials == null) { // No credentials, nothing to put into the cache. return; } lock (LockObject) { // For each auth type we allow, check whether it's one supported by the server. KeyValuePair <string, CURLAUTH>[] validAuthTypes = s_orderedAuthTypes; for (int i = 0; i < validAuthTypes.Length; i++) { // Is it supported by the server? if ((serverAuthAvail & validAuthTypes[i].Value) != 0) { // And do we have a credential for it? NetworkCredential nc = _serverCredentials.GetCredential(serverUri, validAuthTypes[i].Key); if (nc != null) { // We have a credential for it, so add it, and we're done. Debug.Assert(_credentialCache != null, "Expected non-null credential cache"); try { _credentialCache.Add(serverUri, validAuthTypes[i].Key, nc); } catch (ArgumentException) { // Ignore the case of key already present } break; } } } } }
internal void SetCredentialsOptions(KeyValuePair <NetworkCredential, CURLAUTH> credentialSchemePair) { if (credentialSchemePair.Key == null) { _networkCredential = null; return; } NetworkCredential credentials = credentialSchemePair.Key; CURLAUTH authScheme = credentialSchemePair.Value; string userName = string.IsNullOrEmpty(credentials.Domain) ? credentials.UserName : string.Format("{0}\\{1}", credentials.Domain, credentials.UserName); SetCurlOption(CURLoption.CURLOPT_USERNAME, userName); SetCurlOption(CURLoption.CURLOPT_HTTPAUTH, (long)authScheme); if (credentials.Password != null) { SetCurlOption(CURLoption.CURLOPT_PASSWORD, credentials.Password); } _networkCredential = credentials; VerboseTrace("Set credentials options"); }
private void AddCredentialToCache(Uri serverUri, CURLAUTH authAvail, NetworkCredential nc) { lock (LockObject) { for (int i=0; i < s_authSchemePriorityOrder.Length; i++) { if ((authAvail & s_authSchemePriorityOrder[i]) != 0) { Debug.Assert(_credentialCache != null, "Expected non-null credential cache"); try { _credentialCache.Add(serverUri, s_authenticationSchemes[i], nc); } catch(ArgumentException) { //Ignore the case of key already present } } } } }