2016-11-22 27 views
0

私はAndroidのXamarinでクライアントアプリケーションを使用しています.TLS 1.2とNTLMが必要です。AndroidでXamarinでNTLMとTLS 1.2を有効にするにはどうすればよいですか?

これまでのところ、私は定期的にSystem.Net.HttpClientHandlerを使用している、それがうまく働いた - それは次のようになります。

new System.Net.Http.HttpClientHandler() 
     { 
      Credentials = credentials 
     }; 

しかし、今、私は新しい顧客を持っていると私はTLS 1.2が必要です。環境変数で

new Xamarin.Android.Net.AndroidClientHandler() 
     { 
      Credentials = credentials 
     }; 

XA_HTTP_CLIENT_HANDLER_TYPE=Xamarin.Android.Net.AndroidClientHandler 

は今、このAndroidClientHandlerは限り証明書が行くように動作

だから私は、Androidのために、このコードを作りました。しかし、NTLMも働かなければなりません。私にとって、AndroidClientHandlerは、基本認証スキームとダイジェスト認証スキームだけをサポートしているようです(Xamarin.Android.Net.AuthenticationSchemeを参照)。

私もModernHttpClientで試しましたが、System.Net.Http.HttpClientHandlerと同じ方法でMonoを使用しているようですので、TLS 1.2もそこでは動作しません。

これはかなり一般的なケースであるはずですが、私はまだウェブ上で関連する例を見つけることができません。私はただの何かが明らかでないことを願っています。あなたはどうやってこれを解決しましたか?

+0

最近、TLS 1.2がかなりMono/Xamarinに来ました。どのくらいのビルドを使っていますか? http://tirania.org/blog/archive/2016/Sep-30.html – scotru

+0

こんにちは、scotruと答えに感謝!私はMono.Androidランタイム4.0.30319を使用しています。 Xamarinの最新バージョンでそれが得られると私は思う。 – Christian

+0

私はMiguelが参照している更新がMono.Androidランタイムリリースにまだ出来ていないと思います。 ModernHttpClientはTLS 1.2でも動作するはずです。 https://wolfprogrammer.com/2016/08/23/enabling-tls-1-2-in-xamarin-forms/ – scotru

答えて

0

私はあなたを介して読みすることは有益であろうと信じて:

https://github.com/xamarin/xamarin-android/blob/0c3597869bc4493895e755bda8a26f778e4fe9e0/src/Mono.Android/Xamarin.Android.Net/AndroidClientHandler.cs#L40-L56

/// <para> 
/// The class supports pre-authentication of requests albeit in a slightly "manual" way. Namely, whenever a request to a server requiring authentication 
/// is made and no authentication credentials are provided in the <see cref="PreAuthenticationData"/> property (which is usually the case on the first 
/// request), the <see cref="RequestNeedsAuthorization"/> property will return <c>true</c> and the <see cref="RequestedAuthentication"/> property will 
/// contain all the authentication information gathered from the server. The application must then fill in the blanks (i.e. the credentials) and re-send 
/// the request configured to perform pre-authentication. The reason for this manual process is that the underlying Java HTTP client API supports only a 
/// single, VM-wide, authentication handler which cannot be configured to handle credentials for several requests. AndroidClientHandler, therefore, implements 
/// the authentication in managed .NET code. Message handler supports both Basic and Digest authentication. If an authentication scheme that's not supported 
/// by AndroidClientHandler is requested by the server, the application can provide its own authentication module (<see cref="AuthenticationData"/>, 
/// <see cref="PreAuthenticationData"/>) to handle the protocol authorization.</para> 
/// <para>AndroidClientHandler also supports requests to servers with "invalid" (e.g. self-signed) SSL certificates. Since this process is a bit convoluted using 
/// the Java APIs, AndroidClientHandler defines two ways to handle the situation. First, easier, is to store the necessary certificates (either CA or server certificates) 
/// in the <see cref="TrustedCerts"/> collection or, after deriving a custom class from AndroidClientHandler, by overriding one or more methods provided for this purpose 
/// (<see cref="ConfigureTrustManagerFactory"/>, <see cref="ConfigureKeyManagerFactory"/> and <see cref="ConfigureKeyStore"/>). The former method should be sufficient 
/// for most use cases, the latter allows the application to provide fully customized key store, trust manager and key manager, if needed. Note that the instance of 
/// AndroidClientHandler configured to accept an "invalid" certificate from the particular server will most likely fail to validate certificates from other servers (even 
/// if they use a certificate with a fully validated trust chain) unless you store the CA certificates from your Android system in <see cref="TrustedCerts"/> along with 
/// the self-signed certificate(s).</para> 

基本的にこれは言う:それはBasicDigest認証をサポートしています。サーバーによって要求されたAndroidClientHandlerでサポートされていない認証方式がある場合、アプリケーションは独自の認証モジュールを使用してプロトコル認証を処理できます。

私たちは、その後、RequestedAuthenticationプロパティは、その後、これは、それが私たちのAuthenticationSchemeとしてUnsupportedを返す場合ことを教えてくれるサーバがサポートしているについては、各スキーム:

https://github.com/xamarin/xamarin-android/blob/0c3597869bc4493895e755bda8a26f778e4fe9e0/src/Mono.Android/Xamarin.Android.Net/AndroidClientHandler.cs#L116-L124

/// <summary> 
/// If the website requires authentication, this property will contain data about each scheme supported 
/// by the server after the response. Note that unauthorized request will return a valid response - you 
/// need to check the status code and and (re)configure AndroidClientHandler instance accordingly by providing 
/// both the credentials and the authentication scheme by setting the <see cref="PreAuthenticationData"/> 
/// property. If AndroidClientHandler is not able to detect the kind of authentication scheme it will store an 
/// instance of <see cref="AuthenticationData"/> with its <see cref="AuthenticationData.Scheme"/> property 
/// set to <c>AuthenticationScheme.Unsupported</c> and the application will be responsible for providing an 
/// instance of <see cref="IAndroidAuthenticationModule"/> which handles this kind of authorization scheme 
/// (<see cref="AuthenticationData.AuthModule"/> 
/// </summary> 

を一覧表示することを見ることができますチャレンジを処理する私たち自身のIAndroidAuthenticationModuleを提出する必要があります。ここで

AuthenticationSchemeの列挙です:

https://github.com/xamarin/xamarin-android/blob/24f2aec113857b5c583e14959b9af08ad45b22b1/src/Mono.Android/Xamarin.Android.Net/AuthenticationScheme.cs

namespace Xamarin.Android.Net 
{ 
    /// <summary> 
    /// Authentication schemes supported by <see cref="AndroidClientHandler"/> 
    /// </summary> 
    public enum AuthenticationScheme 
    { 
     /// <summary> 
     /// Default value used in <see cref="AuthenticationData.Scheme"/> 
     /// </summary> 
     None, 

     /// <summary> 
     /// <see cref="AndroidClientHandler"/> doesn't support this scheme, the application must provide its own value. See <see cref="AuthenticationData.Scheme"/> 
     /// </summary> 
     Unsupported, 

     /// <summary> 
     /// The HTTP Basic authentication scheme 
     /// </summary> 
     Basic, 

     /// <summary> 
     /// The HTTP Digest authentication scheme 
     /// </summary> 
     Digest 
    } 
} 

したがって、私たちはあなたの実装にこのインタフェースを拡張してカスタムIAndroidAuthenticationModuleを実装する必要があります:

https://github.com/xamarin/xamarin-android/blob/24f2aec113857b5c583e14959b9af08ad45b22b1/src/Mono.Android/Xamarin.Android.Net/IAndroidAuthenticationModule.cs

その後、その実装をに渡します210プロパティ:

https://github.com/xamarin/xamarin-android/blob/24f2aec113857b5c583e14959b9af08ad45b22b1/src/Mono.Android/Xamarin.Android.Net/AuthenticationData.cs#L37

あなたは、メインクライアントのPreAuthenticationDataプロパティにそれを渡します。私はこれが役に立てば幸い

https://github.com/xamarin/xamarin-android/blob/0c3597869bc4493895e755bda8a26f778e4fe9e0/src/Mono.Android/Xamarin.Android.Net/AndroidClientHandler.cs#L113

+0

Xamarin.FormsについてDroidバージョンはTLS 1.2 Webサイトに接続できません。 イメージロード:https://randomuser.me/api/portraits/med/men/85.jpgのストリームを取得中にエラーが発生しました:System.Net.WebException:エラー:SecureChannelFailure(認証または復号化に失敗しました)---> System.IO.IOException:認証または復号化に失敗しました。 ---> System.IO.IOException:認証または復号化に失敗しました。 ---> Mono.Security.Protocol.Tls.TlsException:認証または復号化に失敗しました。 –

+0

Xamarinフォームは、基になるTLS APIとは何の関係もありません。あなたのハンドシェイクはこのサーバでは失敗しています。そのため、なぜあなたは調査しなければなりません。上記の私の答えは、新しいAndroidClientHandlerで認証スキームとしてNTLMを使用することです。 –

関連する問題