<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Blog do Finger &#187; certificado digital</title>
	<atom:link href="http://leandrofinger.com/tag/certificado-digital/feed/" rel="self" type="application/rss+xml" />
	<link>http://leandrofinger.com</link>
	<description>Conhecimento nunca é demais!</description>
	<lastBuildDate>Fri, 26 Jun 2009 19:12:47 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1-alpha</generator>
		<item>
		<title>Apache com SSL (Https)</title>
		<link>http://leandrofinger.com/2009/04/25/apache-com-ssl-https/</link>
		<comments>http://leandrofinger.com/2009/04/25/apache-com-ssl-https/#comments</comments>
		<pubDate>Sun, 26 Apr 2009 01:06:36 +0000</pubDate>
		<dc:creator>Finger</dc:creator>
				<category><![CDATA[Apache]]></category>
		<category><![CDATA[certificado digital]]></category>
		<category><![CDATA[https]]></category>
		<category><![CDATA[segurança]]></category>
		<category><![CDATA[ssl]]></category>

		<guid isPermaLink="false">http://leandrofinger.com/?p=27</guid>
		<description><![CDATA[Olá pessoal, Neste vou descrever os passos para criar um certificado digital e configurar o Apache para trabalhar com SSL. Semana passada executei este procedimento em um Linux Debian Lenny e hoje vou mostrar com base no Ubuntu Hardy. Supondo que você já está com o Apache2 instalado, vamos instalar o pacote openssl. Abra um [...]]]></description>
			<content:encoded><![CDATA[<p>Olá pessoal,<br />
Neste vou descrever os passos para criar um certificado digital e configurar o Apache para trabalhar com SSL. Semana passada executei este procedimento em um Linux Debian Lenny e hoje vou mostrar com base no Ubuntu Hardy.</p>
<p>Supondo que você já está com o Apache2 instalado, vamos instalar o pacote openssl. Abra um terminal e digite o seguinte comando:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">apt-get</span> <span style="color: #c20cb9; font-weight: bold;">install</span> openssl</pre></div></div>

<p>Depois vamos criar um diretório para salvar nosso certificado.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">mkdir</span> <span style="color: #660033;">-p</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>apache2<span style="color: #000000; font-weight: bold;">/</span>certs
<span style="color: #7a0874; font-weight: bold;">cd</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>apache2<span style="color: #000000; font-weight: bold;">/</span>certs</pre></div></div>

<p>Agora chegamos ao certificado. Nós só precisaremos de um dos dois comandos abaixo, o primeiro deles gera um certificado protegido por uma frase secreta e o segundo não, a diferença está no parâmetro <em>-des3</em>. No meu caso eu utilizei o segundo deles, pois caso você precise reiniciar o apache ou a máquina, esta a frase secreta lhe será solicitada e no caso de um restart acidental do servidor, o apache não iniciará o serviço enquanto este frase não for digitada.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> openssl genrsa <span style="color: #660033;">-des3</span> <span style="color: #660033;">-out</span> server.key <span style="color: #000000;">1024</span></pre></div></div>

<p>ou</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> openssl genrsa  <span style="color: #660033;">-out</span> server.key <span style="color: #000000;">1024</span></pre></div></div>

<p>Digite o comando <em>ls</em> e verifique se o arquivo server.key foi criado. Se não, execute novamente o passo anterior, caso contrário, continuamos. Este próximo comando irá gerar o certificado com base na chave gerada pelo comando anterior.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> openssl req <span style="color: #660033;">-new</span> <span style="color: #660033;">-x509</span> <span style="color: #660033;">-days</span> <span style="color: #000000;">1825</span> <span style="color: #660033;">-key</span> server.key <span style="color: #660033;">-out</span> server.crt</pre></div></div>

<p>Nesse comando você deve ter notado o parâmetro <em>-days 1825</em>, isso significa que a validade do seu certificado é de 1825 dias ou 5 anos, você pode alterar esse valor mas não é recomendável aumentar mais que isso. Continuando&#8230;&#8230;. Responda o questionário com as informações do certificado.</p>

<div class="wp_syntax"><div class="code"><pre class="none" style="font-family:monospace;">You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [AU]:BR
State or Province Name (full name) [Some-State]:Paraná
Locality Name (eg, city) []:Curitiba
Organization Name (eg, company) [Internet Widgits Pty Ltd]:FingerHome
Organizational Unit Name (eg, section) []:Bedroom
Common Name (eg, YOUR name) []:Leandro Finger Romanovski
Email Address []:eu@leandrofinger.com</pre></div></div>

<p>Digite novamente o comando <em>ls</em> e verifique agora se o arquivo server.crt foi criado. Pronto, esse é o nosso certificado. Agora vamos configurar o Apache para utilizá-lo. Vá até o diretório sites-available e edite um arquivo novo com o nome do seu site.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">cd</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>apache2<span style="color: #000000; font-weight: bold;">/</span>sites-available<span style="color: #000000; font-weight: bold;">/</span>
<span style="color: #c20cb9; font-weight: bold;">sudo</span> gedit meusite-ssl</pre></div></div>

<p>Esse arquivo deve conter as informações do nosso site.</p>

<div class="wp_syntax"><div class="code"><pre class="apache" style="font-family:monospace;">&lt;<span style="color: #000000; font-weight:bold;">VirtualHost</span> *:<span style="color: #ff0000;">443</span>&gt;
	<span style="color: #00007f;">Servername</span> www.meudominio.com.br
	<span style="color: #00007f;">ServerAdmin</span> admin@meudominio.com.br
	<span style="color: #00007f;">DocumentRoot</span> /var/www/
	<span style="color: #00007f;">CustomLog</span> /var/log/apache2/access_ssl.log combined
	<span style="color: #00007f;">ErrorLog</span> /var/log/apache2/error_ssl.log
	<span style="color: #00007f;">LogLevel</span> notice
        SSLEngine <span style="color: #0000ff;">on</span>
        SSLCertificateFile /etc/apache2/certs/server.crt
        SSLCertificateKeyFile /etc/apache2/certs/server.key
        <span style="color: #00007f;">ServerSignature</span> <span style="color: #0000ff;">On</span>
	&lt;<span style="color: #000000; font-weight:bold;">Directory</span> /var/www/&gt;
		<span style="color: #00007f;">Options</span> <span style="color: #0000ff;">Indexes</span> <span style="color: #0000ff;">FollowSymLinks</span> MultiViews
		<span style="color: #00007f;">AllowOverride</span> <span style="color: #0000ff;">None</span>
		<span style="color: #00007f;">Order</span> <span style="color: #00007f;">allow</span>,<span style="color: #00007f;">deny</span>
		<span style="color: #00007f;">allow</span> <span style="color: #00007f;">from</span> <span style="color: #00007f;">all</span>
	&lt;/<span style="color: #000000; font-weight:bold;">Directory</span>&gt;
&lt;/<span style="color: #000000; font-weight:bold;">VirtualHost</span>&gt;
&nbsp;
<span style="color: #00007f;">Alias</span> / /var/www/blog/
&lt;<span style="color: #000000; font-weight:bold;">Location</span> /&gt;
	SSLRequireSSL
	<span style="color: #00007f;">ErrorDocument</span> <span style="color: #ff0000;">403</span> https://www.meudominio.com.br/
&lt;/<span style="color: #000000; font-weight:bold;">Location</span>&gt;</pre></div></div>

<p>Salve e feche o arquivo. Agora vamos habilitar o módulo de SSL no Apache. No terminal digite o comando abaixo.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> a2enmod ssl</pre></div></div>

<p>Verifique no arquivo ports.conf se o apache está habilitado para escutar na porta 443, a porta padrão para Https.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> gedit <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>apache2<span style="color: #000000; font-weight: bold;">/</span>ports.conf</pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="apache" style="font-family:monospace;"><span style="color: #00007f;">Listen</span> <span style="color: #ff0000;">80</span>
&nbsp;
<span style="color: #00007f;">Listen</span> <span style="color: #ff0000;">443</span></pre></div></div>

<p>Agora é só reiniciar o Apache e tudo certo.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> apache2ctl restart</pre></div></div>

<p>Grande abraço.</p>
]]></content:encoded>
			<wfw:commentRss>http://leandrofinger.com/2009/04/25/apache-com-ssl-https/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
