Sophie

Sophie

distrib > Fedora > 13 > i386 > media > os > by-pkgid > f806c0f24240b25bde21a53f71766070 > files > 1408

erlang-doc-R13B-04.6.fc13.noarch.rpm

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html xmlns:fn="http://www.w3.org/2005/02/xpath-functions">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" href="../../../../doc/otp_doc.css" type="text/css">
<title>Erlang -- The SSL Protocol</title>
</head>
<body bgcolor="white" text="#000000" link="#0000ff" vlink="#ff00ff" alink="#ff0000"><div id="container">
<script id="js" type="text/javascript" language="JavaScript" src="../../../../doc/js/flipmenu/flipmenu.js"></script><script id="js2" type="text/javascript" src="../../../../doc/js/erlresolvelinks.js"></script><script language="JavaScript" type="text/javascript">
            <!--            
              function getWinHeight() {
                var myHeight = 0;
                if( typeof( window.innerHeight ) == 'number' ) {
                  //Non-IE
                  myHeight = window.innerHeight;
                } else if( document.documentElement && ( document.documentElement.clientWidth || 
                                                         document.documentElement.clientHeight ) ) {
                  //IE 6+ in 'standards compliant mode'
                  myHeight = document.documentElement.clientHeight;
                } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
                  //IE 4 compatible
                  myHeight = document.body.clientHeight;
                }
                return myHeight;            
              }

              function setscrollpos() {
                var objf=document.getElementById('loadscrollpos');
                 document.getElementById("leftnav").scrollTop = objf.offsetTop - getWinHeight()/2;
              }

              function addEvent(obj, evType, fn){ 
                if (obj.addEventListener){ 
                obj.addEventListener(evType, fn, true); 
                return true; 
              } else if (obj.attachEvent){ 
                var r = obj.attachEvent("on"+evType, fn); 
                return r; 
              } else { 
                return false; 
              } 
             }

             addEvent(window, 'load', setscrollpos);

             //--></script><div id="leftnav"><div class="innertube">
<img alt="Erlang logo" src="../../../../doc/erlang-logo.png"><br><small><a href="users_guide.html">User's Guide</a><br><a href="index.html">Reference Manual</a><br><a href="release_notes.html">Release Notes</a><br><a href="../pdf/ssl-3.10.8.pdf">PDF</a><br><a href="../../../../doc/index.html">Top</a></small><p><strong>Secure Socket Layer </strong><br><strong>User's Guide</strong><br><small>Version 3.10.8</small></p>
<br><a href="javascript:openAllFlips()">Expand All</a><br><a href="javascript:closeAllFlips()">Contract All</a><p><small><strong>Chapters</strong></small></p>
<ul class="flipMenu" imagepath="../../../../doc/js/flipmenu">
<li id="loadscrollpos" title="The SSL Protocol" expanded="true">The SSL Protocol<ul>
<li><a href="ssl_protocol.html">
              Top of chapter
            </a></li>
<li title="SSL Connections"><a href="ssl_protocol.html#id2254451">SSL Connections</a></li>
<li title="Certificates"><a href="ssl_protocol.html#id2251968">Certificates</a></li>
<li title="Encryption Algorithms"><a href="ssl_protocol.html#id2259644">Encryption Algorithms</a></li>
<li title="SSL Handshake"><a href="ssl_protocol.html#id2252047">SSL Handshake</a></li>
<li title="Authentication"><a href="ssl_protocol.html#id2259261">Authentication</a></li>
</ul>
</li>
<li id="no" title="Using the SSL application" expanded="false">Using the SSL application<ul>
<li><a href="using_ssl.html">
              Top of chapter
            </a></li>
<li title="The ssl Module"><a href="using_ssl.html#id2255101">The ssl Module</a></li>
<li title="A Client-Server Example"><a href="using_ssl.html#id2258745">A Client-Server Example</a></li>
</ul>
</li>
<li id="no" title="PKIX Certificates" expanded="false">PKIX Certificates<ul>
<li><a href="pkix_certs.html">
              Top of chapter
            </a></li>
<li title="Introduction to Certificates"><a href="pkix_certs.html#id2251860">Introduction to Certificates</a></li>
<li title="PKIX Certificates"><a href="pkix_certs.html#id2252755">PKIX Certificates</a></li>
</ul>
</li>
<li id="no" title="Creating Certificates" expanded="false">Creating Certificates<ul>
<li><a href="create_certs.html">
              Top of chapter
            </a></li>
<li title="The openssl Command"><a href="create_certs.html#id2259452">The openssl Command</a></li>
<li title="An Example"><a href="create_certs.html#id2254962">An Example</a></li>
</ul>
</li>
<li id="no" title="Using SSL for Erlang Distribution" expanded="false">Using SSL for Erlang Distribution<ul>
<li><a href="ssl_distribution.html">
              Top of chapter
            </a></li>
<li title="Introduction"><a href="ssl_distribution.html#id2252297">Introduction</a></li>
<li title="Building boot scripts including the SSL application"><a href="ssl_distribution.html#id2252373">Building boot scripts including the SSL application</a></li>
<li title="Specifying distribution module for net_kernel"><a href="ssl_distribution.html#id2252502">Specifying distribution module for net_kernel</a></li>
<li title="Specifying security options and other SSL options"><a href="ssl_distribution.html#id2257266">Specifying security options and other SSL options</a></li>
<li title="Setting up environment to always use SSL"><a href="ssl_distribution.html#id2257363">Setting up environment to always use SSL</a></li>
</ul>
</li>
<li id="no" title="Licenses" expanded="false">Licenses<ul>
<li><a href="licenses.html">
              Top of chapter
            </a></li>
<li title="OpenSSL License"><a href="licenses.html#id2257489">OpenSSL License</a></li>
<li title="SSLeay License"><a href="licenses.html#id2257546">SSLeay License</a></li>
</ul>
</li>
</ul>
</div></div>
<div id="content">
<div class="innertube">
<h1>1 The SSL Protocol</h1>
  
  <p>Here we provide a short introduction to the SSL protocol. We only
    consider those part of the protocol that are important from a
    programming point of view.
    </p>
  <p>For a very good general introduction to SSL and TLS see the book
    rescorla.
    </p>
  <p><strong>Outline:</strong></p>
  <ul>
    <li>Two types of connections - connection: handshake, data transfer, and
     shutdown - 
     SSL/TLS protocol - server must have certificate - what the the
     server sends to the client - client may verify the server -
     server may ask client for certificate - what the client sends to
     the server - server may then verify the client - verification -
     certificate chains - root certificates - public keys - key
     agreement - purpose of certificate - references</li>
  </ul>

  <h3><a name="id2254451">1.1 
        SSL Connections</a></h3>
    
    <p>The SSL protocol is implemented on top of the TCP/IP protocol.
      From an endpoint view it also has the same type of connections
      as that protocol, almost always created by calls to socket
      interface functions <strong>listen</strong>, <strong>accept</strong> and
      <strong>connect</strong>. The endpoints are <strong>servers</strong> and
      <strong>clients</strong>.
      </p>
    <p>A <strong>server</strong><strong>listen</strong>s for connections on a
      specific address and port. This is done once. The server then
      <strong>accept</strong>s each connections on that same address and
      port. This is typically done indefinitely many times.
      </p>
    <p>A <strong>client</strong> connects to a server on a specific address 
      and port. For each purpose this is done once.
      </p>
    <p>For a plain TCP/IP connection the establishment of a connection
      (through an accept or a connect) is followed by data transfer between
      the client and server, finally ended by a connection close. 
      </p>
    <p>An SSL connection also consists of data transfer and connection
      close, However, the data transfer contains encrypted data, and
      in order to establish the encryption parameters, the data
      transfer is preceded by an SSL <strong>handshake</strong>. In this
      handshake the server plays a dominant role, and the main
      instrument used in achieving a valid SSL connection is the
      server's <strong>certificate</strong>. We consider certificates in the
      next section, and the SSL handshake in a subsequent section.</p>
  

  <h3><a name="id2251968">1.2 
        Certificates</a></h3>
    
    <p>A certificate is similar to a driver's license, or a
      passport. The holder of the certificate is called the
      <strong>subject</strong>.  First of all the certificate identifies the
      subject in terms of the name of the subject, its postal address,
      country name, company name (if applicable), etc.
      </p>
    <p>Although a driver's license is always issued by a well-known and
      distinct authority, a certificate may have an <strong>issuer</strong>
      that is not so well-known. Therefore a certificate also always
      contains information on the issuer of the certificate. That
      information is of the same type as the information on the
      subject. The issuer of a certificate also signs the certificate
      with a <strong>digital signature</strong> (the signature is an inherent
      part of the certificate), which allow others to verify that the
      issuer really is the issuer of the certificate.
      </p>
    <p>Now that a certificate can be checked by verifying the
      signature of the issuer, the question is how to trust the
      issuer. The answer to this question is to require that there is
      a certificate for the issuer as well. That issuer has in turn an
      issuer, which must also have a certificate, and so on. This
      <strong>certificate chain</strong> has to have en end, which then must
      be a certificate that is trusted by other means. We shall cover
      this problem of <strong>authentication</strong> in a subsequent
      section.
      </p>
  

  <h3><a name="id2259644">1.3 
        Encryption Algorithms</a></h3>
    
    <p>An encryption algorithm is a mathematical algorithm for
      encryption and decryption of messages (arrays of bytes,
      say). The algorithm as such is always required to be publicly
      known, otherwise its strength cannot be evaluated, and hence it
      cannot be used reliably. The secrecy of an encrypted message is
      not achieved by the secrecy of the algorithm used, but by the
      secrecy of the <strong>keys</strong> used as input to the encryption and
      decryption algorithms. For an account of cryptography in general
      see schneier.
      </p>
    <p>There are two classes of encryption algorithms: <strong>symmetric key</strong> algorithms and <strong>public key</strong> algorithms.  Both
      types of algorithms are used in the SSL protocol.
      </p>
    <p>In the sequel we assume holders of keys keep them secret (except
      public keys) and that they in that sense are trusted. How a 
      holder of a secret key is proved to be the one it claims to be
      is a question of <strong>authentication</strong>, which, in the context
      of the SSL protocol, is described in a section further below.
      </p>

    <h4>Symmetric Key Algorithms</h4>
      
      <p>A <strong>symmetric key</strong> algorithm has one key only. The key
        is used for both encryption and decryption. Obviously the key
        of a symmetric key algorithm must always be kept secret by the
        users of the key. DES is an example of a symmetric key
        algorithm.
        </p>
      <p>Symmetric key algorithms are fast compared to public key
        algorithms. They are therefore typically used for encrypting
        bulk data.
        </p>
    

    <h4>Public Key Algorithms</h4>
      
      <p>A <strong>public key</strong> algorithm has two keys. Any of the two
        keys can be used for encryption. A message encrypted with one
        of the keys, can only be decrypted with the other key. One of
        the keys is public (known to the world), while the other key
        is private (i.e. kept secret) by the owner of the two keys.
        </p>
      <p>RSA is an example of a public key algorithm.
        </p>
      <p>Public key algorithms are slow compared to symmetric key
        algorithms, and they are therefore seldom used for bulk data
        encryption. They are therefore only used in cases where the
        fact that one key is public and the other is private, provides
        features that cannot be provided by symmetric algorithms.
        </p>
    

    <h4>Digital Signature Algorithms</h4>
      
      <p>An interesting feature of a public key algorithm is that its
        public and private keys can both be used for encryption.
        Anyone can use the public key to encrypt a message, and send
        that message to the owner of the private key, and be sure of
        that only the holder of the private key can decrypt the
        message.
        </p>
      <p>On the other hand, the owner of the private key can encrypt a
        message with the private key, thus obtaining an encrypted
        message that can decrypted by anyone having the public key.
        </p>
      <p>The last approach can be used as a digital signature
        algorithm.  The holder of the private key signs an array of
        bytes by performing a specified well-known <strong>message digest algorithm</strong> to compute a hash of the array, encrypts the
        hash value with its private key, an then presents the original
        array, the name of the digest algorithm, and the encryption of
        the hash value as a <strong>signed array of bytes</strong>.
        </p>
      <p>Now anyone having the public key, can decrypt the encrypted
        hash value with that key, compute the hash with the specified
        digest algorithm, and check that the hash values compare equal
        in order to verify that the original array was indeed signed
        by the holder of the private key.
        </p>
      <p>What we have accounted for so far is by no means all that can
        be said about digital signatures (see schneierfor
        further details).
        </p>
    

    <h4>Message Digests Algorithms</h4>
      
      <p>A message digest algorithm is a hash function that accepts 
        an array bytes of arbitrary but finite length of input, and 
        outputs an array of bytes of fixed length. Such an algorithm
        is also required to be very hard to invert.  
        </p>
      <p>MD5 (16 bytes output) and SHA1 (20 bytes output) are examples
        of message digest algorithms.
        </p>
    
  

  <h3><a name="id2252047">1.4 
        SSL Handshake</a></h3>
    
    <p>The main purpose of the handshake performed before an an SSL
      connection is established is to negotiate the encryption
      algorithm and key to be used for the bulk data transfer between
      the client and the server. We are writing <strong>the</strong> key,
      since the algorithm to choose for bulk encryption one of the
      symmetric algorithms.
      </p>
    <p>There is thus only one key to agree upon, and obviously that
      key has to be kept secret between the client and the server. To
      obtain that the handshake has to be encrypted as well.
      </p>
    <p>The SSL protocol requires that the server always sends its
      certificate to the client in the beginning of the handshake. The
      client then retrieves the server's public key from the
      certificate, which means that the client can use the server's
      public key to encrypt messages to the server, and the server can
      decrypt those messages with its private key. Similarly, the
      server can encrypt messages to the client with its private key,
      and the client can decrypt messages with the server's public
      key. It is thus is with the server's public and private keys
      that messages in the handshake are encrypted and decrypted, and
      hence the key agreed upon for symmetric encryption of bulk data
      can be kept secret (there are more things to consider to really
      keep it secret, see rescorla).
      </p>
    <p>The above indicates that the server does not care who is
      connecting, and that only the client has the possibility to
      properly identify the server based on the server's certificate.
      That is indeed true in the minimal use of the protocol, but it
      is possible to instruct the server to request the certificate of
      the client, in order to have a means to identify the client, but
      it is by no means required to establish an SSL connection.
      </p>
    <p>If a server request the client certificate, it verifies, as a
      part of the protocol, that the client really holds the private
      key of the certificate by sending the client a string of bytes
      to encrypt with its private key, which the server then decrypts
      with the client's public key, the result of which is compared
      with the original string of bytes (a similar procedure is always
      performed by the client when it has received the server's
      certificate).
      </p>
    <p>The way clients and servers <strong>authenticate</strong> each other,
      i.e. proves that their respective peers are what they claim to
      be, is the topic of the next section.
      </p>
  

  <h3><a name="id2259261">1.5 
        Authentication</a></h3>
    
    <p>As we have already seen the reception of a certificate from a
      peer is not enough to prove that the peer is authentic. More
      certificates are needed, and we have to consider how certificates
      are issued and on what grounds.
      </p>
    <p>Certificates are issued by <strong>certification authorities</strong>
      (<strong>CA</strong>s) only. They issue certificates both for other CAs
      and ordinary users (which are not CAs). 
      </p>
    <p>Certain CAs are <strong>top CAs</strong>, i.e. they do not have a
      certificate issued by another CA. Instead they issue their own
      certificate, where the subject and issuer part of the
      certificate are identical (such a certificate is called a
      self-signed certificate). A top CA has to be well-known, and has
      to have a publicly available policy telling on what grounds it
      issues certificates. 
      </p>
    <p>There are a handful of top CAs in the world. You can examine the
      certificates of several of them by clicking through the menus of
      your web browser. 
      </p>
    <p>A top CA typically issues certificates for other CAs, called
      <strong>intermediate CAs</strong>, but possibly also to ordinary users. Thus
      the certificates derivable from a top CA constitute a tree, where
      the leaves of the tree are ordinary user certificates. 
      </p>
    <p>A <strong>certificate chain</strong> is an ordered sequence of
      certificates, <span class="code">C1, C2, ..., Cn</span>, say, where <span class="code">C1</span> is a
      top CA certificate, and where <span class="code">Cn</span> is an ordinary user
      certificate, and where the holder of <span class="code">C1</span> is the issuer of
      <span class="code">C2</span>, the holder of <span class="code">C2</span> is the issuer of <span class="code">C3</span>,
      ..., and the holder of <span class="code">Cn-1</span> is the issuer of <span class="code">Cn</span>,
      the ordinary user certificate. The holders of <span class="code">C2, C3, ..., Cn-1</span> are then intermediate CAs.
      </p>
    <p>Now to verify that a certificate chain is unbroken we have to
      take the public key from each certificate <span class="code">Ck</span>, and apply
      that key to decrypt the signature of certificate <span class="code">Ck-1</span>,
      thus obtaining the message digest computed by the holder of the
      <span class="code">Ck</span> certificate, compute the real message digest of the
      <span class="code">Ck-1</span> certificate and compare the results. If they compare
      equal the link of the chain between <span class="code">Ck</span> and <span class="code">Ck-1</span> is
      considered to unbroken. This is done for each link k = 1, 2,
      ..., n-1. If all links are found to be unbroken, the user
      certificate <span class="code">Cn</span> is considered authenticated.
      </p>

    <h4>Trusted Certificates</h4>
      
      <p>Now that there is a way to authenticate a certificate by
        checking that all links of a certificate chain are unbroken,
        the question is how you can be sure to trust the certificates
        in the chain, and in particular the top CA certificate of the
        chain.
        </p>
      <p>To provide an answer to that question consider the
        perspective of a client, which have just received the
        certificate of the server. In order to authenticate the server
        the client has to construct a certificate chain and to prove
        that the chain is unbroken. The client has to have a set of CA
        certificates (top CA or intermediate CA certificates) not
        obtained from the server, but obtained by other means. Those
        certificates are kept <span class="code">locally</span> by the client, and are 
        trusted by the client.
        </p>
      <p>More specifically, the client does not really have to have
        top CA certificates in its local storage. In order to
        authenticate a server it is sufficient for the client to
        posses the trusted certificate of the issuer of the server
        certificate.
        </p>
      <p>Now that is not the whole story. A server can send an
        (incomplete) certificate chain to its client, and then the
        task of the client is to construct a certificate chain that
        begins with a trusted certificate and ends with the server's
        certificate. (A client can also send a chain to its server, 
        provided the server requested the client's certificate.)
        </p>
      <p>All this means that an unbroken certificate chain begins with
        a trusted certificate (top CA or not), and ends with the peer
        certificate. That is the end of the chain is obtained from the
        peer, but the beginning of the chain is obtained from local
        storage, which is considered trusted.
        </p>
    
  
</div>
<div class="footer">
<hr>
<p>Copyright © 1999-2010 Ericsson AB. All Rights Reserved.</p>
</div>
</div>
</div></body>
</html>