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

ASP.NET Discussion :

Connection à un lecteur smartcard depuis un navigateur internet en utilisant ASP


Sujet :

ASP.NET

  1. #1
    Candidat au Club
    Inscrit en
    Octobre 2010
    Messages
    1
    Détails du profil
    Informations forums :
    Inscription : Octobre 2010
    Messages : 1
    Points : 2
    Points
    2
    Par défaut Connection à un lecteur smartcard depuis un navigateur internet en utilisant ASP
    Bonjour,

    Je souhaite utiliser ASP NET pour me connecter à un lecteur smartcard
    connecté à un PC.

    Principe : Le serveur web founit un asp qui est utilisé en local pour se connecter à un lecteur smartcard.

    J'ai écris le code suivant qui permet de lister les lecteurs pcsc connectés au PC
    via le navigateur lorsqu'on click sur Button1_Click. Cela fonctionne.

    Ma question : les lecteurs smartard listés sont t'ils ceux connectés sur le serveur web ou ceux de mon PC en local ?

    default.aspx :

    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
     
    <%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %>
     
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
     
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title>test</title>
    </head>
    <body>Please enter you login and password below, you will be authenticate        <form id="form1" runat="server">
        <div>
     
        </div>
        <asp:Login ID="Login1" runat="server" onauthenticate="Login1_Authenticate">
        </asp:Login>
        <asp:ListBox ID="ListBox1" runat="server" 
            onselectedindexchanged="ListBox1_SelectedIndexChanged" Width="136px">
        </asp:ListBox>
        <br />
        <br />
        <asp:Button ID="Button1" runat="server" Text="List readers" 
            onclick="Button1_Click" />
        </form>
    </body>
    </html>

    default.aspx.cs

    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
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
     
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Drawing;
    using System.Collections;
    using System.ComponentModel;
    using System.Data;
    // Neded for [DllImport] 
    using System.Runtime.InteropServices;
     
    using System.Windows.Forms;
    using System.Text;
     
    public partial class _Default : System.Web.UI.Page 
    {
        private int nContext;				//Card reader context handle - DWORD
        // private int nCard;
        // private int nActiveProtocol;        //T0/T1 
     
     
        [StructLayout(LayoutKind.Sequential)] 
        internal class SCARD_IO_REQUEST
        {
        internal uint dwProtocol;
        internal int cbPciLength;
        public SCARD_IO_REQUEST()
          {
            dwProtocol = 0;
          }
        }
     
     
        // WinSCard API's to be imported
        [DllImport("WinScard.dll")]
        public static extern int SCardEstablishContext(uint dwScope, int nNotUsed1,
            int nNotUsed2, ref int phContext);
        [DllImport("WinScard.dll")]
        public static extern int SCardReleaseContext(int phContext);
        [DllImport("WinScard.dll")]
        public static extern int SCardConnect(int hContext, string cReaderName,
            uint dwShareMode, uint dwPrefProtocol, ref int phCard, ref int ActiveProtocol);
        [DllImport("WinScard.dll")]
        public static extern int SCardDisconnect(int hCard, int Disposition);
        [DllImport("WinScard.dll")]
        public static extern int SCardListReaderGroups(int hContext, ref string cGroups, ref int nStringSize);
     
        [DllImport("winscard.dll")]
        public static extern int SCardListReaders(int hContext, string cGroups, byte[] cReaderLists, ref int nReaderCount); 
     
        [DllImport("WinScard.dll")]
        public static extern int SCardFreeMemory(int hContext, string cResourceToFree);
        [DllImport("WinScard.dll")]
        public static extern int SCardGetAttrib(int hContext, uint dwAttrId,
            ref byte[] bytRecvAttr, ref int nRecLen);
        [DllImport("winscard.dll")]
        static extern int SCardConnect(int hContext,[MarshalAs(UnmanagedType.LPTStr)] string szReader,
               UInt32 dwShareMode, 
                UInt32 dwPreferredProtocols, 
                out int phCard, 
                out UInt32 pdwActiveProtocol);
     
     
        [DllImport("WinScard.dll")]
        static extern int SCardTransmit(int hCard, IntPtr pioSendPci, byte[] pbSendBuffer, int cbSendLength, SCARD_IO_REQUEST pioRecvPci, 
            byte[] pbRecvBuffer, ref int pcbRecvLength);
     
     
        protected void Page_Load(object sender, EventArgs e)
        {
            MessageBox.Show("start");
        }
        protected void Button1_Click(object sender, EventArgs e)
        {
            // MessageBox.Show("Button click");
            //First step in using smart cards is CSardEstablishContext()
            uint nContext = 2;		//system
            int nNotUsed1 = 0;
            int nNotUsed2 = 0;
            this.nContext = 0;		//handle to context - SCARDCONTEXT
     
            int nRetVal1 = SCardEstablishContext(nContext, nNotUsed1, nNotUsed2, ref this.nContext);
            if (nRetVal1 != 0)
            {
                MessageBox.Show("Error returned by SCardEstablishContext()");
                return;
            }
     
            //next we split up the null delimited strings into a string array
            char[] delimiter = new char[1];
            delimiter[0] = Convert.ToChar(0);
     
            //Next we need to call the  SCardListReaderGroups() to find reader groups to use
            string cGroupList = "" + Convert.ToChar(0);
            int nStringSize = -1;	//SCARD_AUTOALLOCATE
            int nRetVal2 = SCardListReaderGroups(this.nContext, ref cGroupList, ref nStringSize);
            if (nRetVal2 != 0)
            {
                MessageBox.Show("Error returned by SCardListReaderGroups()");
                return;
            }
     
            string[] cGroups = cGroupList.Split(delimiter);
     
            int nReaderCount = -1;
     
            // Get the reader list
    		int nRetVal4 = SCardListReaders(this.nContext, cGroups[0], null, ref nReaderCount);
            if (nRetVal4 != 0)
            {
                MessageBox.Show(" Error returned by SCardListReaders()");
                return;
            }
     
            byte[] cReaderList = new byte[nReaderCount];
     
            nRetVal4 = SCardListReaders(this.nContext, cGroups[0], cReaderList, ref nReaderCount);
            if (nRetVal4 != 0)
            {
                MessageBox.Show(" Error returned by SCardListReaders()");
                return;
            }
     
     
            ASCIIEncoding asc = new ASCIIEncoding();
            String[] cReaders = asc.GetString(cReaderList).Split('\0');
     
            foreach (string cName in cReaders)
            {
                MessageBox.Show("Found Reader Name: " + cName, "Found Reader");
                // listBox1.Items.Add(cName);
            }
    		// listBox1.Items.Clear();
     
     
    	}
        protected void Login1_Authenticate(object sender, AuthenticateEventArgs e)
        {
     
        }
     
        protected void ListBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
     
        }
    }
    Merci.

  2. #2
    Expert éminent
    Avatar de Immobilis
    Homme Profil pro
    Développeur .NET
    Inscrit en
    Mars 2004
    Messages
    6 559
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Bouches du Rhône (Provence Alpes Côte d'Azur)

    Informations professionnelles :
    Activité : Développeur .NET

    Informations forums :
    Inscription : Mars 2004
    Messages : 6 559
    Points : 9 506
    Points
    9 506
    Par défaut
    Salut,

    Pour des questions de sécurité évidente une page web n'a pas plus le droit de se connecter à une smartcard, qu'une web cam, que la souris de ton clavier.

    A+
    "Winter is coming" (ma nouvelle page d'accueil)

  3. #3
    Expert éminent
    Avatar de Webman
    Profil pro
    Inscrit en
    Janvier 2004
    Messages
    1 232
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Janvier 2004
    Messages : 1 232
    Points : 8 154
    Points
    8 154
    Par défaut
    Bonjour,

    Cependant il est possible de réaliser un ActiveX qui pourra accéder au lecteur de carte. Par contre bon courage pour accéder à un lecteur de carte puce (c'est déjà pas simple), mais lire(ou écrire) les informations sur la carte c'est encore moins simple... Ta seule chance c'est d'avoir un driver de lecteur de carte à puce qui possède un bon SDK correctement documenté. Pour avoir un peu travaillé sur ces problématiques je préfère t'avertir, tu te lances dans une belle galère, mais bon c'est la beauté du dev . Bon courage.

    Cordialement,
    Ronald
    Rédacteur .Net
    MVP C#
    Mes articles - CodeQuake (blog)
    Pas de question technique par MP, merci.

  4. #4
    Expert éminent
    Avatar de Webman
    Profil pro
    Inscrit en
    Janvier 2004
    Messages
    1 232
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Janvier 2004
    Messages : 1 232
    Points : 8 154
    Points
    8 154
    Par défaut
    Oups , j'avais lu trop vite, je viens relire ton message et effectivement ton application peut se connecter au lecteur de SmartCard puisque le lecteur se trouve sur la même machine que ton site Web, donc pas de problème de ce côté là. Donc tu peux le faire dans une appli ASP.Net (pas besoin d'ActiveX) mais cela reste pour autant tout aussi galère... Désolé!

    Pour répondre à ta question c'est bien évidemment le lecteur de SmartCard du serveur auquel tu te connectes. Pour te connecter au lecteur de SmartCard du client il te faut un ActiveX (ou peut être avec Silverlight, mais là je ne saurais pas te répondre avec certitude sur ce dernier point).

    Cordialement,
    Ronald
    Rédacteur .Net
    MVP C#
    Mes articles - CodeQuake (blog)
    Pas de question technique par MP, merci.

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Connection sur lecteur en réseau
    Par Benjii dans le forum Paradox
    Réponses: 9
    Dernier message: 01/08/2007, 11h55
  2. Lancement d'un navigateur internet sur une URL SIMPLEMENT
    Par Jean-mich dans le forum Autres Logiciels
    Réponses: 7
    Dernier message: 10/12/2005, 23h46
  3. Télécharger un fichier Zip depuis une adresse internet
    Par jmjmjm dans le forum Web & réseau
    Réponses: 8
    Dernier message: 18/10/2005, 19h12
  4. Editer un XML avec un navigateur internet...
    Par kobe dans le forum APIs
    Réponses: 11
    Dernier message: 17/10/2005, 12h58
  5. Connecter un lecteur reseau
    Par manusweb dans le forum C++Builder
    Réponses: 4
    Dernier message: 03/09/2002, 12h07

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