Skip to content

Instantly share code, notes, and snippets.

@artem-smotrakov
artem-smotrakov / build_picotls_with_gcov.sh
Created June 11, 2018 18:51
Clone and build picotls with gcov
#!/bin/bash
git clone https://github.com/h2o/picotls
cd picotls
export CFLAGS="-fprofile-arcs -ftest-coverage -g -O0 -fsanitize=address -fno-omit-frame-pointer"
export LDFLAGS="-fsanitize=address"
cmake \
@artem-smotrakov
artem-smotrakov / cli.patch
Created June 11, 2018 19:10
A patch for t/cli.c which adds a signal handler for dumping code coverage data
diff --git a/t/cli.c b/t/cli.c
index 8d9b68b..99cc4ab 100644
--- a/t/cli.c
+++ b/t/cli.c
@@ -19,6 +19,11 @@
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
* IN THE SOFTWARE.
*/
+
+/*
@artem-smotrakov
artem-smotrakov / SecurityConfiguration.java
Last active August 21, 2018 14:18
An example of SecurityConfiguration for an application based on Spring framework
@Configuration
public class SecurityConfiguration extends WebSecurityConfigurerAdapter {
private static final String readScope = "#oauth2.isOAuth() && #oauth2.hasScope('read')";
@Bean
@Override
public AuthenticationManager authenticationManagerBean() throws Exception {
return super.authenticationManagerBean();
}
package com.gypsyengineer.tlsbunny.jsse;
import javax.net.ssl.SSLServerSocket;
import javax.net.ssl.SSLServerSocketFactory;
import javax.net.ssl.SSLSocket;
import javax.net.ssl.SSLSocketFactory;
import java.io.*;
/*
* Don't forget to set the following system properties when you run the class:
package com.gypsyengineer.innerclass.field;
public class Outer {
private int secret = 10;
public void check() {
if (secret < 0) {
System.out.println("Oops");
} else {
public class A {
private int secret;
public class B {
public go() {
// do something
}
}
}
package com.gypsyengineer.innerclass.field;
public class AccessPrivateField {
public static void test01() throws Exception {
System.out.println("Test #1: try to modify a private field with the same classloader");
System.out.println(" (no exception is expected, 'oops' should be printed out)");
Outer outer = new Outer();
go(outer);
outer.check();
package com.gypsyengineer.innerclass.field;
public class AccessPrivateField {
public static void test02(ClassLoader cl) throws Exception {
System.out.println("Test #2: try to modify a private field with different classloader");
System.out.println(" (an exception is expected)");
// Load AccessPrivateField class with different classloader
Class clazz = cl.loadClass(
"com.gypsyengineer.innerclass.field.AccessPrivateField");
@artem-smotrakov
artem-smotrakov / ChannelSecurityConfig.java
Last active October 10, 2018 14:01
Enforcing HTTPS and enabling HSTS header in Spring security config, see more in https://blog.gypsyengineer.com/en/security/tips-configuring-security-rest-api-spring.html
@Configuration
@EnableWebSecurity
public class ChannelSecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http.requiresChannel().anyRequest().requiresSecure();
http.headers().httpStrictTransportSecurity();
// ...
}
@artem-smotrakov
artem-smotrakov / SecurityConfig.java
Last active October 10, 2018 14:01
Disabling built-in session management in Spring Boot config, see more in https://blog.gypsyengineer.com/en/security/tips-configuring-security-rest-api-spring.html
@Configuration
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http.sessionManagement()
.sessionCreationPolicy(SessionCreationPolicy.STATELESS);
// ...
}