Commit graph

125 commits

Author SHA1 Message Date
cinap_lenrek 346f5828e0 libsec: sha256 support for thumbprint files, use it in ssh as well
initThumbprints() now takes an application tag argument
so x509 and ssh can coexist.

the thumbprint entries can now hold both sha1 and sha256
hashes. okThumbprint() now takes a len argument for the
hash length used.

the new function okCertificate() hashes the certificate
with both and checks for any matches.

on failure, okCertificate() returns 0 and sets error string.

we also check for include loops now in thumbfiles, limiting
the number of includes to 8.
2017-04-23 19:00:08 +02:00
cinap_lenrek 249ff9a24c tlshand: simplify tlsReadN() 2017-04-04 19:01:57 +02:00
cinap_lenrek de80075fc6 tlshand: fix mpint to bytes conversion, reorganize send/recv buffer, check for overflow in msgSend()
when converting mpint to bytes, always pad it to the size of
the modulus (RSA,DHE,ECDHE). mptobytes() now takes a byte len
parameter which the caller usually calculates from the group
modulus using mpsignif(). this bug sometimes caused "bad record mac"
after the handshake.

use a shared buffer, given that msgSend()/msgRecv() don't overlap
we can use the first half for sending, and the top half for
receiving, shifting down as neccesary. the space beween sendp and
recvp is free.

explicitely check for overflow in msgSend().
2017-04-04 01:59:17 +02:00
cinap_lenrek 6ff5c10ffb tlshand: fix ECDHE and DHE for SSLv3 2017-04-03 02:48:47 +02:00
cinap_lenrek 6840a9aafd libsec: zero name buffer in X509toECpub() 2017-02-10 21:42:11 +01:00
cinap_lenrek fb2abc2a04 libsec: make X509toECpub() return CN name like X509toRSApub() 2017-02-10 21:36:19 +01:00
cinap_lenrek 24007b9120 libsec: revert asn1mpint(), rewrite rsa signature validation, cleanups
reverting asn1mpint() as all users really just expect
unsigned integers here. also openssl seems to interpret
rsa modulus as unsigned no matter what... so keeping
it as it was before.

handle nil cipher bytes in factotum_rsa_decrypt() due
to pkcs1padbuf() failing.

apply some lessions from intels berzerk paper:

instead of parsing the decrypted digest info blob, we
generate the *expected* blob's for all digest algorithms
that match the digest size and compare the results.

provide pkcs1 pad and unpad functions that consistently
enforce minimum padding size and handles block types 1
and 2.
2017-02-10 00:08:38 +01:00
cinap_lenrek 6386a0391a libsec: handle signed asn.1 bigint to mpint conversion for x509 2017-02-06 21:40:42 +01:00
cinap_lenrek bbce9c0566 rsagen: prefer 65537 as the default exponent when elen == 0, otherwise pick randomly 2017-02-06 04:25:38 +01:00
cinap_lenrek 5256f4063e libsec: fix mkbigint(), asn.1 uses two's compement signed representation
quick fix is to bias the rounding so the msb will always
be zero. should write proper conversion code to actually
deal with signed mpints... also for asn1mpint()... -- cinap
2017-02-06 03:50:03 +01:00
cinap_lenrek 02b3c609ed libsec: check if modulus is too small for message in pkcs1padbuf() 2017-02-06 02:03:16 +01:00
cinap_lenrek 1df513a2a1 libsec: need PKCS#9 "Extension Request" attribute (rsareq()) 2017-02-06 01:01:34 +01:00
cinap_lenrek 00575e07bb libsec: have rsagen() always produce postive !dk to avoid confusion 2017-02-05 05:15:17 +01:00
cinap_lenrek e9bf14eceb libsec: avoid temp variables in chacha/salsa ENCRYPT() macro
given that we only pass uchar* with constant offsets
to the s and d arguments of ENCRYPT(), we do not need
the temporary variables sp/dp and the compiler is
smart enougth to combine the const offset with the ones
from GET4() and PUT4() and emit single load and store
instructions for the byte accesses.
2017-01-15 04:09:47 +01:00
cinap_lenrek 2e23780d2f libsec: implement extended 192-bit nonce xchacha variant and hchacha function 2017-01-12 20:16:38 +01:00
cinap_lenrek ed9fdc72f5 libsec: replace des based X9.17 genrandom() with chacha random number generator 2016-12-28 02:02:00 +01:00
cinap_lenrek 6fc0e0541c libsec: remove unused get32() function 2016-11-17 19:54:13 +01:00
ftrvxmtrx 8f221cfec1 libsec: remove unused aes_setupDec 2016-11-17 02:02:32 +01:00
cinap_lenrek c9d55cadb3 libsec: add secp384r1 curve parameters for tls 2016-10-30 02:15:40 +01:00
cinap_lenrek 1492f46f87 libsec: add scrypt password based key derivation function 2016-07-10 21:41:57 +02:00
cinap_lenrek 67a9174ff8 chacha: calculate rounds in separate function (helps registerizer), get rid of unrolled code 2016-06-26 15:28:01 +02:00
cinap_lenrek 675ee1db15 auth/rsa2x509: generate x509v3 cert as extension field might not otherwise not be expected 2016-05-12 12:41:32 +02:00
cinap_lenrek 67158d5b05 auth/rsa2x509, auth/rsa2csr: allow appending SubjectAlternativeNames (SAN) to multi-domain certificate generation 2016-05-12 03:17:15 +02:00
cinap_lenrek 986886f2b8 retire the dec alpha port 2016-05-04 16:11:48 +02:00
cinap_lenrek 17a67eeb65 libsec: implement server side SCSV preventing silly client fallbacks
silly clients (web*) reconnect when the handshake failed with a lower
protocol version, which allows downgrade attacks (POODLE). but instead
of stopping this madness, they invented a new magic TLSID to indicate
to the server that this connection attempt is a retry, and rely on the
server to notice and stop them from sabotaging themselfs.
2016-04-22 02:33:29 +02:00
cinap_lenrek 7b3334775e libsec: order tlshand cipher suits by: keyexchange>=cipher>=hash, ignore client preference
client preference is usualy crazy, so just ignore it.
we always want the diffie hellman suits before static
rsa and prefer chacha over aes-gcm.
2016-04-21 23:29:59 +02:00
cinap_lenrek 42c4cc75a6 libsec: remove affine coordinate point operations from ecc
we now just do point addtion in jacobian coordinate system, and
convert the result to affine when s->z == nil.
2016-04-21 20:41:19 +02:00
cinap_lenrek 2fa4c8ef66 libsec: implement elliptic curve group operations in jacobian coordinate system 2016-04-20 20:09:59 +02:00
cinap_lenrek ff47cbd464 libsec: implement server side ECDHE key exchange with secp256r1, move DH state in TlsSec structure, simplify
implement ECDHE key exchange with secp256r1 on the server side, providing
perfect forward secrecy (tho slowly).

it is easier to just keep the ECDH/DH state in the TlsSec structure,
which fits better with the grouping of the functions. we do the cleanup
in tlsConnectionFree() now, so a lot of error handling logic could go
away.

reinvestigated some error paths and removed the ones that cannot error.

move functions to fit the logical grouping.

combine the code for signing handshake hashes (for client certs) and
DH parameters. provide digestDHparams() function to be shared between
server and client code.
2016-04-18 19:24:57 +02:00
cinap_lenrek ad6b99359d libsec: massive cleanup of tlshand.c
don't pass or generate sessionID's. this was never used nor
actually implemented and leaks the process pid.

get rid of version and random field duplications, move TlsSec
structure into TlsConnection.

make msgRecv() clear the message first, get rid of unneccesary
msgClear() calls.
2016-04-17 07:20:54 +02:00
cinap_lenrek 54c49284e0 libsec: fix memory leak of RSApub, avoid parsing certificate twice to extract rsa public key
instead of letting factotum_rsa_open() parse the certificate,
we pass in the rsa public key which is then matched against the
factotum keyring. this avoids parsing the x509 certificate
twice.

the sec->rsapub was not freed, so free it in tlsSecClose()
2016-04-16 23:36:55 +02:00
cinap_lenrek 294e08fa1e libsec: recognize and decode PKCS#8 wrapped RSA private keys for auth/asn12rsa
example usage:

auth/pemdecode 'PRIVATE KEY' test.pem | auth/asn12rsa
2016-04-16 04:16:10 +02:00
cinap_lenrek 9e08127ba6 libsec: x509: convert to UTF8 from BMPString and UNIString, reject \0 bytes 2016-04-15 23:51:52 +02:00
cinap_lenrek 44cbb29308 libsec: make #include headers consistent 2016-04-10 20:23:18 +02:00
cinap_lenrek c3c726a5d0 libsec: dont use mips assembly routines for spim, wrong endianess 2016-04-10 20:22:00 +02:00
cinap_lenrek fd9560d7d8 libsec: fix tlsid for TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256, TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256
the previous cipher id's where fore TLS_ECDH_* not TLS_ECDHE_*... sorry :(
2016-03-28 21:58:37 +02:00
cinap_lenrek aa6673fcfb add portable AES-GCM (Galois/Counter Mode) implementation to libsec and devtls 2016-03-23 02:45:35 +01:00
cinap_lenrek bf04ac5173 libsec: remove weakCipher[] array check as we do not support any of these weak ciphers 2016-03-12 13:24:46 +01:00
cinap_lenrek 169bfb4610 libsec: fix verifyDHparams() for version <= TLS1.1
for version <= TLS1.1, there is no sigalg field in the ServerKeyExchange
message and the signature digest algorithm is fixed to md5+sha1 and we
only support RSA signatures (TLS1.1 doesnt know about ECDSA).
2016-03-01 11:30:01 +01:00
cinap_lenrek e1633ed338 libsec: remove unused tlsSecKill() 2016-02-19 09:14:09 +01:00
cinap_lenrek 0cad8a59ed libsec: fix memset() size in tlsConnectionFree(), remove #include <bio.h> 2016-02-18 18:42:04 +01:00
cinap_lenrek 7f2599254a libsec: add libc.h include for aes_xts.c (drawterm) 2016-02-17 18:50:23 +01:00
cinap_lenrek eeb96dca21 libsec: simplify pkcs1_decrypt() 2016-02-11 22:59:25 +01:00
cinap_lenrek 6033931b02 libsec: fix double free in pkcs1_decrypt(), handle bad epm length in tlsSecRSAs(), cleanup 2016-02-11 22:42:28 +01:00
cinap_lenrek b63a6bf626 libsec: fix missing error case unlock() in tlshands initCiphers() 2016-02-07 00:31:30 +01:00
cinap_lenrek b7f2aed0f2 libsec: mpconv -> mpfmt 2016-02-06 07:19:31 +01:00
cinap_lenrek 78808ca314 libsec: refactor asn1 encoding of digest for rsa signatures, fix memory leak in ecverify 2016-02-03 04:18:54 +01:00
cinap_lenrek a291bbdedd libsec: ecdsa client support for tlshand, cleanups 2016-02-01 21:34:49 +01:00
cinap_lenrek 7cf11db685 libsec: add salsa20 stream cipher 2016-01-19 12:50:33 +01:00
cinap_lenrek 5e24adafef libsec: make sure theres no garbage after the asn.1 decode, cleanup 2016-01-06 05:30:44 +01:00