OpenSSLã®èå¼±æ§(CVE-2015-1793)ã«ããAltãã§ã¼ã³è¨¼ææ¸å½é ã®ä»çµã¿
TL;DR ãã£ã±ãæ¸ãã¦ãããé·æã«ãªã£ã¦ãã¾ãã¾ããããã¾ãã¡ããã¨æ¨æ²ããæ°åããªãã®ã§ãå¤ãªæç« ã«ãªã£ã¦ããããããã¾ããããäºæ¿ããã ããæ¹ã®ã¿ãèªã¿ãã ããã
1. ã¯ããã«
æ¨æ©æªæã«OpenSSL-1.0.2d, 1.0.1pããªãªã¼ã¹ããã¾ãããäºåã«äºåããã¦ããéãæ·±å»åº¦é«ã®èå¼±æ§CVE-2015-1793ãä¿®æ£ããã¦ãã¾ããAdvisoryãè¦ãã¨ããã®èå¼±æ§ãiojs/Nodeã«å½±é¿ãããã¨ãããã¨ãå¤æããã®ã§ç´ã¡ã«iojs/Nodeã®ã¢ãããã¼ããè¡ããä»ææªæã«ç¡äºèå¼±æ§å¯¾å¿çããªãªã¼ã¹ãã¾ããã
ä»åãåãã¦ã§ã¯ããã¾ããããæ·±å¤ã«æ¥æ¬§ç±³ã®ã¨ã³ã¸ãã¢ãgithubä¸ã§äºãã«é£æºããªããéããã«ã»ãã¥ãªãã£å¯¾çã®ãªãªã¼ã¹ä½æ¥ãè¡ããã¨ã¯ä½åãã£ã¦ããªããªããã³ããçµé¨ã§ããæå·®ããããªããªãä½åçã«ã¯è¾ããã®ãããã¾ãããä¸çã®è¶ ä¸æµã®ã¨ã³ã¸ãã¢ã¨å ±åã§ãªã¢ã«ã¿ã¤ã ã«ããã¸ã§ã¯ããé²ãããã¨ãã§ããç°å¢ã¯ã¨ã³ã¸ãã¢å¥å©ã«å°½ãã¾ãã
ãã¦ä»åã®èå¼±æ§ã Alternative chains certificate forgery ã¯ãæ¥æ¬èªã«è¨³ãã¨ã代æ¿ããã§ã¼ã³è¨¼ææ¸ã®å½é ãã«ãªããã§ããããï¼ ãã® Alternative chains certificate ã®æ©è½ï¼ä»¥ä¸ Alt Cert Chainã¨æ¸ãã¾ãï¼ã¯ãå®ã¯ãªããªãèªåã¨å ç¸ãããé¢ä¿ãããã¾ããä¸çªæåã¯ãæ¨å¹´æ«ã®「Node-v0.10.34がはまったクロスルート証明書とOpenSSLの落とし穴」ã®åºæ¥äºããã§ããï¼ããã¾ã èªãã§ããªãæ¹ã¯æ¯éï¼ã
ãã®æ㯠OpenSSLã«ä¿®æ£ãå ¥ãããNodeå´ã§1024bitã®è¨¼ææ¸ã復活対å¿ã㦠issue ãåé¿ãã¾ããããã®å¾ openssl ã® master(1.1.0ç³») ã« alt cert chain ã®æ©è½ãå®è£ ããã¾ããããã®æã«1.0.2ã¸ã®ããã¯ãã¼ããããã©ããèããã®ã§ãããæ©è½å¤æ´ã«ãªãã®ã§ããã¯ãã¼ãã¯ããªãã¨ããè¿äºãããã£ããããiojsã§ã¯ç¬èªã«opensslã«ãããããã¦ã¦éç¨ãã¦ã¾ããã
ãã®å¾ãã£ã±ã1024bitã®è¨¼ææ¸å»æ¢ã®æµãã«è² ãã¦ããOpenSSLããã¸ã§ã¯ãã1.0.2/1.0.1ç³»ã¸alt cert chainã®ããã¯ãã¼ããè¡ããã¾ãããããç¬èªãããããã¦ãå¿ è¦ããªããªãã®ã§åãã ã®ã§ãããããè¦ãã¨ãªãããããªããã®ã¾ã§ããã¯ãã¼ãããã¦ãããããã§åãåãããã¨ããééã£ã¦ããããå ¥ãè¾¼ãã ã¨ãããã¨ã§ 'Revert "Fix verify algorithm." 'ã®ä¿®æ£ãå ¥ãã¾ããããã®ãããã§OpenSSLã®ã³ããããã°ã«ããããã¯ã¬ã¸ãããå ¥ãã¦ããããã¨ã¦ãå¬ããã£ãã§ãã
ã¾ãã¯ãä»åã®ä¿®æ£ã³ããã "Fix alternate chains certificate forgery issue" ãè¦ã¦ã¿ã¾ãããã
diff --git a/crypto/x509/x509_vfy.c b/crypto/x509/x509_vfy.c index 8ce41f9..33896fb 100644 --- a/crypto/x509/x509_vfy.c +++ b/crypto/x509/x509_vfy.c @@ -389,8 +389,8 @@ int X509_verify_cert(X509_STORE_CTX *ctx) xtmp = sk_X509_pop(ctx->chain); X509_free(xtmp); num--; - ctx->last_untrusted--; } + ctx->last_untrusted = sk_X509_num(ctx->chain); retry = 1; break; }
ããã¯ããããã2è¡ã§ããå¾ã¦ãã¦ãããããã®ããããã¾ãããããã¾ã§ãã®ãããé¨åã¯çµæ§èªã¿è¾¼ãã§ããã«ãé¢ããããä»åã®ã¯å ¨ãè¦ã¤ãããã¨ãã§ãã¾ããã§ãããã¾ãç¡å¿µã§ãããã°ãæ¢ãåºããã®ã¯ Google BoringSSL ã® agl ãããã®ãã¼ã ããã£ã±æµç³ã§ãã
ããããåçãè¸ã¾ãã¤ã¤ãä»åã® Alt cert chain ã®èå¼±æ§ãã©ãããçç±ã§è¡ã£ãã®ããå°ã解説ãã¦ã¿ããã¨æãã¾ãã
2. 証ææ¸æ¤è¨¼ã®ããã³
ã¾ãã¯ãä¸è¬çã«TLSæ¥ç¶ã§è¨¼ææ¸ãã©ãæ¤è¨¼ããã¦ãããã®èª¬æã§ã(å³1)ã
ã¯ã©ã¤ã¢ã³ãã«ã¯ãããããã«ã¼ã証ææ¸çèªåãä¿¡é ¼ãã証ææ¸ãOSãªãã¢ããªãªãã«ã¤ã³ã¹ãã¼ã«ããã¦ãã¾ããã¯ã©ã¤ã¢ã³ããTLSãµã¼ãã«æ¥ç¶ããã¨åæã®ãã³ãã·ã§ã¤ã¯ã§ãµã¼ãããããµã¼ã証ææ¸ãä¸é証ææ¸ãéä¿¡ããã¦ãã¾ãã証ææ¸ã«ã¯èªåèªèº«ã表ã Subject ã¨çºè¡è
ã表ã Issuer ãè¨è¼ããã¦ãããã¯ã©ã¤ã¢ã³ãã¯ãæ¥ç¶ããTLSãµã¼ã証ææ¸ãã Issuerããã©ã£ã¦ãããæçµçã«ã«ã¼ã証ææ¸ã¾ã§ã®ãã§ã¼ã³ãä½ããã¾ãã
ããã§ãããããã®ç½²åæ¤è¨¼ã証ææ¸ãã£ã¼ã«ãã®ãã§ãã¯ãçµã¦ãæçµçã«æ£å½ãªãµã¼ã証ææ¸ã§ãããã¨ãå¤æãã¾ãã
ãã®è¨¼ææ¸ãã§ã¼ã³ã®æ£å½æ§ã®æ¤è¨¼ã¯ãTLSæ¥ç¶ã®å®å
¨æ§ã確ä¿ããæ ¹æ¬çãªä»çµã¿ã§ããããã«ã»ããã³ãããã¨ãããã¡ã§ãããã®ããä»åã®èå¼±æ§ã¯ãæ·±å»åº¦é«ã«ã«ãã´ã©ã¤ãºããã¾ããã
ã¾ããããã§åºã¦ããã«ã¼ã証ææ¸ãä¸é証ææ¸ã¯èª°ã§ãçºè¡ã§ãããã®ã§ã¯ããã¾ãããããªã·ã¼çãªå¶éãããã¾ããã証ææ¸ã® X509v3 Basic Constraints ã CA:TRUE ã«ãªã£ã¦ããå¿
è¦ãããã¾ãã
ä»åã®èå¼±æ§ã¯ãCA:FALSEã¨ãªã£ã¦ããé常ä¸é証ææ¸ã¨ãã¦ä½¿ããªã証ææ¸ããä¸é証ææ¸ã¨å½é ããæ£å½ãªè¨¼ææ¸ãã§ã¼ã³ã¨ãã¦æ¤è¨¼ããã¹ããããã®ã§ãã
ä¾ãã°ãèªåã®ãµã¼ã証ææ¸ãCAã¨ãã¦ä½¿ã£ã¦åæã«ããããªãµã¼ã証ææ¸ãçºè¡ãã¦å©ç¨ããã¨ãã¦ãããªãã®åé¡ãªã使ãã¦ãã¾ãã¨ãããã¨ã§ããããã¯TLSéä¿¡ã®ä¿¡é ¼æ§ã®æ ¹æ¬ãæºãããåé¡ã§ãã
3. ã¯ãã¹è¨¼ææ¸ã¨ã¯
ä»ååé¡ã¨ãªã£ã Alt Cert Chain ã¯ãã¯ãã¹è¨¼ææ¸ã¨ä¸ç·ã«ä½¿ãããæ©è½ã§ããã¯ãã¹è¨¼ææ¸ã«ã¤ãã¦ç°¡åã«è§¦ãã¾ãã
以åã¯ã«ã¼ã証ææ¸ã¯1024bitsã®ã主æµã§ããããè¨ç®æ©è³æºã®çºéã«ãããã¯ã1024bitã§ã¯å®å
¨ã§ãªããªã£ã¦ãã¾ãããããã§æ¬æ ¼çã«å±ãªããªãåã«2048bitsã®ã«ã¼ã証ææ¸ã¸æ´æ°ãè¡ããããã¨ã¨ãªãã¾ããããã å¤ã端æ«ã§ã¯2048bitsã®è¨¼ææ¸ãæ±ããã¨ãã§ãããã¯ãã¹è¨¼ææ¸ãããããã¨ã«ãã£ã¦äºææ§ãæãããªããéç¨ãã¦ãããã¨ãè¡ããã¦ãã¾ãï¼å³ï¼ï¼ã
Alt Cert Chainã¨ã¯ããã®ã¯ãã¹è¨¼ææ¸ã使ããã¦ããå ´åã«å¤ãã«ã¼ã証ææ¸ã¸ã®ãã¹ãä½ããªããªã£ãæã«ããä¸æ¹ã®è¨¼ææ¸ãã§ã¼ã³ãä½ã£ã¦æ£å½æ§ã®æ¤è¨¼ãè¡ãæ©è½ãæãã¾ãï¼å³ï¼ï¼ã
OpenSSLã®å ´åãæåã«ãµã¼ãããéããã証ææ¸ãªã¹ããå
ã«ãã§ã¼ã³ãä½æãããããã©ããã¦ãå·¦å´ã®é·ãæ¹ãæåã«æ¤è¨¼ããããã¨ã«ãªãã¾ãã
4. OpenSSLã«ããç½²åæ¤è¨¼ã¨ Alt Cert Chain ã®ä½æã®ããæ¹
OpenSSLã¯ãã©ããã£ã¦ç½²åæ¤è¨¼ã Alt Cert Chainãä½ã£ã¦ããã®ã§ããããï¼
ç´°ããé¨åãçãã¨å³ï¼ã®éãåç´ãªã¹ã¿ãã¯æ§é ã«å
¥ãè¾¼ã¿ããµã¼ãããéããã¦æ¥ã証ææ¸ã untrusted ãªãã®ã¨ãã¦è²åããã¦ãã¾ãã
å³ã®å ´åã§ã¯ããµã¼ãããéãããuntrusted ãªè¨¼ææ¸ã¯8ã¤ãã¯ã©ã¤ã¢ã³ãã«ä¿åããã¦ããæå¾ã®ã«ã¼ã証ææ¸ã trusted ã§1ã¤ãåè¨9ã¤ã®ã¹ã¿ãã¯ã«ãã Cert Chain ã®åºæ¥ä¸ããã§ãã
Alt Cert Chainã¯ããµã¼ãããéãããä¸æ¦ãã®ã¹ã¿ãã¯ãæ¤è¨¼ãã¦ããä½æãã¾ããã«ã¼ã証ææ¸ã¾ã§ã®ãã¹ãæ¤è¨¼ã§ããªãã®ã§ä¸ããé çªã«ä¿åãã¦ãã trusted ã®è¨¼ææ¸ã®ä¸ãã該å½ãããã®ããªããæ¢ãã«è¡ãã¾ãï¼å³ï¼ï¼ã
å³ã®å ´åã¯ãä¸é証ææ¸Dã®ã¨ããã§ã«ã¼ã証ææ¸Eãè¦ã¤ããã¾ãããããã§ä¸é証ææ¸Dããä¸ã®é¨åãæ¨ã¦å»ã£ã¦ Alt Cert Chainãä½æãã¾ãï¼å³ï¼ï¼ã
ãã®å ´åãuntrusted certã®æ°ãåè¨ç®ããã®ã§ããã4ã¤åãé¤ããã®ã§ 8-4=4 ã§4ã® untrusted ã¨ã«ã¼ãã®åè¨5ã¤ã® Alt Cert Chainã¹ã¿ãã¯ã®å®æã§ããããã§ç½²åæ¤è¨¼ãæåããã°æ£å½æ§ãç¡äºä¿è¨¼ããã¾ãããã®æ¤è¨¼ãè¡ãå ´åãuntrusted ã§çªå·2以ä¸ã®ãã®ã¯ä¸é証ææ¸ã§ãããã CA:TRUE ã§ãããã®ãã§ãã¯ãè¡ããã¾ãã
å®ã¯ããã®untrustedã®è¨¼ææ¸ãæ±ããå¼ãç®ã«ãã°ããã£ãã®ã§ãã
5.CVE-2015-1793ã«ãã証ææ¸å½é ã®ããæ¹
CVE-2015-1793ã§åé¡ã¨ãªã£ã証ææ¸ãã§ã¼ã³ãå³7ã«ç¤ºãã¾ãã
ããã¾ã§ã¨éãã®ã¯ãæåã®ãã§ã¼ã³ã§ trustedãªä¸é証ææ¸Dãåå¨ãããã¨ãããã¦ä¸é証ææ¸Bã®CA:FALSEã«ãªã£ã¦ããã¨ããã§ãããã®ãã§ã¼ã³ã¯ãä¸é証ææ¸Dã® issuerã®ã«ã¼ã証ææ¸ããªãã®ã§æ¤è¨¼ã¯å¤±æãã¾ãããã㧠Alt Cert Chainãæ¢ãã«è¡ãã¾ãã
ä¸é証ææ¸Bã®ã¨ãã㧠Alt Cert Chain ãã§ããã®ã§ãåä½æãã¦ã¿ãã¨å³ï¼ã®æ§ã«ãªãã¾ãã
証ææ¸ã2ã¤ã¹ã¿ãã¯ããæ¨ã¦ãã®ã§ untrusted ã®æ°ã¯ã3-2=1 ã§ãããã£ã¨ãã§ããµã¼ãããéããã untrusted証ææ¸ã¯Aã¨Bã®2ã¤ã§ããAããCã¾ã§ã®è¨¼ææ¸ãã§ã¼ã³ã®æ¤è¨¼ã¯æ£å½ãªããæåãã¾ããããã untrusted ãªè¨¼ææ¸ã®æ°ã1ã§ããããã証ææ¸Bã«å¯¾ã㦠CA:TRUE ã®ãã§ãã¯ãè¡ããã¾ããããªã®ã§æ¬æ¥ä¸é証ææ¸ã¨ãã¦ä½¿ããã¨ãã§ããªã証ææ¸Bãä¸é証ææ¸ã¨å½é ãããã¨ã«æåãã¦ããããã§ãã
ã©ããã¦ãããããã¨ãèµ·ããã®ãï¼
ãã㯠untrusted ã®è¨ç®æ¹æ³ã«ããã¾ããã
æ¨ã¦ã証ææ¸2ã¤ã§ãã証ææ¸D㯠trusted ãªãã®ã§ãã trustedãæ¨ã¦ãã®ã« untrusted ã®æ°ãå¼ãç®ããããæ°ãåããªããªãããããããã°ã«èµ·å ããèå¼±æ§ã§ãããæåã®æ¹ã«è¨è¼ããããããè¦ã¦ããããã°ãããã¾ãããuntrusted ã® decrement ãããã¦ãuntrusted ã¯ã«ã¼ã証ææ¸Cãã®ã£ããåã®ã¹ã¿ãã¯æ°ï¼=2)ãä»£å ¥ããããå¤æ´ãã¦ãã¾ããããããã°æçµçã« untrusted ã®æ°ã®ã¤ãã¤ã¾ãåãã¾ãã
6. å®éã« CVE-2015-1793ã試ãã
å®éã«ãããã¦ã¿ã¾ããããhttps://github.com/openssl/openssl/tree/master/test/certs ã«èå¼±æ§ã試é¨ããä¸é£ã®è¨¼ææ¸ãããã¾ãããããæµç¨ãã¦ã¿ã¾ãã
// // Test for CVE-2015-1793 (Alternate Chains Certificate Forgery) // // RootCA(missing) // | // interCA // | // subinterCA subinterCA (self-signed) // | | // leaf(CA:false)---------------- // | // bad(CA:false) var tls = require('tls'); var fs = require('fs'); var bad = fs.readFileSync('./bad.pem'); var bad_key = fs.readFileSync('./bad.key'); var interCA = fs.readFileSync('./interCA.pem'); var subinterCA = fs.readFileSync('./subinterCA.pem'); var subinterCA_ss = fs.readFileSync('./subinterCA-ss.pem'); var leaf = fs.readFileSync('./leaf.pem'); var opts = { cert: bad, key: bad_key, ca: [leaf, subinterCA] }; var server = tls.createServer(opts); server.listen(8443, function() { var opts = { host: 'bad', port: 8443, ca: [interCA, subinterCA_ss] }; var client = tls.connect(opts, function() { console.log('connected'); client.end(); server.close(); }); });
èå¼±æ§ã®ãã iojs-2.3.1ã§ã¯ã
ohtsu@ubuntu:~/tmp/CVE-2015-1793$ ~/tmp/oldiojs/iojs-v2.3.1/iojs alt-cert-test.js
connected
éä¸ã« CA:FALSEã®ä¸é証ææ¸ãæã¾ã£ã¦ããã®ã«æ£å¸¸ã«æ¥ç¶ã§ãã¦ãã¾ã£ã¦ã¾ãã
èå¼±æ§å¯¾å¿çã§ã¯ã
ohtsu@ubuntu:~/tmp/CVE-2015-1793$ ~/github/io.js/iojs alt-cert-test.js events.js:141 throw er; // Unhandled 'error' event ^ Error: unsupported certificate purpose at Error (native) at TLSSocket.<anonymous> (_tls_wrap.js:989:38) at emitNone (events.js:67:13) at TLSSocket.emit (events.js:166:7) at TLSSocket._finishInit (_tls_wrap.js:566:8)
ãã¼ãã¡ããã¨ãã§ãã¯ããã¦ãã¾ãã
å®éã«ãã®èå¼±æ§ãçªã証ææ¸ã®æ§æãç¾ç¶å¯è½ãã©ããã¾ã§ã¯èª¿ã¹ã¦ãã¾ããããTLSæ¥ç¶ã®æ ¹æ¬ã«ãããã証ææ¸æ¤è¨¼ããã¤ãã¹ããç©´ã¯æ¬å½ã«å±éºã§ãããã³ãã¡ãã£ã¨ãããã°ã§ãããã»ãã¥ãªãã£ã«é¢ããé¨åã¯æ¬å½ã«è´å½çãªæ¬ é¥ã«ã¤ãªãããªã¨æ¹ãã¦æãã¾ããã