<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Segurança on Cesar Gimenes</title><link>https://crg.eti.br/en/tags/seguran%C3%A7a/</link><description>Recent content in Segurança on Cesar Gimenes</description><generator>Hugo -- gohugo.io</generator><language>en</language><managingEditor>crg@crg.eti.br (Cesar Gimenes)</managingEditor><webMaster>crg@crg.eti.br (Cesar Gimenes)</webMaster><lastBuildDate>Sun, 31 May 2026 00:38:32 -0300</lastBuildDate><atom:link href="https://crg.eti.br/en/tags/seguran%C3%A7a/index.xml" rel="self" type="application/rss+xml"/><item><title>Encryption at rest with Go's stdlib</title><link>https://crg.eti.br/en/post/criptografia-at-rest-com-a-stdlib-go/</link><pubDate>Sun, 31 May 2026 00:38:32 -0300</pubDate><author>crg@crg.eti.br (Cesar Gimenes)</author><guid>https://crg.eti.br/en/post/criptografia-at-rest-com-a-stdlib-go/</guid><description>&lt;p>I want to store a piece of data on disk so that, even if the file leaks, it is only readable with the password and any tampering is detected.&lt;/p>
&lt;p>To do this we protect the data by encrypting it &amp;ldquo;at rest&amp;rdquo;, which basically means the data is protected while it sits on disk and can only be accessed by whoever has the right password.&lt;/p>
&lt;p>You can do this with the standard library alone:&lt;/p></description></item><item><title>Capturing Passwords in the Terminal with Go</title><link>https://crg.eti.br/en/post/capturando-senhas-no-terminal-go/</link><pubDate>Sat, 30 May 2026 10:00:00 -0300</pubDate><author>crg@crg.eti.br (Cesar Gimenes)</author><guid>https://crg.eti.br/en/post/capturando-senhas-no-terminal-go/</guid><description>&lt;p>Reading a password in the terminal looks trivial, but it has two pitfalls: the password shows up on screen if you use ordinary input, and you need to make sure you&amp;rsquo;re really dealing with a terminal and not a redirection. Let&amp;rsquo;s solve both with the &lt;code>golang.org/x/term&lt;/code> package.&lt;/p>
&lt;p>If you read with &lt;code>bufio.Scanner&lt;/code> or &lt;code>fmt.Scanln&lt;/code>, every keystroke shows up on screen. That won&amp;rsquo;t do for a password. &lt;code>term.ReadPassword&lt;/code> reads straight from the terminal, without echo:&lt;/p></description></item><item><title>Data Transmission Using Sound: An Experiment with a 'Cup Telephone'</title><link>https://crg.eti.br/en/post/transmissao-de-dados-usando-som-via-telefone-de-copos/</link><pubDate>Sat, 25 Jan 2025 21:58:10 -0300</pubDate><author>crg@crg.eti.br (Cesar Gimenes)</author><guid>https://crg.eti.br/en/post/transmissao-de-dados-usando-som-via-telefone-de-copos/</guid><description>&lt;p>When I started playing with computers, the only way to load a program into the machine was to type it from scratch. My old computer had no storage; there was no hard drive, floppy disk, or any other way to store data. At startup, the machine loaded &lt;em>BASIC&lt;/em> straight from ROM and that was it. Eventually I got a tape recorder, but it was terrible. With no money for a recorder made for computers, I used a household one. It took a long time adjusting the volume and other settings before I could load anything. The equipment was so finicky that I taped the controls down to keep them from moving, because the slightest change would prevent loading.&lt;/p></description></item><item><title>Optimizing Message Integrity Checks with FNV-1a in Go</title><link>https://crg.eti.br/en/post/checksum-com-golang/</link><pubDate>Sat, 18 Jan 2025 00:43:18 -0300</pubDate><author>crg@crg.eti.br (Cesar Gimenes)</author><guid>https://crg.eti.br/en/post/checksum-com-golang/</guid><description>&lt;p>In the article &lt;a href="https://crg.eti.br/en/post/hmac-assinatura-de-mensagens-segura-em-go/">HMAC (Hash-based Message Authentication Code)&lt;/a>, we saw how that technique ensures a message was not altered in transit and confirms the validity of the signature.&lt;/p>
&lt;p>However, while secure, that process is slow and resource-intensive. When we only need to verify message integrity without validating a signature, we can use a faster hash function. For that, we will use the FNV-1a (Fowler-Noll-Vo) algorithm, known for its speed and low collision rate.&lt;/p></description></item><item><title>mTLS: Implementing Mutual Authentication Between Client and Server in Go</title><link>https://crg.eti.br/en/post/mtls-implementando-autenticacao-mutua/</link><pubDate>Sat, 11 Jan 2025 19:49:40 -0300</pubDate><author>crg@crg.eti.br (Cesar Gimenes)</author><guid>https://crg.eti.br/en/post/mtls-implementando-autenticacao-mutua/</guid><description>&lt;p>mTLS (Mutual TLS) authenticates both client and server. Each one presents a digital certificate signed by a trusted certificate authority. By controlling certificate issuance, you ensure that only authorized clients access your service. It also makes it easy to identify the client without needing an API Key or Token. I also recommend using an &lt;a href="https://crg.eti.br/pt-br/post/hmac-assinatura-de-mensagens-segura-em-go/">HMAC (Hash-based Message Authentication Code)&lt;/a> header as an additional layer of security and message integrity.&lt;/p>
&lt;h2 id="creating-certificates">Creating Certificates&lt;/h2>
&lt;p>In this example, I&amp;rsquo;ll create the certificates in a simple way for local testing. When deploying to production, be careful with the parameters you use. It&amp;rsquo;s important to include Subject Alternative Names (SANs), since relying on the CN (Common Name) alone is no longer recommended.&lt;/p></description></item><item><title>HMAC (Hash-based Message Authentication Code) in Golang</title><link>https://crg.eti.br/en/post/hmac-assinatura-de-mensagens-segura-em-go/</link><pubDate>Fri, 10 Jan 2025 23:33:11 -0300</pubDate><author>crg@crg.eti.br (Cesar Gimenes)</author><guid>https://crg.eti.br/en/post/hmac-assinatura-de-mensagens-segura-em-go/</guid><description>&lt;p>When building APIs, it&amp;rsquo;s a good idea to add an authentication header to guarantee message integrity. For example, when your server sends a request or a webhook, include an &lt;code>X-Signature&lt;/code> header with an HMAC (Hash-based Message Authentication Code) signature.&lt;/p>
&lt;p>To generate the HMAC signature, you use a secret key and the content to be signed, such as the request &lt;em>body&lt;/em>, and send the signature in the header. It&amp;rsquo;s important to make clear exactly what is being signed. I&amp;rsquo;ve run into problems with clients who couldn&amp;rsquo;t validate the signature because they used the &lt;em>body&lt;/em> parsed as JSON instead of the &lt;em>raw body&lt;/em> received in the request.&lt;/p></description></item><item><title>Manipulating Special Permission Bits</title><link>https://crg.eti.br/en/post/manipulando-setuid-e-setgid/</link><pubDate>Sat, 04 Jan 2025 00:36:51 -0300</pubDate><author>crg@crg.eti.br (Cesar Gimenes)</author><guid>https://crg.eti.br/en/post/manipulando-setuid-e-setgid/</guid><description>&lt;p>In the article on &lt;a href="https://crg.eti.br/en/post/reducao-de-privilegios-com-golang/">Privilege Reduction in Programs&lt;/a>, we used the &lt;code>sudo&lt;/code> command to run a program with superuser privileges. However, it&amp;rsquo;s possible to do this without an external command.&lt;/p>
&lt;p>For that, we use special file permissions known as the &lt;em>setuid bit&lt;/em> and the &lt;em>setgid bit&lt;/em>. These attributes allow files to be executed with the &lt;strong>privileges of the owning user or group&lt;/strong>.&lt;/p>
&lt;p>To set the &lt;code>setuid&lt;/code> and &lt;code>setgid&lt;/code> bits, we use the &lt;code>chmod&lt;/code> command with the &lt;code>u+s&lt;/code> and &lt;code>g+s&lt;/code> options, respectively.&lt;/p></description></item><item><title>Dropping Privileges in Go Programs to Improve Security</title><link>https://crg.eti.br/en/post/reducao-de-privilegios-com-golang/</link><pubDate>Thu, 02 Jan 2025 22:43:45 -0300</pubDate><author>crg@crg.eti.br (Cesar Gimenes)</author><guid>https://crg.eti.br/en/post/reducao-de-privilegios-com-golang/</guid><description>&lt;p>A good practice for improving the security of a system is to drop a program&amp;rsquo;s execution privileges. Ideally, a program should run with the fewest privileges possible.&lt;/p>
&lt;p>On UNIX-like systems, you can change the user and group a program runs as. Let&amp;rsquo;s walk through how to do that in Go.&lt;/p>
&lt;h2 id="checking-whether-the-program-is-running-as-root">Checking Whether the Program Is Running as Root&lt;/h2>
&lt;p>First, check whether the program is running as root. This matters because we&amp;rsquo;ll use system calls that require root privileges. (There are other ways to grant these privileges, but we&amp;rsquo;ll cover that in another article.)&lt;/p></description></item></channel></rss>