<commit_before>#!/usr/bin/perl

use constant VERSION => "0.1";

#
# this is the backend postprocessing for the chaosvpn client
#
#
# normal client users do not need this!
#
#
# to setup your own backend you need to install a bunch of additional
# debian packages, create your own rsa backend secret key, and change
# the paths below.
#
# create secret rsa key:
# openssl genrsa -out privkey.pem 4096
#
# export public key part:
# openssl rsa -in privkey.pem -pubout -out pubkey.pem
#


# v0.01 20100127 <EMAIL>
# - first revision, based on old chaosvpn perl client

use strict;
use Data::Dumper;
use Archive::Ar;		# libarchive-ar-perl
use Compress::Zlib;		# libcompress-zlib-perl
use Crypt::OpenSSL::Random;     # libcrypt-openssl-random-perl
use Crypt::OpenSSL::RSA - RSA;  # libcrypt-openssl-rsa-perl
use Crypt::CBC;			# libcrypt-cbc-perl
use Crypt::Rijndael;		# libcrypt-rijndael-perl / AES

$| = 1;

my $GIT_DIR = $ENV{"GIT_DIR"};
if (!defined($GIT_DIR) || $GIT_DIR eq "" || !-d $GIT_DIR ) {
  print STDERR "\$GIT_DIR undefined!\n";
  exit(1);
}

my $destdir = `git config chaosvpn.destdir 2>/dev/null`;
$destdir =~ s/\s*$//s;
my $cleartextconfig = `git config chaosvpn.cleartextconfig 2>/dev/null`;
$cleartextconfig =~ s/\s*$//s;
my $signkey = "$GIT_DIR/chaosvpn-private/clearprivkey.pem";
my $signpubkey = "$GIT_DIR/chaosvpn-private/pubkey.pem";


# --- no changes needed below for simple usage ---


my $fileformat_version = "3";
# increase this number for every incompatible file format change


# check if git settings were there
if (!$destdir) {
  print STDERR "'git config chaosvpn.destdir' NOT DEFINED!\n";
  exit(1);
}
if (!$cleartextconfig) {
  print STDERR "'git config chaosvpn.cleartextconfig' NOT DEFINED!\n";
  exit(1);
}


my $config = read_file_into_string("<$GIT_DIR/export/chaosvpn-data.conf") || die "config read error\n";

my $sign_secret_key = read_file_into_string("<$signkey") || die "signkey read error\n";
my $sign_public_key = read_file_into_string("<$signpubkey") || die "signpubkey read error\n";

openssl_init();


# add warning header
$config =
  "#\n" .
  "# AUTOGENERATED FILE - DO NOT MODIFY MANUALLY!\n" .
  "# Edit only in chaosvpn-admin.git!\n" .
  "#\n" .
  "\n" .
  $config;

# first: compatibility for old perl script:
write_string_into_file(">$cleartextconfig", $config);
# second: compatibility for old sign method:
my $signature = rsa_sign_data($config, $sign_secret_key);
write_string_into_file(">$cleartextconfig.sig", $signature);


# third: new sign and encrypt
my $peers = parse_config($config);
if ($peers) {<commit_msg>Backend: disabled cleartext configfile in webtree<commit_after>#!/usr/bin/perl

use constant VERSION => "0.2";

#
# this is the backend postprocessing for the chaosvpn client
#
#
# normal client users do not need this!
#
#
# to setup your own backend you need to install a bunch of additional
# debian packages, create your own rsa backend secret key, and change
# the paths below.
#
# create secret rsa key:
# openssl genrsa -out privkey.pem 4096
#
# export public key part:
# openssl rsa -in privkey.pem -pubout -out pubkey.pem
#


# v0.01 20100127 <EMAIL>
# - first revision, based on old chaosvpn perl client
# v0.02 20100412 <EMAIL>
# - disabled cleartext config file in webtree

use strict;
use Data::Dumper;
use Archive::Ar;		# libarchive-ar-perl
use Compress::Zlib;		# libcompress-zlib-perl
use Crypt::OpenSSL::Random;     # libcrypt-openssl-random-perl
use Crypt::OpenSSL::RSA - RSA;  # libcrypt-openssl-rsa-perl
use Crypt::CBC;			# libcrypt-cbc-perl
use Crypt::Rijndael;		# libcrypt-rijndael-perl / AES

$| = 1;

my $GIT_DIR = $ENV{"GIT_DIR"};
if (!defined($GIT_DIR) || $GIT_DIR eq "" || !-d $GIT_DIR ) {
  print STDERR "\$GIT_DIR undefined!\n";
  exit(1);
}

my $destdir = `git config chaosvpn.destdir 2>/dev/null`;
$destdir =~ s/\s*$//s;
#my $cleartextconfig = `git config chaosvpn.cleartextconfig 2>/dev/null`;
#$cleartextconfig =~ s/\s*$//s;
my $signkey = "$GIT_DIR/chaosvpn-private/clearprivkey.pem";
my $signpubkey = "$GIT_DIR/chaosvpn-private/pubkey.pem";


# --- no changes needed below for simple usage ---


my $fileformat_version = "3";
# increase this number for every incompatible file format change


# check if git settings were there
if (!$destdir) {
  print STDERR "'git config chaosvpn.destdir' NOT DEFINED!\n";
  exit(1);
}
#if (!$cleartextconfig) {
#  print STDERR "'git config chaosvpn.cleartextconfig' NOT DEFINED!\n";
#  exit(1);
#}


my $config = read_file_into_string("<$GIT_DIR/export/chaosvpn-data.conf") || die "config read error\n";

my $sign_secret_key = read_file_into_string("<$signkey") || die "signkey read error\n";
my $sign_public_key = read_file_into_string("<$signpubkey") || die "signpubkey read error\n";

openssl_init();


# add warning header
$config =
  "#\n" .
  "# AUTOGENERATED FILE - DO NOT MODIFY MANUALLY!\n" .
  "# Edit only in chaosvpn-admin.git!\n" .
  "#\n" .
  "\n" .
  $config;

# first: compatibility for old perl script:
#write_string_into_file(">$cleartextconfig", $config);
# second: compatibility for old sign method:
#my $signature = rsa_sign_data($config, $sign_secret_key);
#write_string_into_file(">$cleartextconfig.sig", $signature);


# third: new sign and encrypt
my $peers = parse_config($config);
if ($peers) {
{'fraction_non_alphanumeric': 0.14481185860889395, 'fraction_numerical': 0.01121246674268339, 'mean_word_length': 4.44824016563147, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 16, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1541056', 'n_tokens_mistral': 2018, 'n_tokens_neox': 1941, 'n_words': 524}