%PDF- %PDF-
Direktori : /usr/local/share/emacs/27.2/lisp/net/ |
Current File : //usr/local/share/emacs/27.2/lisp/net/nsm.elc |
;ELC ;;; Compiled ;;; in Emacs version 27.2 ;;; with all optimizations. ;;; This file contains utf-8 non-ASCII characters, ;;; and so cannot be loaded into Emacs 22 or earlier. (and (boundp 'emacs-version) (< (aref emacs-version (1- (length emacs-version))) ?A) (string-lessp emacs-version "23") (error "`%s' was compiled for Emacs 23 or later" #$)) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (byte-code "\300\301!\210\300\302!\210\300\303!\210\300\304!\210\300\305!\207" [require cl-lib rmc subr-x seq map] 2) (defvar nsm-permanent-host-settings nil) (defvar nsm-temporary-host-settings nil) (byte-code "\300\301\302\303\304\305\306\307&\210\310\311\312\313\314DD\315\304\305\316\317&\210\310\320\312\313\321DD\322\304\323\316\324&\210\310\325\312\313\326DD\327\304\305\316\330&\210\310\331\312\313\332DD\333\304\305\316\334&\207" [custom-declare-group nsm nil "Network Security Manager" :version "25.1" :group comm custom-declare-variable network-security-level funcall function #[0 "\300\207" [medium] 1] "How secure the network should be.\nIf a potential problem with the security of the network\nconnection is found, the user is asked to give input into how the\nconnection should be handled.\n\nThe following values are possible:\n\n`low': No checks are performed: This is extremely insecure.\n`medium': Default. Suitable for most circumstances.\n`high': Warns about additional issues not enabled in `medium' due to\ncompatibility concerns.\n`paranoid': On this level, the user is queried for most new connections.\n\nSee the Emacs manual for a description of all things that are\nchecked and warned against." :type (choice (const :tag "Low" low) (const :tag "Medium" medium) (const :tag "High" high) (const :tag "Paranoid" paranoid)) nsm-trust-local-network #[0 "\300\207" [nil] 1] "Disable warnings when visiting trusted hosts on local networks.\n\nThe default suite of TLS checks in NSM is designed to follow the\nmost current security best practices. Under some situations,\nsuch as attempting to connect to an email server that do not\nfollow these practices inside a school or corporate network, NSM\nmay produce warnings for such occasions. Setting this option to\na non-nil value, or a zero-argument function that returns non-nil\ntells NSM to skip checking for potential TLS vulnerabilities when\nconnecting to hosts on a local network.\n\nMake sure you know what you are doing before enabling this\noption." "27.1" (choice (const :tag "On" t) (const :tag "Off" nil) (function :tag "Custom function")) nsm-settings-file #[0 "\301\302\"\207" [user-emacs-directory expand-file-name "network-security.data"] 3] "The file the security manager settings will be stored in." file nsm-save-host-names #[0 "\300\207" [nil] 1] "If non-nil, always save host names in the structures in `nsm-settings-file'.\nBy default, only hosts that have exceptions have their names\nstored in plain text." boolean] 8) #@116 If non-nil, the connection is opened in a non-interactive context. This means that no queries should be performed. (defvar nsm-noninteractive nil (#$ . 2933)) #@781 Verify the security status of PROCESS that's connected to HOST:PORT. If PROCESS is a gnutls connection, the certificate validity will be examined. If it's a non-TLS connection, it may be compared against previous connections. If the function determines that there is something odd about the connection, the user will be queried about what to do about it. The process is returned if everything is OK, and otherwise, the process will be deleted and nil is returned. If SAVE-FINGERPRINT, always save the fingerprint of the server (if the connection is a TLS connection). This is useful to keep track of the TLS status of STARTTLS servers. If WARN-UNENCRYPTED, query the user if the connection is unencrypted. (fn PROCESS HOST PORT &optional SAVE-FINGERPRINT WARN-UNENCRYPTED) (defalias 'nsm-verify-connection #[1283 "\300!\301\"\302!\303!\204 \304\202P \204' \305%\202P \306%\211\203M \203M \302!\204M \307\310\304\311&\210\211\262\207" [gnutls-peer-status nsm-id nsm-host-settings process-live-p nil nsm-check-plain-connection nsm-check-tls-connection nsm-save-host fingerprint always] 16 (#$ . 3099)]) (byte-code "\300\301\302\303\304DD\305\306\307\310\311&\207" [custom-declare-variable network-security-protocol-checks funcall function #[0 "\300\207" [((version medium) (compression medium) (renegotiation-info-ext medium) (verify-cert medium) (same-cert medium) (null-suite medium) (export-kx medium) (anon-kx medium) (md5-sig medium) (rc4-cipher medium) (dhe-prime-kx medium) (sha1-sig medium) (ecdsa-cbc-cipher medium) (dhe-kx high) (rsa-kx high) (3des-cipher high) (cbc-cipher high))] 1] "This variable specifies what TLS connection checks to perform.\nIt's an alist where the key is the name of the check, and the\nvalue is the minimum security level the check should begin.\n\nEach check function is called with the parameters HOST PORT\nSTATUS SETTINGS. HOST is the host domain, PORT is a TCP port\nnumber, STATUS is the peer status returned by\n`gnutls-peer-status', and SETTINGS is the persistent and session\nsettings for the host HOST. Please refer to the contents of\n`nsm-settings-file' for details. If a problem is found, the check\nfunction is required to return an error message, and nil\notherwise.\n\nSee also: `nsm-check-tls-connection', `nsm-save-host-names',\n`nsm-settings-file'" :version "27.1" :type (repeat (list (symbol :tag "Check function") (choice :tag "Level" :value medium (const :tag "Low" low) (const :tag "Medium" medium) (const :tag "High" high))))] 8) #@245 Save the certificate's fingerprint. In order to detect man-in-the-middle attacks, when `network-security-level' is `high', this function will save the fingerprint of the certificate for check functions to check. (fn HOST PORT STATUS &rest _) (defalias 'nsm-save-fingerprint-maybe #[899 "\301!\301\302!Y\205 \303\304\305\306&\207" [network-security-level nsm-level high nsm-save-host fingerprint nil always] 11 (#$ . 5642)]) #@331 Functions to run after checking a TLS session. Each function will be run with the parameters HOST PORT STATUS SETTINGS and RESULTS. The parameters HOST PORT STATUS and SETTINGS are the same as those supplied to each check function. RESULTS is an alist where the keys are the checks run and the values the results of the checks. (defvar nsm-tls-post-check-functions '(nsm-save-fingerprint-maybe) (#$ . 6081)) #@223 Return t if IP is in the same subnet as LOCAL-IP/MASK. LOCAL-IP, MASK, and IP are specified as vectors of integers, and are expected to have the same length. Works for both IPv4 and IPv6 addresses. (fn LOCAL-IP MASK IP) (defalias 'nsm-network-same-subnet #[771 "\300GG\301>\203 \211\302>\204 \303\304\"\210U\205L \211\305\211W\203I \211\205? \306 H H\"\306H\nH\"U\262\210\211T\262\202 \266\207" [t (4 5 8 9) (4 5 8 9) error "Unexpected length of IP address %S" 0 logand] 14 (#$ . 6498)]) #@276 Determine whether NSM should check for TLS problems for HOST. If `nsm-trust-local-network' is or returns non-nil, and if the host address is a localhost address, or in the same subnet as one of the local interfaces, this function returns nil. Non-nil otherwise. (fn HOST) (defalias 'nsm-should-check #[257 "\301!\302\303!\303C\304!\203 \204 \203* \305\306\307\310\311\312\"\313\"\314\315%\"\210\211\242\207" [nsm-trust-local-network network-lookup-address-info network-interface-list t functionp mapc make-byte-code 257 "\302\303\304\305\306\307\301\"\310\"\311\312%\300\"\207" vconcat vector [mapc make-byte-code 257 "\211A@\3028\303\304\305\306#\304\305\306#\304\301\305\306##\205 \300\307\240\207" vconcat vector [2 nsm-network-same-subnet substring 0 -1 nil] 10 "\n\n(fn INFO)"] 9 "\n\n(fn IP)"] 12 (#$ . 7020)]) #@802 Check TLS connection against potential security problems. This function runs each test defined in `network-security-protocol-checks' in the order specified against the TLS connection's peer status STATUS for the host HOST and port PORT. If one or more problems are found, this function will collect all the error messages returned by the check functions, and confirm with the user in interactive mode whether to continue with the TLS session. If the user declines to continue, or problem(s) are found under non-interactive mode, the process PROCESS will be deleted, thus terminating the connection. This function returns the process PROCESS if no problems are found, and nil otherwise. See also: `network-security-protocol-checks' and `nsm-noninteractive' (fn PROCESS HOST PORT STATUS SETTINGS) (defalias 'nsm-check-tls-connection #[1285 "\302!\203\333 \303\211\211\211:\203Z @\262\304\305\306@\"!\262\307\310\">?\205F \311 !\311A@!Y\205F \304\305\312@\"! $\262\203S BB\262A\262\202 \211\237\266\205\307\313\"\314!\244 \315=\203x \316\"\204x \317B\262\203\313 \320\307\310\"\"\204\313 \321\322\323\324 \nG\325V\203\241 \326\202\242 \327\330\331\332!\333\334\335#\266\202\333\"\336\334\335#\266\202P%&\204\313 \337!\203\313 \303\262\340\341&\266\207" [network-security-protocol-checks network-security-level nsm-should-check nil intern format ":%s" plist-get :conditions nsm-level "nsm-protocol-check--%s" :warnings map-keys paranoid nsm-fingerprint-ok-p (:not-seen . "Certificate not seen before") seq-set-equal-p nsm-query conditions format-message "The TLS connection to %s:%s is insecure\nfor the following reason%s:\n\n%s" 1 "s" "" "* " split-string map-values "\n" mapconcat identity "\n* " delete-process run-hook-with-args nsm-tls-post-check-functions] 26 (#$ . 7865)]) #@272 Check for warnings from the certificate verification status. This is the most basic security check for a TLS connection. If certificate verification fails, it means the server's identity cannot be verified by the credentials received. (fn HOST PORT STATUS SETTINGS) (defalias 'nsm-protocol-check--verify-cert #[1028 "\300\301\"\211\205 \302\"?\205 \303\304\305#\207" [plist-get :warnings nsm-warnings-ok-p mapconcat gnutls-peer-status-warning-describe "\n"] 9 (#$ . 9728)]) #@220 Check for certificate fingerprint mismatch. If the fingerprints saved do not match the fingerprint of the certificate presented, the TLS session may be under a man-in-the-middle attack. (fn HOST PORT STATUS SETTINGS) (defalias 'nsm-protocol-check--same-cert #[1028 "\300\"?\205 \301\302!\207" [nsm-fingerprint-ok-p format-message "fingerprint has changed"] 7 (#$ . 10220)]) #@1029 Check for static RSA key exchange. Static RSA key exchange methods do not offer perfect forward secrecy, therefore, the security of a TLS session is only as secure as the server's private key. Due to TLS' use of RSA key exchange to create a session key (the key negotiated between the client and the server to encrypt traffic), if the server's private key had been compromised, the attacker will be able to decrypt any past TLS session recorded, as opposed to just one TLS session if the key exchange was conducted via a key exchange method that offers perfect forward secrecy, such as ephemeral Diffie-Hellman key exchange. By default, this check is only enabled when `network-security-level' is set to `high' for compatibility reasons. Reference: Sheffer, Holz, Saint-Andre (May 2015). "Recommendations for Secure Use of Transport Layer Security (TLS) and Datagram Transport Layer Security (DTLS)", "(4.1. General Guidelines)" `https://tools.ietf.org/html/rfc7525#section-4.1' (fn HOST PORT STATUS &optional SETTINGS) (defalias 'nsm-protocol-check--rsa-kx #[1027 "\300\301\"\302\303\"\205 \304\305\"\207" [plist-get :key-exchange string-match "^\\bRSA\\b" format-message "RSA key exchange method (%s) does not offer perfect forward secrecy"] 8 (#$ . 10607)]) #@1036 Check for the key strength of DH key exchange based on integer factorization. This check is a response to Logjam[1]. Logjam is an attack that allows an attacker with sufficient resource, and positioned between the user and the server, to downgrade vulnerable TLS connections to insecure 512-bit export grade cryptography. The Logjam paper suggests using 1024-bit prime on the client to mitigate some effects of this attack, and upgrade to 2048-bit as soon as server configurations allow. According to SSLLabs' SSL Pulse tracker, only about 75% of server support 2048-bit key exchange in June 2018[2]. To provide a balance between compatibility and security, this function only checks for a minimum key strength of 1024-bit. See also: `nsm-protocol-check--dhe-kx' Reference: [1]: Adrian et al (2014). "Imperfect Forward Secrecy: How Diffie-Hellman Fails in Practice", `https://weakdh.org/' [2]: SSL Pulse (June 03, 2018). "Key Exchange Strength", `https://www.ssllabs.com/ssl-pulse/' (fn HOST PORT STATUS &optional SETTINGS) (defalias 'nsm-protocol-check--dhe-prime-kx #[1027 "\300\301\"\302\303\300\304\"\"\205 \211\305W\205 \306\307\305#\207" [plist-get :diffie-hellman-prime-bits string-match "^\\bDHE\\b" :key-exchange 1024 format-message "Diffie-Hellman key strength (%s bits) too weak (%s bits)"] 10 (#$ . 11888)]) #@829 Check for existence of DH key exchange based on integer factorization. In the years since the discovery of Logjam, it was discovered that there were rampant use of small subgroup prime or composite number for DHE by many servers, and thus allowed themselves to be vulnerable to backdoors[1]. Given the difficulty in validating Diffie-Hellman parameters, major browser vendors had started to remove DHE since 2016[2]. Emacs stops short of banning DHE and terminating connection, but prompts the user instead. References: [1]: Dorey, Fong, and Essex (2016). "Indiscreet Logs: Persistent Diffie-Hellman Backdoors in TLS.", `https://eprint.iacr.org/2016/999.pdf' [2]: Chrome Platform Status (2017). "Remove DHE-based ciphers", `https://www.chromestatus.com/feature/5128908798164992' (fn HOST PORT STATUS &optional SETTINGS) (defalias 'nsm-protocol-check--dhe-kx #[1027 "\300\301\"\302\303\"\205 \304\305\"\207" [plist-get :key-exchange string-match "^\\bDHE\\b" format-message "unable to verify Diffie-Hellman key exchange method (%s) parameters"] 8 (#$ . 13231)]) #@718 Check for RSA-EXPORT key exchange. EXPORT cipher suites are a family of 40-bit and 56-bit effective security algorithms legally exportable by the United States in the early 90s[1]. They can be broken in seconds on 2018 hardware. Prior to 3.2.0, GnuTLS had only supported RSA-EXPORT key exchange. Since 3.2.0, RSA-EXPORT had been removed, therefore, this check has no effect on GnuTLS >= 3.2.0. Reference: [1]: Schneier, Bruce (1996). Applied Cryptography (Second ed.). John Wiley & Sons. ISBN 0-471-11709-9. [2]: N. Mavrogiannopoulos, FSF (Apr 2015). "GnuTLS NEWS -- History of user-visible changes." Version 3.4.0, `https://gitlab.com/gnutls/gnutls/blob/master/NEWS' (fn HOST PORT STATUS &optional SETTINGS) (defalias 'nsm-protocol-check--export-kx #[1027 "\301W\205 \302\303\"\304\305\"\205 \306\307\"\262\207" [libgnutls-version 30200 plist-get :key-exchange string-match "\\bEXPORT\\b" format-message "EXPORT level key exchange (%s) is insecure"] 8 (#$ . 14311)]) #@307 Check for anonymous key exchange. Anonymous key exchange exposes the connection to man-in-the-middle attacks. Reference: GnuTLS authors (2018). "GnuTLS Manual 4.3.3 Anonymous authentication", `https://www.gnutls.org/manual/gnutls.html#Anonymous-authentication' (fn HOST PORT STATUS &optional SETTINGS) (defalias 'nsm-protocol-check--anon-kx #[1027 "\300\301\"\302\303\"\205 \304\305\"\207" [plist-get :key-exchange string-match "\\bANON\\b" format-message "anonymous key exchange method (%s) can be unsafe"] 8 (#$ . 15301)]) #@877 Check for CBC mode ciphers. CBC mode cipher in TLS versions earlier than 1.3 are problematic because of MAC-then-encrypt. This construction is vulnerable to padding oracle attacks[1]. Since GnuTLS 3.4.0, the TLS encrypt-then-MAC extension[2] has been enabled by default[3]. If encrypt-then-MAC is negotiated, this check has no effect. Reference: [1]: Sullivan (Feb 2016). "Padding oracles and the decline of CBC-mode cipher suites", `https://blog.cloudflare.com/padding-oracles-and-the-decline-of-cbc-mode-ciphersuites/' [2]: P. Gutmann (Sept 2014). "Encrypt-then-MAC for Transport Layer Security (TLS) and Datagram Transport Layer Security (DTLS)", `https://tools.ietf.org/html/rfc7366' [3]: N. Mavrogiannopoulos (Nov 2015). "An overview of GnuTLS 3.4.x", `https://nikmav.blogspot.com/2015/11/an-overview-of-gnutls-34x.html' (fn HOST PORT STATUS &optional SETTINGS) (defalias 'nsm-protocol-check--cbc-cipher #[1027 "\300\301\"?\205 \300\302\"\303\304\"\205 \305\306\"\262\207" [plist-get :encrypt-then-mac :cipher string-match "\\bCBC\\b" format-message "CBC mode cipher (%s) can be insecure"] 8 (#$ . 15841)]) #@1231 Check for CBC mode cipher usage under ECDSA key exchange. CBC mode cipher in TLS versions earlier than 1.3 are problematic because of MAC-then-encrypt. This construction is vulnerable to padding oracle attacks[1]. Due to current widespread use of CBC mode ciphers by servers, this function only checks for CBC mode cipher usage in combination with ECDSA key exchange, which is virtually non-existent[2]. Since GnuTLS 3.4.0, the TLS encrypt-then-MAC extension[3] has been enabled by default[4]. If encrypt-then-MAC is negotiated, this check has no effect. References: [1]: Sullivan (Feb 2016). "Padding oracles and the decline of CBC-mode cipher suites", `https://blog.cloudflare.com/padding-oracles-and-the-decline-of-cbc-mode-ciphersuites/' [2]: Chrome Platform Status (2017). "Remove CBC-mode ECDSA ciphers in TLS", `https://www.chromestatus.com/feature/5740978103123968' [3]: P. Gutmann (Sept 2014). "Encrypt-then-MAC for Transport Layer Security (TLS) and Datagram Transport Layer Security (DTLS)", `https://tools.ietf.org/html/rfc7366' [4]: N. Mavrogiannopoulos (Nov 2015). "An overview of GnuTLS 3.4.x", `https://nikmav.blogspot.com/2015/11/an-overview-of-gnutls-34x.html' (fn HOST PORT STATUS &optional SETTINGS) (defalias 'nsm-protocol-check--ecdsa-cbc-cipher #[1027 "\300\301\"?\205$ \300\302\"\300\303\"\304\305\"\205\"