summaryrefslogtreecommitdiffstats
path: root/doc/proto-doc.txt
blob: cdfaec2736e1b50e0d253db5df51b0e4e8069201 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
Protocol Specification.

Terminology.

Client - software instance that interacts with human users and lets them send and
receive encrypted messages over Pica Pica.

Node - software instance that coordinates Pica Pica network, maintains list of
all active nodes and provides connectivity to clients.

Connections.
There are 4 types of connections between Pica Pica nodes and clients.

-client to node (c2n) - control connection from client to node

-client to client (c2c) - data connection between clients through node acting
as a proxy

-node to node (n2n) - control & data connection between nodes

-direct client to client (directc2c) - direct connection between clients,
using IPv4/IPv6/DNS 
address of accepting client previously communicated through c2c connection.

These connections use TCP transport. First 3 connection types start
with TLS 1.2 handshake using anonymous Diffie-Hellman ciphersuite,
connecting host acts as a TLS client, accepting host is TLS server.
After connection type is identified by accepting node, anonymous TLS
session is gracefully closed in case of c2n and c2c connections. Node starts
new TLS session with client in case of c2n, where node acts as a TLS client and
client acts as a TLS server, using client's RSA certificate. In case of
c2c connection node acts as a transparent proxy, sending chunks of data
received from the first client to the second one and vise versa. Clients
establish mutually authenticated TLS session over proxied connection, 
initiator client is a TLS client, accepting client has TLS server role.
n2n connection continues to operate in ADH TLS session, as by design nodes
do not store state that identifies them except network address.


Packet Format.

Pica Pica protocol message packet contains header and tail.

[Header][Tail]

Header is a 2 octet sequence that identifies packet. First and second octets
are always equal to each other.
Tail is a remaining part of the packet. Can be empty. Tail can have fixed
predefined length or in case of variable length packet it begins with 1 or 2
octet sequence that contains unsigned integer number which defines length in 
octets of remaining part of the tail not including length octets. Length field
is stored in little-endian format, least significant octet first.
Whole packet length is limited to 65536 octets, so length field value is within
0..65532 range.

Example:

0x55 0x55 0x03 0x00 0xAA 0xBB 0xCC
[0x55 0x55] - header
[0x03 0x00] - tail length, 2 octets
[0xAA 0xBB 0xCC] payload, 3 octets


C2N Messages.
====================================================
C2N Connection initialization request.
Sent by client.
ANON TLS

[0xCA 0xCA][VER_MAJOR][VER_MINOR]

4 octets

====================================================
C2N connection initialization success.
Sent by node.
ANON TLS

[0x01 0x01]['O']['K']

4 octets

After this message client and node initiate ANON TLS session shutdown
and after successful shutdown initiate new authenticated TLS session
over the same TCP connection. Client acts as a TLS server and presents
client sertificate, node acts as a TLS client and does not present
certificate.
====================================================
Protocol versions mismatch.
Sent by node.
ANON TLS

[0x02 0x02][VER_MAJOR][VER_MINOR]

4 octets

VER_MAJOR, VER_MINOR - Pica Pica protocol version supported by node

This message is sent if node and client protocol versions are not equal.
After sending and receiving this message TCP connection is closed by both
hosts.
====================================================
Multilogin notification.
Sent by client that logged in. Retranslated to other nodes.
Delivered to existing connected client instance.

[0x0E 0x0E][length 2 octets][timestamp][node address][signature from UH, timestamp, node
address]

timestamp - time when client logged in, 64-bit Unix timestamp in UTC timezone

node address - one of 0xA0, 0xA1, 0xA2 message, announced address of the node
which sending client is connected to.

signature - digital signature using SHA224 hash and private RSA key of sending
client. Signature is calculated from concatenated sender's UH, timestamp and
node address = Sign(UH|timestamp|node address)