summaryrefslogtreecommitdiff
path: root/sys/src/libsec
AgeCommit message (Collapse)Author
2023-05-13libsec: add parentesis to squelch gcc warning in drawtermcinap_lenrek
not a bug, just make it easier to keep drawtem code and libsec in sync...
2023-02-19mkfiles: add 'mk test' supportOri Bernstein
9front has several tests scattered throughout the source, as well as more tests in an external 'regress' repository. Many of these tests are broken, because there is no easy way to build and track all of them. This pulls in several tests from different sources, deletes the broken tests, tests with missing data, and adds a single command that can be run from the root of the src directory to test our system. The hope is that as we develop new code, we add more tests, and eventually start running the tests on every commit. Please enter the commit message for your changes. Lines starting
2022-11-10libsec: add minimal support for the tls renegotiationAnthony Martin
OpenSSL 3.0 clients refuse to connect to servers that do not support the renegotiation extension (RFC 5746) unless the default configuration is changed to allow it. Since we do not support renegotiation, we only need to make minor changes to the initial handshake to comply with the specification: 1. For tlsClient, simply add the proper SCSV to the ClientHello cipher list (cf. RFC 5746 § 3.3); 2. For tlsServer, respond with an empty renegotiation extension in the ServerHello if we received either the SCSV or an empty renegotiation extension in the ClientHello. Since we close the hand file and never open it after the initial handshake, we can rely on tls(3) to send the "no renegotiation" alerts if subsequent handshake records are received.
2023-01-06libsec: fix inconsistent prototypes for des (from drawterm)cinap_lenrek
2022-12-25libsec: use /net/tls instead of #a/tlscinap_lenrek
Namespace files have been updated and the tls device is now available under /net.
2022-06-24upas/dkim: dkim signing for upasori@eigenstate.org
This change adds support for dkim signing to upas. It has2 pieces: 1. Adding support for different asn1 formats to auth/rsa2asn1; we can now generate SubjectPublicKeyInfo RSA keys, which wrap the keys up with an algorithm identifier. 2. Adding a upas/dkim command which filters a message and signs it using dkim. To configure dkim, you need to generate a (small-ish) rsa key; large keys do not fit into DNS text records: # generate the private key and add it to factotum ramfs -p cd /tmp auth/rsagen -b 2048 -t 'service=dkim role=sign hash=sha256 domain=orib.dev owner=*' > dkim.key cat dkim.key > factotum.ctl # extract the public key, encode it, and strip out the junk pubkey=`{ <dkim.key auth/rsa2asn1 -f spki | \ auth/pemencode WHATEVER | \ grep -v 'WHATEVER' | \ ssam 'x/\n/d' } domain=example.org # then add it to /lib/ndb.local echo 'dom=dkim._domainkey.'$domain' soa= ip=144.202.1.203 refresh=600 ttl=600 ns=ns.orib.dev txt="k=rsa; v='$pubkey \ >> /lib/ndb/local Then, finally, insert it into your outgoing mail pipeline. One thing to be careful of is that upas will do some outgoing 'From:' rewriting, so you may need to make sure that either '$upasname' is set, or 'upas/dkim' is inserted after the rewrite stage. A good place is in /mail/lib/qmail, in place of upas/vf: % cat /mail/lib/qmail rfork s upas/dkim -d example.com | upas/qer /mail/queue mail $* || exit 'qer failed' upas/runq -n 10 /mail/queue /mail/lib/remotemail </dev/null >/dev/null >[2=1] &
2022-03-27libsec: fix wrong tls1.0 prf regressioncinap_lenrek
The change 775a4bea4386c12067057de0e56dd8baa34f43ec "libsec: various changes to tls" ... 4. simply prf code... ... broke the TLS1.0 prf function, missing the fact that the prf ouput for sha1 and md5 need to be xored together.
2022-01-10reduce: use if() to test for exit status of pipelinecinap_lenrek
The new rc's exit status will be '' for a successfull pipeline execution instead of '|'. This is a bit too tightly coupled, so just use if() statement instead, handling this in a portable way.
2021-10-31libsec: no point in checking for "xn--" marker, just call idn2utf().cinap_lenrek
2021-10-31libsec: decode international domain names in certificat subject, fix ↵cinap_lenrek
overflow botch this is for consistency, so all certificte subjects will be returned in utf8.
2021-10-31libsec: handle international domain names in certificate requestcinap_lenrek
2021-10-22libsec: fix wrong assert condition (introduced in ↵cinap_lenrek
775a4bea4386c12067057de0e56dd8baa34f43ec)
2021-10-17libsec: fix operator precedence bugs (thanks kemal)cinap_lenrek
2021-10-17libsec: fix bugs in tls extension handling (thanks kemal)cinap_lenrek
this patch fixes bugs in tls extension handling: 1. if conn->serverName is an empty string, tlsClientExtensions will generate a SNI with an empty hostname, which is forbidden according to RFC 6066: opaque HostName<1..2^16-1>; check if conn->serverName has at least one char. 2. checkClientExtensions fail with clients that doesn't have extensions, because it doesn't check if ext is nil. fix that up. 3. rewrite checkClientExtensions. some parts of the code does not check the length properly, and it could be simplified heavily.
2021-08-09x509: encode empty sequence as constructedOri Bernstein
According to the ASN.1 BER spec, we should be encoding all sequences (including empty ones) as constructed: 8.9.1 The encoding of a sequence value shall be constructed. 8.10.1 The encoding of a sequence-of value shall be constructed. 8.11.1 The encoding of a set value shall be constructed. 8.12.1 The encoding of a set-of value shall be constructed. However, we were only setting them as constructed when the list was non-empty. This changes it, and makes letsencrypt happy with the CSRs that we generate.
2021-07-08libsec: take just the CN part of Distinguished Name in subjectAltNamecinap_lenrek
2021-07-04libsec: do proper type checking, fix wrong deduplication checkcinap_lenrek
2021-07-04libsec: add X509reqtoRSApub() function and return subject alt names in ↵cinap_lenrek
X509to*pub() name buffer We need a way to parse a rsa certificate request and return the public key and subject names. The new function X509reqtoRSApub() works the same way as X509toRSApub() but on a certificate request. We also need to support certificates that are valid for multiple domain names (as tlshand does not support certificate selection). For this reason, a comma separated list is returned as the certificate subject, making it symmetric to X509rsareq() handling. A little helper is provided with this change (auth/x5092pub) that takes a certificate (or a certificate request when -r flag is provided) and outputs the RSA public key in plan 9 format appended with the subject attribute.
2021-06-21libsec: restore old behaviour for generating self signed certcinap_lenrek
2021-06-20libsec: emulate openssl asn1 when generating x509 csrcinap_lenrek
when trying to request certificates from letsencrypt, their test api would reject our csr because of "tuncated sequence" unless we force subectAltName by passing multiple domains (as comma separated list). apparently, we need to provide the context specific tag "cont [ 0 ]" for the extensions even when we do have any extensions for the csr (triggered when we need to have subjectAltNames). for this, we change mkcont() to take a Elist* instead, which then can be nil when not used. also put the tag number argument first, which makes it easier to read.
2021-06-20libsec: move zero check to curve25519_dh_finish()cinap_lenrek
As checking for all zero has to be done in a timing-safe way to avoid a side channel, it is best todo this here instead of letting the caller deal with it. This adds a return type of int to curve25519_dh_finish() where returning 0 means we got a all zero shared key. RFC7748 states: The check for the all-zero value results from the fact that the X25519 function produces that value if it operates on an input corresponding to a point with small order, where the order divides the cofactor of the curve.
2021-06-18libsec: various changes to tlskemal
1. add the curve x25519 to tls, both client and server. it's more faster, immune to timing attacks by design, does not require verifying if the public key is valid, etc etc. server-side has to check if the client supports the curve, so a new function has been introduced to parse the client's extensions. 2. reject weak dhe primes that can be easily cracked with the number field sieve algorithm. this avoids attacks like logjam. 3. stop putting unix time to the first 4 bytes of client/ server random. it can allow fingerprinting, tls 1.3 doesn't recommend it any more and there was a draft to deprecate this behaviour earlier.[1] 4. simply prf code, remove useless cipher enums. [1] https://datatracker.ietf.org/doc/html/draft-mathewson-no-gmtunixtime-00
2020-12-07libsec: open internal file-descriptors with OCEXEC flagcinap_lenrek
2020-04-28libsec/base58enc: null-terminate the resultSigrid
2020-03-01libsec: remove hash pickle functions, document ripemd160, cleanup sechash(2) ↵cinap_lenrek
manpage
2019-08-30auth/rsa2asn1: implement private key export with -a flag (thanks kvik)cinap_lenrek
kvik writes: I needed to convert the RSA private key that was laying around in secstore into a format understood by UNIX® tools like SSH. With asn12rsa(8) we can go from the ASN.1/DER to Plan 9 format, but not back - so I wrote the libsec function asn1encodeRSApriv(2) and used it in rsa2asn1(8) by adding the -a flag which causes the full private key to be encoded and output.
2019-05-03libsec: dummy mkfile for arm64cinap_lenrek
2018-12-02libsec: fix memory leak in pkcs1_decrypt()cinap_lenrek
2018-01-06libsec: remove asn1toDSApriv()cinap_lenrek
2017-12-30libsec: implement SPKI fingerprinting for okCertificate()cinap_lenrek
Instead of only using a hash over the whole certificate for white/black-listing, now we can also use a hash over the Subject Public Key Info (SPKI) field of the certificate which contians the public key algorithm and the public key itself. This allows certificates to be renewed independendtly of the public key. X509dump() now prints the public key thumbprint in addition to the certificate thumbprint. tlsclient will print the certificate when run with -D flag. okCertificate() will print the public key thumbprint in its error string when no match has been found.
2017-12-30libsec: fix mistake: strnchr -> strchrcinap_lenrek
2017-12-30libsec: avoid unneccesary memory copies and redundant code in x509cinap_lenrek
getting rid of some functions that take Byte* and instead pass uchar* and length. keeping the signature and public key fields in CertX509 as Bits* allows ownership transfer by swapping pointers. use common code to copy CN from subject field.
2017-12-29libsec: get rid of dummy data[1] in Bytes and Ints types (thanks pr)cinap_lenrek
2017-11-30libsec: make includes consistent for sha2block*.ccinap_lenrek
2017-11-30libsec: unroll portable sha1block functioncinap_lenrek
just 6-10% slower than most assembly versions. 20% faster on zynq.
2017-11-30libsec: unroll portable sha2block functionscinap_lenrek
- unroll the loops - rotate the taps on each step, avoiding copies - simplify boolean formulas for Ch() and Maj() this yields arround 40% throughput increase on 32/64bit archs for sha2_256 and sha2_512 on amd64.
2017-11-27libsec: optimize aesCBCencrypt()/aesCBCdecrypt()cinap_lenrek
- get rid of the temporary copies and memmoves() - when the data pointer is aligned, do xor and copying inline speedup for auth/aescbc encryption depends on arch: - zynq 7% (arm) - t23 13% (386) - x230 20% (amd64, aes-ni) - apu2 25% (amd64, aes-ni)
2017-11-20libsec: write optimized _chachablock() function for amd64 / sse2cinap_lenrek
doing 4 quarterround's in parallel using 128-bit vector registers. for second round shuffle the columns and then shuffle back. code is rather obvious. only trick here is for the first quaterround PSHUFLW/PSHUFHW is used to swap the halfwords for the <<<16 rotation.
2017-11-12libsec: AES-NI support for amd64cinap_lenrek
Add assembler versions for aes_encrypt/aes_decrypt and the key setup using AES-NI instruction set. This makes aes_encrypt and aes_decrypt into function pointers which get initialized by the first call to setupAESstate(). Note that the expanded round key words are *NOT* stored in big endian order as with the portable implementation. For that reason the AESstate.ekey and AESstate.dkey fields have been changed to void* forcing an error when someone is accessing the roundkey words. One offender was aesXCBmac, which doesnt appear to be used and the code looks horrible so it has been deleted. The AES-NI implementation is for amd64 only as it requires the kernel to save/restore the FPU state across syscalls and pagefaults.
2017-10-29libsec: rewrite aex_xts_encrypt()/aes_xts_decrypt()cinap_lenrek
the previous implementation was not portable at all, assuming little endian in gf_mulx() and that one can cast unaligned pointers to ulong in xor128(). also the error code is likely to be ignored, so better abort() when the length is not a multiple of the AES block size. we also pass in full AESstate structures now instead of the expanded key longs, so that we do not need to hardcode the number of rounds. this allows each indiviaul keys to be bigger than 128 bit.
2017-10-17libsec: make sectorNumber argument for aes_xts routines uvlongcinap_lenrek
2017-10-17libsec: add AES CFB and AES OFB stream cipherscinap_lenrek
2017-10-06libsec: export asn1encodedigest(), asn1encodeRSApub(), asn1toRSApub(), ↵cinap_lenrek
pkcs1padbuf() and pkcs1unpadbuf()
2017-10-05libsec: allow \r\n terminated lines in decodePEM()cinap_lenrek
2017-04-23libsec: sha256 support for thumbprint files, use it in ssh as wellcinap_lenrek
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-04tlshand: simplify tlsReadN()cinap_lenrek
2017-04-04tlshand: fix mpint to bytes conversion, reorganize send/recv buffer, check ↵cinap_lenrek
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-03tlshand: fix ECDHE and DHE for SSLv3cinap_lenrek
2017-02-10libsec: zero name buffer in X509toECpub()cinap_lenrek
2017-02-10libsec: make X509toECpub() return CN name like X509toRSApub()cinap_lenrek