IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Android Discussion :

Application Login sur un website


Sujet :

Android

  1. #1
    Membre à l'essai
    Homme Profil pro
    Étudiant
    Inscrit en
    Février 2012
    Messages
    38
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Seine Maritime (Haute Normandie)

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Électronique et micro-électronique

    Informations forums :
    Inscription : Février 2012
    Messages : 38
    Points : 24
    Points
    24
    Par défaut Application Login sur un website
    Bonjour

    Je développes une application pour me connecter au Wifi de mon école.


    Voici comment je dois procéder pour me connecter depuis un pc/ordi

    1°) Ouvrir mon navigateur
    2°) Accepter de comprendre les risques
    3°) Et me connecter

    Cependant, le certificat de l'école n'est pas "sur"

    C'est à dire que je dois par exemple pour utiliser le wifi de mon école sur un ordi, ajouter une exception pour le navigateur Firefox et comprendre les risque sur Chrome.

    Comment je peux faire pour "passer directement à l'étape d'après" c'est a dire de l'étape 1 -> 3 directement à la connexion et donc ne pas passer par l'étape certificats ou alors accepter automatiquement d'ajouter cette exception.
    Actuellement avec mon application, l'erreur afficher est "no peer certificate"

    Cf code
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    package com.example.loginapp;
     
    import android.os.Bundle;
    import android.app.Activity;
    import android.view.Menu;
    import java.util.ArrayList;
    import org.apache.http.NameValuePair;
    import org.apache.http.message.BasicNameValuePair;
    import android.annotation.SuppressLint;
    import android.app.Activity;
    import android.os.Bundle;
    import android.view.View;
    import android.widget.Button;
    import android.widget.EditText;
    import android.widget.TextView;
     
    	@SuppressLint("NewApi")
    	public class MainActivity extends Activity {
    	 EditText un, pw;
    	 TextView error;
    	 Button ok;
    	 private String resp;
    	 private String errorMsg;
     
    	 /** Called when the activity is first created. */
    	 @Override
    	 public void onCreate(Bundle savedInstanceState) {
    	  super.onCreate(savedInstanceState);
    	  setContentView(R.layout.activity_main);
    	  un = (EditText) findViewById(R.id.et_un);
    	  pw = (EditText) findViewById(R.id.et_pw);
    	  ok = (Button) findViewById(R.id.btn_login);
    	  error = (TextView) findViewById(R.id.tv_error);
     
    	  ok.setOnClickListener(new View.OnClickListener() {
     
    	   @Override
    	   public void onClick(View v) {
    	    /** According with the new StrictGuard policy,  running long tasks on the Main UI thread is not possible
                So creating new thread to create and execute http operations */
    	    new Thread(new Runnable() {
     
    	     @Override
    	     public void run() {
    	      ArrayList<NameValuePair> postParameters = new ArrayList<NameValuePair>();
    	      postParameters.add(new BasicNameValuePair("username",un.getText().toString()));
    	      postParameters.add(new BasicNameValuePair("password",pw.getText().toString()));
     
    	      String response = null;
    	      try {
    	       response = SimpleHttpClient.executeHttpPost("https://10.20.0.1:4100/logon.shtml", postParameters);
    	    	 //response = SimpleHttpClient.executeHttpPost("https://accounts.google.com/Login?hl=FR", postParameters);
    	       String res = response.toString();
    	       resp = res.replaceAll("\\s+", "");
     
    	      } catch (Exception e) {
    	       e.printStackTrace();
    	       errorMsg = e.getMessage();
    	      }
    	     }
     
    	    }).start();
    	    try {
     
    	    /** wait a second to get response from server */
    	    Thread.sleep(1000);
    	    /** Inside the new thread we cannot update the main thread
                So updating the main thread outside the new thread */
     
    	     error.setText(resp);
     
    	     if (null != errorMsg && !errorMsg.isEmpty()) {
    	      error.setText(errorMsg);
    	     }
    	    } catch (Exception e) {
    	     error.setText(e.getMessage());
    	    }
    	   }
    	  });
    	 }
    }
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    public class SimpleHttpClient {
    	 /** The time it takes for our client to timeout */
    	    public static final int HTTP_TIMEOUT = 30 * 1000; // milliseconds
     
    	    /** Single instance of our HttpClient */
    	    private static HttpClient mHttpClient;
     
    	    /**
                 * Get our single instance of our HttpClient object.
                 *
                 * @return an HttpClient object with connection parameters set
                 */
    	    private static HttpClient getHttpClient() {
    	        if (mHttpClient == null) {
    	            mHttpClient = new DefaultHttpClient();
    	            final HttpParams params = mHttpClient.getParams();
    	            HttpConnectionParams.setConnectionTimeout(params, HTTP_TIMEOUT);
    	            HttpConnectionParams.setSoTimeout(params, HTTP_TIMEOUT);
    	            ConnManagerParams.setTimeout(params, HTTP_TIMEOUT);
    	        }
    	        return mHttpClient;
    	    }
     
    	    /**
                 * Performs an HTTP Post request to the specified url with the
                 * specified parameters.
                 *
                 * @param url The web address to post the request to
                 * @param postParameters The parameters to send via the request
                 * @return The result of the request
                 * @throws Exception
                 */
    	    public static String executeHttpPost(String url, ArrayList<NameValuePair> postParameters) throws Exception {
    	        BufferedReader in = null;
    	        try {
    	            HttpClient client = getHttpClient();
    	            HttpPost request = new HttpPost(url);
    	            UrlEncodedFormEntity formEntity = new UrlEncodedFormEntity(postParameters);
    	            request.setEntity(formEntity);
    	            HttpResponse response = client.execute(request);
    	            in = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
     
    	            StringBuffer sb = new StringBuffer("");
    	            String line = "";
    	            String NL = System.getProperty("line.separator");
    	            while ((line = in.readLine()) != null) {
    	                sb.append(line + NL);
    	            }
    	            in.close();
     
    	            String result = sb.toString();
    	            return result;
    	        }
    	        finally {
    	            if (in != null) {
    	                try {
    	                    in.close();
    	                } catch (IOException e) {
    	                    e.printStackTrace();
    	                }
    	            }
    	        }
    	    }
     
    	    /**
                 * Performs an HTTP GET request to the specified url.
                 *
                 * @param url The web address to post the request to
                 * @return The result of the request
                 * @throws Exception
                 */
    	    public static String executeHttpGet(String url) throws Exception {
    	        BufferedReader in = null;
    	        try {
    	            HttpClient client = getHttpClient();
    	            HttpGet request = new HttpGet();
    	            request.setURI(new URI(url));
    	            HttpResponse response = client.execute(request);
    	            in = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
     
    	            StringBuffer sb = new StringBuffer("");
    	            String line = "";
    	            String NL = System.getProperty("line.separator");
    	            while ((line = in.readLine()) != null) {
    	                sb.append(line + NL);
    	            }
    	            in.close();
     
    	            String result = sb.toString();
    	            return result;
    	        }
    	        finally {
    	            if (in != null) {
    	                try {
    	                    in.close();
    	                } catch (IOException e) {
    	                    e.printStackTrace();
    	                }
    	            }
    	        }
    	    }
    	}

  2. #2
    Membre éclairé
    Avatar de LeBzul
    Homme Profil pro
    Inscrit en
    Décembre 2008
    Messages
    381
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Meurthe et Moselle (Lorraine)

    Informations forums :
    Inscription : Décembre 2008
    Messages : 381
    Points : 832
    Points
    832
    Par défaut
    J'ai déjà eu un problème similaire, il faut ajouter ton certificat dans les res/asset et le charger à la main...

    J'etais tombé la dessus :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    public class MyHttpClient extends DefaultHttpClient {
     
        private Resources _resources;
     
        public MyHttpClient(Resources resources) {
            _resources = resources;
        }
     
        @Override
        protected ClientConnectionManager createClientConnectionManager() {
            SchemeRegistry registry = new SchemeRegistry();
            registry.register(new Scheme("http", PlainSocketFactory
                .getSocketFactory(), 80));
            if (_resources != null) {
                registry.register(new Scheme("https", newSslSocketFactory(), 443));
            } else {
                registry.register(new Scheme("https", SSLSocketFactory
                    .getSocketFactory(), 443));
            }
            return new SingleClientConnManager(getParams(), registry);
        }
     
        private SSLSocketFactory newSslSocketFactory() {
            try {
                KeyStore trusted = KeyStore.getInstance("BKS");
                InputStream in = _resources.openRawResource(R.raw.mystore);
                try {
                    trusted.load(in, "pwd".toCharArray());
                } finally {
                    in.close();
                }
                return new SSLSocketFactory(trusted);
            } catch (Exception e) {
                throw new AssertionError(e);
            }
        }
    }
    "Quand la lune n'est pas là, la nuit mène une existence obscure"

  3. #3
    Membre à l'essai
    Homme Profil pro
    Étudiant
    Inscrit en
    Février 2012
    Messages
    38
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Seine Maritime (Haute Normandie)

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Électronique et micro-électronique

    Informations forums :
    Inscription : Février 2012
    Messages : 38
    Points : 24
    Points
    24
    Par défaut
    Bonjour,

    Comment je récupère le certificat ?
    Le code que tu m'as donné me permet d'utiliser le certificat, mais après reste la question de le récupérer d'abord =)

  4. #4
    Membre éclairé
    Avatar de LeBzul
    Homme Profil pro
    Inscrit en
    Décembre 2008
    Messages
    381
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Meurthe et Moselle (Lorraine)

    Informations forums :
    Inscription : Décembre 2008
    Messages : 381
    Points : 832
    Points
    832
    Par défaut
    Salut
    Il faut connaitre le fournisseur SSL;
    A l'époque j'avais été ennuyé avec le certificat GeoTrust, sur leur site on peut télécharger le certificat root dont à besoin :
    https://www.geotrust.com/resources/root-certificates/

    J'imagine qu'il y a un équivalent pour chaque fournisseur.
    "Quand la lune n'est pas là, la nuit mène une existence obscure"

  5. #5
    Membre à l'essai
    Homme Profil pro
    Étudiant
    Inscrit en
    Février 2012
    Messages
    38
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Seine Maritime (Haute Normandie)

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Électronique et micro-électronique

    Informations forums :
    Inscription : Février 2012
    Messages : 38
    Points : 24
    Points
    24
    Par défaut
    j'ai récupéré le certificat via FireFox;

    Cela marche-t-il ?

  6. #6
    Membre à l'essai
    Homme Profil pro
    Étudiant
    Inscrit en
    Février 2012
    Messages
    38
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Seine Maritime (Haute Normandie)

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Électronique et micro-électronique

    Informations forums :
    Inscription : Février 2012
    Messages : 38
    Points : 24
    Points
    24
    Par défaut
    J'ai réussi a trouver un certificat (enfin je pense) mais j'ai une question :

    Ceci :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    public class MyHttpClient extends DefaultHttpClient {
     
        private Resources _resources;
     
        public MyHttpClient(Resources resources) {
            _resources = resources;
        }
     
        @Override
        protected ClientConnectionManager createClientConnectionManager() {
            SchemeRegistry registry = new SchemeRegistry();
            registry.register(new Scheme("http", PlainSocketFactory
                .getSocketFactory(), 80));
            if (_resources != null) {
                registry.register(new Scheme("https", newSslSocketFactory(), 443));
            } else {
                registry.register(new Scheme("https", SSLSocketFactory
                    .getSocketFactory(), 443));
            }
            return new SingleClientConnManager(getParams(), registry);
        }
     
        private SSLSocketFactory newSslSocketFactory() {
            try {
                KeyStore trusted = KeyStore.getInstance("BKS");
                InputStream in = _resources.openRawResource(R.raw.mystore);
                try {
                    trusted.load(in, "pwd".toCharArray());
                } finally {
                    in.close();
                }
                return new SSLSocketFactory(trusted);
            } catch (Exception e) {
                throw new AssertionError(e);
            }
        }
    }
    Je le met ou ?

    Dans ma classe MainActivity ou bien dans ma classe SimpleHttpClient ?

    Cordialement

  7. #7
    Membre éclairé
    Avatar de LeBzul
    Homme Profil pro
    Inscrit en
    Décembre 2008
    Messages
    381
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Meurthe et Moselle (Lorraine)

    Informations forums :
    Inscription : Décembre 2008
    Messages : 381
    Points : 832
    Points
    832
    Par défaut
    C'est censé remplacer ton
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
     
    * Get our single instance of our HttpClient object.
    	     *
    	     * @return an HttpClient object with connection parameters set
    	     */
    	    private static HttpClient getHttpClient() {
    	        if (mHttpClient == null) {
    	            mHttpClient = new DefaultHttpClient();
    [...]
    	        }
    	        return mHttpClient;
    	    }
    par :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
     
    * Get our single instance of our HttpClient object.
    	     *
    	     * @return an HttpClient object with connection parameters set
    	     */
    	    private static HttpClient getHttpClient() {
    	        if (mHttpClient == null) {
    	            mHttpClient = new MyHttpClient();
    [...]
    	        }
    	        return mHttpClient;
    	    }
    J'ai pas lu tout ton code, mais ca devrais le faire normalement.
    "Quand la lune n'est pas là, la nuit mène une existence obscure"

  8. #8
    Membre à l'essai
    Homme Profil pro
    Étudiant
    Inscrit en
    Février 2012
    Messages
    38
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Seine Maritime (Haute Normandie)

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Électronique et micro-électronique

    Informations forums :
    Inscription : Février 2012
    Messages : 38
    Points : 24
    Points
    24
    Par défaut
    J'ai maintenant l'erreur suivante :

    android hostname in certificate didn't match :<10.20.0.1> !=fireware web ca

Discussions similaires

  1. SSH invoquer application graphique sur serveur distant
    Par knecmotet dans le forum Réseau
    Réponses: 7
    Dernier message: 07/09/2008, 19h33
  2. Login sur slackware perdu
    Par ieee dans le forum Administration système
    Réponses: 4
    Dernier message: 29/09/2005, 08h13
  3. [MFC]Application basée sur des boites de dialogue
    Par -=Spoon=- dans le forum MFC
    Réponses: 2
    Dernier message: 24/08/2005, 11h55
  4. [Intraweb] Déployer une application intraweb sur IIS ?
    Par maxgar dans le forum Web & réseau
    Réponses: 9
    Dernier message: 21/07/2004, 14h21
  5. Application Portable sur differents types de BDD
    Par sylvain_2020 dans le forum Décisions SGBD
    Réponses: 11
    Dernier message: 23/09/2003, 12h59

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo