Skip to content

Instantly share code, notes, and snippets.

View maretekent's full-sized avatar

kent marete maretekent

  • http://glosoftgroup.com
  • Nairobi Kenya
View GitHub Profile
@maretekent
maretekent / Hashing files
Last active August 29, 2017 10:02
Hashing the files to enable to ability to checksum
import hashlib
filename = '/path/to/file/file1.txt';
def file_hash(filename):
h = hashlib.sha256()
with open(filename, 'rb', buffering=0) as f:
for b in iter(lambda : f.read(128*1024), b''):
h.update(b)
return h.hexdigest()
import httplib
import re
import socket
import sys
import urllib2
import ssl
class InvalidCertificateException(httplib.HTTPException, urllib2.URLError):
def __init__(self, host, cert, reason):
httplib.HTTPException.__init__(self)
# Create the CA Key and Certificate for signing Client Certs
openssl req -new -x509 -days 3650 -newkey rsa:4096 -out client.crt -keyout ca.key
# Create the Server Key, CSR, and Certificate
openssl req -new -newkey rsa:4096 -nodes -out server.csr -keyout server.key
# We're self signing our own server cert here. This is a no-no in production.
openssl x509 -req -days 365 -in server.csr -CA ca.crt -CAkey ca.key -set_serial 01 -out server.crt
# Create the Client Key and CSR
import socket
import ssl
def ssl_expiry_datetime(hostname):
ssl_date_fmt = r'%b %d %H:%M:%S %Y %Z'
context = ssl.create_default_context()
conn = context.wrap_socket(
socket.socket(socket.AF_INET),
server_hostname=hostname,
#[allow(non_snake_case)]
mod myMod {
#[allow(dead_code)]
pub struct Mammals<T>{
pub somedata: T,
}
impl<T> Mammals<T> {
pub fn new(somedata: T) -> Mammals<T> {
@maretekent
maretekent / server.js
Created February 2, 2018 08:45
node js server
var http = require('http');
var server = undefined;
function HttpServer(config) {
this.port = config.port;
}
HttpServer.prototype.start = function (fn) {
server = http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'application/json'});
@maretekent
maretekent / server.spec.js
Created February 2, 2018 08:46
node js server testing
var should = require('should');
var request = require('request');
var url = 'http://localhost:8080';
var HttpServer = require('./server').HttpServer;
var server;
describe('HttpServer', function () {
before(function (done) {
server = new HttpServer({port: 8080}).start(done);
@maretekent
maretekent / user_input.rs
Created February 10, 2018 18:21
trim user input
use std::io;
fn main() {
let mut user_input = String::new();
io::stdin()
.read_line(&mut user_input)
.expect("failed to read from stdin");
let trim_input = user_input.trim();
match trim_input.parse::<u32>() {
@maretekent
maretekent / Notes on security
Created March 28, 2018 18:38
basic django security key elements worthy noting
XXE injection:
To use these parsers safely, you have to explicitly disable referencing of external entities in the
SAX parser implementation you use.
problem:
from django.http import HttpResponse
from lxml import etree
parser = etree.XMLParser(resolve_entities=True)
try:
document = etree.fromstring(content, parser)
except etree.XMLSyntaxError:
Excessive Logging:
private void logD(String message) {
if (BuildConfig.DEBUG)
Log.d(this.getLocalClassName(), message);
}
Execessive logging of sensitive security data should be avoided in prod env.