]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/extra/m_sslinfo.cpp
We now have a test module that can dump someones certificate information: /sslinfo...
[user/henk/code/inspircd.git] / src / modules / extra / m_sslinfo.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd is copyright (C) 2002-2006 ChatSpike-Dev.
6  *                       E-mail:
7  *                <brain@chatspike.net>
8  *                <Craig@chatspike.net>
9  *     
10  * Written by Craig Edwards, Craig McLure, and others.
11  * This program is free but copyrighted software; see
12  *            the file COPYING for details.
13  *
14  * ---------------------------------------------------
15  */
16
17 using namespace std;
18
19 #include <stdio.h>
20 #include "users.h"
21 #include "channels.h"
22 #include "modules.h"
23 #include "ssl_cert.h"
24 #include "wildcard.h"
25 #include "inspircd.h"
26 #include "dns.h"
27
28 /* $ModDesc: Provides /sslinfo command used to test who a mask matches */
29          
30 class cmd_sslinfo : public command_t
31 {
32  public:
33         cmd_sslinfo (InspIRCd* Instance) : command_t(Instance,"SSLINFO", 0, 1)
34         {
35                 this->source = "m_sslinfo.so";
36                 this->syntax = "<nick>";
37         }
38
39         void Handle (const char** parameters, int pcnt, userrec *user)
40         {
41                 userrec* target = ServerInstance->FindNick(parameters[0]);
42                 ssl_cert* cert;
43
44                 if (target)
45                 {
46                         if (target->GetExt("ssl_cert", cert))
47                         {
48                                 if (cert->GetError().length())
49                                 {
50                                         user->WriteServ("NOTICE %s :*** Error:             %s", user->nick, cert->GetError().c_str());
51                                 }
52                                 user->WriteServ("NOTICE %s :*** Distinguised Name: %s", user->nick, cert->GetDN().c_str());
53                                 user->WriteServ("NOTICE %s :*** Issuer:            %s", user->nick, cert->GetIssuer().c_str());
54                                 user->WriteServ("NOTICE %s :*** Key Fingerprint:   %s", user->nick, cert->GetFingerprint().c_str());
55                         }
56                         else
57                         {
58                                 user->WriteServ("NOTICE %s :*** No SSL certificate information for this user.", user->nick);
59                         }
60                 }
61                 else
62                         user->WriteServ("401 %s %s :No such nickname", user->nick, parameters[0]);
63         }
64 };
65
66 class ModuleSSLInfo : public Module
67 {
68         cmd_sslinfo* newcommand;
69  public:
70         ModuleSSLInfo(InspIRCd* Me)
71                 : Module::Module(Me)
72         {
73                 
74                 newcommand = new cmd_sslinfo(ServerInstance);
75                 ServerInstance->AddCommand(newcommand);
76         }
77
78         void Implements(char* List)
79         {
80         }
81
82         virtual ~ModuleSSLInfo()
83         {
84         }
85         
86         virtual Version GetVersion()
87         {
88                 return Version(1, 0, 0, 0, VF_VENDOR);
89         }
90 };
91
92
93 class ModuleSSLInfoFactory : public ModuleFactory
94 {
95  public:
96         ModuleSSLInfoFactory()
97         {
98         }
99         
100         ~ModuleSSLInfoFactory()
101         {
102         }
103         
104         virtual Module * CreateModule(InspIRCd* Me)
105         {
106                 return new ModuleSSLInfo(Me);
107         }
108         
109 };
110
111
112 extern "C" void * init_module( void )
113 {
114         return new ModuleSSLInfoFactory;
115 }
116