aboutsummaryrefslogtreecommitdiffstats
path: root/test/netlib/data/verificationcerts/generate.py
blob: 6d4d855055a8af9a9a7d57e6393fa1c17ee40e2c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
"""
Generate SSL test certificates.
"""
import subprocess
import shlex
import os
import shutil


ROOT_CA = "trusted-root"
SUBJECT = "/CN=example.mitmproxy.org/"


def do(args):
    print("> %s" % args)
    args = shlex.split(args)
    output = subprocess.check_output(args)
    return output


def genrsa(cert):
    do("openssl genrsa -out {cert}.key 2048".format(cert=cert))


def sign(cert):
    do("openssl x509 -req -in {cert}.csr "
       "-CA {root_ca}.crt "
       "-CAkey {root_ca}.key "
       "-CAcreateserial "
       "-days 1024 "
       "-out {cert}.crt".format(root_ca=ROOT_CA, cert=cert)
       )


def mkcert(cert, args):
    genrsa(cert)
    do("openssl req -new -nodes -batch "
       "-key {cert}.key "
       "{args} "
       "-out {cert}.csr".format(cert=cert, args=args)
       )
    sign(cert)
    os.remove("{cert}.csr".format(cert=cert))


# create trusted root CA
genrsa("trusted-root")
do("openssl req -x509 -new -nodes -batch "
   "-key trusted-root.key "
   "-days 1024 "
   "-out trusted-root.crt"
   )
h = do("openssl x509 -hash -noout -in trusted-root.crt").decode("ascii").strip()
shutil.copyfile("trusted-root.crt", "{}.0".format(h))

# create trusted leaf cert.
mkcert("trusted-leaf", "-subj {}".format(SUBJECT))

# create self-signed cert
genrsa("self-signed")
do("openssl req -x509 -new -nodes -batch "
   "-key self-signed.key "
   "-subj {} "
   "-days 1024 "
   "-out self-signed.crt".format(SUBJECT)
   )
.num_frames = 4, .loop = false, .frame_lengths = {0, MS2ST(1000), MS2ST(5000), 0}, .frame_functions = {display_welcome, keyframe_animate_backlight_color, keyframe_no_operation, enable_visualization}, }; // The color animation animates the LCD color when you change layers static keyframe_animation_t color_animation = { .num_frames = 2, .loop = false, // Note that there's a 200 ms no-operation frame, // this prevents the color from changing when activating the layer // momentarily .frame_lengths = {MS2ST(200), MS2ST(500)}, .frame_functions = {keyframe_no_operation, keyframe_animate_backlight_color}, }; // The LCD animation alternates between the layer name display and a // bitmap that displays all active layers static keyframe_animation_t lcd_animation = { .num_frames = 2, .loop = true, .frame_lengths = {MS2ST(2000), MS2ST(2000)}, .frame_functions = {keyframe_display_layer_text, keyframe_display_layer_bitmap}, }; void initialize_user_visualizer(visualizer_state_t* state) { // The brightness will be dynamically adjustable in the future // But for now, change it here. lcd_backlight_brightness(0x50); state->current_lcd_color = LCD_COLOR(0x00, 0x00, 0xFF); state->target_lcd_color = LCD_COLOR(0x10, 0xFF, 0xFF); start_keyframe_animation(&startup_animation); } void update_user_visualizer_state(visualizer_state_t* state) { // Add more tests, change the colors and layer texts here // Usually you want to check the high bits (higher layers first) // because that's the order layers are processed for keypresses // You can for check for example: // state->status.layer // state->status.default_layer // state->status.leds (see led.h for available statuses) if (state->status.layer & 0x2) { state->target_lcd_color = LCD_COLOR(0xA0, 0xB0, 0xFF); state->layer_text = "Layer 2"; } else { state->target_lcd_color = LCD_COLOR(0x50, 0xB0, 0xFF); state->layer_text = "Layer 1"; } // You can also stop existing animations, and start your custom ones here // remember that you should normally have only one animation for the LCD // and one for the background. But you can also combine them if you want. start_keyframe_animation(&lcd_animation); start_keyframe_animation(&color_animation); }