Erlang 21 - 3. Configuring algorithms in SSH
3 SSH में एल्गोरिदम को कॉन्फ़िगर करना

3 SSH में एल्गोरिदम को कॉन्फ़िगर करना
३.१ परिचय
एल्गोरिदम को कॉन्फ़िगर करने के तरीके को पूरी तरह से समझने के लिए, एसएसएच प्रोटोकॉल की बुनियादी समझ होना आवश्यक है और ओटीपी एसएसएच ऐप किस संबंधित वस्तुओं को संभालता है
पहली उपधारा एसएसएच प्रोटोकॉल की एक छोटी पृष्ठभूमि देगी जबकि बाद में अनुभाग कार्यान्वयन का वर्णन करता है और कुछ उदाहरण प्रदान करता है
एसएच प्रोटोकॉल के एल्गोरिदम को संभालने की मूल बातें
SSH एक सत्र के विभिन्न चरणों में एल्गोरिदम के विभिन्न सेटों का उपयोग करता है।
किस एल्गोरिदम का उपयोग क्लाइंट और सर्वर द्वारा एक सत्र की शुरुआत में किया जाता है।
विवरण के लिए
RFC 4253
, "द सिक्योर शेल (SSH) ट्रांसपोर्ट लेयर प्रोटोकॉल" देखें।
बातचीत सरल है: दोनों सहकर्मी समर्थित अल्गोरिथम्स की अपनी सूची दूसरे हिस्से को भेजते हैं। क्लाइंट की सूची पर पहला एल्गोरिथ्म जो सर्वर की सूची में भी चुना गया है। तो यह क्लाइंट की सूची का आदेश है जो एल्गोरिदम के लिए प्राथमिकता देता है।
कनेक्शन सेटअप में पांच सूचियों का आदान-प्रदान होता है। उनमें से तीन को दो दिशाओं में और सर्वर से भी विभाजित किया गया है।
सूचियाँ हैं (एसएसएच आवेदन के विकल्पों में नामित):
-
kex
-
प्रमुख विनिमय।
एक एल्गोरिथ्म एक गुप्त एन्क्रिप्शन कुंजी कंप्यूटिंग के लिए चुना जाता है। उदाहरणों में शामिल हैं: पुराना आजकल का सप्ताह
'diffie-hellman-group-exchange-sha1'
और बहुत मजबूत और आधुनिक'ecdh-sha2-nistp512'
। -
public_key
-
सर्वर होस्ट कुंजी
सर्वर के निजी-सार्वजनिक होस्ट कुंजी जोड़े में उपयोग किए जाने वाले असममित एन्क्रिप्शन एल्गोरिथ्म। उदाहरणों में प्रसिद्ध RSA
'ssh-rsa'
और दीर्घवृत्त वक्र'ecdsa-sha2-nistp521'
। -
cipher
-
पेलोड एन्क्रिप्शन के लिए सिमिट्रिक सिफर एल्गोरिथ्म का उपयोग किया जाता है। यह एल्गोरिथ्म kex चरण में गणना की गई कुंजी का उपयोग करेगा (अन्य जानकारी के साथ) वास्तविक कुंजी का उपयोग करने के लिए। उदाहरण हैं
'3des-cbc'
-डीईएस'3des-cbc'
और कई एईएस वेरिएंट'aes192-ctr'
।यह सूची वास्तव में दो है - प्रत्येक दिशा सर्वर-से-क्लाइंट और क्लाइंट-टू-सर्वर के लिए एक। इसलिए यह संभव है लेकिन एक कनेक्शन में दो दिशाओं में अलग-अलग एल्गोरिदम होना दुर्लभ है।
-
mac
-
संदेश प्रमाणीकरण कोड
साथियों के बीच भेजे गए प्रत्येक संदेश की "जाँच राशि"। उदाहरण SHA
'hmac-sha1'
और SHA2'hmac-sha2-512'
।यह सूची भी दोनों दिशाओं के लिए दो भागों में विभाजित है
-
compression
-
यदि और कैसे संदेश संपीड़ित करने के लिए। उदाहरण
none
, अर्थात कोई संपीड़न औरzlib
।यह सूची भी दोनों दिशाओं के लिए दो भागों में विभाजित है
SSH ऐप का तंत्र
डिफ़ॉल्ट रूप से SSH ऐप द्वारा उपयोग किए जाने वाले एल्गोरिदम का सेट, समर्थित अल्गोरिथम पर निर्भर करता है:
-
crypto
ऐप, -
क्रिप्टोलिब OTP के साथ जुड़ा हुआ है, जो कि OS का उपयोग करता है, शायद ओपनएसएसएल,
-
और SSH एप क्या लागू करता है, इसे अंतिम रूप दें
इसके कारण, प्रलेखन में यह सूचीबद्ध करना असंभव है कि एक निश्चित स्थापना में कौन से एल्गोरिदम उपलब्ध हैं।
वास्तविक एल्गोरिदम और उनके क्रम को सूचीबद्ध करने के लिए एक महत्वपूर्ण कमांड है:
ssh:default_algorithms/0
।
0> ssh:default_algorithms(). [{kex,['ecdh-sha2-nistp384','ecdh-sha2-nistp521', 'ecdh-sha2-nistp256','diffie-hellman-group-exchange-sha256', 'diffie-hellman-group16-sha512', 'diffie-hellman-group18-sha512', 'diffie-hellman-group14-sha256', 'diffie-hellman-group14-sha1', 'diffie-hellman-group-exchange-sha1']}, {public_key,['ecdsa-sha2-nistp384','ecdsa-sha2-nistp521', 'ecdsa-sha2-nistp256','ssh-rsa','rsa-sha2-256', 'rsa-sha2-512','ssh-dss']}, {cipher,[{client2server,['[email protected]', 'aes256-ctr','aes192-ctr','[email protected]', 'aes128-ctr','aes128-cbc','3des-cbc']}, {server2client,['[email protected]','aes256-ctr', 'aes192-ctr','[email protected]','aes128-ctr', 'aes128-cbc','3des-cbc']}]}, {mac,[{client2server,['hmac-sha2-256','hmac-sha2-512', 'hmac-sha1']}, {server2client,['hmac-sha2-256','hmac-sha2-512', 'hmac-sha1']}]}, {compression,[{client2server,[none,'[email protected]',zlib]}, {server2client,[none,'[email protected]',zlib]}]}]
एल्गोरिथ्म सूची को बदलने के लिए, दो विकल्प हैं जो
ssh:connect/2,3,4
में उपयोग किए जा सकते हैं
ssh:connect/2,3,4
और
ssh:daemon/2,3
।
बेशक, कनेक्शन शुरू करने वाले अन्य सभी कार्यों में विकल्पों का उपयोग किया जा सकता है।
विकल्प
modify_algorithms
और
modify_algorithms
।
पहले वाला डिफ़ॉल्ट सेट बदलता है, जबकि दूसरा डिफ़ॉल्ट सेट को संशोधित करता है।
3.2 डिफ़ॉल्ट सेट को बदलना: पसंदीदा_ एल्गोरिथम
विवरण के लिए
Reference Manual
देखें
यहां सरल से अधिक जटिल तक के उदाहरणों की एक श्रृंखला है।
एक विकल्प के प्रभाव को
ssh:chk_algos_opts(Opts)
लिए एक प्रयोगात्मक कार्य
ssh:chk_algos_opts(Opts)
।
यह
ssh:dameon
,
ssh:connect
और उनके मित्रों के समान
modify_algorithms
और
modify_algorithms
का विकल्प देता है।
उदाहरण 1
एकल एल्गोरिथ्म
'diffie-hellman-group14-sha256'
साथ केएक्स एल्गोरिदम सूची को बदलें:
1> ssh:chk_algos_opts( [{preferred_algorithms, [{kex, ['diffie-hellman-group14-sha256']} ] } ]). [{kex,['diffie-hellman-group14-sha256']}, {public_key,['ecdsa-sha2-nistp384','ecdsa-sha2-nistp521', 'ecdsa-sha2-nistp256','ssh-rsa','rsa-sha2-256', 'rsa-sha2-512','ssh-dss']}, {cipher,[{client2server,['[email protected]', 'aes256-ctr','aes192-ctr','[email protected]', 'aes128-ctr','aes128-cbc','3des-cbc']}, {server2client,['[email protected]','aes256-ctr', 'aes192-ctr','[email protected]','aes128-ctr', 'aes128-cbc','3des-cbc']}]}, {mac,[{client2server,['hmac-sha2-256','hmac-sha2-512', 'hmac-sha1']}, {server2client,['hmac-sha2-256','hmac-sha2-512', 'hmac-sha1']}]}, {compression,[{client2server,[none,'[email protected]',zlib]}, {server2client,[none,'[email protected]',zlib]}]}]
ध्यान दें कि
public_key
सूचियाँ (
public_key
,
cipher
,
mac
और
compression
) संयुक्त राष्ट्र के परिवर्तित हैं।
उदाहरण 2
उन सूचियों में जो दो दिशाओं (cf
cipher
) के लिए दो में विभाजित हैं, दोनों दिशाओं को एक साथ बदलना संभव है:
2> ssh:chk_algos_opts( [{preferred_algorithms, [{cipher,['aes128-ctr']} ] } ]). [{kex,['ecdh-sha2-nistp384','ecdh-sha2-nistp521', 'ecdh-sha2-nistp256','diffie-hellman-group-exchange-sha256', 'diffie-hellman-group16-sha512', 'diffie-hellman-group18-sha512', 'diffie-hellman-group14-sha256', 'diffie-hellman-group14-sha1', 'diffie-hellman-group-exchange-sha1']}, {public_key,['ecdsa-sha2-nistp384','ecdsa-sha2-nistp521', 'ecdsa-sha2-nistp256','ssh-rsa','rsa-sha2-256', 'rsa-sha2-512','ssh-dss']}, {cipher,[{client2server,['aes128-ctr']}, {server2client,['aes128-ctr']}]}, {mac,[{client2server,['hmac-sha2-256','hmac-sha2-512', 'hmac-sha1']}, {server2client,['hmac-sha2-256','hmac-sha2-512', 'hmac-sha1']}]}, {compression,[{client2server,[none,'[email protected]',zlib]}, {server2client,[none,'[email protected]',zlib]}]}]
ध्यान दें कि
cipher
में दोनों सूचियों को प्रदान किए गए मूल्य (
'aes128-ctr'
) में बदल दिया गया है।
उदाहरण 3
दो दिशाओं (cf
cipher
) के लिए दो में विभाजित की गई सूचियों में केवल एक दिशा बदलना संभव है:
3> ssh:chk_algos_opts( [{preferred_algorithms, [{cipher,[{client2server,['aes128-ctr']}]} ] } ]). [{kex,['ecdh-sha2-nistp384','ecdh-sha2-nistp521', 'ecdh-sha2-nistp256','diffie-hellman-group-exchange-sha256', 'diffie-hellman-group16-sha512', 'diffie-hellman-group18-sha512', 'diffie-hellman-group14-sha256', 'diffie-hellman-group14-sha1', 'diffie-hellman-group-exchange-sha1']}, {public_key,['ecdsa-sha2-nistp384','ecdsa-sha2-nistp521', 'ecdsa-sha2-nistp256','ssh-rsa','rsa-sha2-256', 'rsa-sha2-512','ssh-dss']}, {cipher,[{client2server,['aes128-ctr']}, {server2client,['[email protected]','aes256-ctr', 'aes192-ctr','[email protected]','aes128-ctr', 'aes128-cbc','3des-cbc']}]}, {mac,[{client2server,['hmac-sha2-256','hmac-sha2-512', 'hmac-sha1']}, {server2client,['hmac-sha2-256','hmac-sha2-512', 'hmac-sha1']}]}, {compression,[{client2server,[none,'[email protected]',zlib]}, {server2client,[none,'[email protected]',zlib]}]}]
उदाहरण 4
एक से अधिक सूची बदलना निश्चित रूप से संभव है:
4> ssh:chk_algos_opts( [{preferred_algorithms, [{cipher,['aes128-ctr']}, {mac,['hmac-sha2-256']}, {kex,['ecdh-sha2-nistp384']}, {public_key,['ssh-rsa']}, {compression,[{server2client,[none]}, {client2server,[zlib]}]} ] } ]). [{kex,['ecdh-sha2-nistp384']}, {public_key,['ssh-rsa']}, {cipher,[{client2server,['aes128-ctr']}, {server2client,['aes128-ctr']}]}, {mac,[{client2server,['hmac-sha2-256']}, {server2client,['hmac-sha2-256']}]}, {compression,[{client2server,[zlib]}, {server2client,[none]}]}]
ध्यान दें कि सूचियों में tuples का क्रम मायने नहीं रखता था।
3.3 डिफ़ॉल्ट सेट को संशोधित करना: संशोधित_आलगोरिथम
एक ऐसी स्थिति जहां एल्गोरिदम को जोड़ना उपयोगी हो सकता है, जब एक समर्थित लेकिन अक्षम एक का उपयोग करने की आवश्यकता होती है।
एक उदाहरण
'diffie-hellman-group1-sha1'
जो आजकल बहुत असुरक्षित है और इसलिए अक्षम है।
हालांकि यह अभी भी समर्थित है और इसका इस्तेमाल किया जा सकता है।
एकल एल्गोरिदम को जोड़ने या निकालने के लिए
preferred_algorithms
करने के लिए
preferred_algorithms
विकल्प_ एल्गोरिदम जटिल हो सकता है।
पहले व्यक्ति को उन्हें
ssh:default_algorithms()
के साथ सूचीबद्ध करना होगा और फिर सूचियों में परिवर्तन करना होगा।
एल्गोरिदम को जोड़ने या हटाने की सुविधा के लिए
modify_algorithms
उपलब्ध है।
विवरण के लिए
Reference Manual
देखें।
विकल्प एल्गोरिदम को जोड़ने, प्रस्तुत करने या हटाने के निर्देशों के साथ एक सूची लेता है:
{modify_algorithms, [{append, ...}, {prepend, ...}, {rm, ...} ]}
...
प्रत्येक में से एक
algs_list()
विकल्प के तर्क के रूप में हो सकता है।
उदाहरण 5
एक उदाहरण के रूप में डिफ-हेलमैन ग्रुप 1 को पहले kex सूची में जोड़ते हैं।
यह
Supported algoritms
अनुसार
Supported algoritms
।
5> ssh:chk_algos_opts( [{modify_algorithms, [{prepend, [{kex,['diffie-hellman-group1-sha1']}] } ] } ]). [{kex,['diffie-hellman-group1-sha1','ecdh-sha2-nistp384', 'ecdh-sha2-nistp521','ecdh-sha2-nistp256', 'diffie-hellman-group-exchange-sha256', 'diffie-hellman-group16-sha512', 'diffie-hellman-group18-sha512', 'diffie-hellman-group14-sha256', 'diffie-hellman-group14-sha1', 'diffie-hellman-group-exchange-sha1']}, {public_key,['ecdsa-sha2-nistp384','ecdsa-sha2-nistp521', 'ecdsa-sha2-nistp256','ssh-rsa','rsa-sha2-256', 'rsa-sha2-512','ssh-dss']}, {cipher,[{client2server,['[email protected]', 'aes256-ctr','aes192-ctr','[email protected]', 'aes128-ctr','aes128-cbc','3des-cbc']}, {server2client,['[email protected]','aes256-ctr', 'aes192-ctr','[email protected]','aes128-ctr', 'aes128-cbc','3des-cbc']}]}, {mac,[{client2server,['hmac-sha2-256','hmac-sha2-512', 'hmac-sha1']}, {server2client,['hmac-sha2-256','hmac-sha2-512', 'hmac-sha1']}]}, {compression,[{client2server,[none,'[email protected]',zlib]}, {server2client,[none,'[email protected]',zlib]}]}]
और परिणाम दिखाता है कि डिफ-हेलमैन ग्रुप 1 को केएक्स सूची के प्रमुख में जोड़ा गया है
उदाहरण 6
इस उदाहरण में, हम पहले 'डिफी-हेलमैन-ग्रुप1-शा 1
'ecdh-sha2-nistp521'
और
'ecdh-sha2-nistp521'
को भी केएक्स लिस्ट में अंत तक ले जाते हैं, यानी इसे
append
हैं।
6> ssh:chk_algos_opts( [{modify_algorithms, [{prepend, [{kex, ['diffie-hellman-group1-sha1']} ]}, {append, [{kex, ['ecdh-sha2-nistp521']} ]} ] } ]). [{kex,['diffie-hellman-group1-sha1','ecdh-sha2-nistp384', 'ecdh-sha2-nistp256','diffie-hellman-group-exchange-sha256', 'diffie-hellman-group16-sha512', 'diffie-hellman-group18-sha512', 'diffie-hellman-group14-sha256', 'diffie-hellman-group14-sha1', 'diffie-hellman-group-exchange-sha1','ecdh-sha2-nistp521']}, {public_key,['ecdsa-sha2-nistp384','ecdsa-sha2-nistp521', ..... ]
ध्यान दें कि संलग्न एल्गोरिथ्म अपने मूल स्थान से हटा दिया जाता है और फिर उसी सूची में जोड़ा जाता है।
उदाहरण 7
इस उदाहरण में, हम दोनों विकल्पों (
modify_algorithms
और
modify_algorithms
) का उपयोग
preferred_algorithms
और एक असमर्थित एल्गोरिथ्म को प्रस्तुत करने का भी प्रयास करते हैं।
किसी भी असमर्थित एल्गोरिथ्म को चुपचाप हटा दिया जाता है।
7> ssh:chk_algos_opts( [{preferred_algorithms, [{cipher,['aes128-ctr']}, {mac,['hmac-sha2-256']}, {kex,['ecdh-sha2-nistp384']}, {public_key,['ssh-rsa']}, {compression,[{server2client,[none]}, {client2server,[zlib]}]} ] }, {modify_algorithms, [{prepend, [{kex, ['some unsupported algorithm']} ]}, {append, [{kex, ['diffie-hellman-group1-sha1']} ]} ] } ]). [{kex,['ecdh-sha2-nistp384','diffie-hellman-group1-sha1']}, {public_key,['ssh-rsa']}, {cipher,[{client2server,['aes128-ctr']}, {server2client,['aes128-ctr']}]}, {mac,[{client2server,['hmac-sha2-256']}, {server2client,['hmac-sha2-256']}]}, {compression,[{client2server,[zlib]}, {server2client,[none]}]}]
यह निश्चित रूप से संदेहास्पद है कि क्यों कोई भी इन दोनों विकल्पों का एक साथ उपयोग करना चाहेगा, लेकिन यह संभव है कि यदि कोई अप्रत्याशित आवश्यकता उत्पन्न हो।