1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd: (C) 2002-2008 InspIRCd Development Team
6 * See: http://www.inspircd.org/wiki/index.php/Credits
8 * This program is free but copyrighted software; see
9 * the file COPYING for details.
11 * ---------------------------------------------------
16 #include <gnutls/gnutls.h>
17 #include <gnutls/x509.h>
19 #include "inspircd_config.h"
20 #include "configreader.h"
26 #include "transport.h"
30 #pragma comment(lib, "libgnutls-13.lib")
31 #undef MAX_DESCRIPTORS
32 #define MAX_DESCRIPTORS 10000
35 /* $ModDesc: Provides SSL support for clients */
36 /* $CompileFlags: exec("libgnutls-config --cflags") */
37 /* $LinkerFlags: rpath("libgnutls-config --libs") exec("libgnutls-config --libs") */
38 /* $ModDep: transport.h */
39 /* $CopyInstall: conf/key.pem $(CONPATH) */
40 /* $CopyInstall: conf/cert.pem $(CONPATH) */
42 enum issl_status { ISSL_NONE, ISSL_HANDSHAKING_READ, ISSL_HANDSHAKING_WRITE, ISSL_HANDSHAKEN, ISSL_CLOSING, ISSL_CLOSED };
44 bool isin(const std::string &host, int port, const std::vector<std::string> &portlist)
46 if (std::find(portlist.begin(), portlist.end(), "*:" + ConvToStr(port)) != portlist.end())
49 if (std::find(portlist.begin(), portlist.end(), ":" + ConvToStr(port)) != portlist.end())
52 return std::find(portlist.begin(), portlist.end(), host + ":" + ConvToStr(port)) != portlist.end();
55 /** Represents an SSL user's extra data
57 class issl_session : public classbase
60 gnutls_session_t sess;
68 class CommandStartTLS : public Command
72 /* Command 'dalinfo', takes no parameters and needs no special modes */
73 CommandStartTLS (InspIRCd* Instance, Module* mod) : Command(Instance,"STARTTLS", 0, 0, true), Caller(mod)
75 this->source = "m_ssl_gnutls.so";
78 CmdResult Handle (const char* const* parameters, int pcnt, User *user)
80 if (!user->GetExt("tls"))
84 Caller->OnRawSocketAccept(user->GetFd(), user->GetIPString(), user->GetPort());
90 class ModuleSSLGnuTLS : public Module
97 std::vector<std::string> listenports;
100 issl_session sessions[MAX_DESCRIPTORS];
102 gnutls_certificate_credentials x509_cred;
103 gnutls_dh_params dh_params;
106 std::string certfile;
109 std::string sslports;
114 CommandStartTLS* starttls;
118 ModuleSSLGnuTLS(InspIRCd* Me)
121 ServerInstance->Modules->PublishInterface("BufferedSocketHook", this);
123 // Not rehashable...because I cba to reduce all the sizes of existing buffers.
124 inbufsize = ServerInstance->Config->NetBufferSize;
126 gnutls_global_init(); // This must be called once in the program
128 if(gnutls_certificate_allocate_credentials(&x509_cred) != 0)
129 ServerInstance->Logs->Log("m_ssl_gnutls",DEFAULT, "m_ssl_gnutls.so: Failed to allocate certificate credentials");
131 // Guessing return meaning
132 if(gnutls_dh_params_init(&dh_params) < 0)
133 ServerInstance->Logs->Log("m_ssl_gnutls",DEFAULT, "m_ssl_gnutls.so: Failed to initialise DH parameters");
135 // Needs the flag as it ignores a plain /rehash
136 OnRehash(NULL,"ssl");
138 // Void return, guess we assume success
139 gnutls_certificate_set_dh_params(x509_cred, dh_params);
140 Implementation eventlist[] = { I_On005Numeric, I_OnRawSocketConnect, I_OnRawSocketAccept, I_OnRawSocketClose, I_OnRawSocketRead, I_OnRawSocketWrite, I_OnCleanup,
141 I_OnBufferFlushed, I_OnRequest, I_OnSyncUserMetaData, I_OnDecodeMetaData, I_OnUnloadModule, I_OnRehash, I_OnWhois, I_OnPostConnect, I_OnEvent, I_OnHookUserIO };
142 ServerInstance->Modules->Attach(eventlist, this, 17);
144 starttls = new CommandStartTLS(ServerInstance, this);
145 ServerInstance->AddCommand(starttls);
148 virtual void OnRehash(User* user, const std::string ¶m)
150 Conf = new ConfigReader(ServerInstance);
156 for(int index = 0; index < Conf->Enumerate("bind"); index++)
158 // For each <bind> tag
159 std::string x = Conf->ReadValue("bind", "type", index);
160 if(((x.empty()) || (x == "clients")) && (Conf->ReadValue("bind", "ssl", index) == "gnutls"))
162 // Get the port we're meant to be listening on with SSL
163 std::string port = Conf->ReadValue("bind", "port", index);
164 std::string addr = Conf->ReadValue("bind", "address", index);
166 irc::portparser portrange(port, false);
168 while ((portno = portrange.GetToken()))
173 listenports.push_back(addr + ":" + ConvToStr(portno));
175 for (size_t i = 0; i < ServerInstance->Config->ports.size(); i++)
176 if ((ServerInstance->Config->ports[i]->GetPort() == portno) && (ServerInstance->Config->ports[i]->GetIP() == addr))
177 ServerInstance->Config->ports[i]->SetDescription("ssl");
178 ServerInstance->Logs->Log("m_ssl_gnutls",DEFAULT, "m_ssl_gnutls.so: Enabling SSL for port %d", portno);
180 sslports.append((addr.empty() ? "*" : addr)).append(":").append(ConvToStr(portno)).append(";");
182 catch (ModuleException &e)
184 ServerInstance->Logs->Log("m_ssl_gnutls",DEFAULT, "m_ssl_gnutls.so: FAILED to enable SSL on port %d: %s. Maybe it's already hooked by the same port on a different IP, or you have an other SSL or similar module loaded?", portno, e.GetReason());
190 if (!sslports.empty())
191 sslports.erase(sslports.end() - 1);
199 std::string confdir(ServerInstance->ConfigFileName);
200 // +1 so we the path ends with a /
201 confdir = confdir.substr(0, confdir.find_last_of('/') + 1);
203 cafile = Conf->ReadValue("gnutls", "cafile", 0);
204 crlfile = Conf->ReadValue("gnutls", "crlfile", 0);
205 certfile = Conf->ReadValue("gnutls", "certfile", 0);
206 keyfile = Conf->ReadValue("gnutls", "keyfile", 0);
207 dh_bits = Conf->ReadInteger("gnutls", "dhbits", 0, false);
209 // Set all the default values needed.
216 if (certfile.empty())
217 certfile = "cert.pem";
222 if((dh_bits != 768) && (dh_bits != 1024) && (dh_bits != 2048) && (dh_bits != 3072) && (dh_bits != 4096))
225 // Prepend relative paths with the path to the config directory.
227 cafile = confdir + cafile;
229 if(crlfile[0] != '/')
230 crlfile = confdir + crlfile;
232 if(certfile[0] != '/')
233 certfile = confdir + certfile;
235 if(keyfile[0] != '/')
236 keyfile = confdir + keyfile;
240 if((ret =gnutls_certificate_set_x509_trust_file(x509_cred, cafile.c_str(), GNUTLS_X509_FMT_PEM)) < 0)
241 ServerInstance->Logs->Log("m_ssl_gnutls",DEFAULT, "m_ssl_gnutls.so: Failed to set X.509 trust file '%s': %s", cafile.c_str(), gnutls_strerror(ret));
243 if((ret = gnutls_certificate_set_x509_crl_file (x509_cred, crlfile.c_str(), GNUTLS_X509_FMT_PEM)) < 0)
244 ServerInstance->Logs->Log("m_ssl_gnutls",DEFAULT, "m_ssl_gnutls.so: Failed to set X.509 CRL file '%s': %s", crlfile.c_str(), gnutls_strerror(ret));
246 if((ret = gnutls_certificate_set_x509_key_file (x509_cred, certfile.c_str(), keyfile.c_str(), GNUTLS_X509_FMT_PEM)) < 0)
248 // If this fails, no SSL port will work. At all. So, do the smart thing - throw a ModuleException
249 throw ModuleException("Unable to load GnuTLS server certificate: " + std::string(gnutls_strerror(ret)));
252 // This may be on a large (once a day or week) timer eventually.
258 void GenerateDHParams()
260 // Generate Diffie Hellman parameters - for use with DHE
261 // kx algorithms. These should be discarded and regenerated
262 // once a day, once a week or once a month. Depending on the
263 // security requirements.
267 if((ret = gnutls_dh_params_generate2(dh_params, dh_bits)) < 0)
268 ServerInstance->Logs->Log("m_ssl_gnutls",DEFAULT, "m_ssl_gnutls.so: Failed to generate DH parameters (%d bits): %s", dh_bits, gnutls_strerror(ret));
271 virtual ~ModuleSSLGnuTLS()
273 gnutls_dh_params_deinit(dh_params);
274 gnutls_certificate_free_credentials(x509_cred);
275 gnutls_global_deinit();
278 virtual void OnCleanup(int target_type, void* item)
280 if(target_type == TYPE_USER)
282 User* user = (User*)item;
286 // User is using SSL, they're a local user, and they're using one of *our* SSL ports.
287 // Potentially there could be multiple SSL modules loaded at once on different ports.
288 User::QuitUser(ServerInstance, user, "SSL module unloading");
290 if (user->GetExt("ssl_cert", dummy))
293 user->GetExt("ssl_cert", tofree);
295 user->Shrink("ssl_cert");
302 virtual void OnUnloadModule(Module* mod, const std::string &name)
306 for(unsigned int i = 0; i < listenports.size(); i++)
308 for (size_t j = 0; j < ServerInstance->Config->ports.size(); j++)
309 if (listenports[i] == (ServerInstance->Config->ports[j]->GetIP()+":"+ConvToStr(ServerInstance->Config->ports[j]->GetPort())))
310 ServerInstance->Config->ports[j]->SetDescription("plaintext");
315 virtual Version GetVersion()
317 return Version(1, 2, 0, 0, VF_VENDOR, API_VERSION);
321 virtual void On005Numeric(std::string &output)
323 output.append(" SSL=" + sslports);
326 virtual void OnHookUserIO(User* user, const std::string &targetip)
328 if (!user->io && isin(targetip,user->GetPort(),listenports))
330 /* Hook the user with our module */
335 virtual const char* OnRequest(Request* request)
337 ISHRequest* ISR = (ISHRequest*)request;
338 if (strcmp("IS_NAME", request->GetId()) == 0)
342 else if (strcmp("IS_HOOK", request->GetId()) == 0)
344 const char* ret = "OK";
347 ret = ServerInstance->Config->AddIOHook((Module*)this, (BufferedSocket*)ISR->Sock) ? "OK" : NULL;
349 catch (ModuleException &e)
355 else if (strcmp("IS_UNHOOK", request->GetId()) == 0)
357 return ServerInstance->Config->DelIOHook((BufferedSocket*)ISR->Sock) ? "OK" : NULL;
359 else if (strcmp("IS_HSDONE", request->GetId()) == 0)
361 if (ISR->Sock->GetFd() < 0)
364 issl_session* session = &sessions[ISR->Sock->GetFd()];
365 return (session->status == ISSL_HANDSHAKING_READ || session->status == ISSL_HANDSHAKING_WRITE) ? NULL : "OK";
367 else if (strcmp("IS_ATTACH", request->GetId()) == 0)
369 if (ISR->Sock->GetFd() > -1)
371 issl_session* session = &sessions[ISR->Sock->GetFd()];
374 if ((Extensible*)ServerInstance->FindDescriptor(ISR->Sock->GetFd()) == (Extensible*)(ISR->Sock))
376 VerifyCertificate(session, (BufferedSocket*)ISR->Sock);
386 virtual void OnRawSocketAccept(int fd, const std::string &ip, int localport)
388 /* Are there any possibilities of an out of range fd? Hope not, but lets be paranoid */
389 if ((fd < 0) || (fd > MAX_DESCRIPTORS))
392 issl_session* session = &sessions[fd];
395 session->inbuf = new char[inbufsize];
396 session->inbufoffset = 0;
398 gnutls_init(&session->sess, GNUTLS_SERVER);
400 gnutls_set_default_priority(session->sess); // Avoid calling all the priority functions, defaults are adequate.
401 gnutls_credentials_set(session->sess, GNUTLS_CRD_CERTIFICATE, x509_cred);
402 gnutls_dh_set_prime_bits(session->sess, dh_bits);
404 /* This is an experimental change to avoid a warning on 64bit systems about casting between integer and pointer of different sizes
405 * This needs testing, but it's easy enough to rollback if need be
406 * Old: gnutls_transport_set_ptr(session->sess, (gnutls_transport_ptr_t) fd); // Give gnutls the fd for the socket.
407 * New: gnutls_transport_set_ptr(session->sess, &fd); // Give gnutls the fd for the socket.
409 * With testing this seems to...not work :/
412 gnutls_transport_set_ptr(session->sess, (gnutls_transport_ptr_t) fd); // Give gnutls the fd for the socket.
414 gnutls_certificate_server_set_request(session->sess, GNUTLS_CERT_REQUEST); // Request client certificate if any.
419 virtual void OnRawSocketConnect(int fd)
421 /* Are there any possibilities of an out of range fd? Hope not, but lets be paranoid */
422 if ((fd < 0) || (fd > MAX_DESCRIPTORS))
425 issl_session* session = &sessions[fd];
428 session->inbuf = new char[inbufsize];
429 session->inbufoffset = 0;
431 gnutls_init(&session->sess, GNUTLS_CLIENT);
433 gnutls_set_default_priority(session->sess); // Avoid calling all the priority functions, defaults are adequate.
434 gnutls_credentials_set(session->sess, GNUTLS_CRD_CERTIFICATE, x509_cred);
435 gnutls_dh_set_prime_bits(session->sess, dh_bits);
436 gnutls_transport_set_ptr(session->sess, (gnutls_transport_ptr_t) fd); // Give gnutls the fd for the socket.
441 virtual void OnRawSocketClose(int fd)
443 /* Are there any possibilities of an out of range fd? Hope not, but lets be paranoid */
444 if ((fd < 0) || (fd > MAX_DESCRIPTORS))
447 CloseSession(&sessions[fd]);
449 EventHandler* user = ServerInstance->SE->GetRef(fd);
451 if ((user) && (user->GetExt("ssl_cert", dummy)))
454 user->GetExt("ssl_cert", tofree);
456 user->Shrink("ssl_cert");
460 virtual int OnRawSocketRead(int fd, char* buffer, unsigned int count, int &readresult)
462 /* Are there any possibilities of an out of range fd? Hope not, but lets be paranoid */
463 if ((fd < 0) || (fd > MAX_DESCRIPTORS))
466 issl_session* session = &sessions[fd];
471 CloseSession(session);
475 if (session->status == ISSL_HANDSHAKING_READ)
477 // The handshake isn't finished, try to finish it.
479 if(!Handshake(session))
481 // Couldn't resume handshake.
485 else if (session->status == ISSL_HANDSHAKING_WRITE)
488 MakePollWrite(session);
492 // If we resumed the handshake then session->status will be ISSL_HANDSHAKEN.
494 if (session->status == ISSL_HANDSHAKEN)
496 // Is this right? Not sure if the unencrypted data is garaunteed to be the same length.
497 // Read into the inbuffer, offset from the beginning by the amount of data we have that insp hasn't taken yet.
498 int ret = gnutls_record_recv(session->sess, session->inbuf + session->inbufoffset, inbufsize - session->inbufoffset);
502 // Client closed connection.
504 CloseSession(session);
509 if (ret == GNUTLS_E_AGAIN || ret == GNUTLS_E_INTERRUPTED)
517 CloseSession(session);
522 // Read successfully 'ret' bytes into inbuf + inbufoffset
523 // There are 'ret' + 'inbufoffset' bytes of data in 'inbuf'
524 // 'buffer' is 'count' long
526 unsigned int length = ret + session->inbufoffset;
530 memcpy(buffer, session->inbuf, count);
531 // Move the stuff left in inbuf to the beginning of it
532 memcpy(session->inbuf, session->inbuf + count, (length - count));
533 // Now we need to set session->inbufoffset to the amount of data still waiting to be handed to insp.
534 session->inbufoffset = length - count;
535 // Insp uses readresult as the count of how much data there is in buffer, so:
540 // There's not as much in the inbuf as there is space in the buffer, so just copy the whole thing.
541 memcpy(buffer, session->inbuf, length);
542 // Zero the offset, as there's nothing there..
543 session->inbufoffset = 0;
549 else if(session->status == ISSL_CLOSING)
555 virtual int OnRawSocketWrite(int fd, const char* buffer, int count)
557 /* Are there any possibilities of an out of range fd? Hope not, but lets be paranoid */
558 if ((fd < 0) || (fd > MAX_DESCRIPTORS))
561 issl_session* session = &sessions[fd];
562 const char* sendbuffer = buffer;
566 CloseSession(session);
570 session->outbuf.append(sendbuffer, count);
571 sendbuffer = session->outbuf.c_str();
572 count = session->outbuf.size();
574 if (session->status == ISSL_HANDSHAKING_WRITE)
576 // The handshake isn't finished, try to finish it.
584 if (session->status == ISSL_HANDSHAKEN)
586 ret = gnutls_record_send(session->sess, sendbuffer, count);
590 CloseSession(session);
594 if(ret != GNUTLS_E_AGAIN && ret != GNUTLS_E_INTERRUPTED)
596 CloseSession(session);
605 session->outbuf = session->outbuf.substr(ret);
609 MakePollWrite(session);
611 /* Who's smart idea was it to return 1 when we havent written anything?
612 * This fucks the buffer up in BufferedSocket :p
614 return ret < 1 ? 0 : ret;
617 // :kenny.chatspike.net 320 Om Epy|AFK :is a Secure Connection
618 virtual void OnWhois(User* source, User* dest)
623 // Bugfix, only send this numeric for *our* SSL users
624 if (dest->GetExt("ssl", dummy) || ((IS_LOCAL(dest) && (dest->io == this))))
626 ServerInstance->SendWhoisLine(source, dest, 320, "%s %s :is using a secure connection", source->nick, dest->nick);
630 virtual void OnSyncUserMetaData(User* user, Module* proto, void* opaque, const std::string &extname, bool displayable)
632 // check if the linking module wants to know about OUR metadata
635 // check if this user has an swhois field to send
636 if(user->GetExt(extname, dummy))
638 // call this function in the linking module, let it format the data how it
639 // sees fit, and send it on its way. We dont need or want to know how.
640 proto->ProtoSendMetaData(opaque, TYPE_USER, user, extname, displayable ? "Enabled" : "ON");
645 virtual void OnDecodeMetaData(int target_type, void* target, const std::string &extname, const std::string &extdata)
647 // check if its our metadata key, and its associated with a user
648 if ((target_type == TYPE_USER) && (extname == "ssl"))
650 User* dest = (User*)target;
651 // if they dont already have an ssl flag, accept the remote server's
652 if (!dest->GetExt(extname, dummy))
654 dest->Extend(extname, "ON");
659 bool Handshake(issl_session* session)
661 int ret = gnutls_handshake(session->sess);
665 if(ret == GNUTLS_E_AGAIN || ret == GNUTLS_E_INTERRUPTED)
667 // Handshake needs resuming later, read() or write() would have blocked.
669 if(gnutls_record_get_direction(session->sess) == 0)
671 // gnutls_handshake() wants to read() again.
672 session->status = ISSL_HANDSHAKING_READ;
676 // gnutls_handshake() wants to write() again.
677 session->status = ISSL_HANDSHAKING_WRITE;
678 MakePollWrite(session);
684 CloseSession(session);
685 session->status = ISSL_CLOSING;
692 // Handshake complete.
693 // This will do for setting the ssl flag...it could be done earlier if it's needed. But this seems neater.
694 User* extendme = ServerInstance->FindDescriptor(session->fd);
697 if (!extendme->GetExt("ssl", dummy))
698 extendme->Extend("ssl", "ON");
701 // Change the seesion state
702 session->status = ISSL_HANDSHAKEN;
704 // Finish writing, if any left
705 MakePollWrite(session);
711 virtual void OnPostConnect(User* user)
713 // This occurs AFTER OnUserConnect so we can be sure the
714 // protocol module has propagated the NICK message.
715 if ((user->GetExt("ssl", dummy)) && (IS_LOCAL(user)))
717 // Tell whatever protocol module we're using that we need to inform other servers of this metadata NOW.
718 std::deque<std::string>* metadata = new std::deque<std::string>;
719 metadata->push_back(user->nick);
720 metadata->push_back("ssl"); // The metadata id
721 metadata->push_back("ON"); // The value to send
722 Event* event = new Event((char*)metadata,(Module*)this,"send_metadata");
723 event->Send(ServerInstance); // Trigger the event. We don't care what module picks it up.
727 VerifyCertificate(&sessions[user->GetFd()],user);
728 if (sessions[user->GetFd()].sess)
730 std::string cipher = gnutls_kx_get_name(gnutls_kx_get(sessions[user->GetFd()].sess));
731 cipher.append("-").append(gnutls_cipher_get_name(gnutls_cipher_get(sessions[user->GetFd()].sess))).append("-");
732 cipher.append(gnutls_mac_get_name(gnutls_mac_get(sessions[user->GetFd()].sess)));
733 user->WriteServ("NOTICE %s :*** You are connected using SSL cipher \"%s\"", user->nick, cipher.c_str());
738 void MakePollWrite(issl_session* session)
740 //OnRawSocketWrite(session->fd, NULL, 0);
741 EventHandler* eh = ServerInstance->FindDescriptor(session->fd);
743 ServerInstance->SE->WantWrite(eh);
746 virtual void OnBufferFlushed(User* user)
748 if (user->GetExt("ssl"))
750 issl_session* session = &sessions[user->GetFd()];
751 if (session && session->outbuf.size())
752 OnRawSocketWrite(user->GetFd(), NULL, 0);
756 void CloseSession(issl_session* session)
760 gnutls_bye(session->sess, GNUTLS_SHUT_WR);
761 gnutls_deinit(session->sess);
766 delete[] session->inbuf;
769 session->outbuf.clear();
770 session->inbuf = NULL;
771 session->sess = NULL;
772 session->status = ISSL_NONE;
775 void VerifyCertificate(issl_session* session, Extensible* user)
777 if (!session->sess || !user)
781 const gnutls_datum_t* cert_list;
783 unsigned int cert_list_size;
784 gnutls_x509_crt_t cert;
786 unsigned char digest[MAXBUF];
787 size_t digest_size = sizeof(digest);
788 size_t name_size = sizeof(name);
789 ssl_cert* certinfo = new ssl_cert;
791 user->Extend("ssl_cert",certinfo);
793 /* This verification function uses the trusted CAs in the credentials
794 * structure. So you must have installed one or more CA certificates.
796 ret = gnutls_certificate_verify_peers2(session->sess, &status);
800 certinfo->data.insert(std::make_pair("error",std::string(gnutls_strerror(ret))));
804 if (status & GNUTLS_CERT_INVALID)
806 certinfo->data.insert(std::make_pair("invalid",ConvToStr(1)));
810 certinfo->data.insert(std::make_pair("invalid",ConvToStr(0)));
812 if (status & GNUTLS_CERT_SIGNER_NOT_FOUND)
814 certinfo->data.insert(std::make_pair("unknownsigner",ConvToStr(1)));
818 certinfo->data.insert(std::make_pair("unknownsigner",ConvToStr(0)));
820 if (status & GNUTLS_CERT_REVOKED)
822 certinfo->data.insert(std::make_pair("revoked",ConvToStr(1)));
826 certinfo->data.insert(std::make_pair("revoked",ConvToStr(0)));
828 if (status & GNUTLS_CERT_SIGNER_NOT_CA)
830 certinfo->data.insert(std::make_pair("trusted",ConvToStr(0)));
834 certinfo->data.insert(std::make_pair("trusted",ConvToStr(1)));
837 /* Up to here the process is the same for X.509 certificates and
838 * OpenPGP keys. From now on X.509 certificates are assumed. This can
839 * be easily extended to work with openpgp keys as well.
841 if (gnutls_certificate_type_get(session->sess) != GNUTLS_CRT_X509)
843 certinfo->data.insert(std::make_pair("error","No X509 keys sent"));
847 ret = gnutls_x509_crt_init(&cert);
850 certinfo->data.insert(std::make_pair("error",gnutls_strerror(ret)));
855 cert_list = gnutls_certificate_get_peers(session->sess, &cert_list_size);
856 if (cert_list == NULL)
858 certinfo->data.insert(std::make_pair("error","No certificate was found"));
862 /* This is not a real world example, since we only check the first
863 * certificate in the given chain.
866 ret = gnutls_x509_crt_import(cert, &cert_list[0], GNUTLS_X509_FMT_DER);
869 certinfo->data.insert(std::make_pair("error",gnutls_strerror(ret)));
873 gnutls_x509_crt_get_dn(cert, name, &name_size);
875 certinfo->data.insert(std::make_pair("dn",name));
877 gnutls_x509_crt_get_issuer_dn(cert, name, &name_size);
879 certinfo->data.insert(std::make_pair("issuer",name));
881 if ((ret = gnutls_x509_crt_get_fingerprint(cert, GNUTLS_DIG_MD5, digest, &digest_size)) < 0)
883 certinfo->data.insert(std::make_pair("error",gnutls_strerror(ret)));
887 certinfo->data.insert(std::make_pair("fingerprint",irc::hex(digest, digest_size)));
890 /* Beware here we do not check for errors.
892 if ((gnutls_x509_crt_get_expiration_time(cert) < time(0)) || (gnutls_x509_crt_get_activation_time(cert) > time(0)))
894 certinfo->data.insert(std::make_pair("error","Not activated, or expired certificate"));
897 gnutls_x509_crt_deinit(cert);
902 void OnEvent(Event* ev)
904 GenericCapHandler(ev, "tls", "tls");
909 MODULE_INIT(ModuleSSLGnuTLS)