Commit Graph
28 Commits
Author SHA1 Message Date
ac-stef 0b656d2380 add server-side player vita database
The server keeps track of every player ID that ever connected successfully.
This database stores the last names and IPs used by the player and the
last countries the connections came from. Some stats are counted, like
"time connected" and "total tks". Most importantly, the database stores
rights (like admin) and restrictions (like ban). All rights and
restrictions are kept as dates (or timecodes), so, for example, if your
ban date is in the future, you are banned - and if it's in the past, you
can play. The collected stats are meant to help server owners at managing
players - especially, if they want to give someone admin rights.

The database is periodically saved to a file and read from that file on
startup. The default file is config/servervita.cfg and one backup is kept
in config/servervita_bak.cfg. During server start, if the regular file
can't be loaded, the backup is tried instead.

While the server is running, it checks periodically for a file named
config/servervita_update.cfg, and if the file exists, it is renamed to
a backup filename including a timecode and read and merged into the
database. The automatic rename makes sure, that a file is only read once.
Using such updates, a server owner can easily give several people admin
rights or for example, add clan tags for a whole list of IDs. (Yes, the
database also stores a clan tag for every ID...)

The database also stores two short comments for every ID. One can only be
read by server admins, but the other one is public. The public reason, for
example, can state a reason for a ban.

One database record takes up 264 bytes of RAM. During autosave, accounts,
that have not been used for a specified time (default 12 months), will
not be written. After a server restart, those old records will be gone.

Currently, there is no process in place, to also clean up old records
from RAM. Maybe, that'll be added later...
2017-06-27 15:15:23 +02:00
ac-stef d6af5be3da add auth to client server connect protocol 2017-06-27 15:15:23 +02:00
ac-stef 3376c5e299 detect server config file changes by hashing
Checking only file sizes obviously misses content changes that don't
change the size.
2017-06-27 15:15:22 +02:00
ac-stef e147000ba2 replace some more strtok
also make sure, randomMT survives concurring use from different threads
2017-06-27 15:15:22 +02:00
ac-stef b49dd05411 add incremental mode for tiger hash
also clean up and fix some stuff: lilswap(unsigned long long int) mapped
to the 32-bit swap code...

added some runtime tests for the hash functions - now they will crash at
startup, if some test vectors fail (because big endian is still untested)
2017-05-24 11:18:18 +02:00
ac-stef 458b911ecd fix initialisation of entropy pool
have to know home dir before loading entropy.dat

add dummy screenshots on keypress events during first run to get entropy
2017-05-13 20:02:18 +02:00
David Carlierandac-stef 3335508955 Memory leaks and delete operator fixes.
(pull request #168)
2017-03-26 15:42:29 +02:00
ac-stef 422b407e79 misc VS warning fixes 2016-08-27 12:03:23 +02:00
ac-stef c4b570e8fd new menus for account management
During startup, it is checked, if the game account needs to be unlocked
by password. If so, the password is asked and applied.

If no game account exists yet, the creation of a new account is offered.

new command "mypubkey": returns public key of game account, or empty
  string, if no account exists or it is unusable (due to missing password,
  for example)

DOCREF mypubkey
2016-08-26 14:28:54 +02:00
ac-stef 4a9ae84613 add hashes for map files on server 2016-08-26 14:28:54 +02:00
ac-stef 1f5b3ed92a add basic cert management 2016-08-26 14:28:54 +02:00
ac-stef 400f1a318d add authkey command
authkey manages a list of keys other than the game key (which is managed
by authsetup). For example, this can be server owner keys or clan boss
keys.

authkey clear
  Empties the list and comments out all lines in config/authkeys.cfg.

authkey list
  Lists all authkeys that are currently in memory.

authkey delete keyname
  Deletes the key <keyname> from memory.

authkey new keyname
  Generates a new key with the name <keyname>. If a key of that name
  already exists, it is deleted. The key is added to the list in memory
  and also written to the file config/authkeys.cfg.

authkey add keyname privkey
  Adds a key with the name <keyname> to the list in memory. The privkey
  is a 32-byte hexadecimal string, preferrably generated by authkey new.
  The matching public key is generated automatically from the private key.

authkey selfcert keyname [comment]
  Generates a self-signed certificate for the key <keyname>. Being able to
  create such a cert is proof, that you own the private key of a certain
  public key.

DOCREF authkey
2016-08-26 14:28:54 +02:00
ac-stef 381e770210 add authsetup command
authsetup contains all the funtionality needed to generate, load and save
private and public keys, and to lock and unlock the private key with a
password.

Private and public keys are used to authenticate the player to servers,
and are loaded from config/authprivate.cfg. Private keys can be stored
in an "encrypted with password" version - in which case the player has
to enter the password after game start. To prevent brute-force cracking
of the password, the key-derivation function uses a constant time to
encode (usually several seconds). Because of that, the decoding at game
start can be done in the background.

The private key is actually itself a public key generated from the
prepriv key. The prepriv key should be kept away from the computer, either
as hardcopy or on a thumbdrive. The prepriv key is not required to play
the game. It can be used to prove ownership of the private key, in case
the private key gets stolen. It can also be used to regenerate private
and public keys, in case they are lost. The prepriv key can also be
encrypted by its own password.

authsetup
  checks private and public key and returns "1", if they match.

authsetup pre preprivhex [psalthex pwdcfg]
  loads prepriv key into memory. optionally supports encrypted keys.

authsetup priv privhex [salthex pwdcfg]
  loads private key into memory. optionally supports encrypted keys.

authsetup pub pubhex
  loads public key into memory.

authsetup ppass preprivpass
  decrypts prepriv key with password

authsetup pass privpass
  decrypts private key with password

authsetup passd privpass [commandwhendone]
  decrypts private key with password in background. optionally executes
  cubescript command when done.

authsetup needpass
  returns "1" if the private key needs decryption.

authsetup genpre [prelen]
  generates new prepriv key.

authsetup genpriv
  generates private key from prepriv key.

authsetup genpub
  generates public key from private key.

authsetup newppass preprivpass [preprivfilename]
  encrypts prepriv key with new password and saves the result to file.
  The default filename is config/authpreprivate.cfg and an existing file
  gets overwritten - but the former file content is kept and also written,
  each line commented out.

authsetup newpass privpass [privatefilename]
  encrypts private key with new password and saves the encrypted private
  key and the public key to file. The default filename is
  config/authprivate.cfg and an existing file gets overwritten - but the
  former file content is kept and also written, each line commented out.

authsetup unarmed
  sets private and public keys to a fixed value. For testing only.
  Can be used to "log out".

authmemusage, authrounds, authmaxtime are only used, when new passwords are
  created (authsetup new[p]pass). authmemusage is the number of megabytes
  of RAM that are used for the password hash calculation. If authrounds
  is zero (as is default), then the hash algorithm calculates as many
  rounds as possible in the number of milliseconds specified in
  authmaxtime. If authrounds is a positive number, then that is the number
  of rounds to be done, regardless the required time. Note that, since the
  password hash algorithm is not endianness-aware, it is not possible to
  move an encrypted password to a machine with different endianness.
  Moving between 32- and 64-bit machines should be no problem.

  FIXME: the command is not blocked against use in multiplayer. It has to
         be determined later, if this is a problem or feature. Especially
         the background password calculation may be a problem.

DOCREF authsetup cryptodebug authmemusage authrounds authmaxtime
2016-08-26 14:28:54 +02:00
ac-stef 940cc2e3d9 crypto tool functions and ed25519 vector test
* FNV-1a:  very fast, non-cryptographic hash
* bin2hex, hex2bin:  hex ascii parser and hex string formatter
* ed25519test:  vector test for all ed25519 functions
* ed25519speedtest:  yep, that
2016-08-26 14:28:54 +02:00
ac-stef 806e0f4f7e add Ed25519 ECC signature algorithm
The Ed25519 sources were taken from the crypto_sign/ed25519/ref
subdirectory of the SUPERCOP benchmarking tool.
The Ed25519 software is in the public domain.

Contributors (in alphabetical order)
    Daniel J. Bernstein, University of Illinois at Chicago
    Niels Duif, Technische Universiteit Eindhoven
    Tanja Lange, Technische Universiteit Eindhoven
    Peter Schwabe, National Taiwan University
    Bo-Yin Yang, Academia Sinica
2016-08-26 14:28:53 +02:00
ac-stef b080d634fc add memory-heavy key derivation function
* basically a hash function that delivers keylen bytes calculated
  from password and salt
* uses a lot of memory and a quite complex algorithm, to make
  brute-force offline-attacks on short passwords as hard as possible
* last line of defense against "evil little brothers"
2016-08-26 14:28:53 +02:00
ac-stef 8c7baa979c add SHA512 hash function and an entropy collector
SHA512 was adapted from a few public domain sources and pseudocode from
wikipedia. The entropy collector gathers entropy from keyboard events and
mouse movement - and, just for fun, from screenshots.
The entropy pool is saved at program exit and reloaded at program start.
Entropy is used to re-seed the pseudorandom generator (not that it would
make a difference).
2016-08-26 14:28:53 +02:00
ac-stef a45d926919 remove current auth system
* fix tiger hash for bigendian (we use the byte output, not the chunks)
* remove all ECC functions and comment out all calls to it
2016-08-26 14:28:53 +02:00
ac-stef 98d01d1f34 fix some errors and warnings for GCC 6
* do not use std::abs() because math.h includes one, that converts ints
  to double. Use own iabs(), which directly uses labs() instead.
* don't use the word "gamma" as name for variables
* don't use a homebrew round() function
2016-02-27 22:50:06 +01:00
ac-stef 50d1413d5c fix some warnings
Removed homebrew round() - now we just use the math library.
2015-08-03 20:57:50 +02:00
ac-stef 685dbb8326 store old state of random generator to restore after a seed()
The light calculation requires the random generator to be seeded with a
constant - otherwise repeated light recalculations would make the lights
change.

This patch allows the random generator to go back to the state before the
static seed().
2015-02-08 17:39:14 +01:00
ac-stef eb60302e67 cleanup
- fix possible crash in conc (but it's still an ugly hack)
- fix noob usage of strcmp
- flag some memory leaks (it would be nice, if the author(s) would clean
   up the mess himself)
- fix crash in substr
- whitespace cleanup

there are plenty more memory leaks in command.cpp - for example, every
goto in cubescript does not clean up anything
2014-05-14 22:54:37 +02:00
ac-stef d0722dbc27 fix seedlen 2014-05-14 22:38:29 +02:00
ac-stef ac54bdbb5a substitute non-portable printf format string
the printf format "llx" can not be used on all platforms (for example,
mingw uses a different name for it)

this patch provides a function, that manually converts a 64-bit integer
to a hex string

Thx, Jpablon
2014-05-14 22:17:21 +02:00
Lee Salzman 67392bd0fc cleaner Mersenne Twister implementation
git-svn-id: svn://svn.code.sf.net/p/actiongame/code/trunk/ac@6247 e016b1c5-ed68-44aa-a2f7-31cac88cffde
2011-04-14 14:36:05 +00:00
Lee Salzman 32d96b2be4 fix weirdness in random numbers and ray creation
git-svn-id: svn://svn.code.sf.net/p/actiongame/code/trunk/ac@6005 e016b1c5-ed68-44aa-a2f7-31cac88cffde
2011-01-15 21:20:31 +00:00
Glen Masgai 527d733688 password hash endianess fix
git-svn-id: svn://svn.code.sf.net/p/actiongame/code/trunk/ac@5765 e016b1c5-ed68-44aa-a2f7-31cac88cffde
2010-10-18 17:57:18 +00:00
flowtron e61d9f6c45 crypto >= hash
git-svn-id: svn://svn.code.sf.net/p/actiongame/code/trunk/ac@5636 e016b1c5-ed68-44aa-a2f7-31cac88cffde
2010-08-16 11:11:05 +00:00