Skip to content

Instantly share code, notes, and snippets.

@chris-carneiro
chris-carneiro / mitigate-http-requests.txt
Last active June 29, 2017 12:47
Mitigate http(s) requests to docker containers
Replaces firewalld by iptables:
# yum install iptables-services
# yum install ebtables
# yum install ipset-service
# systemctl mask --now firewalld.service // disable firewalld
# systemctl status iptables.service // should be inactive
# systemctl enable --now iptables.service
# systemctl enable --now ip6tables.service
# systemctl enable --now etables.service
@chris-carneiro
chris-carneiro / TamperUtils.java
Last active January 20, 2025 10:45
How to check android apk integrity/tampering at runtime
package com.twinpeek.android.app;
import java.io.File;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.security.NoSuchProviderException;
import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageInfo;
@chris-carneiro
chris-carneiro / MainThreadBus.java
Last active June 29, 2017 13:17
Init EventBus singleton class for Otto library
import android.os.Handler;
import android.os.Looper;
import com.squareup.otto.Bus;
/**
* Maintains a singleton instance for obtaining the bus. Ideally this would be replaced with a more efficient means
* such as through injection directly into interested classes.
* <p>
* Created by ChrisC on 17/05/17.
*/
@chris-carneiro
chris-carneiro / RestClient.java
Last active June 29, 2017 13:23
Example of a Rest Client using retrofit
/**
* Created by ChrisC on 22/05/17.
*/
public enum RestClient {
INSTANCE;
@chris-carneiro
chris-carneiro / TokerInterceptor.java
Created June 29, 2017 13:25
Token interceptor for okhttp 3
public class TokenInterceptor implements Interceptor {
private static final String TAG = TokenManager.class.getName();
private static final String header = "X-Header";
/**
* Constructor for Token interceptor
*/
public TokenInterceptor() {
@chris-carneiro
chris-carneiro / APIKeyInterceptor.java
Created June 29, 2017 13:28
Simple class that adds a secret key to each ws request using okhttp3
public class APIKeyInterceptor implements Interceptor {
private static final String SECRET_KEY_HEADER = "secret_key";
private static final String UUID_HEADER = "uuid";
private static final String TAG = "APIKeyInterceptor";
@Override
public Response intercept(Chain chain) throws IOException {
Request request = chain.request();
Log.d(TAG, "intercept ===============> "+request.url());
@chris-carneiro
chris-carneiro / TokenManager.java
Created June 29, 2017 13:29
Simple token manager for android
public class TokenManager {
private static final String TAG = TokenManager.class.getName();
private static TokenManager instance;
private String token;
private TokenManager() {
token = "";
@chris-carneiro
chris-carneiro / MailClient.java
Created June 29, 2017 13:34
Simple Mail client that uses JavaMail for android
import java.util.Properties;
import javax.mail.Authenticator;
import javax.mail.Folder;
import javax.mail.MessagingException;
import javax.mail.Session;
import javax.mail.Store;
import android.support.annotation.Nullable;
import android.support.annotation.WorkerThread;
@chris-carneiro
chris-carneiro / proguard-rules.pro
Last active September 28, 2022 06:30
Proguard rules sample for Retrofit2, Gson, OrmLite, Javamail, Otto, disable logging
# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in /home/chris/Android/Sdk/tools/proguard/proguard-android.txt
# You can edit the include path and order by changing the proguardFiles
# directive in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html
# Add any project specific keep options here:
@chris-carneiro
chris-carneiro / WebSecurityConfigurer.java
Last active February 1, 2018 13:53
Example of how to protect actuator endpoints with a basic auth
import org.springframework.boot.actuate.autoconfigure.ManagementServerProperties;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.core.annotation.Order;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.web.authentication.www.BasicAuthenticationEntryPoint;