views:

40

answers:

0

Alright so, before I really get into this post, I am going to have to warn you that this might not be an easy fix. Whoever reads and is able to reply to this post must know a lot of c/c++, and at least some python to be able to answer the question I have above.

Basically, I have a connection method from Mumble (a VOIP client), that connects to a server and sends it an SSL certificate for authentication purposes. I also have a Python script that connects to the same Mumble VOIP server, but I don't send a certificate.

I need to modify my existing code to send a certificate, as the current Mumble client does.

--

Here is the C++ code that seems to send a certificate:

    ServerHandler::ServerHandler() {
         MumbleSSL::addSystemCA();

          {
           QList<QSslCipher> pref;
           foreach(QSslCipher c, QSslSocket::defaultCiphers()) {
           if (c.usedBits() < 128)
             continue;
            pref << c;
           }
           if (pref.isEmpty())
            qFatal("No ciphers of at least 128 bit found");
           QSslSocket::setDefaultCiphers(pref);
          }

    void ServerHandler::run() {
          qbaDigest = QByteArray();
          QSslSocket *qtsSock = new QSslSocket(this);

           qtsSock->setPrivateKey(g.s.kpCertificate.second);
           qtsSock->setLocalCertificate(g.s.kpCertificate.first.at(0));
           QList<QSslCertificate> certs = qtsSock->caCertificates();
           certs << g.s.kpCertificate.first;
           qtsSock->setCaCertificates(certs);

          cConnection = ConnectionPtr(new Connection(this, qtsSock));

          qtsSock->setProtocol(QSsl::TlsV1);
          qtsSock->connectToHostEncrypted(qsHostName, usPort);

     void ServerHandler::serverConnectionConnected() {
          tConnectionTimeoutTimer->stop();

          qscCert = cConnection->peerCertificateChain();
          qscCipher = cConnection->sessionCipher();

          if (! qscCert.isEmpty()) {
           const QSslCertificate &qsc = qscCert.last();
           qbaDigest = sha1(qsc.publicKey().toDer());
           bUdp = Database::getUdp(qbaDigest);
                  } else {
           bUdp = true;
          }

          QStringList tokens = Database::getTokens(qbaDigest);
          foreach(const QString &qs, tokens)
           mpa.add_tokens(u8(qs));

          QMap<int, CELTCodec *>::const_iterator i;
          for (i=g.qmCodecs.constBegin(); i != g.qmCodecs.constEnd(); ++i)
                mpa.add_celt_versions(i.key());

          sendMessage(mpa);

--

And alas, this is what I do to connect to it right now (in python):

    try:
        self.socket.connect(self.host)
    except:
        print self.threadName,"Couldn't connect to server"
        return
    self.socket.setblocking(0)
    print self.threadName,"connected to server"

--

Soo... what do I need to do more to my Python source to connect to servers that require a certificate? Because my source currently connects just fine to any mumble server with requirecert set to false. I need it to work on all servers, as this will be used on my own server (which ironically enough, has requirecerts on.)

I can pregenerate the certificate as a .p12 or w/e type file, so I don't need the program to generate the cert. I just need it to send the cert as the server wants it (as is done in the c++ I posted).

Please help me really soon! If you need more info, message me again. Stripped out all irrelevant code, now it's just the code that deals with ssl.