Skip to content

Instantly share code, notes, and snippets.

View ggrandes's full-sized avatar
🛠️
I may be slow to respond.

G.Grandes ggrandes

🛠️
I may be slow to respond.
View GitHub Profile
@ggrandes
ggrandes / cert-generator-with-int.sh
Last active September 9, 2021 11:53
Generate X.509 Certificate (Server/Client/Mail) with OpenSSL and Intermediate CA - Linux
#!/bin/bash
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Original Source:
# https://gist.github.com/ggrandes/c1765904e804db15b8c57d90299d006f
#
@ggrandes
ggrandes / base32.pl
Last active April 25, 2017 13:52
Base32 encoding/decoding RFC-3548
#!/usr/bin/perl -wT
# https://gist.github.com/ggrandes/df7151b9e2fca02da93acf44bedf7b43
use strict;
my $op = ($ARGV[0] || "");
my $text = ($ARGV[1] || "");
if (length($text) < 1) {
print_usage();
} elsif (($op eq "-e") || ($op eq "--encode")) {
print encode_rfc3548($text), "\n";
} elsif (($op eq "-d") || ($op eq "--decode")) {
@ggrandes
ggrandes / readline.c
Created April 11, 2016 00:52
Readline C
#define _GNU_SOURCE
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(int argc, char *argv[])
{
char *line = NULL;
size_t len = 0;
ssize_t read;
@ggrandes
ggrandes / gpg-crypt.sh
Last active April 25, 2017 14:47
GnuPG Examples
#!/bin/bash
# Original Source:
# https://gist.github.com/ggrandes/09bc477ac20b8fcb0565d68b8aebe40e
#
date_log () {
printf '%(%Y-%m-%dT%H:%M:%S%z)T %s\n' -1 "$*"
}
recipients=(--trust-model always)
recipients+=(--keyring "./user.pub" --secret-keyring "./user.sec")
for i in user-*.pub; do {
@ggrandes
ggrandes / openssl-smime.sh
Last active December 21, 2023 07:15
OpenSSL S/MIME 3.1 (CMS) - Encrypt/Signature - Verify/Decrypt
# Original Source:
# https://gist.github.com/ggrandes/a57c401f1bad6bd0ffd87a557b7b5790
# SIGN / VERIFY
openssl cms -sign -keyid -md sha256 -nodetach -binary -in /etc/passwd -signer user.crt -inkey user.key -out x.smime -outform SMIME
openssl cms -verify -CAfile ca.crt -in x.smime -inform SMIME
# ENCRYPT / DECRYPT
openssl cms -encrypt -keyid -aes-256-cbc -in /etc/passwd -binary -out x.smime -outform SMIME user.crt
openssl cms -decrypt -in x.smime -inform SMIME -recip user.crt -inkey user.key
@ggrandes
ggrandes / sample-curl-mail.sh
Last active April 25, 2017 14:00
Sample Mail with cURL
#!/bin/bash
# Original Source:
# https://gist.github.com/ggrandes/4a2cfef2fdf102420121
#
sed 's/$/\r/' | curl -q -f -sS -m 180 --retry 3 \
--url "smtp://mailhost:25" \
--mail-from "test.from@noreply.acme.com" \
--mail-rcpt "test.to@acme.com" \
--user "user@acme.com:password" \
--upload-file /dev/stdin <<"END"
@ggrandes
ggrandes / openssl-ecdsa-signature.sh
Last active April 25, 2017 13:55
OpenSSL ECDSA file Signature / Verify
# Original Source:
# https://gist.github.com/ggrandes/2564f7815cfa6c2e9b61
# Generate ECDSA Key-Pair
openssl ecparam -name secp521r1 -genkey -out test.key
openssl ec -pubout -in test.key -out test.pub
# Signature
openssl dgst -sha512 -sign test.key some-file.txt | openssl enc -a -e > some-file.txt.sign
# Verify
openssl enc -a -d < some-file.txt.sign | openssl dgst -sha512 -verify test.pub -signature /dev/stdin some-file.txt
@ggrandes
ggrandes / self-signed-ecc-cert-generator.sh
Last active April 25, 2017 13:58
Self-Signed ECC X.509 Certificates (Server/Client/Mail) with OpenSSL - Linux
#!/bin/bash
# Original Source:
# https://gist.github.com/ggrandes/4cf69a924ccbfcb1253c
#
# Generate Self-Signed certificates (not for production)
# Default Password por PKCS12 file is "changeit"
# Default Expire 5 years
EXPIRE_DAYS=${EXPIRE_DAYS:-$[365 * 5 + 1]}
usage () {
echo "$0 <client|server> <CN> <outputname>"
@ggrandes
ggrandes / cert-ecc-generator.sh
Last active November 26, 2019 19:48
Generate ECC X.509 Certificate (Server/Client/Mail) with OpenSSL - Linux
#!/bin/bash
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@ggrandes
ggrandes / get-machine-info.sh
Last active April 25, 2017 14:49
Get Machine Information
#!/bin/bash
# Original Source:
# https://gist.github.com/ggrandes/b6af6654fb8f5126db6a
#
# 2016-02-27, v1, ggrandes
# Get Machine Information
get_machine_info () {
local DEVS DEV_IDS
local UPTIME IDLE
DEVS=(/sys/class/net/eth*)