cascardo/libreceita.git
10 years agoDocument operating system as GNU.
Alexandre Oliva [Sun, 9 Mar 2014 03:29:48 +0000 (00:29 -0300)]
Document operating system as GNU.

The code sets so to GNU, but the docs suggested Linux.  Fix the latter
to match.

10 years agoUpdate cliente version to that of ReceitaNet 2014.
Alexandre Oliva [Sun, 9 Mar 2014 03:29:43 +0000 (00:29 -0300)]
Update cliente version to that of ReceitaNet 2014.

Odds are the reception side will reject IRPF2014 declarations transferred
by a ReceitaNet implementation that claims to be last year's.

10 years agoSet versao_java to a fake gij string.
Alexandre Oliva [Sun, 9 Mar 2014 03:29:35 +0000 (00:29 -0300)]
Set versao_java to a fake gij string.

We're not running Java at all, so we might as well pretend to be the
GNU Interpreter for Java.

10 years agoSend right part of the header for 2014.
Thadeu Lima de Souza Cascardo [Fri, 7 Mar 2014 23:28:14 +0000 (20:28 -0300)]
Send right part of the header for 2014.

The code was sending a piece of the header as expected by the server,
considering the header size for 2013. Now, we check for the year we are
submitting for, and use the proper size.

Reported-by: Alexandre Oliva <lxoliva@fsfla.org>
10 years agoUse macros for the header size.
Thadeu Lima de Souza Cascardo [Fri, 7 Mar 2014 23:27:29 +0000 (20:27 -0300)]
Use macros for the header size.

For each year, use a macro for the header size we expect.

10 years agoGrow message by just the needed amount
Alexandre Oliva [Thu, 6 Mar 2014 16:17:12 +0000 (13:17 -0300)]
Grow message by just the needed amount

Do not allocate more space than required for the message to grow.
We used to nearly double the amount of space every time, which is
nice to avoid quadratic complexity, but files are small enough
that it probably doesn't matter much, and it just makes things
confusing.

10 years agoConvert chars to len with unsigned buffer
Alexandre Oliva [Thu, 6 Mar 2014 13:07:22 +0000 (10:07 -0300)]
Convert chars to len with unsigned buffer

Introduce chars2len to compute a len out of an unsigned char buf[2].
This avoids problems when any of the chars is negative, if char is
signed.

10 years agoSilence compiler warning in 64-bit mode
Alexandre Oliva [Thu, 6 Mar 2014 13:07:14 +0000 (10:07 -0300)]
Silence compiler warning in 64-bit mode

Casting an int to gnutls_transport_ptr_t gets a warning when
sizeof(void*)!=sizeof(int).  Casting the int to int_ptr first
silences the warning.

10 years agoAdd documentation about where to find header documentation.
Thadeu Lima de Souza Cascardo [Thu, 6 Mar 2014 11:47:18 +0000 (08:47 -0300)]
Add documentation about where to find header documentation.

The DEC file "documentation" can be found as a resource file at Receita
Federal IRPF JAR.

10 years agoRelease v2014.0. v2014.0
Thadeu Lima de Souza Cascardo [Thu, 6 Mar 2014 11:44:35 +0000 (08:44 -0300)]
Release v2014.0.

Use the year in the release version, indicating support for that year.

10 years agoDistinguish between 2013 and 2014.
Thadeu Lima de Souza Cascardo [Thu, 6 Mar 2014 11:42:07 +0000 (08:42 -0300)]
Distinguish between 2013 and 2014.

The file format changes throughout the years, with added fields in the
header. Verify the size of the header and the year indicated, and add
support for year 2014.

10 years agoUse errno to indicate error in parsing file.
Thadeu Lima de Souza Cascardo [Thu, 6 Mar 2014 11:30:35 +0000 (08:30 -0300)]
Use errno to indicate error in parsing file.

10 years agoRelease v0.1.1. v0.1.1 v2013.1
Thadeu Lima de Souza Cascardo [Sat, 2 Nov 2013 21:25:39 +0000 (19:25 -0200)]
Release v0.1.1.

10 years agoIndicate a retifying field in the header.
Thadeu Lima de Souza Cascardo [Sat, 2 Nov 2013 21:19:10 +0000 (19:19 -0200)]
Indicate a retifying field in the header.

Use the field in the DEC file to determine if this is a retifying file
or note, and use this in the hash in the first message.

10 years agoSixth byte in some messages are not always 1.
Thadeu Lima de Souza Cascardo [Sat, 2 Nov 2013 21:09:15 +0000 (19:09 -0200)]
Sixth byte in some messages are not always 1.

The first message, with the hash, uses the sixth byte as 1. The second
message, on the other hand, uses it as 0.

10 years agoHandle uncompressed messages.
Thadeu Lima de Souza Cascardo [Sat, 2 Nov 2013 21:03:54 +0000 (19:03 -0200)]
Handle uncompressed messages.

Some messages may come uncompressed, and we need to handle them.

10 years agoProvide function to remove a header from a message.
Thadeu Lima de Souza Cascardo [Sat, 2 Nov 2013 21:03:01 +0000 (19:03 -0200)]
Provide function to remove a header from a message.

Remove the first n bytes from a message.

10 years agoFix use of deflate output length.
Thadeu Lima de Souza Cascardo [Sat, 2 Nov 2013 20:53:00 +0000 (18:53 -0200)]
Fix use of deflate output length.

avail_out has the remaining bytes in the buffer, not the number of bytes
output, which is found on total_out.

10 years agoUpdate TODO. v0.1 v2013.0
Thadeu Lima de Souza Cascardo [Fri, 14 Jun 2013 11:58:48 +0000 (08:58 -0300)]
Update TODO.

10 years agoJust to be safe, show message and try to save file.
Thadeu Lima de Souza Cascardo [Fri, 14 Jun 2013 11:53:25 +0000 (08:53 -0300)]
Just to be safe, show message and try to save file.

When we receive a response we are not sure how to handle, try to find a
message and a file in the response and use them.

10 years agoHandle error response.
Thadeu Lima de Souza Cascardo [Fri, 14 Jun 2013 11:50:58 +0000 (08:50 -0300)]
Handle error response.

10 years agoHandle response when DEC has already been transmitted.
Thadeu Lima de Souza Cascardo [Fri, 14 Jun 2013 11:46:16 +0000 (08:46 -0300)]
Handle response when DEC has already been transmitted.

The response given by the server when the file has already been
transmitted includes a message to the user and the receipt file, which
is saved at the user's home or a temporary directory with a unique
filename.

10 years agoParse key/value message, extracting the values of its keys.
Thadeu Lima de Souza Cascardo [Fri, 14 Jun 2013 11:45:33 +0000 (08:45 -0300)]
Parse key/value message, extracting the values of its keys.

10 years agoCheck for responses and send second message.
Thadeu Lima de Souza Cascardo [Fri, 14 Jun 2013 10:58:36 +0000 (07:58 -0300)]
Check for responses and send second message.

This completes the protocol. The responses need to be decoded and
handled now.

10 years agoCreate helpers to send and receive messages.
Thadeu Lima de Souza Cascardo [Fri, 14 Jun 2013 00:19:32 +0000 (21:19 -0300)]
Create helpers to send and receive messages.

Needs to do some input and error checking and maybe add some timeouts.

10 years agoFix inflate.
Thadeu Lima de Souza Cascardo [Fri, 14 Jun 2013 00:18:32 +0000 (21:18 -0300)]
Fix inflate.

Inflate support was miscalculating the size of the output buffer.

10 years agoUpdate TODO.
Thadeu Lima de Souza Cascardo [Thu, 13 Jun 2013 11:21:46 +0000 (08:21 -0300)]
Update TODO.

10 years agoAdd the missing field in the first message.
Thadeu Lima de Souza Cascardo [Thu, 13 Jun 2013 11:15:32 +0000 (08:15 -0300)]
Add the missing field in the first message.

It's composed of part of the header register. It's more simple to build
it as a substring of the register itself, than composing it field by
field.

10 years agoFix size of field.
Thadeu Lima de Souza Cascardo [Thu, 13 Jun 2013 11:14:02 +0000 (08:14 -0300)]
Fix size of field.

tam_dados_val_chave is, in fact, only 4 bytes long. Due to a known bug
in the decoder used during reverse engineering, the value of
tam_dados_val was appended to the value of tam_dados_val_chave, since
the two keys have the same prefix.

10 years agoFix key for type of identification.
Thadeu Lima de Souza Cascardo [Thu, 13 Jun 2013 11:00:47 +0000 (08:00 -0300)]
Fix key for type of identification.

It's called tp_ni, not tipo_ni.

10 years agoCalculate message hash and use it.
Thadeu Lima de Souza Cascardo [Wed, 12 Jun 2013 23:17:16 +0000 (20:17 -0300)]
Calculate message hash and use it.

Use gcrypt to calculate stripped file MD5 hash and add it to the
key/value message.

10 years agoAllow an arbitrarily-sized buffer into the key/value message.
Thadeu Lima de Souza Cascardo [Wed, 12 Jun 2013 23:08:37 +0000 (20:08 -0300)]
Allow an arbitrarily-sized buffer into the key/value message.

10 years agoAdd transmission length to the key/value message.
Thadeu Lima de Souza Cascardo [Wed, 12 Jun 2013 22:55:43 +0000 (19:55 -0300)]
Add transmission length to the key/value message.

Use the length of the stripped file that is going to be transmitted for
some of the keys in the first message.

10 years agoStrip the DEC file from control numbers.
Thadeu Lima de Souza Cascardo [Wed, 12 Jun 2013 22:07:40 +0000 (19:07 -0300)]
Strip the DEC file from control numbers.

In order to send the second part of the message, we need to strip the
declaration registers from their control numbers.

10 years agoFix bug when expanding message.
Thadeu Lima de Souza Cascardo [Wed, 12 Jun 2013 22:01:37 +0000 (19:01 -0300)]
Fix bug when expanding message.

If we need to expand a message while adding a field to it, we need to
update the pointer we are using, and the one we are returning back.

10 years agoUse a pointer for message functions when it needs a resize.
Thadeu Lima de Souza Cascardo [Wed, 12 Jun 2013 21:43:28 +0000 (18:43 -0300)]
Use a pointer for message functions when it needs a resize.

Always use a pointer to a pointer to struct rnet_message in those
functions where it is possible that it may be resized.

10 years agoAdd more fields to the first message.
Thadeu Lima de Souza Cascardo [Wed, 12 Jun 2013 11:40:58 +0000 (08:40 -0300)]
Add more fields to the first message.

The only missing fields are the size and hash of the second message and
part of the header register.

10 years agoAdd 64-bit values support for rnet_message.
Thadeu Lima de Souza Cascardo [Wed, 12 Jun 2013 11:39:15 +0000 (08:39 -0300)]
Add 64-bit values support for rnet_message.

10 years agoInclude some extra fields in the message.
Thadeu Lima de Souza Cascardo [Wed, 12 Jun 2013 11:34:55 +0000 (08:34 -0300)]
Include some extra fields in the message.

These fields are mostly machine/software/network identity numbers. Some
choices here may be political. Perhaps we should let the user pick them
up at some point, as long as there are sensible defaults.

10 years agoAllow a 16-bit value to be added to the key/value pair.
Thadeu Lima de Souza Cascardo [Wed, 12 Jun 2013 11:29:21 +0000 (08:29 -0300)]
Allow a 16-bit value to be added to the key/value pair.

10 years agoSend the 8-bit value address instead of its value.
Thadeu Lima de Souza Cascardo [Wed, 12 Jun 2013 11:28:32 +0000 (08:28 -0300)]
Send the 8-bit value address instead of its value.

10 years agoAdd more fields to the first message.
Thadeu Lima de Souza Cascardo [Wed, 12 Jun 2013 11:26:36 +0000 (08:26 -0300)]
Add more fields to the first message.

10 years agoAllow a single byte value to be added as a key/pair value.
Thadeu Lima de Souza Cascardo [Wed, 12 Jun 2013 11:23:27 +0000 (08:23 -0300)]
Allow a single byte value to be added as a key/pair value.

10 years agoEncode some fields in the first protocol message.
Thadeu Lima de Souza Cascardo [Tue, 11 Jun 2013 22:06:25 +0000 (19:06 -0300)]
Encode some fields in the first protocol message.

Read some fields from the decfile and add those to a message built for
the ReceitaNet protocol.

10 years agoBuild rnet_message.
Thadeu Lima de Souza Cascardo [Wed, 12 Jun 2013 11:14:55 +0000 (08:14 -0300)]
Build rnet_message.

10 years agoFix exercicio_pgd in protocol documentation.
Thadeu Lima de Souza Cascardo [Wed, 12 Jun 2013 11:05:53 +0000 (08:05 -0300)]
Fix exercicio_pgd in protocol documentation.

Due to a bug in the parser used for reverse engineering, the field named
"exercicio" was appended to the field "exercicio_pgd".

10 years agoCreate rnet_message to encode messages.
Thadeu Lima de Souza Cascardo [Tue, 11 Jun 2013 21:21:50 +0000 (18:21 -0300)]
Create rnet_message to encode messages.

rnet_message allows us to encode messages in the form used for
ReceitaNet, which is a kind of set of key/values.

10 years agoParse DEC file header.
Thadeu Lima de Souza Cascardo [Tue, 11 Jun 2013 21:18:13 +0000 (18:18 -0300)]
Parse DEC file header.

Include fields from the header in a pmhash and introduce a function to
retrieve them. Some of those fields are needed to send the first message
to the server.

10 years agoIntroduce poor man's hash.
Thadeu Lima de Souza Cascardo [Tue, 11 Jun 2013 11:33:03 +0000 (08:33 -0300)]
Introduce poor man's hash.

This lookup array is helpful for adding fields parsed from the DEC file.

10 years agoRemove handshake success message
Thadeu Lima de Souza Cascardo [Tue, 11 Jun 2013 10:55:07 +0000 (07:55 -0300)]
Remove handshake success message

10 years agoStart parsing a DEC file.
Thadeu Lima de Souza Cascardo [Sat, 8 Jun 2013 12:40:21 +0000 (09:40 -0300)]
Start parsing a DEC file.

Read lines from a DEC file and store them in an array for later parsing.

10 years agoUpdate TODO
Thadeu Lima de Souza Cascardo [Sat, 8 Jun 2013 11:50:26 +0000 (08:50 -0300)]
Update TODO

10 years agoUpdate copyright years
Thadeu Lima de Souza Cascardo [Sat, 8 Jun 2013 11:50:18 +0000 (08:50 -0300)]
Update copyright years

10 years agoDocument server answer and next client message.
Thadeu Lima de Souza Cascardo [Fri, 7 Jun 2013 11:33:54 +0000 (08:33 -0300)]
Document server answer and next client message.

10 years agoComplete format documentation.
Thadeu Lima de Souza Cascardo [Tue, 28 May 2013 11:25:20 +0000 (08:25 -0300)]
Complete format documentation.

10 years agoDocument message header.
Thadeu Lima de Souza Cascardo [Tue, 28 May 2013 09:17:03 +0000 (06:17 -0300)]
Document message header.

10 years agoStart of documentation about the protocol.
Thadeu Lima de Souza Cascardo [Tue, 28 May 2013 09:15:46 +0000 (06:15 -0300)]
Start of documentation about the protocol.

10 years agoCreate a function for the first handshake.
Thadeu Lima de Souza Cascardo [Fri, 7 Jun 2013 22:04:15 +0000 (19:04 -0300)]
Create a function for the first handshake.

10 years agoUse getaddrinfo to obtain receitanet's addresses.
Thadeu Lima de Souza Cascardo [Fri, 7 Jun 2013 21:55:18 +0000 (18:55 -0300)]
Use getaddrinfo to obtain receitanet's addresses.

The name address for receitanet is receitanet.receita.fazenda.gov.br.
Instead of using its IPv4 address directly, tries to resolve the name
and use the given addresses.

As a bonus, allows us to use /etc/hosts to debug with a test server.

10 years agoIncrease buffer size for testing.
Thadeu Lima de Souza Cascardo [Tue, 28 May 2013 11:26:43 +0000 (08:26 -0300)]
Increase buffer size for testing.

For the current tests, the buffer needs to be increased, so the data
file can be read.

10 years agoUse the right IP address for receitanet server
Thadeu Lima de Souza Cascardo [Tue, 28 May 2013 11:26:32 +0000 (08:26 -0300)]
Use the right IP address for receitanet server

10 years agoVerify connect return code.
Thadeu Lima de Souza Cascardo [Tue, 28 May 2013 09:12:20 +0000 (06:12 -0300)]
Verify connect return code.

If connect is not successful, exit.

10 years agoFirst take at a client for ReceitaNet.
Thadeu Lima de Souza Cascardo [Tue, 28 May 2013 09:09:37 +0000 (06:09 -0300)]
First take at a client for ReceitaNet.