Skip to content

Instantly share code, notes, and snippets.

Farid Zakaria fzakaria

Block or report user

Report or block fzakaria

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@fzakaria
fzakaria / netty_tls_raw.java
Created Dec 28, 2018
Decrypt by hand TLS payload
View netty_tls_raw.java
public class Test {
@Test
public void testExtractMasterkeyWorksCorrectly() throws Exception {
SelfSignedCertificate cert = new SelfSignedCertificate();
SslContext serverContext = SslContextBuilder.forServer(cert.key(), cert.cert())
.sslProvider(SslProvider.OPENSSL).build();
final OpenSslEngine serverEngine =
(OpenSslEngine) serverContext.newEngine(UnpooledByteBufAllocator.DEFAULT);
@fzakaria
fzakaria / https.java
Last active Aug 14, 2018
How to properly use an http client with a self signed certificate
View https.java
/**
* Too many examples on the internet demonstrate using self-signed certificates by disabling hostname verification
or providing a weak TrustManager (i.e. SelfSignedTrustManager).
This example shows how to properly start a server & client in the same JVM where the client knows about the
generated self-signed certificate.
Also it's all done programmatically! Avoid using keytool and pulling in heavy dependencies like BouncyCastle!~
**/
public class SecureServerTest {
/**
@fzakaria
fzakaria / jaeger_thrift.java
Created Jan 2, 2018
Jaeger reading / writing thrift from a file
View jaeger_thrift.java
import com.uber.jaeger.Span;
import com.uber.jaeger.Tracer;
import com.uber.jaeger.exceptions.SenderException;
import com.uber.jaeger.reporters.Reporter;
import com.uber.jaeger.samplers.ConstSampler;
import com.uber.jaeger.samplers.Sampler;
import com.uber.jaeger.senders.ThriftSender;
import com.uber.jaeger.thriftjava.Process;
import org.apache.thrift.TBase;
import org.apache.thrift.TException;
View SimpleStringCodec.java
/**
* A very simple {@link Injector} and {@link Extractor} that use a {@link StringBuffer} as the transmission.
* This class <b>will only</b> transmit the {@link io.opentracing.SpanContext} without any baggage
* (that's why its simple).
*/
public class SimpleStringCodec implements Injector<StringBuffer> , Extractor<StringBuffer> {
@Override
public void inject(SpanContext spanContext, StringBuffer carrier) {
carrier.append(spanContext.contextAsString());
@fzakaria
fzakaria / SpanMixin.java
Created Nov 17, 2017
Jaeger Span Jackson Mixin
View SpanMixin.java
import com.fasterxml.jackson.annotation.JsonProperty;
import com.uber.jaeger.Span;
import java.util.List;
import java.util.stream.Collectors;
/**
* Jackson mixin for defining how a {@link com.uber.jaeger.Span} gets turned into JSON
* This was built using the fixtures from Jaeger codebase --
* The usefulness of this class would be if as part of your infrastructure there are already ways to get log data
@fzakaria
fzakaria / BigByteBuffer.java
Created Aug 23, 2017
A BufferFacade that wraps many ByteBuffers beyond the integer length
View BigByteBuffer.java
package casper.verification.struct;
import net.sf.kdgcommons.buffer.BufferFacade;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.MappedByteBuffer;
import java.util.function.Function;
public class BigByteBuffer implements BufferFacade {
@fzakaria
fzakaria / Base85.java
Created Feb 2, 2016
A simple Base85 / Ascii85 codec
View Base85.java
/**
* A very simple class that helps encode/decode for Ascii85 / base85
* The version that is likely most similar that is implemented here would be the Adobe version.
* @see <a href="https://en.wikipedia.org/wiki/Ascii85">Ascii85</a>
*/
public class Base85 {
private final static int ASCII_SHIFT = 33;
@fzakaria
fzakaria / double_array.go
Created Jan 21, 2016
How to iterate over a double array in Cgo
View double_array.go
package avformat
//#cgo pkg-config: libavformat
//#include <libavformat/avformat.h>
import "C"
import (
"unsafe"
)
//https://www.ffmpeg.org/doxygen/2.7/structAVFormatContext.html
@fzakaria
fzakaria / EchoApplication.java
Created Jan 18, 2016
Netty HTTP Echo Server & Client
View EchoApplication.java
import io.netty.bootstrap.Bootstrap;
import io.netty.bootstrap.ServerBootstrap;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import io.netty.channel.Channel;
import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelFutureListener;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.EventLoopGroup;
@fzakaria
fzakaria / EchoApplication.java
Created Jan 18, 2016
Netty HTTP Echo Server & Client
View EchoApplication.java
import io.netty.bootstrap.Bootstrap;
import io.netty.bootstrap.ServerBootstrap;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import io.netty.channel.Channel;
import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelFutureListener;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.EventLoopGroup;
You can’t perform that action at this time.