Blog jubilado de Paco Ros

Fue bonito mientras duró

Archive for abril 2008

No pulses el botón

Posted by Paco Ros en 27 \27\+01:00 abril \27\+01:00 2008

Visto en http://dharma.co.uk/

Posted in Varios | Leave a Comment »

Configurar postfix para que envíe correo a través del SMTP de GMail

Posted by Paco Ros en 14 \14\+01:00 abril \14\+01:00 2008

Hace tiempo, no había ningún problema en tener un servidor SMTP en la red local para el envío de correo.
Si el servidor estaba en marcha las 24h, era una buena opción porque el correo se enviaba casi de inmediato hacia la cola del servidor y nos despreocupábamos.

De un tiempo hacia acá, con la proliferación de las IPs dinámicas y las «black lists» cada vez era más habitual que te tocara una IP de un PC zombie que había sido usado para enviar SPAM, con lo cual la mayoría de los servidores de correo rechazaban en envío.

La solución temporal que me fue más cómoda pasó por configurar directamente el SMTP de GMail en todos los clientes de correo, pero me tenía que «comer» todo el correo local además de algunos otros correos. La cosa funcionaba, pero claramente desorganizada.

Estuve buscando y rebuscando y haciendo pruebas y al fin funcionó. Me alegraré de que estos pasos le sean útiles a alguien más, pero me los pongo aquí como recordatorio personal por si tengo que repetir la jugada un día.

Paso 1: Crear un directorio de trabajo (que al final eliminaremos)


paco@nena:~$ cd /tmp
paco@nena:/tmp$ mkdir cert
paco@nena:/tmp$ cd cert

Paso 2: Creamos una autoridad de certificación (se crea en un directorio demoCA)


paco@nena:/tmp/cert$ /usr/lib/ssl/misc/CA.pl -newca

Salida:

CA certificate filename (or enter to create)


Making CA certificate ...
Generating a 1024 bit RSA private key
.......++++++
......................................................++++++
unable to write 'random state'
writing new private key to './demoCA/private/cakey.pem'
Enter PEM pass phrase:
Verifying - Enter PEM pass phrase:
-----
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]:ES
State or Province Name (full name) [Some-State]:Balearic Islands
Locality Name (eg, city) []:
Organization Name (eg, company) [Internet Widgits Pty Ltd]:Nombre y Apellidos
Organizational Unit Name (eg, section) []:
Common Name (eg, YOUR name) []:Nombre y Apellidos
Email Address []:usuario_gmail@gmail.com


Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:
An optional company name []:
Using configuration from /usr/lib/ssl/openssl.cnf
Enter pass phrase for ./demoCA/private/cakey.pem:
Check that the request matches the signature
Signature ok
Certificate Details:
Serial Number:
xx:xx:xx:xx:xx:xx:xx:xx
Validity
Not Before: Apr 14 07:34:14 2008 GMT
Not After : Apr 14 07:34:14 2011 GMT
Subject:
countryName = ES
stateOrProvinceName = Balearic Islands
organizationName = Nombre y Apellidos
commonName = Nombre y Apellidos
emailAddress = usuario_gmail@gmail.com
X509v3 extensions:
X509v3 Subject Key Identifier:
xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx
X509v3 Authority Key Identifier:
keyid:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx
DirName:/C=ES/ST=Balearic Islands/O=Paco Ros/CN=Nombre y Apellidos/emailAddress=usuario_gmail@gmail.com
serial:xx:xx:xx:xx:xx:xx:xx:xx


X509v3 Basic Constraints:
CA:TRUE
Certificate is to be certified until Apr 14 07:34:14 2011 GMT (1095 days)


Write out database with 1 new entries
Data Base Updated

Paso 3: Crear el certificado que usaremos con Postfix en el servidor (se pega en una sola línea):


paco@nena:/tmp/cert$ openssl req -new -nodes -subj '/CN=casa.pacoros.net/O=Nombre y Apellidos/C=ES/ST=Balearic Islands/L=/emailAddress=usuario_gmail@gmail.com' -keyout cert-key.pem -out cert-req.pem -days 3650

Salida:

Generating a 1024 bit RSA private key
..........................................................................................................++++++
..............++++++
unable to write 'random state'
writing new private key to 'cert-key.pem'

Paso 4: Firmar el certificado usando la CA creada en el paso 2:


paco@nena:/tmp/cert$ openssl ca -out cert.pem -infiles cert-req.pem

Salida:

Using configuration from /usr/lib/ssl/openssl.cnf
Enter pass phrase for ./demoCA/private/cakey.pem:
Check that the request matches the signature
Signature ok
Certificate Details:
Serial Number:
xx:xx:xx:xx:xx:xx:xx:xx
Validity
Not Before: Apr 14 07:39:47 2008 GMT
Not After : Apr 14 07:39:47 2009 GMT
Subject:
countryName = ES
stateOrProvinceName = Balearic Islands
organizationName = Nombre y Apellidos
commonName = casa.pacoros.net
emailAddress = usuario_gmail@gmail.com
X509v3 extensions:
X509v3 Basic Constraints:
CA:FALSE
Netscape Comment:
OpenSSL Generated Certificate
X509v3 Subject Key Identifier:
xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx
X509v3 Authority Key Identifier:
keyid:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx


Certificate is to be certified until Apr 14 07:39:47 2009 GMT (365 days)
Sign the certificate? [y/n]:y


1 out of 1 certificate requests certified, commit? [y/n]y
Write out database with 1 new entries
Data Base Updated

Paso 5: Bajar el certificado raíz de Thawte y guardarlo en un directorio «root»


paco@nena:/tmp/cert$ mkdir root
paco@nena:/tmp/cert$ cd root/
paco@nena:/tmp/cert/root$ wget https://www.verisign.com/support/thawte-roots.zip

Salida:

--09:44:38-- https://www.verisign.com/support/thawte-roots.zip
=> `thawte-roots.zip'
Resolviendo www.verisign.com... 65.205.249.60
Connecting to www.verisign.com|65.205.249.60|:443... conectado.
Petición HTTP enviada, esperando respuesta... 200 OK
Longitud: 28,793 (28K) [application/zip]


100%[====================================================================================================================>] 28,793 55.90K/s


09:44:41 (55.73 KB/s) - `thawte-roots.zip' saved [28793/28793]


paco@nena:/tmp/cert/root$ unzip thawte-roots.zip
Archive: thawte-roots.zip
inflating: Thawte SGC CA.cer
inflating: Thawte SSL Domain CA.cer
inflating: ThawtePersonalBasicCA.cer
inflating: ThawtePersonalFreemailCA.cer
inflating: ThawtePersonalPremiumCA.cer
inflating: Thawte Server Roots/Thawte Server Roots.txt
inflating: Thawte Server Roots/ThawtePremiumServerCA.509
inflating: Thawte Server Roots/ThawtePremiumServerCA.cer
inflating: Thawte Server Roots/ThawteServerCA.509
inflating: Thawte Server Roots/ThawteServerCA.cer
inflating: Thawte Test Roots/Thawte Test Root _TEXT.txt
inflating: Thawte Test Roots/Thawte Test Root.cer
inflating: Thawte Code Signing CA.cer
inflating: Thawte_EV_SSL_CA.cer
inflating: Thawte Extended Validation Root/Thawte_EV_Root.cer
inflating: Thawte Extended Validation Root/Thawte_EV_Root.txt
inflating: Thawte_EV_SSL_CA_b64.txt
inflating: Thawte SSL Domain CA_b64.txt
inflating: Thawte SGC CA_b64.txt
inflating: Thawte Code Signing CA_b64.txt
inflating: ThawtePersonalPremiumCA_b64.txt
inflating: ThawtePersonalFreemailCA_b64.txt
inflating: ThawtePersonalBasicCA_b64.txt
inflating: Thawte Extended Validation Root/Thawte_EV_Root_b64.txt
inflating: Thawte Primary Root CA/Thawte_Primary_Root_CA.cer
inflating: Thawte Primary Root CA/Thawte_Primary_Root_CA.txt
inflating: Thawte Primary Root CA/Thawte_Primary_Root_CA_b64.txt
inflating: Thawte Server Roots/ThawteServerCA_b64.txt
inflating: Thawte Server Roots/ThawtePremiumServerCA_b64.txt

Paso 6: Poner los certificados en un directorio «certs» de /etc/postfix con permisos adecuados y añadir el certificado raíz:


paco@nena:/tmp/cert/root$ cd /etc/postfix/
paco@nena:/tmp/cert/root$ sudo mkdir certs
paco@nena:/etc/postfix$ sudo cp /tmp/cert/demoCA/cacert.pem /tmp/cert/cert.pem /tmp/cert/cert-key.pem ./certs/
paco@nena:/etc/postfix$ cd certs
paco@nena:/etc/postfix/certs$ chmod 644 *
paco@nena:/etc/postfix/certs$ chmod 400 key.pem
paco@nena:/etc/postfix/certs$ sudo cat /tmp/cert/root/Thawte Server Roots/ThawtePremiumServerCA_b64.txt >> cacert.pem

Paso 7: Editar los ficheros de configuración de postfix para añadir TLS, autentificación SASL y un nuevo «transport» hacia GMail:

Añadir a /etc/postfix/main.cf

## TLS
#
smtp_tls_CAfile = /etc/postfix/certs/cacert.pem
smtp_tls_cert_file = /etc/postfix/certs/cert.pem
smtp_tls_key_file = /etc/postfix/certs/key.pem
smtp_tls_session_cache_database = btree:/var/run/smtp_tls_session_cache
smtp_use_tls = yes
smtpd_tls_CAfile = /etc/postfix/certs/cacert.pem
smtpd_tls_cert_file = /etc/postfix/certs/cert.pem
smtpd_tls_key_file = /etc/postfix/certs/key.pem
smtpd_tls_received_header = yes
smtpd_tls_session_cache_database = btree:/var/run/smtpd_tls_session_cache
smtpd_use_tls = yes
tls_random_source = dev:/dev/urandom
#
## SASL Settings
# This is going in to THIS server
smtpd_sasl_auth_enable = no
# We need this
smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtpd_sasl_local_domain = $myhostname
smtp_sasl_security_options = noanonymous
#smtp_sasl_security_options =
smtp_sasl_tls_security_options = noanonymous
smtpd_sasl_application_name = smtpd

Crear un /etc/postfix/transport:

# Envío del correo hacia el SMTP de GMail
gmail.com smtp:[smtp.gmail.com]:587

Crear un /etc/postfix/sasl_password (este es el más feo)

#Usuario y contraseña para que postfix use el SMTP de GMail
#
[smtp.gmail.com]:587 usuario_gmail@gmail.com:password_gmail

Ya que estamos, le ponemos unos permisos más restrictivos:

paco@nena:/etc/postfix$ sudo chmod 600 sasl_password

Paso 8: Crear los Hashes de los nuevos ficheros:


paco@nena:/etc/postfix$ sudo postmap sasl_passwd && sudo postmap transport

Paso 9: Reiniciar Postfix:


paco@nena:/etc/postfix$ sudo /etc/init.d/postfix restart

Salida:

Stopping Postfix Mail Transport Agent: postfix.
Starting Postfix Mail Transport Agent: postfix.

Paso 10: Borrar el directorio con certificados de /tmp que habíamos creado al prinicipio:


paco@nena:/etc/postfix$ cd /tmp
paco@nena:/tmp$ rm -rf cert

Para probar la configuración hay muchas maneras, pero he descubierto una que no sabía y la pego aquí también como recordatorio:

paco@nena:~$ sudo sendmail -bv unadireccion@decorreo.com
paco@nena:~$ tail /var/log/mail.log

Si todo ha ido bien, veremos una línea como esta en el log:

pr 14 09:57:34 nena postfix/smtp[15115]: B4577163409E: to=, relay=aspmx.l.google.com[66.249.93.27]:25, delay=7, delays=0.02/0.09/0.86/6, dsn=2.1.5, status=deliverable (250 2.1.5 OK)

Si no ha ido bien pondrá «undeliverable» en lugar de «deliverable».

Anuncio publicitario

Posted in Libre, Linux, Software | 1 Comment »

Link: Cómo traerse un coche de Alemania

Posted by Paco Ros en 13 \13\+01:00 abril \13\+01:00 2008

Visto en Auto Bild: Cómo comprar un coche usado en Alemania

Posted in Motor | Leave a Comment »