title: Mongodb connection attempt failed: SSLHandshakeFailed: SSL peer certificate validation failed: self signed certificate
body: <p>I set up a mongoDB database with SSL security on an Ubuntu 16.04.5 LTS server and I have been using it for a few months. To set up SSL on mongo I followed the tutorial by Rajan Maharjan on medium.com <a href="https://medium.com/@rajanmaharjan/secure-your-mongodb-connections-ssl-tls-92e2addb3c89" rel="nofollow noreferrer">(link)</a>. Coming back to my server after a short period of not using it, I received the following error message:</p>
  
  <p><code>SSL peer certificate validation failed: certificate has expired</code> </p>
  
  <p>Looking at the mongo log, I found:</p>
  
  <p><code>[PeriodicTaskRunner] Server certificate is now invalid. It expired on 2018-11-10T08:10:11.000Z</code></p>
  
  <p>So I regenerated and re-signed all my certificates with the rootCA.key file, following the same steps as when creating certificates for the first time. I restarted mongod with:</p>
  
  <p><code>service mongod restart</code></p>
  
  <p>And now I have the "self signed certificate" error:</p>
  
  <pre><code>MongoDB shell version v4.0.2
  connecting to: mongodb://IP:port/
  2018-11-21T13:11:10.584+0000 E NETWORK  [js] SSL peer certificate     
  validation failed: self signed certificate
  2018-11-21T13:11:10.584+0000 E QUERY    [js] Error: 
  couldn't connect to server IP:port, connection attempt failed: 
  SSLHandshakeFailed: SSL peer certificate validation failed: self signed certificate :
  connect@src/mongo/shell/mongo.js:257:13
  @(connect):1:6
  exception: connect failed
  </code></pre>
  
  <p>My connection string is the following:</p>
  
  <p><code>mongo --ssl --sslCAFile /PATH/TO/rootCA.pem --sslPEMKeyFile /PATH/TO/mongodb.pem --host IP:port</code></p>
  
  <p>I have not found any resources on re-signing certificates for mongoDB. Any help would be much appreciated.</p>
  
  <h2>EDIT</h2>
  
  <p>/etc/mongod.conf :</p>
  
  <pre><code># mongod.conf
  
  # for documentation of all options, see:
  #   http://docs.mongodb.org/manual/reference/configuration-options/
  
  # Where and how to store data.
  storage:
    dbPath: /var/lib/mongodb
    journal:
      enabled: true
  #  engine:
  #  mmapv1:
  #  wiredTiger:
  
  # where to write logging data.
  systemLog:
    destination: file
    logAppend: true
    path: /var/log/mongodb/mongod.log
  
  # network interfaces
  net:
    port: PORT
    bindIp: IP
    ssl:
      mode: requireSSL
      PEMKeyFile: /etc/ssl/mongodb.pem
      CAFile: /etc/ssl/rootCA.pem
  
  # how the process runs
   processManagement:
    timeZoneInfo: /usr/share/zoneinfo
  
  #security:
  security:
     authorization: "enabled"
  
  #operationProfiling:
  
  #replication:
  
  #sharding:
  
  ## Enterprise-Only Options:
  
  #auditLog:
  
  #snmp:
  </code></pre>