Using Stratum protocol in PHP is it possible? Is there any equivalent to Go’s ‘net.Dial’?

Posted on

Question :

I wanted to use the Electrum servers, listed here , it uses a protocol called ” Stratum, “which is documented here , but I do not even know it’s the most up to date one.

I can “work” using the tls library and net (in case I do not use TLS) in Golang, as it is a test I did as follows:

config := &tls.Config{
InsecureSkipVerify: true,
// NOTA:
// O Electrum permite servidores com certificados self-signed!
// O melhor que posso fazer é um Public Key-Pinning baseado em Trust On First Use.
}

PKHashConfiavel := []byte{0x8c, 0x45, 0x01, 0x95, 0x91, 0xd5, 0x4a, 0x50, 0xc8, 0xf6, 0xac, 0x84, 0xa3, 0xf9, 0x70, 0xb1, 0xa7, 0x3b, 0x7e, 0x51, 0xc6, 0xb1, 0x18, 0x72, 0x64, 0x40, 0x00, 0x29, 0xfd, 0xaa, 0xa7, 0xed, 0xbc, 0x8c, 0xd4, 0x2a, 0xf8, 0xe5, 0xdb, 0x55, 0x5f, 0x09, 0x13, 0x56, 0x55, 0x2f, 0x95, 0x39}

// Se conecta com o servidor
conn, err := tls.Dial("tcp", "electrum.hsmiths.com:50002", config)
if err != nil {
panic(err)
}

connState := conn.ConnectionState()
var isConfiavel bool = false

// Verifica a hash do certificado no qual me conectei
for _, cert := range connState.PeerCertificates {
PKDer, _ := x509.MarshalPKIXPublicKey(cert.PublicKey)
PKHash := blake2b.Sum384(PKDer)

if hmac.Equal(PKHashConfiavel, PKHash[:]) {
isConfiavel = true
}
}

if isConfiavel {

// Envia a requisição
comando := "{"id"": 1, ""method"": ""blockchain.address.get_history"", ""params"": [""1DB8zJn99HSVUUwWRCgKxiZV33yPfBSVYr""]}""

Answer :

Leave a Reply

Your email address will not be published. Required fields are marked *