Dominio Internet: TCP, UDP, SSL e TLS

ssl://, tls://, sslv2:// & sslv3://.

Nota: Se non viene specificato alcun trasporto, verrà assunto tcp://.

  • 127.0.0.1
  • fe80::1
  • www.example.com
  • tcp://127.0.0.1
  • tcp://fe80::1
  • tcp://www.example.com
  • udp://www.example.com
  • ssl://www.example.com
  • sslv2://www.example.com
  • sslv3://www.example.com
  • tls://www.example.com

I socket del dominio Internet si aspettano un numero di porta oltre a un indirizzo di destinazione. Nel caso di fsockopen() questo è specificato in un secondo parametro e quindi non influisce sulla formattazione dell'URL del trasporto. Con stream_socket_client() e funzioni correlate, come con gli URL tradizionali, il numero di porta è specificato come suffisso dell'URL del trasporto delimitato da due punti.

  • tcp://127.0.0.1:80
  • tcp://[fe80::1]:80
  • tcp://www.example.com:80

Nota: Indirizzi IPv6 numerici con numeri di porta
Nel secondo esempio sopra, mentre gli esempi IPv4 e hostname sono lasciati intatti a parte l'aggiunta dei due punti e del numero di porta, l'indirizzo IPv6 è racchiuso tra parentesi quadre: [fe80::1]. Questo serve a distinguere tra i due punti usati in un indirizzo IPv6 e i due punti usati per delimitare il numero di porta.

I trasporti ssl:// e tls:// (disponibili solo quando il supporto openssl è compilato in PHP) sono estensioni del trasporto tcp:// che includono la crittografia SSL.

ssl:// tenterà di negoziare una connessione SSL V2 o SSL V3 a seconda delle capacità e delle preferenze dell'host remoto. sslv2:// e sslv3:// selezioneranno il protocollo SSL V2 o SSL V3 esplicitamente.

add a note

User Contributed Notes 2 notes

up
16
christian at lantian dot eu
12 years ago
@pablo dot livardo  :  I think that the problem you found is caused by the difference between the client/server encryption methods used.

The 465 port is used for SMTPS, and the server starts the encryption immediately it receives your connection. So, your code will work.

The 587 port is used for Submission (MSA or Mail Submission Agent) which works like the port 25. The server accepts your connection and doesn't activate the encryption. If you want an encrypted connection on the port 587, you must connect on it without encryption, you must start to dialog with the server (with EHLO) and after that you must ask the server to start the encrypted connection using the STARTTLS command. The server starts the encryption and now you can start as well the encryption on your client. 

So, in few words, you can not use : 

<?php $fp = fsockopen("tls://mail.example.com", 587, $errno, $errstr);  ?>  

but you can use:

 <?php $fp = stream_socket_client("mail.example.com:587", $errno, $errstr); ?>  

and after you send the STARTTLS command, you can enable the crypto:

<?php stream_socket_enable_crypto($fp, true, STREAM_CRYPTO_METHOD_SSLv23_CLIENT); ?>

P.S. My previous note on this page was totally wrong, so I ask the php.net admin to remove it.

:)
up
6
stefan at example dot com
15 years ago
Actually, PHP is very able to start with an unencrypted connection and then switch to an encrypted one - refer to http://php.net/stream_socket_enable_crypto .
To Top