Add csharp guide for Smartcard 81/152681/5
authorjh8801.jung <jh8801.jung@samsung.com>
Wed, 27 Sep 2017 01:25:06 +0000 (10:25 +0900)
committersaerome kim <saerome.kim@samsung.com>
Tue, 10 Oct 2017 01:28:36 +0000 (01:28 +0000)
PS3: Reviewed
PS4: Modified text in image to make it work for both native and .NET

Signed-off-by: jh8801.jung <jh8801.jung@samsung.com>
Change-Id: I87f03a425866862b86fa82dad3a1c47b3077ad1a

org.tizen.guides/html/dotnet/connectivity/smartcard_cs.htm [new file with mode: 0644]
org.tizen.guides/html/images/smartcard_architecture.png

diff --git a/org.tizen.guides/html/dotnet/connectivity/smartcard_cs.htm b/org.tizen.guides/html/dotnet/connectivity/smartcard_cs.htm
new file mode 100644 (file)
index 0000000..b7af5da
--- /dev/null
@@ -0,0 +1,299 @@
+<!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" xml:lang="en" lang="en">
+<head>
+    <meta http-equiv="content-type" content="text/html; charset=utf-8"/>
+    <meta http-equiv="X-UA-Compatible" content="IE=9" />
+    <link rel="stylesheet" type="text/css" href="../../css/styles.css" />
+    <link rel="stylesheet" type="text/css" href="../../css/snippet.css" />
+    <script type="text/javascript" src="../../scripts/snippet.js"></script>
+    <script type="text/javascript" src="../../scripts/jquery.util.js" charset="utf-8"></script>
+    <script type="text/javascript" src="../../scripts/common.js" charset="utf-8"></script>
+    <script type="text/javascript" src="../../scripts/core.js" charset="utf-8"></script>
+    <script type="text/javascript" src="../../scripts/search.js" charset="utf-8"></script>
+  <title>Smart Card</title>
+ </head>
+ <body onload="prettyPrint()" style="overflow: auto;">
+
+ <div id="toc-navigation">
+    <div id="toc_border"><div id="toc">
+               <p class="toc-title">Dependencies</p>
+               <ul class="toc">
+                       <li>Tizen 4.0 and Higher</li>
+               </ul>
+               <p class="toc-title">Content</p>
+               <ul class="toc">
+                       <li><a href="#prerequisites">Prerequisites</a></li>
+                       <li><a href="#manager">Retrieving Readers</a></li>
+                       <li><a href="#reader">Managing the Reader</a></li>
+                       <li><a href="#session">Managing Sessions</a></li>
+                       <li><a href="#channel">Managing Channels</a></li>
+               </ul>
+        <p class="toc-title">Related Info</p>
+        <ul class="toc">
+                       <li><a href="https://developer.tizen.org/dev-guide/csapi/namespaceTizen_1_1Network_1_1Smartcard.html">Tizen.Network.Smartcard Namespace</a></li>
+               </ul>
+    </div></div>
+</div>
+
+<div id="container"><div id="contents"><div class="content">
+<h1>Smart Card</h1>
+
+<p>You can use smart card functionalities, such as accessing a secure element (SE). Before using the Tizen.Network.Smartcard namespace, make sure you have an SE in the device. The smart card service allows you to open a session on an SE, open a channel to the applet in the SE, send a command to the channel, and finally receive a response to the command.</p>
+
+<p>The main features of the Tizen.Network.Smartcard namespace include:</p>
+
+<ul>
+    <li>Smart card reader
+       <p>The <a href="https://developer.tizen.org/dev-guide/csapi/classTizen_1_1Network_1_1Smartcard_1_1SmartcardManager.html">Tizen.Network.Smartcard.SmartcardManager</a> class allows you to <a href="#manager">get the available readers</a>. Each reader functions as a connector to the SE framework system.</p>
+       <p>The <a href="https://developer.tizen.org/dev-guide/csapi/classTizen_1_1Network_1_1Smartcard_1_1SmartcardReader.html">Tizen.Network.Smartcard.SmartcardReader</a> class allows you to access the SE connected with the selected reader. You can <a href="#reader">get the reader name and open and close sessions</a>.</p>
+    </li>
+    <li>Smart card session
+       <p>A session is an open connection between an application on the device and an SE.</p>
+       <p>The <a href="https://developer.tizen.org/dev-guide/csapi/classTizen_1_1Network_1_1Smartcard_1_1SmartcardSession.html">Tizen.Network.Smartcard.SmartcardSession</a> class allows you to <a href="#session">open and close basic and logical channels</a>, and get ATR (answer to reset).</p>
+    </li>
+    <li>Smart card channel
+       <p>A channel is an open connection between an application on the device and an applet on the SE.</p>
+       <p>The <a href="https://developer.tizen.org/dev-guide/csapi/classTizen_1_1Network_1_1Smartcard_1_1SmartcardChannel.html">Tizen.Network.Smartcard.SmartcardChannel</a> class allows you to <a href="#channel">close channels and transmit application protocol data units</a> (APDU).</p>
+    </li>
+</ul>
+
+<p>The following figure illustrates the smart card service architecture in Tizen. The Smartcard service sends and receives data through the terminal of each SE.</p>
+<p align="center"><strong>Figure: Smart card service architecture</strong></p>
+<p align="center"> <img alt="Smart card service architecture" src="../../images/smartcard_architecture.png" /> </p>
+
+<p>The Tizen.Network.Smartcard namespace is a reference implementation of the SIMalliance Open Mobile 3.0 API specification that enables Tizen applications to communicate with secure elements. For more information, see the <a href="http://simalliance.org/" target="_blank">SimAlliance</a>.</p>
+<p>The Tizen implementation differs from the original, since only the transport layer is provided. There is no service layer support in Tizen.</p>
+
+
+<h2 id="prerequisites">Prerequisites</h2>
+
+<p>To enable your application to use the smart card functionality:</p>
+<ol>
+       <li>To use the <a href="https://developer.tizen.org/dev-guide/csapi/namespaceTizen_1_1Network_1_1Smartcard.html">Tizen.Network.Smartcard</a> namespace, the application has to request permission by adding the following privilege to the <code>tizen-manifest.xml</code> file:
+<pre class="prettyprint">
+&lt;privileges&gt;
+   &lt;privilege&gt;http://tizen.org/privilege/secureelement&lt;/privilege&gt;
+&lt;/privileges&gt;
+</pre>
+       </li>
+       <li>To use the methods and properties of the Tizen.Network.Smartcard namespace, include it in your application:
+<pre class="prettyprint">
+using Tizen.Network.Smartcard;
+</pre>
+       </li>
+</ol>
+
+<h2 id="manager">Retrieving Readers</h2>
+
+<p>To retrieve the available smart card readers, use the <code>GetReaders()</code> method of the <a href="https://developer.tizen.org/dev-guide/csapi/classTizen_1_1Network_1_1Smartcard_1_1SmartcardManager.html">Tizen.Network.Smartcard.SmartcardManager</a> class:</p>
+<pre class="prettyprint">
+public static void GetReaders_RETURN_LIST_OF_READERS()
+{
+    try
+    {
+        var count = 0;
+        <span class="highlight">readers = SmartcardManager.GetReaders();</span>
+
+        foreach (SmartcardReader reader in readers)
+        {
+            count++;
+        }
+
+        Assert.Greater(count, 0, "The reader count should be greater than 0");
+    }
+    catch (NotSupportedException)
+    {
+        Assert.IsTrue(isSupported == false, "Method throws the NotSupportedException, but Tizen supports the smart card operation");
+    }
+    catch (Exception ex)
+    {
+        Assert.True(false, "Exception occurs. Msg: " + ex.ToString());
+    }
+}
+</pre>
+
+ <h2 id="reader">Managing the Reader</h2>
+
+<p>To manage a reader:</p>
+
+<ol>
+       <li>Retrieve the name of the reader with the <code>Name</code> property of the <a href="https://developer.tizen.org/dev-guide/csapi/classTizen_1_1Network_1_1Smartcard_1_1SmartcardReader.html">Tizen.Network.Smartcard.SmartcardReader</a> class:
+<pre class="prettyprint">
+public static void Name_READ_ONLY()
+{
+    try
+    {
+        readers = SmartcardManager.GetReaders();
+
+        foreach (SmartcardReader reader in readers)
+        {
+            Assert.IsInstanceOf&lt;string&gt;(reader.Name);
+            Assert.IsNotNull(reader.Name, "Reader Name should be not null.");
+</pre>
+       </li>
+       <li>Before establishing a session, use the <code>IsSecureElementPresent</code> property of the <code>Tizen.Network.Smartcard.SmartcardReader</code> class to make sure that the SE is present in the reader:
+<pre class="prettyprint">
+            Assert.IsInstanceOf&lt;bool&gt;(reader.IsSecureElementPresent);
+            Assert.True(reader.IsSecureElementPresent, "IsSecureElementPresent property should be true.");
+
+            if (reader.IsSecureElementPresent == false)
+            {
+                Assert.True(false, "SecureElement is not present on the reader with the name, " + reader.Name);
+
+                return;
+            }
+</pre>
+       </li>
+       <li>Open a session to connect to the SE in the reader using the <code>OpenSession()</code> method of the <code>Tizen.Network.Smartcard.SmartcardReader</code> class.
+       <p>When you no longer need the reader, use the <code>CloseSessions()</code> method to close all sessions opened on the specific reader.</p>
+<pre class="prettyprint">
+            SmartcardSession session = reader.OpenSession();
+            Assert.IsNotNull(session, "Session should be not null");
+
+            reader.CloseSessions();
+        }
+    }
+    catch (NotSupportedException)
+    {
+        Assert.IsTrue(isSupported == false, "Method throws the NotSupportedException, but Tizen supports the smart card operation");
+    }
+    catch (Exception ex)
+    {
+        Assert.True(false, "Exception occurs. Msg: " + ex.ToString());
+    }
+}
+</pre>
+       </li>
+</ol>
+
+ <h2 id="session">Managing Sessions</h2>
+
+<p>You can manage a session using the <a href="https://developer.tizen.org/dev-guide/csapi/classTizen_1_1Network_1_1Smartcard_1_1SmartcardSession.html">Tizen.Network.Smartcard.SmartcardSession</a> instance that you have created when opening the session with a reader.</p>
+<p>To manage sessions:</p>
+
+<ul>
+       <li>Retrieve the reader that provides the session:
+<pre class="prettyprint">
+/// Open a session
+SmartcardSession session = reader.OpenSession();
+
+Assert.IsInstanceOf&lt;SmartcardReader&gt;(session.Reader);
+Assert.IsNotNull(session.Reader, "Session.Reader value should be not null.");
+Assert.True(session.Reader == reader, "Session.Reader value should be equal to reader");
+</pre>
+       </li>
+       <li>Retrieve the answer to reset (ATR) value of the SE with the <code>Atr</code> property of the <code>Tizen.Network.Smartcard.SmartcardSession</code> class:
+<pre class="prettyprint">
+/// Open a session
+SmartcardSession session = reader.OpenSession();
+
+Assert.IsInstanceOf&lt;byte[]&gt;(session.Atr);
+Assert.IsNotNull(session.Atr, "Session Atr should be not null.");
+</pre>
+</li>
+       <li>To open and close basic and logical channels:
+               <ol>
+                       <li>A basic channel is defined in the ISO/IEC 7816-4 specification (the one that has number 0). To open a logical channel with the SE, you must select the applet represented by the given application ID (AID).
+                       <p>To open a logical channel, use the <code>OpenLogicalChannel()</code> method of the <code>Tizen.Network.Smartcard.SmartcardSession</code> class:</p>
+
+<pre class="prettyprint">
+/// Open a session
+SmartcardSession session = reader.OpenSession();
+
+byte[] aid = new byte[3]{0x04, 0x05, 0x06};
+byte p2 = 0x00;
+
+session.OpenLogicalChannel(aid, p2);
+</pre>
+                       </li>
+                       <li>To close all channels opened for a specific session, use the <code>CloseChannels()</code> method:
+<pre class="prettyprint">
+session.CloseChannels();
+</pre>
+                       </li>
+               </ol>
+       </li>
+       <li>Close a session and check that it is truly closed:
+<pre class="prettyprint">
+/// Open a session
+SmartcardSession session = reader.OpenSession();
+
+Assert.IsInstanceOf&lt;bool&gt;(session.IsClosed);
+Assert.IsFalse(session.IsClosed, "session IsClosed should be not true.");
+</pre>
+       </li>
+</ul>
+
+<h2 id="channel">Managing Channels</h2>
+
+<p>You can manage a channel using the <a href="https://developer.tizen.org/dev-guide/csapi/classTizen_1_1Network_1_1Smartcard_1_1SmartcardChannel.html">Tizen.Network.Smartcard.SmartcardChannel</a> instance that you have created when opening the channel with a session.</p>
+<p>To manage channels:</p>
+
+<ul>
+       <li>Retrieve the session that opened a specific channel by using the <code>Session</code> property of the <code>Tizen.Network.Smartcard.SmartcardChannel</code> class:
+<pre class="prettyprint">
+/// Open a session and channel
+SmartcardSession session = reader.OpenSession();
+byte[] aid = new byte[3]{0x04, 0x05, 0x06};
+byte p2 = 0x00;
+
+SmartcardChannel channel = session.OpenLogicalChannel(aid, p2);
+
+/// Retrieve the channel session information
+Assert.IsTrue(session == channel.Session, "session should be equal to channel.Session");
+</pre>
+       </li>
+       <li>To close the channel opened for a specific SE, use the <code>Close()</code> method of the <code>Tizen.Network.Smartcard.SmartcardChannel</code> class:
+<pre class="prettyprint">
+/// Open a session and channel
+SmartcardSession session = reader.OpenSession();
+byte[] aid = new byte[3]{0x04, 0x05, 0x06};
+byte p2 = 0x00;
+
+SmartcardChannel channel = session.OpenLogicalChannel(aid, p2);
+Assert.IsTrue(channel.IsClosed == false, "channel.IsClosed should be false when channel is open");
+
+/// Close the channel
+channel.Close();
+Assert.IsTrue(channel.IsClosed == true, "channel.IsClosed should be true when channel is closed");
+</pre>
+       </li>
+       <li>To transmit an APDU command (as per ISO/IEC 7816-4) to the SE, use the <code>Transmit()</code> method:
+<pre class="prettyprint">
+/// Open a session and channel
+SmartcardSession session = reader.OpenSession();
+byte[] aid = new byte[3]{0x04, 0x05, 0x06};
+byte p2 = 0x00;
+
+SmartcardChannel channel = session.OpenLogicalChannel(aid, p2);
+byte[] selectCmd = new byte[8]{0x00, 0xA4, 0x04, 0x00, 0x03, 0x0A, 0x0B, 0x0C};
+
+/// Transmit the command
+channel.Transmit(selectCmd);
+</pre>
+       </li>
+</ul>
+
+<script type="text/javascript" src="../../scripts/jquery.zclip.min.js"></script>
+<script type="text/javascript" src="../../scripts/showhide.js"></script>
+</div></div></div>
+
+<a class="top sms" href="#"><img src="../../images/btn_top.gif" alt="Go to top" /></a>
+
+<div id="footer">
+<p class="footer">Except as noted, this content - excluding the Code Examples - is licensed under <a href="http://creativecommons.org/licenses/by/3.0/legalcode" target="_blank">Creative Commons Attribution 3.0</a> and all of the Code Examples contained herein are licensed under <a href="https://www.tizen.org/bsd-3-clause-license" target="_blank">BSD-3-Clause</a>.<br/>For details, see the <a href="https://www.tizen.org/content-license" target="_blank">Content License</a>.</p>
+</div>
+
+<script type="text/javascript">
+var _gaq = _gaq || [];
+_gaq.push(['_setAccount', 'UA-25976949-1']);
+_gaq.push(['_trackPageview']);
+(function() {
+var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
+ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
+var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
+})();
+</script>
+
+</body>
+</html>
index cee4642..f3ca756 100644 (file)
Binary files a/org.tizen.guides/html/images/smartcard_architecture.png and b/org.tizen.guides/html/images/smartcard_architecture.png differ