msimerson/Haraka

View on GitHub
tls_socket.js

Summary

Maintainability
F
6 days
Test Coverage

File tls_socket.js has 583 lines of code (exceeds 250 allowed). Consider refactoring.
Open

'use strict';
/*--------------------------------------------------------------------------*/
/* Obtained and modified from http://js.5sh.net/starttls.js on 8/18/2011.   */
/*--------------------------------------------------------------------------*/

Severity: Major
Found in tls_socket.js - About 1 day to fix

    Function load_default_opts has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring.
    Open

    exports.load_default_opts = () => {
    
        const cfg = certsByHost['*'];
    
        if (cfg.dhparam && typeof cfg.dhparam === 'string') {
    Severity: Minor
    Found in tls_socket.js - About 2 hrs to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    Function get_certs_dir has 62 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

    exports.get_certs_dir = (tlsDir, done) => {
    
        this.config.getDir(tlsDir, {}, (iterErr, files) => {
            if (iterErr) return done(iterErr);
    
    
    Severity: Major
    Found in tls_socket.js - About 2 hrs to fix

      Function connect has 52 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

      function connect (port, host) {
          let conn_options = {};
          if (typeof port === 'object') {
              conn_options = port;
          }
      Severity: Major
      Found in tls_socket.js - About 2 hrs to fix

        Function attach has 50 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            attach (socket) {
                this.targetsocket = socket;
                this.targetsocket.on('data', data => {
                    this.emit('data', data);
                });
        Severity: Minor
        Found in tls_socket.js - About 2 hrs to fix

          Function load_tls_ini has 48 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

          exports.load_tls_ini = (opts) => {
          
              log.loginfo(`loading tls.ini`); // from ${this.config.root_path}`);
          
              const cfg = exports.config.get('tls.ini', {
          Severity: Minor
          Found in tls_socket.js - About 1 hr to fix

            Function connect has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
            Open

            function connect (port, host) {
                let conn_options = {};
                if (typeof port === 'object') {
                    conn_options = port;
                }
            Severity: Minor
            Found in tls_socket.js - About 1 hr to fix

            Cognitive Complexity

            Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

            A method's cognitive complexity is based on a few simple rules:

            • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
            • Code is considered more complex for each "break in the linear flow of the code"
            • Code is considered more complex when "flow breaking structures are nested"

            Further reading

            Function load_default_opts has 42 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

            exports.load_default_opts = () => {
            
                const cfg = certsByHost['*'];
            
                if (cfg.dhparam && typeof cfg.dhparam === 'string') {
            Severity: Minor
            Found in tls_socket.js - About 1 hr to fix

              Function applySocketOpts has 42 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

              exports.applySocketOpts = name => {
              
                  if (!certsByHost[name]) certsByHost[name] = {};
              
                  // https://nodejs.org/api/tls.html#tls_new_tls_tlssocket_socket_options
              Severity: Minor
              Found in tls_socket.js - About 1 hr to fix

                Function load_tls_ini has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
                Open

                exports.load_tls_ini = (opts) => {
                
                    log.loginfo(`loading tls.ini`); // from ${this.config.root_path}`);
                
                    const cfg = exports.config.get('tls.ini', {
                Severity: Minor
                Found in tls_socket.js - About 1 hr to fix

                Cognitive Complexity

                Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                A method's cognitive complexity is based on a few simple rules:

                • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                • Code is considered more complex for each "break in the linear flow of the code"
                • Code is considered more complex when "flow breaking structures are nested"

                Further reading

                Function createServer has 39 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                function createServer (cb) {
                    const server = net.createServer(cryptoSocket => {
                
                        const socket = new pluggableStream(cryptoSocket);
                
                
                Severity: Minor
                Found in tls_socket.js - About 1 hr to fix

                  Function upgrade has 39 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                      socket.upgrade = (options, cb2) => {
                          socket.clean();
                          cryptoSocket.removeAllListeners('data');
                  
                          if (exports.tls_valid) {
                  Severity: Minor
                  Found in tls_socket.js - About 1 hr to fix

                    Function server has 36 lines of code (exceeds 25 allowed). Consider refactoring.
                    Open

                        const server = net.createServer(cryptoSocket => {
                    
                            const socket = new pluggableStream(cryptoSocket);
                    
                            exports.addOCSP(server);
                    Severity: Minor
                    Found in tls_socket.js - About 1 hr to fix

                      Function addOCSP has 31 lines of code (exceeds 25 allowed). Consider refactoring.
                      Open

                      exports.addOCSP = server => {
                          if (!ocsp) {
                              log.logdebug('addOCSP: not available');
                              return;
                          }
                      Severity: Minor
                      Found in tls_socket.js - About 1 hr to fix

                        Function upgrade has 31 lines of code (exceeds 25 allowed). Consider refactoring.
                        Open

                                socket.upgrade = cb2 => {
                                    log.logdebug('Upgrading to TLS');
                        
                                    socket.clean();
                        
                        
                        Severity: Minor
                        Found in tls_socket.js - About 1 hr to fix

                          Function parse_x509_names has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
                          Open

                          exports.parse_x509_names = string => {
                              // receives the text value of a x509 certificate and returns an array of
                              // of names extracted from the Subject CN and the v3 Subject Alternate Names
                              const names_found = [];
                          
                          
                          Severity: Minor
                          Found in tls_socket.js - About 55 mins to fix

                          Cognitive Complexity

                          Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                          A method's cognitive complexity is based on a few simple rules:

                          • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                          • Code is considered more complex for each "break in the linear flow of the code"
                          • Code is considered more complex when "flow breaking structures are nested"

                          Further reading

                          Function applySocketOpts has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
                          Open

                          exports.applySocketOpts = name => {
                          
                              if (!certsByHost[name]) certsByHost[name] = {};
                          
                              // https://nodejs.org/api/tls.html#tls_new_tls_tlssocket_socket_options
                          Severity: Minor
                          Found in tls_socket.js - About 55 mins to fix

                          Cognitive Complexity

                          Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                          A method's cognitive complexity is based on a few simple rules:

                          • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                          • Code is considered more complex for each "break in the linear flow of the code"
                          • Code is considered more complex when "flow breaking structures are nested"

                          Further reading

                          Function addOCSP has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                          Open

                          exports.addOCSP = server => {
                              if (!ocsp) {
                                  log.logdebug('addOCSP: not available');
                                  return;
                              }
                          Severity: Minor
                          Found in tls_socket.js - About 45 mins to fix

                          Cognitive Complexity

                          Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                          A method's cognitive complexity is based on a few simple rules:

                          • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                          • Code is considered more complex for each "break in the linear flow of the code"
                          • Code is considered more complex when "flow breaking structures are nested"

                          Further reading

                          Function get_certs_dir has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                          Open

                          exports.get_certs_dir = (tlsDir, done) => {
                          
                              this.config.getDir(tlsDir, {}, (iterErr, files) => {
                                  if (iterErr) return done(iterErr);
                          
                          
                          Severity: Minor
                          Found in tls_socket.js - About 45 mins to fix

                          Cognitive Complexity

                          Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                          A method's cognitive complexity is based on a few simple rules:

                          • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                          • Code is considered more complex for each "break in the linear flow of the code"
                          • Code is considered more complex when "flow breaking structures are nested"

                          Further reading

                          Similar blocks of code found in 2 locations. Consider refactoring.
                          Open

                                  const asArray = cfg.cert.map(certFileName => {
                                      if (!certFileName) return;
                                      const cert = this.config.get(certFileName, 'binary');
                                      if (!cert) {
                                          log.logerror(`tls cert ${path.join(this.config.root_path, certFileName)} could not be loaded.`);
                          Severity: Major
                          Found in tls_socket.js and 1 other location - About 3 hrs to fix
                          tls_socket.js on lines 380..387

                          Duplicated Code

                          Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                          Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                          When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                          Tuning

                          This issue has a mass of 100.

                          We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                          The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                          If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                          See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                          Refactorings

                          Further Reading

                          Similar blocks of code found in 2 locations. Consider refactoring.
                          Open

                                  const asArray = cfg.key.map(keyFileName => {
                                      if (!keyFileName) return;
                                      const key = this.config.get(keyFileName, 'binary');
                                      if (!key) {
                                          log.logerror(`tls key ${path.join(this.config.root_path, keyFileName)} could not be loaded.`);
                          Severity: Major
                          Found in tls_socket.js and 1 other location - About 3 hrs to fix
                          tls_socket.js on lines 392..399

                          Duplicated Code

                          Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                          Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                          When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                          Tuning

                          This issue has a mass of 100.

                          We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                          The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                          If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                          See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                          Refactorings

                          Further Reading

                          Similar blocks of code found in 2 locations. Consider refactoring.
                          Open

                              if (cfg.ca && typeof cfg.ca === 'string') {
                                  log.loginfo(`loading CA certs from ${cfg.ca}`);
                                  this.saveOpt('*', 'ca', this.config.get(cfg.ca, 'binary'));
                              }
                          Severity: Major
                          Found in tls_socket.js and 1 other location - About 1 hr to fix
                          tls_socket.js on lines 359..362

                          Duplicated Code

                          Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                          Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                          When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                          Tuning

                          This issue has a mass of 58.

                          We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                          The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                          If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                          See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                          Refactorings

                          Further Reading

                          Similar blocks of code found in 2 locations. Consider refactoring.
                          Open

                              if (cfg.dhparam && typeof cfg.dhparam === 'string') {
                                  log.logdebug(`loading dhparams from ${cfg.dhparam}`);
                                  this.saveOpt('*', 'dhparam', this.config.get(cfg.dhparam, 'binary'));
                              }
                          Severity: Major
                          Found in tls_socket.js and 1 other location - About 1 hr to fix
                          tls_socket.js on lines 364..367

                          Duplicated Code

                          Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                          Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                          When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                          Tuning

                          This issue has a mass of 58.

                          We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                          The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                          If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                          See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                          Refactorings

                          Further Reading

                          Similar blocks of code found in 2 locations. Consider refactoring.
                          Open

                                  this.targetsocket.on('secure', (a, b) => {
                                      this.emit('secureConnection', a, b);
                                      this.emit('secure', a, b);
                                  });
                          Severity: Minor
                          Found in tls_socket.js and 1 other location - About 40 mins to fix
                          tls_socket.js on lines 63..66

                          Duplicated Code

                          Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                          Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                          When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                          Tuning

                          This issue has a mass of 49.

                          We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                          The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                          If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                          See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                          Refactorings

                          Further Reading

                          Similar blocks of code found in 2 locations. Consider refactoring.
                          Open

                                      if (!parsed.cert) {
                                          return iter_done(null, {
                                              err: new Error(`no CERT in ${file.path}`),
                                              file
                                          });
                          Severity: Minor
                          Found in tls_socket.js and 1 other location - About 40 mins to fix
                          tls_socket.js on lines 429..434

                          Duplicated Code

                          Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                          Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                          When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                          Tuning

                          This issue has a mass of 49.

                          We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                          The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                          If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                          See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                          Refactorings

                          Further Reading

                          Similar blocks of code found in 2 locations. Consider refactoring.
                          Open

                                      if (!parsed.key) {
                                          return iter_done(null, {
                                              err: new Error(`no PRIVATE key in ${file.path}`),
                                              file
                                          });
                          Severity: Minor
                          Found in tls_socket.js and 1 other location - About 40 mins to fix
                          tls_socket.js on lines 435..440

                          Duplicated Code

                          Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                          Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                          When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                          Tuning

                          This issue has a mass of 49.

                          We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                          The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                          If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                          See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                          Refactorings

                          Further Reading

                          Similar blocks of code found in 2 locations. Consider refactoring.
                          Open

                                  this.targetsocket.on('secureConnect', (a, b) => {
                                      this.emit('secureConnect', a, b);
                                      this.emit('secure', a, b);
                                  });
                          Severity: Minor
                          Found in tls_socket.js and 1 other location - About 40 mins to fix
                          tls_socket.js on lines 72..75

                          Duplicated Code

                          Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                          Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                          When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                          Tuning

                          This issue has a mass of 49.

                          We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                          The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                          If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                          See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                          Refactorings

                          Further Reading

                          There are no issues that match your filters.

                          Category
                          Status